:root {
  --paper: #EDF0F7; --ink: #0C1633; --cobalt: #2B45F5; --gold: #FFB224;
  --red: #FF5A4F; --red-ink: #C62D24; --muted: #46527A;
  --cell-top: #1B2858; --cell-bot: #111B42;
  --display: "Unbounded", system-ui, sans-serif;
  --mono: "Martian Mono", ui-monospace, Menlo, monospace;
  --text: "Instrument Sans", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 400 1.0625rem/1.55 var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; }
#room :focus-visible { outline-color: var(--gold); }

/* Buttons: tactile, like hardware keys */
button {
  font: 600 1rem var(--text); color: var(--ink); background: #fff;
  border: 2px solid var(--ink); border-radius: 14px; padding: .7rem 1.1rem; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
button:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
button:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
button.primary { background: var(--cobalt); color: #fff; font: 600 1rem var(--display); padding: 1rem 1.6rem; }
button.link { background: none; border: 0; box-shadow: none; text-decoration: underline; padding: .4rem 0; color: var(--muted); }
button.link:hover:not(:disabled), button.link:active:not(:disabled) { transform: none; box-shadow: none; }

/* Home and lobby */
.view:not(#room) { min-height: 100%; padding: 28px clamp(20px, 5vw, 72px) 56px; }
.brand { display: flex; align-items: center; gap: .6rem; font: 600 .9rem var(--display); }
h1, h2 { font-family: var(--display); font-weight: 800; letter-spacing: -.03em; line-height: 1.04; margin: 0; }
h1 { font-size: clamp(2.2rem, 5.6vw, 4.4rem); max-width: 14ch; }
h2 { font-size: clamp(1.7rem, 4vw, 2.6rem); margin-bottom: 1.25rem; }
.sub { color: var(--muted); max-width: 34rem; margin: 1.25rem 0 0; }
.fine { color: var(--muted); font-size: .9rem; margin: 2rem 0 0; }
.error { color: var(--red-ink); min-height: 1.5em; font-weight: 600; }
.actions, .row { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.25rem; margin-top: 2rem; }
.row { margin-top: 1.75rem; }
#join-form { display: flex; gap: .6rem; }
#code-input {
  width: 11.5rem; min-width: 0; font: 700 1.1rem var(--mono); letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink); background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: .65rem 1rem;
}
#code-input::placeholder { font: 500 .95rem var(--text); letter-spacing: 0; text-transform: none; color: #6B7599; }

#home { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 2.5rem; }
.hero { margin: 0; }
.hero figcaption { color: var(--muted); font-size: .95rem; margin-top: 1.1rem; max-width: 26rem; }
@media (min-width: 960px) {
  #home { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: center; column-gap: 5vw; }
  .brand { grid-column: 1 / -1; align-self: start; }
  .view#home { min-height: 100vh; }
}
#lobby { max-width: 46rem; }

/* The memorable thing: the split-flap board */
.board {
  display: flex; gap: clamp(4px, .8vw, 9px); width: max-content; max-width: 100%;
  padding: clamp(10px, 1.8vw, 18px); background: var(--ink); border-radius: 18px; perspective: 700px;
}
.hero .board { transform: rotate(-2deg); }
.cell {
  position: relative; display: grid; place-items: center; width: clamp(2.5rem, 7vw, 4.2rem); aspect-ratio: 3 / 4;
  border-radius: 8px; overflow: hidden; background: linear-gradient(var(--cell-top) 50%, var(--cell-bot) 50%);
  color: var(--gold); font: 700 clamp(1.4rem, 4.2vw, 2.6rem) / 1 var(--mono);
}
.cell::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px; background: #050A1E; }
.cell.land { animation: land .22s ease-out; }
@keyframes land { from { transform: rotateX(-70deg); filter: brightness(1.6); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .cell.land { animation: none; } }

/* Room */
#room {
  position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--ink); color: #fff;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.roombar { display: flex; align-items: center; gap: .9rem; padding: 12px 16px 4px; }
#room-chip { font: 700 .95rem var(--mono); letter-spacing: .18em; color: var(--gold); background: var(--cell-bot); padding: .35rem .7rem; border-radius: 8px; }
.roomname { font: 600 .85rem var(--display); color: #9FB0DE; }
.banner { margin: 8px 16px 0; background: var(--gold); color: var(--ink); padding: .6rem 1rem; border-radius: 12px; font-weight: 600; }
#grid {
  flex: 1; min-height: 0; display: grid; gap: 12px; padding: 8px 16px;
  grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(0, 1fr);
}
#grid[data-n="2"], #grid[data-n="3"], #grid[data-n="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 640px) { #grid[data-n="2"] { grid-template-columns: minmax(0, 1fr); } }
#grid[data-n="1"] { grid-template-rows: minmax(0, 1fr) auto; }
#grid[data-n="1"]::after { content: "Waiting for others. Send them the code, or tap Copy link."; text-align: center; color: #9FB0DE; padding: .25rem 0 .5rem; }
.tile { position: relative; min-height: 0; overflow: hidden; border-radius: 22px; background: #050A1E; border: 2px solid var(--cell-top); }
.tile video { display: block; width: 100%; height: 100%; object-fit: contain; background: #050A1E; }
.tile video.mirror { transform: scaleX(-1); }
.tag { position: absolute; left: 10px; bottom: 10px; background: var(--paper); color: var(--ink); padding: .15rem .65rem; border-radius: 999px; font: 600 .8rem var(--text); }
#controls { display: flex; flex-wrap: wrap; justify-content: center; gap: .7rem; padding: 12px 16px 20px; }
#controls button { box-shadow: 3px 3px 0 var(--cobalt); }
#controls button:hover:not(:disabled) { box-shadow: 4px 4px 0 var(--cobalt); }
#controls button:active:not(:disabled) { box-shadow: 0 0 0 var(--cobalt); }
#controls button.off { background: var(--red); color: #fff; border-color: #fff; }
#controls button.danger { background: var(--red-ink); color: #fff; border-color: #fff; margin-left: .6rem; }
