:root {
  --bg: #05060a;
  --ink: #e6e9f2;
  --dim: #7b8194;
  --line: rgba(230, 233, 242, 0.25);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* hidden always wins over a layout style */

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "JetBrains Mono", ui-monospace, Menlo, monospace;
}

#stage canvas { display: block; }

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px));
  text-align: center;
  padding: 28px 24px;
  background: rgba(5, 6, 10, 0.72);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.panel[hidden] { display: none; }

.panel.bottom {
  top: auto;
  bottom: 32px;
  transform: translateX(-50%);
  background: none;
  border: none;
  backdrop-filter: none;
}

h1 { font-weight: 400; letter-spacing: 0.3em; text-transform: lowercase; margin: 0 0 12px; }
h2 { font-weight: 400; font-size: 15px; margin: 0 0 12px; }
p { color: var(--dim); margin: 8px 0; }
.credit { font-size: 12px; margin-top: 20px; }
.quiet-text { font-size: 12px; }

button {
  font: inherit;
  color: var(--ink);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 18px;
  margin: 6px 4px;
  cursor: pointer;
}
button:hover { border-color: var(--ink); }
button.quiet { border-color: transparent; color: var(--dim); }
button.quiet:hover { color: var(--ink); }

.row { display: flex; justify-content: center; flex-wrap: wrap; }
.pickers { margin-top: 14px; }
.picker { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0; flex-wrap: wrap; }
.picker > span { min-width: 72px; text-align: right; }
select {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px;
}
.swatches { display: flex; gap: 6px; }
.swatch { width: 18px; height: 18px; padding: 0; margin: 0; border-radius: 50%; border: 2px solid transparent; }
.swatch.on { border-color: var(--ink); }
.swatch:disabled { opacity: 0.15; cursor: not-allowed; }

#bank-say { font-size: 72px; line-height: 1.2; margin: 8px 0; }

#record {
  padding: 14px 28px;
  margin: 12px 0;
  user-select: none;
  touch-action: none;
}
#record.on { background: #ff5a6e; border-color: #ff5a6e; color: #05060a; }

#message {
  width: 100%;
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  background: rgba(5, 6, 10, 0.6);
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 10px 4px;
  outline: none;
  text-align: center;
}
#message:focus { border-bottom-color: var(--ink); }

.encore { background: rgba(5, 6, 10, 0.6); backdrop-filter: blur(4px); padding: 10px 16px; border-radius: 14px; bottom: 16px; }
.encore p { margin: 4px 0; }
details summary { cursor: pointer; }
.secret { font-size: 12px; color: #ffd27a; min-height: 1em; }
#end-recipe { color: var(--ink); opacity: 0.75; }
#end-lyrics { list-style: none; padding: 0; margin: 8px 0; text-align: left; max-height: 30vh; overflow-y: auto; }
#end-lyrics li { margin: 10px 0; font-size: 16px; }

/* ── duet hub, lobby, compose bar ── */
.mode { text-transform: uppercase; letter-spacing: 0.35em; font-size: 11px; color: var(--dim); margin: -6px 0 14px; }
.join { gap: 6px; align-items: center; margin: 4px 0; }
.join input, #message { font-size: 16px; } /* 16px+ stops iPhone zooming in on focus */
.join input {
  width: 7.5em; text-align: center; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--ink); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; font-family: inherit;
}
#lobby-code { font-size: 44px; letter-spacing: 0.35em; margin: 4px 0 8px 0.35em; }
#lobby .picker { margin: 14px 0; }

.compose { display: flex; align-items: center; gap: 8px; }
.compose #message { flex: 1; min-width: 0; }
button.round { width: 42px; height: 42px; padding: 0; margin: 0; flex: none; font-size: 16px; }
#mic.on { background: #ff5a6e; border-color: #ff5a6e; color: #05060a; }

#status {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  margin: 0; padding: 6px 14px; border-radius: 999px; font-size: 12px; color: var(--ink);
  background: rgba(5, 6, 10, 0.75); border: 1px solid var(--line); z-index: 10;
  width: max-content; max-width: calc(100vw - 32px); text-align: center; line-height: 1.4;
}

/* ── phones ── */
.panel.bottom { bottom: calc(16px + env(safe-area-inset-bottom)); }
@media (max-width: 600px) {
  .panel { padding: 22px 16px; }
  h1 { font-size: 26px; letter-spacing: 0.22em; }
  .picker > span { min-width: 0; width: 100%; text-align: center; }
  #bank-say { font-size: 56px; }
}

