:root {
  --bg: #0a0f18;
  --bg-soft: #0f1625;
  --panel: #131b2d;
  --panel-2: #1a2540;
  --border: #2b3b64;
  --text: #eef4ff;
  --muted: #9fb2d7;
  --accent: #56d9ff;
  --accent-2: #8dffb1;
  --danger: #ff6f7d;
  --editor-bg: #0c1320;
  --surface-alpha: rgba(14, 22, 38, 0.9);
}

body[data-theme="light"] {
  --bg: #f2f6fc;
  --bg-soft: #fcfdff;
  --panel: #e5ebf8;
  --panel-2: #d9e4fb;
  --border: #b9c8e6;
  --text: #17233a;
  --muted: #4e5f82;
  --accent: #0e8bc2;
  --accent-2: #2ca96d;
  --danger: #d24a57;
  --editor-bg: #ffffff;
  --surface-alpha: rgba(252, 253, 255, 0.96);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 10%, rgba(28, 47, 83, 0.5) 0, transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(20, 52, 66, 0.38) 0, transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.app-shell {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.03), transparent 30%), var(--bg-soft);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  min-height: calc(100vh - 48px);
  min-height: calc(100dvh - 48px);
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alpha);
  backdrop-filter: blur(8px);
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px var(--accent);
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn.danger:hover {
  border-color: var(--danger);
  color: color-mix(in srgb, var(--danger) 70%, white 30%);
}

.editor-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-soft) 60%, transparent 40%);
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-title {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.section-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.section-toggle[aria-expanded="true"] {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border) 55%);
}

.section-toggle-brand {
  display: none;
}

.collapsible-content {
  min-height: 0;
}

#file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  margin-top: 12px;
}

#file-list li {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#file-list li.active {
  background: color-mix(in srgb, var(--accent) 20%, transparent 80%);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border) 60%);
  color: var(--text);
}

.workspace {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 0;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-soft) 75%, transparent 25%);
}

.tab {
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  border-color: color-mix(in srgb, var(--accent-2) 65%, var(--border) 35%);
  color: var(--text);
  background: color-mix(in srgb, var(--accent-2) 18%, var(--panel-2) 82%);
}

.find-panel {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 84%, transparent 16%);
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
}

.field input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--editor-bg);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
}

.field input:focus {
  outline: 1px solid color-mix(in srgb, var(--accent) 65%, transparent 35%);
}

.find-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--panel);
  font-size: 12px;
  color: var(--muted);
}

.check input {
  margin: 0;
}

.editor-wrap {
  min-height: 0;
  position: relative;
  overflow: hidden;
}

#editor-syntax,
#editor-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 18px;
  border: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  line-height: 1.45;
  pointer-events: none;
}

#editor-syntax {
  color: var(--text);
  z-index: 1;
}

#editor-syntax .syn-key {
  color: color-mix(in srgb, var(--accent) 78%, white 22%);
}

#editor-syntax .syn-string {
  color: color-mix(in srgb, var(--accent-2) 75%, white 25%);
}

#editor-syntax .syn-number {
  color: #f7cf7c;
}

#editor-syntax .syn-bool,
#editor-syntax .syn-null {
  color: #f29cc8;
}

#editor-syntax .syn-punct {
  color: var(--muted);
}

#editor-syntax .syn-csv-header {
  color: color-mix(in srgb, var(--accent) 82%, white 18%);
  font-weight: 600;
}

#editor-syntax .syn-csv-sep {
  color: var(--muted);
}

#editor-syntax .syn-comment {
  color: #8f9dbf;
}

#editor-syntax .syn-xml-tag {
  color: color-mix(in srgb, var(--accent) 76%, white 24%);
}

#editor-syntax .syn-xml-attr {
  color: #d9a6ff;
}

#editor-syntax .syn-yaml-list {
  color: var(--muted);
}

#editor-syntax .syn-ini-section {
  color: color-mix(in srgb, var(--accent) 80%, white 20%);
  font-weight: 600;
}

#editor-syntax .syn-md-heading {
  color: color-mix(in srgb, var(--accent) 80%, white 20%);
  font-weight: 700;
}

#editor-syntax .syn-md-list {
  color: color-mix(in srgb, var(--accent-2) 75%, white 25%);
}

#editor-syntax .syn-md-quote {
  color: #9db0d6;
  font-style: italic;
}

