/* vuer — styled to match the keyhole design system (Raleway, neutral dark,
   subtle white borders, layered shadows, soft reveal animations). Raleway is
   self-hosted (fonts/raleway-latin.woff2) so the strict CSP and offline/LAN
   use both keep working — no Google Fonts round-trip, no external origin.
   Layout is responsive: the toolbar wraps, panels track its height, and the
   stats panel becomes a bottom sheet on phones. */
@font-face {
  font-family: "Raleway";
  font-style: normal;
  font-weight: 200 700;               /* variable font: one file covers the range */
  font-display: swap;
  src: url("fonts/raleway-latin.woff2") format("woff2");
}

:root {
  /* keyhole palette */
  --bg: #181818;                      /* stage backdrop (keyhole card tone) */
  --panel: rgba(24, 24, 24, 0.82);    /* glass panels floating over the 3D scene */
  --panel-solid: #181818;
  --panel-border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --text: #f5f5f7;
  --muted: rgba(255, 255, 255, 0.5);
  --faint: rgba(255, 255, 255, 0.3);
  --btn: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.1);
  --emphasis: rgba(255, 255, 255, 0.14);
  --emphasis-border: rgba(255, 255, 255, 0.22);
  --radius: 16px;
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.03),
            0 4px 24px rgba(0, 0, 0, 0.4),
            0 16px 56px rgba(0, 0, 0, 0.3);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  font-family: "Raleway", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body {
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* Toolbar — wraps to extra rows on narrow screens instead of overflowing.
   js/main.js keeps --toolbar-h in sync with the (possibly wrapped) height. */
#toolbar {
  position: fixed; top: 0; left: 0; right: 0; min-height: 56px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  padding: max(8px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           10px max(14px, env(safe-area-inset-left));
  background: linear-gradient(to bottom, rgba(15,15,15,0.92) 65%, rgba(15,15,15,0));
  z-index: 10; pointer-events: none;
  animation: contentFadeIn 0.9s var(--ease) 0.1s both;
}
#toolbar > * { pointer-events: auto; }
.brand { display: flex; align-items: baseline; margin-right: 6px; filter: drop-shadow(0 0 20px rgba(255,255,255,0.06)); }
.logo {
  font-weight: 600; font-size: 20px; letter-spacing: -0.02em; color: var(--text);
}
.logo-er { font-weight: 300; font-size: 20px; letter-spacing: -0.02em; color: var(--muted); }
.spacer { flex: 1; }

.btn {
  appearance: none; border: 1px solid var(--panel-border); background: var(--btn);
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 500; letter-spacing: 0.01em;
  padding: 7px 13px; border-radius: 10px; cursor: pointer; white-space: nowrap;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.2s var(--ease);
  backdrop-filter: blur(8px);
}
.btn:hover { background: var(--btn-hover); border-color: var(--border-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:hover { background: var(--btn); border-color: var(--panel-border); }
.btn.icon { width: 38px; padding: 6px 0; display: inline-flex; align-items: center; justify-content: center; }
.btn.icon svg { display: block; width: 18px; height: 18px; }
/* Active toggle state (e.g. Up: Y-up) — mirrors keyhole's highlighted control. */
.btn.icon.active { background: var(--emphasis); border-color: var(--emphasis-border); color: #fff; }
.btn.icon.active:hover { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.3); }
.btn.primary {
  background: var(--emphasis); border-color: var(--emphasis-border); color: var(--text); font-weight: 600;
}
.btn.primary:hover { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.3); transform: translateY(-2px); }
.btn.select {
  -webkit-appearance: none; appearance: none;
  padding: 6px 28px 6px 10px; max-width: 200px; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23aeb0b6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 12px;
}
/* Solid menu so the open list is readable — native option lists ignore the
   translucent button background and would render white-on-white. Mirrors
   keyhole's select option styling. */
.btn.select option, .btn.select optgroup { background: #1c1c1c; color: var(--text); }
.btn.select option:disabled { color: var(--muted); }
.btn.select option:checked { background: rgba(255, 255, 255, 0.14); color: #fff; }
.badge {
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 8px;
  text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap;
  background: rgba(255,255,255,0.06); color: var(--muted); border: 1px solid var(--panel-border);
}

/* Stats panel — positioned below the toolbar's live height (wraps on mobile). */
.panel {
  position: fixed; top: calc(var(--toolbar-h, 56px) + 8px); right: 14px; width: 268px;
  max-height: calc(100vh - var(--toolbar-h, 56px) - 24px);
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  backdrop-filter: blur(14px); z-index: 9; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  animation: cardReveal 0.8s var(--ease) both;
}
.panel[hidden] { display: none; } /* the attribute must win over display:flex */
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; font-weight: 500; font-size: 13px; letter-spacing: -0.01em;
  border-bottom: 1px solid var(--panel-border);
}
.panel-body { overflow-y: auto; padding: 4px 0; }
.x { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; padding: 4px 8px; transition: color 0.2s var(--ease); }
.x:hover { color: var(--text); }

section[data-sec] { border-bottom: 1px solid rgba(255,255,255,0.04); }
.sec-title {
  margin: 0; padding: 10px 14px; font-size: 11.5px; font-weight: 500; color: var(--muted);
  cursor: pointer; display: flex; justify-content: space-between; text-transform: uppercase; letter-spacing: 0.08em;
}
.chev { transition: transform 0.2s var(--ease); }
section.collapsed .rows { display: none; }
section.collapsed .chev { transform: rotate(-90deg); }
.rows { padding: 0 14px 10px; }
.rows > div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 12px; }
.rows span { color: var(--muted); font-weight: 300; }
.rows b {
  font-weight: 500; font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 11.5px;
  text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px;
}

/* Empty state */
.empty { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; pointer-events: none; }
.empty.hidden { display: none; }
.empty-card {
  text-align: center; padding: 36px 44px; border-radius: 24px; pointer-events: auto;
  border: 1px solid var(--panel-border); background: rgba(24,24,24,0.55); backdrop-filter: blur(8px);
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
  animation: cardReveal 1.2s var(--ease) both;
}
.empty-logo {
  font-size: 46px; font-weight: 300; letter-spacing: -0.02em; color: var(--text);
  filter: drop-shadow(0 0 20px rgba(255,255,255,0.06)); margin-bottom: 10px;
}
.empty p { margin: 6px 0; font-size: 14px; font-weight: 300; }
.empty .muted { color: var(--muted); font-size: 12.5px; }
.empty code { background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 6px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty .primary { margin-top: 18px; }
.dragging .empty-card { border-color: var(--border-hover); background: rgba(255,255,255,0.05); }

/* Loading */
.loading { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: rgba(15,15,15,0.6); backdrop-filter: blur(4px); }
.loading[hidden] { display: none; }
.loading-card { text-align: center; animation: contentFadeIn 0.5s var(--ease) both; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12); border-top-color: var(--text); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { width: 220px; max-width: 70vw; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; margin: 12px auto 0; overflow: hidden; }
#loadBar { height: 100%; width: 0%; background: var(--text); transition: width 0.1s; }
#loadText { font-size: 13px; font-weight: 300; color: var(--muted); max-width: 80vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toasts — transient pills, keyhole's seek-flash aesthetic (rounded, blurred,
   fade in/out). Stacked below the toolbar's live height. */
.toasts {
  position: fixed; top: calc(var(--toolbar-h, 56px) + 10px); left: 50%; transform: translateX(-50%);
  z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; max-width: calc(100vw - 24px);
}
.toast {
  padding: 9px 16px; border-radius: 999px;
  background: rgba(24, 24, 24, 0.82); border: 1px solid var(--panel-border);
  color: var(--text); font-size: 13px; font-weight: 500; letter-spacing: 0.01em;
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-6px); transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  max-width: 100%; text-align: center; overflow-wrap: anywhere;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(255, 138, 138, 0.4); color: #ffb3b3; }

/* Version + copyright, bottom-right (keyhole's #appFooter). */
#appFooter {
  position: fixed; bottom: 6px; right: 10px; z-index: 7;
  font-size: 10.5px; font-weight: 400; letter-spacing: 0.02em; color: rgba(170, 170, 170, 0.6);
  text-align: right; pointer-events: none; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
#appFooter:empty { display: none; }

/* Keyhole reveal animations */
@keyframes cardReveal {
  from { opacity: 0; transform: translateY(16px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes contentFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Respect reduced-motion preferences (keyhole's animations are decorative). */
@media (prefers-reduced-motion: reduce) {
  #toolbar, .panel, .empty-card, .loading-card { animation: none; }
}

/* Comfortable touch targets on touch devices */
@media (pointer: coarse) {
  .btn { min-height: 40px; padding: 9px 12px; }
  .btn.icon { width: 40px; min-height: 40px; font-size: 18px; }
  .x { font-size: 22px; padding: 6px 10px; }
  .sec-title { padding: 12px; }
}

/* Narrow screens: fewer toolbar items, bottom-sheet stats */
@media (max-width: 640px) {
  #btnFolder { display: none; }         /* directory picker is desktop-only */
  #backendBadge { display: none; }      /* still shown in the stats panel */
  .btn.select { max-width: 130px; }

  /* Stats becomes a bottom sheet — never fights the toolbar for space */
  .panel {
    top: auto; right: 0; left: 0; bottom: 0; width: 100%;
    max-height: 55vh; border-radius: var(--radius) var(--radius) 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-width: 360px) {
  .empty-card { padding: 20px 16px; }
  .empty-logo { font-size: 34px; }
  .btn { font-size: 12px; padding: 8px 9px; }
  .btn.select { max-width: 104px; }
}
