/* =====================================================================
   SADEWA Visualizer 3D — Design System (Fase 1)
   Dark studio shell. Signature (glowing 3D sheet music) datang di fase
   berikutnya; di sini semuanya sengaja dibuat tenang & disiplin.
   ===================================================================== */

:root {
  /* Surface */
  --bg-0: #07070b;   /* viewport terdalam */
  --bg-1: #0d0d14;   /* panel */
  --bg-2: #14141f;   /* panel terangkat */
  --line: rgba(140, 140, 180, 0.12);

  /* Text */
  --text-hi: #f2f2f7;
  --text-lo: #9a9ab0;
  --text-dim: #5a5a72;

  /* Accent — keluarga warna Sadewa + hint glow "sheet beat" */
  --accent:   #7c4dff;  /* ungu Sadewa (UI) */
  --accent-2: #ff4d9d;  /* magenta glow */
  --warm:     #ffb020;  /* amber glow */

  /* Type */
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Metrics */
  --topbar-h: 52px;
  --radius: 10px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-hi);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { position: fixed; inset: 0; }

/* ---------------------------------------------------------------------
   Loading screen
   --------------------------------------------------------------------- */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px;
  background:
    radial-gradient(120% 80% at 50% 120%, rgba(124, 77, 255, 0.10), transparent 60%),
    var(--bg-0);
  transition: opacity 0.6s var(--ease);
}
.loader.is-hidden { opacity: 0; pointer-events: none; }

.loader__brand { text-align: center; }
.loader__mark {
  display: block;
  font-weight: 800; font-size: clamp(28px, 7vw, 44px);
  letter-spacing: 0.22em;
  background: linear-gradient(90deg, var(--warm), var(--accent-2), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.loader__sub {
  display: block; margin-top: 6px;
  font-size: 12px; letter-spacing: 0.42em; text-transform: uppercase;
  color: var(--text-dim);
}
.loader__bar {
  width: min(260px, 62vw); height: 3px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.06); overflow: hidden;
}
.loader__fill {
  display: block; width: 0%; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--warm), var(--accent-2), var(--accent));
  transition: width 0.35s var(--ease);
}
.loader__status {
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.05em; color: var(--text-lo);
}

/* ---------------------------------------------------------------------
   App shell
   --------------------------------------------------------------------- */
.app { position: fixed; inset: 0; }
.app[hidden] { display: none; }

.viewport {
  position: absolute; inset: 0; z-index: 0;
  background: var(--bg-0);
}
.viewport canvas { display: block; width: 100%; height: 100%; }

/* Top bar */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top, 0);
  background: linear-gradient(180deg, rgba(7, 7, 11, 0.72), transparent);
  pointer-events: none;
}
.topbar__left, .topbar__right {
  display: flex; align-items: center; gap: 10px; pointer-events: auto;
}
.wordmark {
  font-weight: 700; font-size: 14px; letter-spacing: 0.16em;
  color: var(--text-hi);
}
.wordmark__accent { color: var(--accent); }
.chip {
  font-family: var(--font-mono); font-size: 10px;
  padding: 3px 7px; border-radius: 999px;
  color: var(--text-lo); background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.btn-icon {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--radius);
  color: var(--text-lo); background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line); cursor: pointer;
  transition: color 0.18s var(--ease), background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.btn-icon:hover { color: var(--text-hi); background: rgba(124, 77, 255, 0.14); border-color: rgba(124, 77, 255, 0.4); }
.btn-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* FPS telemetry */
.stats {
  position: absolute; left: 12px; bottom: 12px; z-index: 10;
  padding-bottom: env(safe-area-inset-bottom, 0);
  font-family: var(--font-mono); font-size: 11px; line-height: 1.5;
  color: var(--text-dim); pointer-events: none; user-select: none;
}
.stats b { color: var(--text-lo); font-weight: 500; }

/* ---------------------------------------------------------------------
   Toast
   --------------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(12px);
  z-index: 200; max-width: min(420px, 86vw);
  padding: 11px 16px; border-radius: var(--radius);
  font-size: 13px; color: var(--text-hi);
  background: var(--bg-2); border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  opacity: 0; transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.toast[hidden] { display: none; }
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { border-color: rgba(255, 77, 157, 0.5); }

/* ---------------------------------------------------------------------
   Panel MIDI (Fase 3)
   --------------------------------------------------------------------- */
.midi-panel {
  position: absolute; right: 14px; top: calc(var(--topbar-h) + 10px); z-index: 10;
  width: min(280px, 78vw);
  display: flex; flex-direction: column; gap: 8px;
}
.midi-panel__row { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }

.btn-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: 999px;
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 600;
  color: var(--text-hi); background: rgba(124, 77, 255, 0.18);
  border: 1px solid rgba(124, 77, 255, 0.45); cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.btn-pill:hover { background: rgba(124, 77, 255, 0.3); }
.btn-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.midi-panel__examples { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.btn-chip {
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 5px 10px; border-radius: 999px;
  color: var(--text-lo); background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line); cursor: pointer;
  transition: color 0.18s var(--ease), background 0.18s var(--ease);
}
.btn-chip:hover { color: var(--text-hi); background: rgba(255, 255, 255, 0.08); }

