/* Warm, low-lit, quiet. The dice should be the brightest thing on screen. */

/* Subset to A-Z (2 KB) — it only ever letters the six faces, and shipping it
   means the engraving looks the same on both your phones. */
@font-face {
  font-family: "Oswald";
  src: url("/static/fonts/oswald-600-caps.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: block;
  unicode-range: U+41-5A;
}

:root {
  --bg: #17130f;
  --bg-lift: #201a14;
  --panel: #241d16;
  --line: #3a2e23;
  --text: #f2e8da;
  --muted: #a3927c;
  --accent: #d9a566;
  --accent-dim: #8f6f45;
  --danger: #d98a6a;

  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
           ui-serif, serif;
  --condensed: "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow",
               var(--sans);

  --pad: clamp(16px, 4vw, 28px);
}

* { box-sizing: border-box; }

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

body::before {
  /* A pool of lamplight behind the dice. */
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 70% 50% at 50% 34%,
              rgba(217, 165, 102, 0.16), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }

/* ---------------------------------------------------------------- gates */

body.gate {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--pad);
}

.card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(24px, 6vw, 38px);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.card .mark { margin-bottom: 14px; }
.card .mark img { opacity: 0.9; }

.card h1 {
  margin: 0 0 10px;
  font-family: var(--condensed);
  font-size: clamp(28px, 7vw, 34px);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lede { margin: 0 0 22px; color: var(--muted); line-height: 1.55; }
.fine { margin: 18px 0 0; color: var(--accent-dim); font-size: 13px; }
.error {
  margin: 0 0 16px;
  color: var(--danger);
  font-size: 14px;
}

.card form { display: grid; gap: 12px; }

.card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-lift);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
}
.card input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.pin-input {
  text-align: center;
  letter-spacing: 0.5em;
  font-size: 24px !important;
  padding-left: 0.5em !important;
}

.card button[type="submit"] {
  padding: 14px 18px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #201a12;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.card button[type="submit"]:hover { filter: brightness(1.06); }

.seat-list { display: grid; gap: 10px; margin-bottom: 18px; }
.seat-btn {
  width: 100%;
  padding: 14px;
  background: var(--bg-lift);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 17px;
}
.seat-btn:hover { border-color: var(--accent); }
.seat-new { border-top: 1px solid var(--line); padding-top: 18px; }
.seat-new.first { border-top: none; padding-top: 0; }

/* ----------------------------------------------------------------- game */

body.game { overflow: hidden; }

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) var(--pad)
           max(10px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 2px;
  flex: none;
}

.players { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  background: var(--bg-lift);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}
.chip.is-you { color: var(--text); border-color: var(--accent-dim); }
.chip .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #5a4a38;
  transition: background 0.3s;
}
.chip.online .dot {
  background: #7ec98a;
  box-shadow: 0 0 8px rgba(126, 201, 138, 0.7);
}

.ghost {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}
.ghost:hover { color: var(--text); border-color: var(--accent-dim); }
.ghost.small { padding: 5px 12px; font-size: 12px; }

/* Dice + prompt. Stacked on a phone, side by side on a wide screen. */
.board {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  /* The dice must never be squeezed to a sliver when the prompt card is long;
     past this point the card scrolls inside itself instead. */
  min-height: min(34dvh, 240px);
}
#dice-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.5s;
}
.loading span {
  width: 30px; height: 30px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.loading.done { opacity: 0; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.controls { flex: none; display: grid; justify-items: center; gap: 8px; padding: 6px 0 2px; }

.roll {
  min-width: 190px;
  padding: 15px 30px;
  background: linear-gradient(180deg, #e6b273, #c98f4f);
  border: none;
  border-radius: 999px;
  color: #221a10;
  font-family: var(--condensed);
  font-size: 19px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  box-shadow: 0 10px 26px rgba(201, 143, 79, 0.28);
  transition: transform 0.12s, box-shadow 0.2s, opacity 0.2s;
}
.roll:hover:not(:disabled) { transform: translateY(-1px); }
.roll:active:not(:disabled) { transform: translateY(1px); }
.roll:disabled { opacity: 0.4; box-shadow: none; }

.status { margin: 0; color: var(--muted); font-size: 12.5px; min-height: 1.2em; }
.status.warn { color: var(--danger); }

/* --------------------------------------------------------------- result */

.result {
  flex: 0 1 auto;
  max-height: 46dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  padding: 14px 0 6px;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.result[hidden] { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.result-who {
  margin: 0 0 4px;
  color: var(--accent-dim);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.result-word {
  margin: 0;
  font-family: var(--condensed);
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.result-blurb {
  margin: 6px auto 0;
  max-width: 34ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.starter {
  margin: 14px auto 10px;
  max-width: 40ch;
  padding: 0;
  font-family: var(--serif);
  font-size: clamp(17px, 4.6vw, 20px);
  line-height: 1.5;
  color: var(--text);
}

/* -------------------------------------------------------------- history */

.history {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(320px, 84vw);
  padding: calc(16px + env(safe-area-inset-top)) 20px 20px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  z-index: 5;
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.5);
  animation: slide-in 0.28s ease;
}
.history[hidden] { display: none; }
@keyframes slide-in { from { transform: translateX(100%); } }

.history h3 {
  margin: 0 0 14px;
  font-family: var(--condensed);
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.history ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.history li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(58, 46, 35, 0.6);
  font-size: 13.5px;
}
.history .h-face {
  font-family: var(--condensed);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}
.history .h-meta { color: var(--muted); font-size: 12px; text-align: right; }
.history .empty { color: var(--muted); font-size: 13px; }
.history-foot { margin-top: 18px; text-align: center; }

/* On a wide screen, stacking the prompt under the dice squeezes the canvas
   into a letterbox. Side by side instead, and the dice keeps its room. */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .board {
    display: grid;
    grid-template-columns: 1fr minmax(300px, 28rem);
    /* Stretch, not centre: the stage column has to fill the row so its Roll
       button stays on screen. The prompt centres itself instead. */
    align-items: stretch;
    gap: clamp(24px, 5vw, 64px);
    min-height: 0;
  }
  .board > .result { align-self: center; }
  .result {
    max-height: none;
    overflow: visible;
    text-align: left;
    padding: 0;
  }
  .result-blurb, .starter { margin-left: 0; font-size: 15px; }
  .starter { font-size: clamp(18px, 1.6vw, 22px); }
}

@media (prefers-reduced-motion: reduce) {
  .result { animation: none; }
  .history { animation: none; }
  .loading span { animation-duration: 2s; }
}