#editor-syntax .syn-md-code {
  color: #f7cf7c;
}

#editor-syntax .syn-md-strong {
  color: #ffd79f;
  font-weight: 700;
}

#editor-syntax .syn-md-em {
  color: #ffd79f;
  font-style: italic;
}

#editor-syntax .syn-md-link {
  color: #7bd4ff;
}

#editor-syntax .syn-log-error {
  color: #ff8b96;
  font-weight: 700;
}

#editor-syntax .syn-log-warn {
  color: #ffd479;
  font-weight: 700;
}

#editor-syntax .syn-log-info {
  color: #95d0ff;
}

#editor-syntax .syn-log-time {
  color: #8f9dbf;
}

#editor-highlight {
  color: transparent;
  z-index: 2;
}

#editor-highlight .hl {
  background: color-mix(in srgb, var(--accent) 30%, transparent 70%);
  border-radius: 3px;
}

#editor-highlight .hl.active {
  background: color-mix(in srgb, var(--accent-2) 45%, transparent 55%);
}

#editor {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  padding: 18px;
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  line-height: 1.45;
  outline: none;
  tab-size: 2;
}

#editor[data-syntax="off"] {
  color: var(--text);
}

.statusbar {
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg-soft) 86%, transparent 14%);
}

.statusbar span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-fab {
  display: none;
}

@media (max-width: 1180px) {
  .find-panel {
    grid-template-columns: 1fr;
  }

  .find-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  body {
    padding: 6px;
  }

  .app-shell {
    min-height: calc(100vh - 12px);
    min-height: calc(100dvh - 12px);
  }

  .topbar {
    padding: 10px 12px;
    gap: 10px;
    align-items: flex-start;
    flex-direction: column;
  }

  .section-toggle-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }

  .collapsible-content {
    overflow: hidden;
    max-height: 520px;
    opacity: 1;
    transition:
      max-height 220ms ease,
      opacity 180ms ease;
  }

  .collapsible-content.is-collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
  }

  .btn {
    font-size: 12px;
    padding: 9px 11px;
    border-radius: 9px;
  }

  .editor-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    min-height: 0;
  }

  .sidebar {
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .section-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .section-toggle-wide {
    display: flex;
    width: 100%;
    justify-content: flex-start;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 9px 12px;
    background: color-mix(in srgb, var(--panel) 84%, transparent 16%);
  }

  #sidebar-content {
    max-height: 34dvh;
    overflow: auto;
  }

  #file-list {
    margin-top: 10px;
  }

  .workspace {
    grid-template-rows: auto auto auto 1fr auto;
  }

  .tabs {
    display: none;
  }

  .find-panel {
    grid-template-columns: 1fr;
    padding: 8px 10px;
    gap: 8px;
  }

  .field input {
    font-size: 16px;
  }

  .find-actions {
    justify-content: flex-start;
  }

  .editor-wrap {
    min-height: 42dvh;
  }

  #editor,
  #editor-syntax,
  #editor-highlight {
    padding: 12px;
    font-size: 16px;
    line-height: 1.5;
  }

  .statusbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 8px 10px;
    font-size: 11px;
  }

  #new-file {
    display: none;
  }

  .mobile-fab {
    display: grid;
    place-items: center;
    position: fixed;
    right: 14px;
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 16px));
    width: 52px;
    height: 52px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--border) 58%);
    background: color-mix(in srgb, var(--panel-2) 74%, var(--accent) 26%);
    color: var(--text);
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    z-index: 1300;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 20, 0.58);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 1000;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
  display: grid;
  gap: 12px;
}

.modal-wide {
  width: min(760px, 100%);
}

.modal-card h2 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  font-size: 13px;
}

.shortcuts-grid div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

kbd {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  white-space: nowrap;
}

.modal-note {
  font-size: 12px;
  color: var(--muted);
}

.modal-field {
  font-size: 13px;
  color: var(--muted);
}

.modal-input {
  border: 1px solid var(--border);
  background: var(--editor-bg);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
}

.modal-input:focus {
  outline: 1px solid color-mix(in srgb, var(--accent) 65%, transparent 35%);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.notice {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1200;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  max-width: min(520px, calc(100vw - 36px));
}

.notice[hidden] {
  display: none;
}

.notice-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

@media (max-width: 900px) {
  .shortcuts-grid {
    grid-template-columns: 1fr;
  }
}
