/* One dark room from the 2020 icon: the phone app's colours, the rough cut's layout. */
@font-face { font-family: Overpass; font-weight: 400 700; font-display: swap; src: url(fonts/Overpass-SemiBold.ttf) format("truetype"); }
@font-face { font-family: Overpass; font-weight: 800 900; font-display: swap; src: url(fonts/Overpass-ExtraBold.ttf) format("truetype"); }

:root {
  --night: #140305;
  --card: #3d0609;
  --row: #22070a;
  --frame: #ab2d2f;
  --line: #5a1d20;
  --ink: #f5ece6;
  --soft: #b79a93;
  --skin: #f3d8c1;
  --syringe: #7fc7a0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--night); color: var(--ink); }
body {
  font: 600 16px/1.35 Overpass, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body.playing { overflow: hidden; overscroll-behavior: none; }
h1, h2, p, ol, ul { margin: 0; }
h1 { font-size: 40px; font-weight: 800; line-height: 1.1; }
h2 { font-size: 24px; font-weight: 800; }
h2:focus { outline: none; }
.soft { color: var(--soft); }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--skin); outline-offset: 2px; }

.key { background: var(--card); border: 2px solid var(--frame); border-radius: 12px; min-height: 48px; padding: 8px 14px; font-weight: 800; }
.key.green { border-color: var(--syringe); color: var(--syringe); }
.key.plain { background: transparent; border-color: var(--line); }

/* ---- home ---- */
#home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: max(20px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  text-align: center;
}
.wide { width: 100%; max-width: 320px; }
#joinForm { display: flex; flex-direction: column; gap: 12px; margin: 0; }
.portrait {
  width: 176px; height: 176px; flex: none; overflow: hidden; position: relative;
  background: var(--card); border: 9px solid var(--frame); border-radius: 34px;
}
.portrait img { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); height: 90%; }
#code {
  width: 100%; min-height: 48px; text-align: center; font-size: 22px; font-weight: 800; letter-spacing: .24em;
  background: var(--row); border: 2px solid var(--line); border-radius: 12px; text-transform: uppercase;
}
#code::placeholder { color: var(--soft); letter-spacing: normal; font-size: 18px; font-weight: 600; text-transform: none; }
.status { min-height: 1.35em; color: var(--skin); }

/* ---- the table: everything on one screen, nothing to scroll while you hold ---- */
#table {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 400px);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  grid-template-areas: "hud" "stage" "toast" "controls" "under";
  justify-content: center;
  gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.hud { grid-area: hud; display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.leave { flex: none; width: 40px; height: 40px; background: transparent; border: 0; color: var(--soft); font-size: 18px; border-radius: 8px; }
.clock { font-size: 24px; font-weight: 800; }
.where { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; line-height: 1.15; color: var(--soft); white-space: nowrap; }
.code { color: var(--skin); font-weight: 800; letter-spacing: .14em; user-select: text; -webkit-user-select: text; }
.code:empty { display: none; }
.role { flex: none; font-weight: 800; padding: 4px 10px; border-radius: 8px; background: var(--card); border: 2px solid var(--frame); }
.role.is-poisoner { border-color: var(--syringe); color: var(--syringe); }
.role:empty { visibility: hidden; }

.stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; }
#room {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  border: 6px solid var(--frame); border-radius: 14px; background: var(--card);
  touch-action: none; box-sizing: content-box;
}

/* Two lines' room always, so a longer message never resizes the room under a thumb. */
.toast { grid-area: toast; height: 38px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--skin); font-size: 15px; line-height: 1.25; overflow: hidden; }

.controls { grid-area: controls; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; align-items: center; }
.pad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 48px); gap: 3px; touch-action: none; }
.pad button { position: relative; touch-action: none; background: var(--card); border: 2px solid var(--frame); border-radius: 12px; }
.pad button:active, .pad button.held { background: var(--frame); }
.pad button::before {
  content: ""; position: absolute; top: 50%; left: 50%; width: 11px; height: 11px;
  border: solid var(--ink); border-width: 3px 0 0 3px;
}
.pad .up { grid-area: 1 / 2; }
.pad .left { grid-area: 2 / 1; }
.pad .right { grid-area: 2 / 3; }
.pad .down { grid-area: 3 / 2; }
.pad .up::before { transform: translate(-50%, -25%) rotate(45deg); }
.pad .left::before { transform: translate(-25%, -50%) rotate(-45deg); }
.pad .right::before { transform: translate(-75%, -50%) rotate(135deg); }
.pad .down::before { transform: translate(-50%, -75%) rotate(225deg); }
.acts { display: flex; flex-direction: column; gap: 8px; }
.acts .key { min-height: 56px; touch-action: none; }