/* ── prompts + the letter key ── */
.toggle { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 0; color: var(--dim); font-size: 13px; cursor: pointer; }
.toggle input { accent-color: #ffd27a; width: 16px; height: 16px; }
.prompt { color: #ffd27a; font-size: 14px; font-style: italic; margin: 0 0 6px; }
#key {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 12px; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 6px; max-width: 45vw; font-size: 13px; pointer-events: none;
}
#key span { padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
#key b { font-weight: 400; color: var(--dim); margin-left: 4px; }
#key span.new { border-color: #ffd27a; animation: keyin 1.2s ease-out; }
@keyframes keyin { from { transform: scale(1.6); background: rgba(255, 210, 122, 0.25); } to { transform: scale(1); } }

#write-count.near { color: #ffd27a; }

/* ── phones: the page never scrolls, and never changes height when the keyboard opens:
   it's locked to the screen's height (--app-h, set in main.js) and the keyboard slides over it ── */
html, body { position: fixed; top: 0; left: 0; right: 0; bottom: auto; height: var(--app-h, 100%); overflow: hidden; overscroll-behavior: none; }
@media (max-width: 600px) {
  #key { max-width: calc(100vw - 24px); justify-content: center; left: 12px; right: 12px; }
  #status { top: auto; bottom: calc(110px + env(safe-area-inset-bottom)); }
}

/* Phones: a compact typing bar. While you type it lifts to the upper middle, out of the
   keyboard's way, so nothing has to chase the keyboard (iPhones report its size too late). */
@media (max-width: 600px) {
  #write.panel.bottom, #waiting.panel.bottom { width: calc(100% - 16px); padding: 8px 0 0; }
  #write h2, #waiting h2 { font-size: 13px; margin: 0 0 6px; }
  #write .quiet-text { margin: 4px 0 0; }
  #write-hint:not(.show) { display: none; }
  body.composing #write .quiet-text { display: none; }
}
body.composing #write.panel.bottom { top: calc(var(--app-h, 100vh) * 0.34); bottom: auto; } /* a third of the way down: just above the keyboard, even on small iPhones */
#mic.voiced { border-color: #ffd27a; color: #ffd27a; }
.byline { font-size: 12px; color: var(--dim); margin: -6px 0 14px; }
/* diary: past entries */
#diary-past { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; max-height: 30vh; overflow-y: auto; }
#diary-past button { margin: 0; padding: 7px 14px; font-size: 12px; text-align: left; display: flex; justify-content: space-between; gap: 10px; }
#diary-past .when { color: var(--ink); white-space: nowrap; }
#diary-past .first { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* inbox: name + words forms, the list of conversations */
.fields { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin: 6px 0; }
.field { font: inherit; font-size: 16px; color: var(--ink); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; width: 11em; text-align: center; }
.field.wide { width: 16.5em; }
button.link { border: none; padding: 0; margin: 0; color: var(--dim); text-decoration: underline; font-size: inherit; }
#phrase-words { color: #ffd27a; font-size: 18px; letter-spacing: 0.06em; margin: 6px 0 10px; }
#inbox-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; max-height: 32vh; overflow-y: auto; }
#inbox-list button { margin: 0; padding: 8px 14px; font-size: 13px; text-align: left; display: flex; justify-content: space-between; gap: 10px; }
#inbox-list button .who { color: var(--ink); }
#inbox-list button .what { color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#inbox-list button.new { border-color: rgba(111, 182, 255, 0.6); }
#inbox-list button.new .what { color: #9fd0ff; }
/* someone wrote back: a little glowing blue dot */
#inbox-list .dot { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: #6fb6ff; box-shadow: 0 0 8px #6fb6ff; vertical-align: middle; animation: dotglow 1.6s ease-in-out infinite; }
@keyframes dotglow { 50% { box-shadow: 0 0 2px #6fb6ff; opacity: 0.7; } }
/* letters: your conversations on the title screen, and a thread's letters */
#my-letters { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
#my-letters button { margin: 0; padding: 6px 12px; font-size: 12px; color: var(--dim); border-color: var(--line); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#letter-list button { margin: 3px; padding: 4px 12px; font-size: 12px; }
#letter-new { border-color: #ffd27a; color: #ffd27a; animation: keyin 1.2s ease-out; }
.save-inbox { margin-top: 8px; }

.panel .back { position: absolute; top: 10px; left: 10px; margin: 0; padding: 4px 10px; font-size: 13px; }
#mic { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* ── game modes ── */
/* The mode switch: equal slots, and one pill that slides to the chosen one (--i = its slot). */
.modes {
  position: relative; display: grid; grid-template-columns: repeat(5, 1fr);
  width: min(100%, 360px); margin: 0 auto 12px; padding: 3px;
  border: 1px solid var(--line); border-radius: 999px;
}
.modes::before {
  content: ''; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / 5);
  border-radius: 999px; background: var(--ink);
  transform: translateX(calc(var(--i, 0) * 100%)); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modes button {
  position: relative; margin: 0; padding: 6px 0; border: none; border-radius: 999px;
  color: var(--dim); font-size: 13px; text-align: center; transition: color 0.2s;
}
.modes button:hover { color: var(--ink); }
.modes button.on { color: var(--bg); }
#mode-blurb { min-height: 4.5em; }
#party-list { list-style: none; padding: 0; margin: 6px 0 10px; font-size: 13px; }
#party-list li { margin: 2px 0; }

/* ── jam ── */
.big-code { font-size: 56px; letter-spacing: 0.35em; margin: 4px 0 8px 0.35em; }
#jam-players { list-style: none; padding: 0; margin: 12px 0; font-size: 15px; }
#jam-players li { margin: 4px 0; }
#jam-players b { font-weight: 400; letter-spacing: 0.4em; margin-left: 8px; }
#jam-hud { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; z-index: 6; }
#jam-timer { font-size: 22px; letter-spacing: 0.1em; }
.glyph-picks { display: flex; justify-content: center; gap: 10px; margin: 10px 0; }
.glyph-picks label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--dim); }
.symbol-strip { display: grid; grid-template-rows: repeat(4, 48px); grid-auto-flow: column; grid-auto-columns: 48px; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 4px 2px 10px; margin: 8px 0; -webkit-overflow-scrolling: touch; }
.symbol-strip button { scroll-snap-align: start; width: 48px; height: 48px; padding: 0; font: inherit; font-size: 24px; color: var(--ink); background: none; border: 1px solid var(--line); border-radius: 12px; }
.symbol-strip button.chosen { border-width: 2px; border-color: currentColor; }
.glyph-picks .slot { display: grid; place-items: center; width: 56px; height: 56px; font-size: 30px; border: 1px dashed var(--line); border-radius: 12px; }
.glyph-picks .slot.filled { border-style: solid; border-color: currentColor; }
.word-input { width: 64px; text-align: center; font: inherit; font-size: 12px; color: var(--ink); background: none; border: none; border-bottom: 1px solid var(--line); padding: 4px 0; }
.word-input::placeholder { color: var(--dim); opacity: 0.6; }
#jam-lyric { position: fixed; left: 0; right: 0; bottom: 22%; text-align: center; font-size: clamp(28px, 6vw, 72px); letter-spacing: 0.08em; pointer-events: none; z-index: 5; animation: lyric 1.6s ease-out forwards; }
@keyframes lyric { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-24px); } }
#jam-pad { position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); z-index: 4; }
#jam-pad[hidden] { display: none; }
#jam-pad-note { text-align: center; margin: 0 0 10px; }
.pads { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; height: min(70vh, 520px); }
.pad { margin: 0; border-radius: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; background: rgba(255, 255, 255, 0.03); transition: transform 0.06s, background 0.2s; }
.pad b { font-weight: 400; font-size: 64px; line-height: 1; }
.pad span { font-size: 12px; color: var(--dim); }
.pad.hit { transform: scale(0.94); background: rgba(255, 255, 255, 0.16); }

