:root {
  color-scheme: dark;
  --bg: #07090f;
  --panel: rgba(14, 18, 27, 0.74);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #e8ecf3;
  --muted: #9aa3b2;
  --accent: #8fb8ff;
  --accent-2: #c9dcff;
  --track: rgba(255, 255, 255, 0.14);
  --radius: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --frame-w: clamp(12px, 2.1vw, 34px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

body.idle #view { cursor: none; }

/* ---------- Window frame ---------- */
.frame {
  position: fixed;
  inset: 0;
  pointer-events: none;
  border: var(--frame-w) solid #16110d;
  border-image: linear-gradient(135deg, #2a211a 0%, #16110d 35%, #0f0b08 65%, #231b15 100%) 1;
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 180, 0.06),
    inset 0 0 0 3px rgba(0, 0, 0, 0.55),
    inset 0 0 38px 6px rgba(0, 0, 0, 0.55);
  transition: opacity 0.6s ease;
}
.frame.is-hidden { opacity: 0; }
.frame::before {
  /* thin inner rebate where the glass meets the frame */
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 210, 160, 0.05);
}
.frame__sill {
  position: absolute;
  left: calc(-1 * var(--frame-w));
  right: calc(-1 * var(--frame-w));
  bottom: calc(-1 * var(--frame-w));
  height: calc(var(--frame-w) * 1.9);
  background: linear-gradient(180deg, #2b221b 0%, #1a140f 30%, #0d0a07 100%);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 215, 170, 0.12);
}

/* ---------- Intro ---------- */
.intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(5, 7, 12, 0.25), rgba(5, 7, 12, 0.7));
  transition: opacity 1.2s ease, visibility 1.2s;
  z-index: 20;
}
.intro.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.intro__card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 420px;
}
.intro h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.4rem, 7vw, 4rem);
  letter-spacing: 0.02em;
  margin: 0;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.6);
}
.intro p {
  margin: 0 0 10px;
  color: var(--accent-2);
  opacity: 0.85;
  font-size: 1.05rem;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.8);
}
.intro small { color: var(--muted); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9); margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s, transform 0.2s, border-color 0.2s;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .icon-btn:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn--primary {
  background: rgba(143, 184, 255, 0.2);
  border-color: rgba(143, 184, 255, 0.45);
  padding: 13px 26px;
  font-size: 1.05rem;
}
.btn--primary:hover { background: rgba(143, 184, 255, 0.3); }
.btn--ghost { background: transparent; }
.btn--small { padding: 7px 14px; font-size: 0.85rem; }

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(14, 18, 27, 0.55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.3s;
}
.icon-btn:hover { background: rgba(40, 50, 68, 0.75); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn--small { width: 34px; height: 34px; }
.icon-btn--small svg { width: 18px; height: 18px; }
#btn-settings:hover svg { transform: rotate(40deg); }
#btn-settings svg { transition: transform 0.5s ease; }
#btn-sound .i-off { display: none; }
#btn-sound.is-muted .i-on { display: none; }
#btn-sound.is-muted .i-off { display: block; }

/* ---------- Dock ---------- */
.dock {
  position: fixed;
  right: calc(var(--frame-w) + 16px);
  bottom: calc(var(--frame-w) * 1.9 + 16px);
  display: flex;
  gap: 10px;
  z-index: 10;
  transition: opacity 0.8s ease;
}
body.idle .dock, body.ui-hidden .dock { opacity: 0; pointer-events: none; }

/* ---------- Panel ---------- */
.panel {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(360px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
  backdrop-filter: blur(22px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 40px));
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 30;
}
.panel.is-open { transform: none; }
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
}
.panel__head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.45rem;
}
.panel__body {
  overflow-y: auto;
  padding: 4px 18px 12px;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.panel__foot {
  border-top: 1px solid var(--panel-border);
  padding: 12px 18px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.keys {
  width: 100%;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.8;
}
kbd {
  font-family: inherit;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
}

.group { margin: 10px 0 4px; }
.group h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 600;
  margin: 16px 0 6px;
}
.ctl { padding: 7px 0; }
.ctl__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9rem;
  margin-bottom: 6px;
}
.ctl__val { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.8rem; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  margin: 0;
  cursor: pointer;
  --pct: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--pct), var(--track) var(--pct));
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--pct), var(--track) var(--pct));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: #f2f6ff;
  border: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #f2f6ff;
  border: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}

.ctl--toggle .ctl__row { margin: 0; align-items: center; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--track);
  transition: background 0.2s;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #f2f6ff;
  transition: transform 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

select {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}
select option { background: #151a24; color: var(--text); }

.fallback[hidden] { display: none; }
.fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

body.ui-hidden .panel { transform: translateX(calc(100% + 40px)); }

@media (max-width: 520px) {
  .panel { top: auto; left: 12px; right: 12px; bottom: 12px; width: auto; max-height: 72vh; transform: translateY(calc(100% + 40px)); }
  .panel.is-open { transform: none; }
  body.ui-hidden .panel { transform: translateY(calc(100% + 40px)); }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .intro, .dock { transition: none; }
}