.under { grid-area: under; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; }
#map { width: 90px; height: 90px; }
/* Two columns, read down then across, so eight players fit under the controls. */
.scores {
  list-style: none; padding: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  grid-template-rows: repeat(var(--rows, 3), auto); gap: 2px 6px; font-size: 14px; font-variant-numeric: tabular-nums;
}
.scores li { display: flex; gap: 4px; padding: 0 7px; line-height: 21px; background: var(--row); border: 1px solid var(--row); border-radius: 5px; white-space: nowrap; }
.scores li.you { background: var(--card); border-color: var(--frame); }
.scores .who { flex: 1; overflow: hidden; }
.scores .bank { color: var(--syringe); }

.hint { grid-area: hint; display: none; color: var(--soft); font-size: 13px; text-align: center; }

.over { position: fixed; inset: 0; z-index: 2; display: flex; padding: 16px; overflow: auto; background: rgba(20, 3, 5, .86); }
.card {
  margin: auto; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; text-align: center;
  background: var(--card); border: 3px solid var(--frame); border-radius: 16px; padding: 18px;
}
.card h2 { font-size: 30px; }
.card p { text-wrap: balance; }
.card ul { list-style: none; padding: 0; text-align: left; font-variant-numeric: tabular-nums; }
.card li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 8px; border-radius: 5px; }
.card li.you { color: var(--skin); background: var(--row); }
.card li.poisoner { color: var(--syringe); }

/* Short phones: the keys give the room some height back, never under 44px. */
@media (max-height: 700px) {
  .pad { grid-template-rows: repeat(3, 44px); gap: 2px; }
  .acts .key { min-height: 50px; }
  #map { width: 78px; height: 78px; }
  .scores { font-size: 13px; }
  .scores li { line-height: 18px; }
  .leave { height: 32px; }
}

/* A really short phone (an iPhone SE in Safari): stacked, the tiles would be 22px, so the map and
   the scores stand beside the room, where there is width to spare. */
@media (max-height: 600px) and (orientation: portrait) {
  #table {
    grid-template-columns: minmax(0, 1fr) 124px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "hud hud" "stage under" "toast toast" "controls controls";
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
  }
  .under { grid-template-columns: minmax(0, 1fr); justify-items: center; align-self: center; }
  .scores { width: 100%; grid-auto-flow: row; grid-template-rows: none; grid-template-columns: minmax(0, 1fr); }
}

/* A phone on its side: the room on the left, the rest beside it. */
@media (orientation: landscape) and (max-height: 559px) {
  #table {
    grid-template-columns: calc((100vh - 24px) * 5 / 9 + 12px) minmax(0, 360px);
    grid-template-columns: calc((100dvh - 24px) * 5 / 9 + 12px) minmax(0, 360px);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "stage hud" "stage toast" "stage controls" "stage under";
    column-gap: 16px;
    align-content: center;
  }
  .stage { height: calc(100vh - 16px); height: calc(100dvh - 16px); grid-row: 1 / -1; grid-column: 1; }
}

/* Wide screens: the room takes the height, everything else stands beside it. */
@media (min-width: 900px) and (min-height: 560px) {
  #table {
    grid-template-columns: min(440px, calc((100vh - 120px) * 5 / 9 + 12px)) 380px;
    grid-template-columns: min(440px, calc((100dvh - 120px) * 5 / 9 + 12px)) 380px;
    grid-template-rows: auto auto auto auto auto 1fr;
    grid-template-areas: "stage hud" "stage toast" "stage controls" "stage under" "stage hint" "stage .";
    column-gap: 36px;
    row-gap: 18px;
    align-content: stretch;
    padding-top: 28px;
    padding-bottom: 28px;
  }
  .toast { height: 48px; font-size: 18px; }
  .pad { grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 56px); gap: 4px; }
  .acts .key { min-height: 64px; }
  #map { width: 120px; height: 120px; }
  .scores { grid-auto-flow: row; grid-template-rows: none; grid-template-columns: minmax(0, 1fr); font-size: 15px; }
  .hint { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