/* duet interludes: what each of you said, decoded, fading in as it's heard */
#interlude-lines { position: fixed; left: 16px; right: 16px; top: calc(14% + env(safe-area-inset-top)); margin: 0; padding: 0; list-style: none; text-align: center; pointer-events: none; z-index: 3; display: flex; flex-direction: column; gap: 10px; }
#interlude-lines li { font-size: clamp(16px, 3.4vw, 26px); letter-spacing: 0.04em; opacity: 0; transform: translateY(6px); transition: opacity 0.6s, transform 0.6s; text-shadow: 0 0 12px rgba(5, 6, 10, 0.9); }
#interlude-lines li.on { opacity: 1; transform: none; }

/* dev: the pattern viewer (/?patterns on localhost) */
#pattern-viewer { position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 20; background: rgba(5, 6, 10, 0.8); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; max-height: 38vh; overflow-y: auto; }
#pattern-viewer p { margin: 0 0 6px; }
#pattern-viewer div { display: flex; flex-wrap: wrap; gap: 4px; }
#pattern-viewer button { font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 8px; color: var(--ink); background: none; border: 1px solid var(--line); }
#pattern-viewer button.pic { border-style: dashed; }
#pattern-viewer button.on { background: var(--ink); color: #05060a; }
#pattern-viewer select { font: inherit; font-size: 12px; background: none; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; }
