:root {
  --bg: #0b0e13;
  --panel: rgba(16, 20, 27, 0.86);
  --stroke: rgba(255, 255, 255, 0.10);
  --text: #e8ecf1;
  --muted: #9aa4b2;
  --accent: #e08a2e;
  --accent-2: #4c9dd8;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#stage { position: fixed; inset: 0; }

#viewer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #9db4cc;
  touch-action: none;
}

/* ---------- top bar ---------- */
.topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #b6541a);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.brand strong { display: block; font-size: 14px; letter-spacing: 0.2px; }
.brand small { color: var(--muted); font-size: 12px; }

.top-actions { display: flex; gap: 8px; pointer-events: auto; }

/* ---------- buttons ---------- */
.icon-btn {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.icon-btn:hover { border-color: rgba(255, 255, 255, 0.28); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.active { border-color: var(--accent); color: var(--accent); }
.icon-btn.close { font-size: 20px; line-height: 1; padding: 2px 10px; }

/* ---------- left rail ---------- */
.rail {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rail button {
  writing-mode: horizontal-tb;
  padding: 10px 14px;
  text-align: left;
  min-width: 96px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: color 0.15s, border-color 0.15s;
}
.rail button:hover { color: var(--text); }
.rail button.active { color: var(--accent); border-color: var(--accent); }

/* ---------- panel ---------- */
.panel {
  position: absolute;
  top: 88px;
  left: 132px;
  width: min(420px, calc(100vw - 170px));
  max-height: calc(100vh - 190px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--stroke);
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-body { padding: 16px; overflow: auto; font-size: 14px; color: #cfd6e0; }
.panel-body p { margin: 0 0 12px; }
.panel-body .lead { color: var(--text); font-size: 15px; }
.panel-body .hint, .panel-body .form-note { color: var(--muted); font-size: 12.5px; }
.panel-body code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.facts { list-style: none; margin: 0 0 14px; padding: 0; }
.facts li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--stroke);
}
.facts span { color: var(--muted); }
.facts strong { font-weight: 600; }

.link { color: var(--accent-2); text-decoration: none; }
.link:hover { text-decoration: underline; }

.units { display: grid; gap: 8px; }
.unit {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.unit:hover { border-color: var(--accent); }
.unit span { color: var(--muted); font-size: 12.5px; }

.media-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.media-grid figure { margin: 0; }
.media-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  display: block;
}
.media-grid figure.empty img { opacity: 0.25; }
.media-grid figcaption { color: var(--muted); font-size: 12px; margin-top: 6px; }

.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 5px; font-size: 12.5px; color: var(--muted); }
.form input, .form textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.form input:focus, .form textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.primary {
  margin-top: 4px;
  padding: 11px 16px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #c2701c);
  color: #17110a;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- dock ---------- */
.dock {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.dock-group { display: flex; gap: 6px; }
.dock-divider { width: 1px; align-self: stretch; background: var(--stroke); }
.dock button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.dock button:hover { color: var(--text); }
.dock button.active { color: var(--accent); border-color: var(--accent); }

/* ---------- splash / toast ---------- */
.splash {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, #141a23, #07090d 70%);
  transition: opacity 0.4s;
  z-index: 5;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-box { text-align: center; }
.splash h1 { margin: 16px 0 6px; font-size: 17px; font-weight: 600; }
.splash p { margin: 0; color: var(--muted); font-size: 13px; max-width: 420px; }
.spinner {
  width: 30px; height: 30px; margin: 0 auto;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%) translateY(8px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hint-bar {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(224, 138, 46, 0.14);
  border: 1px solid rgba(224, 138, 46, 0.45);
  color: #f2c892;
  font-size: 13px;
  max-width: min(560px, calc(100vw - 40px));
}

@media (max-width: 720px) {
  .panel { left: 12px; right: 12px; width: auto; top: 76px; }
  .rail { left: 12px; flex-direction: row; top: auto; bottom: 78px; transform: none; flex-wrap: wrap; max-width: calc(100vw - 24px); }
  .dock { bottom: 12px; }
  .brand small { display: none; }
}

.progress {
  width: 220px;
  height: 3px;
  margin: 18px auto 0;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}
