:root {
  --bg: #0d0f12;
  --bg-raised: #14171b;
  --bg-card: #181c21;
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-bright: rgba(255, 255, 255, 0.14);
  --text: #eef0f2;
  --text-muted: #8b929c;
  --text-dim: #5c636c;
  --accent: #5eead4;
  --accent-dim: #2dd4bf;
  --accent-soft: rgba(94, 234, 212, 0.12);
  --danger: #f87171;
  --mono: 'SF Mono', 'Cascadia Code', Consolas, 'Liberation Mono', monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Every top-level state container below (.landing, .working, .error-box, .browser) sets its own
   `display` explicitly (flex, in every case) — which ties in specificity with the browser's own
   built-in `[hidden] { display: none }` rule, and author CSS wins a specificity tie regardless of
   the hidden attribute being present. Without this, toggling `.hidden` in JS would visually do
   nothing for any of them — confirmed hitting exactly this bug on first load here. !important is
   the deliberate, blunt fix: nothing below should ever need to out-rank an explicit hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
}

body {
  /* A restrained blueprint-grid, not a decorative animation — texture without noise. */
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 42px 42px;
  background-position: -1px -1px;
}

button { font-family: inherit; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 20px;
  border-bottom: 1px solid var(--hairline);
  background: rgba(13, 15, 18, 0.7);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-mark { width: 20px; height: 20px; color: var(--accent); }
.brand-dim { color: var(--text-dim); font-weight: 500; }

.ghost-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--hairline-bright);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent-dim); background: var(--accent-soft); }

/* ---------------------------------------------------------------- landing */

.landing {
  height: calc(100% - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  overflow-y: auto;
  animation: fade-in 0.35s ease both;
}

.landing-inner { max-width: 620px; width: 100%; text-align: center; }

.landing h1 {
  font-size: clamp(28px, 4.5vw, 42px);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
  font-weight: 800;
}

.lede {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto 36px;
}
.lede code {
  font-family: var(--mono);
  background: var(--bg-card);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--accent);
  font-size: 13px;
}

.dropzone {
  border: 1.5px dashed var(--hairline-bright);
  border-radius: 14px;
  padding: 40px 24px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--bg-raised);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.dropzone:hover { border-color: var(--accent-dim); background: var(--bg-card); }
.dropzone:active { transform: scale(0.995); }
.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  border-style: solid;
}
.dropzone-icon { width: 30px; height: 30px; color: var(--text-dim); transition: color 0.15s ease, transform 0.15s ease; }
.dropzone:hover .dropzone-icon, .dropzone.drag-over .dropzone-icon { color: var(--accent); transform: translateY(-2px); }
.dropzone-text { display: flex; flex-direction: column; gap: 3px; }
.dropzone-text strong { font-size: 15px; }
.dropzone-text span { font-size: 13px; color: var(--text-dim); }

.features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 36px;
  text-align: left;
}
.feature {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.015);
}
.feature svg { width: 18px; height: 18px; color: var(--accent-dim); flex: none; margin-top: 1px; }
.feature strong { display: block; font-size: 12.5px; margin-bottom: 2px; }
.feature span { font-size: 11.5px; color: var(--text-dim); line-height: 1.4; }

/* ---------------------------------------------------------------- working / error overlays */

.working, .error-box {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 15, 18, 0.88);
  backdrop-filter: blur(4px);
  z-index: 20;
  animation: fade-in 0.2s ease both;
}

.working-card, .error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--hairline-bright);
  max-width: 340px;
  text-align: center;
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2.5px solid var(--hairline-bright);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.working-title { font-size: 15px; font-weight: 700; }
.working-sub { font-size: 12.5px; color: var(--text-dim); }

.error-card svg { width: 30px; height: 30px; color: var(--danger); }
#errorText { font-size: 14px; color: var(--text-muted); line-height: 1.5; }