.midi-summary {
  padding: 12px 14px; border-radius: var(--radius);
  background: rgba(13, 13, 20, 0.82); border: 1px solid var(--line);
  backdrop-filter: blur(8px); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  font-size: 12px; color: var(--text-lo); line-height: 1.7;
}
.midi-summary[hidden] { display: none; }
.midi-summary b { color: var(--text-hi); font-weight: 600; }
.midi-summary__title {
  color: var(--text-hi); font-weight: 700; font-size: 13px;
  margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.midi-summary__grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.midi-summary__grid dt { color: var(--text-dim); }
.midi-summary__grid dd { color: var(--text-hi); text-align: right; font-family: var(--font-mono); }

.path-picker {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: var(--radius);
  background: rgba(13, 13, 20, 0.82); border: 1px solid var(--line);
  backdrop-filter: blur(8px); font-size: 12px; color: var(--text-lo);
}
.path-picker[hidden] { display: none; }
.path-picker select {
  font-family: var(--font-mono); font-size: 11.5px;
  background: rgba(255, 255, 255, 0.05); color: var(--text-hi);
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
}

/* Overlay saat file diseret ke atas viewport */
.drop-overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 7, 11, 0.72);
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s var(--ease);
}
.viewport.is-dragover .drop-overlay { opacity: 1; }
.drop-overlay__box {
  padding: 22px 34px; border-radius: 14px;
  border: 2px dashed var(--accent);
  color: var(--text-hi); font-weight: 700; font-size: 15px; letter-spacing: 0.02em;
  background: rgba(124, 77, 255, 0.1);
}

@media (max-width: 560px) {
  .midi-panel { right: 10px; width: min(240px, 82vw); }
}

/* ---------------------------------------------------------------------
   Transport (Fase 4)
   --------------------------------------------------------------------- */
.transport {
  position: absolute; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%); z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(13, 13, 20, 0.82); border: 1px solid var(--line);
  backdrop-filter: blur(8px); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  max-width: min(560px, 92vw);
}
.transport[hidden] { display: none; }

.btn-icon--lg { width: 38px; height: 38px; flex-shrink: 0; }

.transport__time {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-lo);
  min-width: 34px; text-align: center; flex-shrink: 0;
}
.transport__seek {
  flex: 1; min-width: 60px; accent-color: var(--accent);
  height: 4px; cursor: pointer;
}
.transport__speed {
  font-family: var(--font-mono); font-size: 11px;
  background: rgba(255, 255, 255, 0.05); color: var(--text-hi);
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 6px;
  flex-shrink: 0;
}
#btn-loop.is-active { color: var(--text-hi); background: rgba(124, 77, 255, 0.3); border-color: rgba(124, 77, 255, 0.5); }
.transport__now {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}

@media (max-width: 560px) {
  .transport { gap: 6px; padding: 7px 10px; max-width: 94vw; }
  .transport__now { display: none; } /* sempit di HP, sembunyikan biar kontrol utama tetap lega */
}

/* ---------------------------------------------------------------------
   Panel kamera (Fase 8)
   --------------------------------------------------------------------- */
.camera-picker {
  position: absolute; left: 14px; top: calc(var(--topbar-h) + 10px); z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--radius);
  background: rgba(13, 13, 20, 0.82); border: 1px solid var(--line);
  backdrop-filter: blur(8px); font-size: 12px; color: var(--text-lo);
}
.camera-picker[hidden] { display: none; }
.camera-picker select {
  font-family: var(--font-mono); font-size: 11.5px;
  background: rgba(255, 255, 255, 0.05); color: var(--text-hi);
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
}
.camera-picker__label-sm { font-size: 10.5px; color: var(--text-dim); margin-left: 4px; }
.camera-picker input[type=range] { width: 64px; accent-color: var(--accent); }
#btn-dof { font-family: var(--font-mono); font-size: 10px; width: auto; padding: 0 8px; height: 28px; }
#btn-dof.is-active { color: var(--text-hi); background: rgba(124, 77, 255, 0.3); border-color: rgba(124, 77, 255, 0.5); }
#btn-ssr { font-family: var(--font-mono); font-size: 10px; width: auto; padding: 0 8px; height: 28px; }
#btn-ssr.is-active { color: var(--text-hi); background: rgba(124, 77, 255, 0.3); border-color: rgba(124, 77, 255, 0.5); }
#btn-snow.is-active { color: var(--text-hi); background: rgba(124, 77, 255, 0.3); border-color: rgba(124, 77, 255, 0.5); }

@media (max-width: 560px) {
  .camera-picker { left: 10px; flex-wrap: wrap; max-width: 60vw; }
}

/* ---------------------------------------------------------------------
   Responsive & accessibility
   --------------------------------------------------------------------- */
@media (max-width: 560px) {
  :root { --topbar-h: 48px; }
  .loader__sub { letter-spacing: 0.3em; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
