@font-face {
  font-family: BandjuPixel;
  src: url("./assets/bandju.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #f4eee5;
  --secondary: #cbd0d0;
  --quiet: #aeb7bb;
  --line: #39434c;
  --header: #141c24;
  --inlay: #10171e;
  --hover: #29333d;
  --selected: #efc49c;
  --selected-ink: #352b26;
  --accent: #f1bc8a;
  --sheet: #1c252e;
  --sheet-border: #414c55;
  --sheet-shadow: #05090d6b;
  --track: #303c46;
  --track-border: #64707b;
  --knob: #c4cbcc;
  --sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="day"] {
  color-scheme: light;
  --ink: #35251b;
  --secondary: #402c1e;
  --quiet: #513a2b;
  --line: #73563c91;
  --header: #cfaa81;
  --inlay: #ffe6c6a3;
  --hover: #f4dbc1;
  --selected: #533827;
  --selected-ink: #fff5e6;
  --accent: #744522;
  --sheet: #fff8ed;
  --sheet-border: #b09274;
  --sheet-shadow: #4c311c38;
  --track: #f1dbc0;
  --track-border: #8b684b;
  --knob: #825f45;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #121b24; font-family: var(--sans); }
body { color: var(--ink); height: 100vh; height: 100dvh; display: flex; flex-direction: column; isolation: isolate; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button, summary { color: inherit; cursor: pointer; font: inherit; }
:where(button, a, summary):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button svg, summary svg, #credits svg, .music-line svg {
  width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none;
}
.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr, .sr-only {
  position: absolute; clip-path: inset(50%); width: 1px; height: 1px; padding: 0;
  border: 0; overflow: hidden; white-space: nowrap;
}
[hidden] { display: none !important; }

.toolbar {
  --gutter: clamp(16px, 2.6vw, 52px);
  direction: ltr;
  position: relative; z-index: 2; flex: none;
  display: grid; grid-template-columns: minmax(max-content, 1fr) max-content minmax(max-content, 1fr);
  align-items: center; gap: clamp(12px, 1.2vw, 22px);
  min-height: 66px; padding: 7px var(--gutter);
  color: var(--ink); background-color: var(--header);
  border-bottom: 1px solid #2a323b;
}
[data-theme="day"] .toolbar {
  background-image: linear-gradient(180deg, #ffe6c738 0%, #f0d0a912 48%, #a87b4c29 98%), url("./assets/walnut.webp");
  background-size: auto, 860px auto;
  background-position: center, 42% 54%;
  border-bottom-color: #8c684c;
  box-shadow: inset 0 1px #f9e4caa6, inset 0 -1px #ffe8c690, 0 1px 4px #25180e45;
}

.brand {
  grid-column: 1; display: flex; align-items: center; width: fit-content;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.brand img { width: 54px; height: 40px; object-fit: contain; margin-right: 9px; transform: translateY(6px); }
.wordmark { font: 700 34px/1 BandjuPixel, monospace; letter-spacing: -1.8px; }
.room-name {
  margin-left: 10px; padding-left: 10px; border-left: 1px solid var(--line);
  color: var(--quiet); font: italic 17px/1 Georgia, serif;
}

.sound-controls, .tools, .channels { display: flex; align-items: center; }
.sound-controls { justify-content: center; gap: clamp(8px, 1.4vw, 20px); }
.tools { justify-content: flex-end; gap: clamp(3px, .5vw, 8px); }
.channels { background: var(--inlay); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
[data-theme="day"] .channels { box-shadow: inset 0 1px 2px #73513820, 0 1px #ffead055; }
.channel, .voice-control, .change, .tools summary {
  border: 0; background: transparent; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; white-space: nowrap; line-height: 1;
  font-size: 14px; font-weight: 570; color: var(--secondary);
}
.channel { height: 33px; padding: 0 14px; border-radius: 8px; }
.channel:hover, .voice-control:hover, .tools button:not([aria-disabled="true"]):hover,
.tools summary:hover, .tools details[open] summary { color: var(--ink); background: var(--hover); }
.channel[aria-pressed="true"] { background: var(--selected); color: var(--selected-ink); }
.voice-control { height: 39px; padding: 0 7px; border-radius: 9px; }
.voice-control[aria-checked="true"] { color: var(--ink); }
.switch-track {
  direction: ltr; display: inline-block; width: 27px; height: 16px; padding: 2px;
  border: 1px solid var(--track-border); background: var(--track); border-radius: 14px;
}
.switch-track i {
  width: 10px; height: 10px; display: block; background: var(--knob);
  border-radius: 50%; transition: transform .2s ease;
}
.voice-control[aria-checked="true"] .switch-track { background: var(--selected); border-color: var(--selected); }
.voice-control[aria-checked="true"] .switch-track i { transform: translateX(10px); background: var(--selected-ink); }
.icon-button, .tools #theme, .tools #credits {
  display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0;
  color: var(--secondary); background: transparent; border: 0; border-radius: 9px; pointer-events: auto;
}
.icon-button:hover { color: var(--ink); background: var(--hover); }
.tools #credits { color: var(--ink); }
.tools #credits svg { width: 20px; height: 20px; }
.tools summary { height: 36px; padding: 0 7px; gap: 4px; list-style: none; border-radius: 9px; }
.tools summary::-webkit-details-marker { display: none; }
.tools summary::marker { content: ""; }
.lang-code, .language-code { font: 600 12px/1 var(--sans); letter-spacing: .035em; text-transform: uppercase; }
#theme .moon, #theme .icon-moon, [data-theme="day"] #theme .sun, [data-theme="day"] #theme .icon-sun { display: none; }
[data-theme="day"] #theme .moon, [data-theme="day"] #theme .icon-moon { display: block; }
.change { border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; height: 36px; }
.language { position: static; }
.language-menu {
  position: absolute; right: var(--gutter); top: calc(100% + 6px); z-index: 3;
  display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 3px; padding: 8px;
  width: min(315px, calc(100vw - 24px)); max-height: min(420px,60dvh); overflow-y: auto;
  background: var(--sheet); color: var(--ink); border: 1px solid var(--sheet-border);
  border-radius: 12px; box-shadow: 0 12px 38px var(--sheet-shadow);
}
.language:not([open]) .language-menu { display: none; }
.language-menu a {
  min-height: 36px; display: flex; align-items: center; padding: 7px 10px; border-radius: 6px;
  color: var(--ink); font-size: 14px; text-decoration: none; overflow-wrap: anywhere;
}
.language-menu a:hover { background: var(--hover); }
.language-menu a[aria-current="page"] { background: var(--selected); color: var(--selected-ink); font-weight: 650; }
.language-menu a:focus-visible { outline-offset: -2px; }
[dir="rtl"] .language-menu, [dir="rtl"] .voice-control, [dir="rtl"] .channel, [dir="rtl"] .change { direction: rtl; }

.viewer { --scene-poster: url("./scene/poster.webp"); flex: 1; position: relative; isolation: isolate; overflow: hidden; min-height: 0; background: #15232e; }
.scene { position: absolute; inset: 0; overflow: hidden; background: #1c2a38 var(--scene-poster) center/cover no-repeat; }
.scene-footer {
  position: absolute; z-index: 1; inset: auto clamp(15px,2.6vw,52px) max(18px,env(safe-area-inset-bottom)) auto;
  pointer-events: none; max-width: min(540px,calc(100% - 30px));
}
.music-line, #playing { display: flex; align-items: center; gap: 8px; min-width: 0; }
.music-line { font-size: 13px; color: #fff9ee; }
#playing {
  max-width: 100%; padding: 7px 11px; border-radius: 8px; background: #101820c9;
  text-shadow: 0 1px 2px #10161a66;
}
.artist { color: #dfd8cb; }
.music-line #track-title, .artist { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bars { height: 15px; display: flex; align-items: center; gap: 2px; color: #f1bc8a; flex: none; }
.bars i { background: currentColor; width: 2px; height: 9px; border-radius: 2px; animation: signal .95s infinite alternate ease-in-out; }
.bars i:nth-child(2) { height: 15px; animation-delay: -.6s; }
.bars i:nth-child(3) { height: 11px; animation-delay: -.3s; }
.bars i:nth-child(4) { height: 6px; animation-delay: -.8s; }
@keyframes signal { to { transform: scaleY(.35); } }
.error-message {
  position: absolute; left: 50%; bottom: 65px; transform: translateX(-50%);
  max-width: 90%; padding: 10px 15px; border-radius: 10px;
  background: var(--sheet); color: var(--ink); font-size: 14px;
}

dialog {
  width: min(510px,calc(100% - 28px)); max-height: 84vh; max-height: 84dvh; overflow-y: auto;
  padding: 23px 26px; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--sheet-border); border-radius: 16px; box-shadow: 0 18px 64px #05090d70;
}
dialog::backdrop { background: #08121b7a; }
.dialog-top { display: flex; align-items: start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.dialog-top h2 { font: 400 26px/1.2 Georgia,serif; margin: 0; align-self: center; }
.dialog-top form { margin: 0; }
dialog h3 { font-size: 15px; line-height: 1.4; margin: 19px 0 4px; }
dialog p { font-size: 14px; line-height: 1.48; margin: 4px 0; }
.project-copy + .project-copy { margin-top: 8px; }
dialog a { color: var(--accent); text-underline-offset: 3px; }
.songs, .license { color: var(--secondary); }
.license { border-top: 1px solid var(--line); margin-top: 15px; padding-top: 12px; }
.close-progress { height: 2px; background: var(--line); overflow: hidden; border-radius: 6px; margin-top: 16px; }
dialog[open] .close-progress::after {
  content: ""; display: block; height: 100%; background: var(--accent);
  transform-origin: left; animation: dialog-timer 10s linear forwards;
}
[dir="rtl"] .close-progress::after { transform-origin: right; }
@keyframes dialog-timer { to { transform: scaleX(0); } }
@media (max-width: 1080px) {
  .toolbar { --gutter: 16px; gap: 10px; }
  .sound-controls { gap: 9px; }
  .channel { padding-inline: 11px; }
  .tools { gap: 2px; }
  .room-name { display: none; }
}
@media (max-width: 830px) {
  .toolbar { grid-template-columns: 1fr auto; grid-template-areas: "brand tools" "controls controls"; row-gap: 5px; min-height: 80px; padding-block: 5px 7px; }
  .brand { grid-area: brand; }
  .tools { grid-area: tools; }
  .sound-controls { grid-area: controls; gap: 16px; }
  .brand img { width: 43px; height: 33px; margin-right: 6px; transform: translateY(6px); }
  .wordmark { font-size: 29px; }
  .room-name { display: inline; }
  .channel { padding-inline: 15px; }
}
@media (max-width: 540px) and (orientation: portrait) {
  .toolbar { --gutter: 12px; row-gap: 8px; padding-top: 8px; padding-bottom: 9px; }
  .room-name { display: none; }
  .sound-controls { justify-content: space-between; gap: 6px; }
  .viewer { display: flex; flex-direction: column; justify-content: center; background: #17242e; }
  .viewer::before {
    content: ""; position: absolute; inset: -16px; z-index: -1;
    background: linear-gradient(#14212c99,#14212cd4),var(--scene-poster) center/cover;
    filter: blur(20px);
  }
  .scene { position: relative; inset: auto; width: 100%; aspect-ratio: 16/9; flex: none; background-size: contain; box-shadow: 0 12px 45px #08111955; }
  .scene-footer { inset: auto 12px max(16px,env(safe-area-inset-bottom)) auto; }
  .error-message { bottom: 48px; }
}
@media (max-width: 475px) {
  .toolbar { --gutter: 10px; column-gap: 5px; }
  .brand img { width: 38px; height: 30px; margin-right: 4px; transform: translateY(5px); }
  .wordmark { font-size: 26px; letter-spacing: -1.4px; }
  .tools { gap: 0; }
  .tools #theme,.tools #credits { width: 33px; }
  .tools summary { padding-inline: 4px; }
  .change { max-width: 115px; min-width: 0; padding-inline: 8px; gap: 5px; white-space: normal; line-height: 1.14; overflow-wrap: anywhere; }
}
@media (max-width: 385px) {
  .toolbar { --gutter: 10px; }
  .tools { gap: 0; }
  .tools #theme,.tools #credits { width: 32px; }
  .tools summary { padding-inline: 4px; }
  .change { padding-inline: 7px; gap: 4px; }
  .channel { padding-inline: 10px; gap: 6px; }
}
@media (min-width: 346px) and (max-width: 385px) {
  .change svg { display: none; }
}
@media (max-width: 345px) {
  .change { font-size: 0; gap: 0; width: 33px; }
  .tools .change span { display: none; }
  .toolbar { gap: 4px; }
}
@media (max-height: 475px) and (orientation: landscape) {
  .toolbar { min-height: 48px; }
  .language-menu { max-height: 58dvh; }
  dialog { max-height: 89dvh; padding-block: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition: none !important; }
  .close-progress { display: none; }
}