.primary-btn {
  font-size: 13px;
  font-weight: 700;
  color: #08201c;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.primary-btn:hover { opacity: 0.92; }
.primary-btn:active { transform: scale(0.96); }

/* ---------------------------------------------------------------- browser (file manager) */

.browser {
  height: calc(100% - 56px);
  display: flex;
  animation: fade-in 0.3s ease both;
}

.sidebar {
  width: 300px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--hairline);
  background: var(--bg-raised);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
}
.job-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: none;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}
.icon-btn:hover { color: var(--accent); background: var(--accent-soft); }
.icon-btn svg { width: 15px; height: 15px; }

.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline);
}
.search-row svg { width: 14px; height: 14px; color: var(--text-dim); flex: none; }
.search-row input {
  flex: 1 1 auto;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}
.search-row input::placeholder { color: var(--text-dim); }

.tree-view, .search-results {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px;
}

.tree-node { user-select: none; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
}
.tree-row:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.tree-row.active { background: var(--accent-soft); color: var(--accent); }
.tree-row .chevron {
  width: 11px; height: 11px; flex: none; color: var(--text-dim);
  transition: transform 0.12s ease;
}
.tree-node.open > .tree-row .chevron { transform: rotate(90deg); }
.tree-row .type-icon { width: 13px; height: 13px; flex: none; opacity: 0.85; }
.tree-children {
  margin-left: 15px;
  padding-left: 6px;
  border-left: 1px solid var(--hairline);
  display: none;
}
.tree-node.open > .tree-children { display: block; }

.search-results { display: flex; flex-direction: column; gap: 2px; }
.search-hint { padding: 10px 8px; font-size: 12px; color: var(--text-dim); }
.result-row {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s ease;
}
.result-row:hover { background: rgba(255, 255, 255, 0.04); }
.result-path {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-dim);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-snippet {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-snippet mark { background: var(--accent-soft); color: var(--accent); border-radius: 2px; }

.viewer { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 42px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg-raised);
}
.viewer-path {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-body { flex: 1 1 auto; overflow: auto; }
.viewer-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 13px;
}

.viewer-body pre {
  margin: 0;
  padding: 16px 20px;
  font-family: var(--mono) !important;
  font-size: 12.5px;
  line-height: 1.65;
}
.viewer-body pre.hljs { background: transparent; }

/* Sits above the code, not instead of it — the point is explaining what's already correctly
   showing below, not blocking it the way the error overlay does. Amber, not the danger red used
   elsewhere: this isn't reporting a failure, it's explaining an expected result. */
.obf-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 14px 20px 0;
  padding: 11px 14px;
  border-radius: 8px;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.22);
  font-size: 12px;
  line-height: 1.5;
  color: #fbd88a;
}
.obf-banner svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: #fbbf24; }

.viewer-body .code-line {
  display: block;
  padding-left: 3.5em;
  position: relative;
}
.viewer-body .code-line::before {
  content: attr(data-line);
  position: absolute;
  left: 0;
  width: 3em;
  text-align: right;
  color: var(--text-dim);
  opacity: 0.5;
  user-select: none;
}
.viewer-body .code-line.highlighted { background: var(--accent-soft); }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mobile-back-btn { display: none; }

/* Below this, the sidebar's fixed 300px + the viewer's remaining space is exactly the "300px
   sidebar, ~75px sliver for a whole code viewer" breakage this was built to fix — confirmed on an
   actual narrow viewport before writing this rule, not just assumed. A file manager's two panes
   genuinely don't both fit next to each other on a phone width the way they do on desktop, so
   this switches to showing exactly one at a time (tree, or the open file) with a back button
   rather than trying to squeeze both into place. */
@media (max-width: 720px) {
  .sidebar, .viewer { width: 100%; }

  .browser:not(.mobile-viewing) .viewer { display: none; }
  .browser.mobile-viewing .sidebar { display: none; }

  .mobile-back-btn { display: flex; }

  .features { grid-template-columns: 1fr; }
}

/* scrollbars, everywhere in the app */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.15) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(94, 234, 212, 0.3); background-clip: content-box; }
