:root {
  /* felt table */
  --felt-0: #10271f;
  --felt-1: #16352a;
  --felt-2: #1d4234;
  --felt-line: #2c5a48;
  /* bone dice */
  --bone: #f4efe1;
  --bone-edge: #d9d1bd;
  --ink: #24211b;
  /* amber tray */
  --amber: #e6a23c;
  --amber-deep: #b26a1c;
  --amber-shadow: #6f4110;
  /* accents */
  --clay: #cf5238;
  --clay-deep: #a63c26;
  --cream: #f1ece0;
  --cream-dim: #a9bcb0;
  --good: #74c69d;
  --bad: #e8907c;

  --display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-lg: 20px;
  --r-md: 12px;
  --r-sm: 8px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--body);
  color: var(--cream);
  background:
    radial-gradient(120% 90% at 50% -10%, var(--felt-2), transparent 60%),
    radial-gradient(140% 120% at 50% 120%, var(--felt-0), var(--felt-1) 55%);
  background-color: var(--felt-1);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* faint stitched-felt texture */
body::before {
  content: "";
  position: fixed; inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.015) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.04) 0 2px, transparent 2px 7px);
  pointer-events: none;
  z-index: 0;
}

#app { position: relative; z-index: 1; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

button, input { font-family: inherit; }

/* ---------------- buttons ---------------- */
.btn {
  border: none; cursor: pointer;
  font-family: var(--display); font-weight: 700;
  font-size: 1rem; letter-spacing: .01em;
  padding: .8rem 1.4rem; border-radius: var(--r-md);
  transition: transform .08s ease, filter .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(2px); }
.btn-sm { padding: .6rem 1rem; font-size: .95rem; }

.btn-amber {
  color: #3a230a;
  background: linear-gradient(180deg, #f2b24e, var(--amber));
  box-shadow: 0 4px 0 var(--amber-shadow), 0 8px 18px rgba(0,0,0,.35);
}
.btn-amber:hover { filter: brightness(1.05); }
.btn-amber:active { box-shadow: 0 2px 0 var(--amber-shadow); }

.btn-ghost {
  color: var(--cream);
  background: rgba(255,255,255,.06);
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.22);
}
.btn-ghost:hover { background: rgba(255,255,255,.12); }

.btn-clay {
  color: #fff;
  background: linear-gradient(180deg, #e0654a, var(--clay));
  box-shadow: 0 4px 0 var(--clay-deep), 0 8px 18px rgba(0,0,0,.3);
}
.btn-clay:active { box-shadow: 0 2px 0 var(--clay-deep); }

.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ================= LANDING ================= */
#landing { align-items: center; justify-content: center; padding: 2rem 1.2rem; }
.landing-inner { width: 100%; max-width: 720px; text-align: center; }

.brand { margin-bottom: 2.4rem; }
.brand-cubes { display: inline-flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.brand-cubes span {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(2.2rem, 9vw, 4.2rem);
  width: 1.35em; height: 1.35em;
  display: grid; place-items: center;
  color: var(--ink);
  background: linear-gradient(160deg, #fbf7ec, var(--bone) 55%, var(--bone-edge));
  border-radius: 16%;
  box-shadow: 0 6px 0 var(--bone-edge), 0 12px 22px rgba(0,0,0,.4), inset 0 2px 2px rgba(255,255,255,.7);
}
.brand-cubes span:nth-child(odd) { transform: rotate(-5deg); }
.brand-cubes span:nth-child(even) { transform: rotate(4deg); }
.brand-cubes span:nth-child(3) { transform: rotate(-2deg) translateY(4px); }

.tagline { margin: 1.6rem 0 0; color: var(--cream-dim); font-size: 1.1rem; }

.name-field { text-align: left; max-width: 340px; margin: 0 auto 1.8rem; }
.name-field label { display: block; font-size: .82rem; text-transform: uppercase; letter-spacing: .1em; color: var(--cream-dim); margin-bottom: .4rem; }

input[type="text"] {
  width: 100%;
  padding: .8rem 1rem;
  font-size: 1.05rem;
  color: var(--cream);
  background: rgba(0,0,0,.28);
  border: 1.5px solid var(--felt-line);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(230,162,60,.22); }
input::placeholder { color: #6f8579; }

.landing-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; text-align: left; }
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  border: 1.5px solid var(--felt-line);
  border-radius: var(--r-lg);
  padding: 1.4rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.card h2 { font-family: var(--display); font-weight: 700; margin: 0; font-size: 1.3rem; }
.card p { margin: 0 0 .6rem; color: var(--cream-dim); font-size: .95rem; flex: 1; }
.card .btn { width: 100%; }
.join-row { display: flex; gap: .5rem; }
.join-row input {
  flex: 1; text-transform: uppercase; letter-spacing: .35em;
  font-family: var(--display); font-weight: 700; text-align: center;
}
.join-row .btn { width: auto; padding-inline: 1.4rem; }

.landing-error { color: var(--bad); margin: 1.2rem 0 0; font-weight: 500; }
.landing-note { margin-top: 2rem; color: var(--cream-dim); font-size: .9rem; line-height: 1.5; max-width: 560px; margin-inline: auto; }

@media (max-width: 560px) {
  .landing-cards { grid-template-columns: 1fr; }
}

/* ================= ROOM ================= */
.room-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.2rem;
  border-bottom: 1px solid var(--felt-line);
  background: rgba(0,0,0,.18);
  flex-wrap: wrap;
}
.room-bar-left, .room-bar-right { display: flex; align-items: center; gap: .6rem; }
.chip {
  border: none; cursor: default;
  font-family: var(--body); font-size: .9rem;
  color: var(--cream);
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  padding: .45rem .9rem;
  display: inline-flex; align-items: center; gap: .45rem;
}
.chip-quiet { cursor: pointer; color: var(--cream-dim); }
.chip-quiet:hover { color: var(--cream); background: rgba(255,255,255,.1); }
.chip-code { cursor: pointer; background: rgba(230,162,60,.15); }
.chip-code strong { font-family: var(--display); font-weight: 800; letter-spacing: .18em; color: var(--amber); font-size: 1.05rem; }
.chip-code .copy-hint { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--cream-dim); }
.chip-code.copied .copy-hint { color: var(--good); }

.conn-dot { font-size: .8rem; color: var(--good); transition: color .3s; }
.conn-dot.off { color: var(--bad); }
.conn-dot.wait { color: var(--amber); }
.conn-text { font-size: .82rem; color: var(--cream-dim); }

.room-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.2rem;
  padding: 1.2rem;
  max-width: 1100px; width: 100%; margin: 0 auto;
}

/* players panel */
.players-panel {
  background: rgba(0,0,0,.2);
  border: 1px solid var(--felt-line);
  border-radius: var(--r-lg);
  padding: 1.1rem;
  align-self: start;
}
.panel-title { margin: 0 0 .8rem; font-family: var(--display); font-weight: 700; font-size: 1rem; text-transform: uppercase; letter-spacing: .08em; color: var(--cream-dim); }
.players-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.player-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .6rem;
  padding: .55rem .7rem; border-radius: var(--r-md);
  background: rgba(255,255,255,.04);
}
.player-row.me { box-shadow: inset 0 0 0 1.5px rgba(230,162,60,.5); }
.pdot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); }
.pdot.off { background: #6b7d72; }
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname .host-tag { font-size: .68rem; color: var(--amber); text-transform: uppercase; letter-spacing: .06em; margin-left: .3rem; }
.pname .off-tag { font-size: .7rem; color: var(--cream-dim); margin-left: .3rem; }
.pscore { font-family: var(--display); font-weight: 700; text-align: right; }
.pscore .sub { display: block; font-family: var(--body); font-weight: 500; font-size: .68rem; color: var(--cream-dim); }

/* stage */
.stage { display: flex; flex-direction: column; align-items: center; }

/* timer ring */
.timer-wrap { margin: .4rem 0 1.4rem; }
.timer-ring {
  --frac: 1;
  --ring: var(--amber);
  width: 132px; height: 132px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--ring) calc(var(--frac) * 360deg), rgba(255,255,255,.08) 0);
  transition: background .3s linear;
  box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.timer-ring.low { --ring: var(--clay); }
.timer-ring.paused { --ring: var(--cream-dim); }
.timer-face {
  width: 104px; height: 104px; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, var(--felt-2), var(--felt-0));
  display: grid; place-content: center; text-align: center;
}
.timer-text { font-family: var(--display); font-weight: 800; font-size: 2rem; font-variant-numeric: tabular-nums; line-height: 1; }
.timer-sub { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--cream-dim); margin-top: .25rem; }

/* tray + dice */
.tray {
  --gap: clamp(8px, 2.2vw, 14px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  border-radius: 22px;
  background:
    linear-gradient(180deg, #f0b660, var(--amber) 40%, var(--amber-deep));
  box-shadow:
    inset 0 3px 6px rgba(255,255,255,.4),
    inset 0 -6px 12px rgba(0,0,0,.35),
    0 14px 30px rgba(0,0,0,.4);
  width: min(88vw, 440px);
  aspect-ratio: 1;
}
.die {
  position: relative;
  display: grid; place-items: center;
  border-radius: 16%;
  background: linear-gradient(158deg, #fbf7ec, var(--bone) 52%, var(--bone-edge));
  color: var(--ink);
  font-family: var(--display); font-weight: 800;
  font-size: clamp(1.3rem, 5.4vw, 2.1rem);
  box-shadow: 0 3px 0 var(--bone-edge), 0 6px 10px rgba(0,0,0,.3), inset 0 2px 2px rgba(255,255,255,.7);
  user-select: none;
  transition: transform .18s ease, opacity .2s;
}
.die.empty { background: rgba(0,0,0,.12); box-shadow: inset 0 2px 6px rgba(0,0,0,.35); color: transparent; }
.die .qu { font-size: .68em; }
.die sub { font-size: .5em; font-weight: 700; }
/* underline for W/M/Z ambiguity */
.die .u-mark { position: absolute; bottom: .18em; width: .5em; height: .12em; border-radius: 2px; background: var(--ink); opacity: .55; }

/* controls */
.controls { margin: 1.5rem 0 .5rem; display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; justify-content: center; }
.controls .status { color: var(--cream-dim); font-size: .95rem; }
.dur-picker { display: inline-flex; gap: .35rem; background: rgba(0,0,0,.25); padding: .3rem; border-radius: 999px; }
.dur-picker button {
  border: none; cursor: pointer; color: var(--cream-dim);
  background: transparent; padding: .4rem .8rem; border-radius: 999px;
  font-family: var(--display); font-weight: 700; font-size: .9rem;
}
.dur-picker button.on { color: var(--ink); background: var(--amber); }

/* word entry */
.word-area { width: min(88vw, 440px); margin-top: .6rem; }
.word-input-row { display: flex; gap: .5rem; }
.word-input-row input { flex: 1; font-family: var(--display); font-weight: 700; letter-spacing: .04em; }
.your-words { margin-top: 1rem; }
.your-words-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; color: var(--cream-dim); font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; }
.pill { background: var(--amber); color: var(--ink); border-radius: 999px; padding: .1rem .6rem; font-family: var(--display); font-weight: 800; font-size: .85rem; letter-spacing: 0; }
.chips-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.chips-list li {
  background: rgba(255,255,255,.08);
  padding: .3rem .7rem; border-radius: 999px;
  font-weight: 600; font-size: .9rem;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ================= RESULTS ================= */
#results-view { width: 100%; max-width: 760px; }
.results-head { text-align: center; margin-bottom: 1.4rem; }
.results-head h2 { font-family: var(--display); font-weight: 800; font-size: 1.8rem; margin: 0; }
.results-head p { color: var(--cream-dim); margin: .3rem 0 0; }

.round-board { display: flex; justify-content: center; margin-bottom: 1.6rem; }
.round-board .tray { width: min(70vw, 300px); }

.result-cards { display: grid; gap: .9rem; margin-bottom: 1.6rem; }
.result-card {
  background: rgba(0,0,0,.2);
  border: 1px solid var(--felt-line);
  border-radius: var(--r-lg);
  padding: 1rem 1.1rem;
}
.result-card.winner { border-color: var(--amber); box-shadow: 0 0 0 1px var(--amber); }
.rc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.rc-name { font-family: var(--display); font-weight: 700; font-size: 1.15rem; }
.rc-name .crown { margin-right: .3rem; }
.rc-score { font-family: var(--display); font-weight: 800; font-size: 1.4rem; color: var(--amber); }
.rc-score .lbl { font-family: var(--body); font-weight: 500; font-size: .7rem; color: var(--cream-dim); text-transform: uppercase; letter-spacing: .08em; margin-left: .3rem; }
.rc-words { display: flex; flex-wrap: wrap; gap: .35rem; }
.wtag { font-size: .85rem; padding: .22rem .55rem; border-radius: 999px; background: rgba(116,198,157,.16); color: #cdeeda; }
.wtag .pt { opacity: .7; font-size: .75em; margin-left: .25rem; }
.wtag.dup { background: rgba(255,255,255,.05); color: #8fa398; text-decoration: line-through; }
.rc-empty { color: var(--cream-dim); font-size: .9rem; font-style: italic; }

.all-words { background: rgba(0,0,0,.2); border: 1px solid var(--felt-line); border-radius: var(--r-lg); overflow: hidden; }
.all-words summary { cursor: pointer; padding: 1rem 1.1rem; font-family: var(--display); font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
.all-words summary::-webkit-details-marker { display: none; }
.all-words summary .count { color: var(--cream-dim); font-family: var(--body); font-weight: 500; }
.all-words[open] summary { border-bottom: 1px solid var(--felt-line); }
.all-words-body { padding: 1rem 1.1rem; max-height: 320px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: .35rem; }
.all-words-body .wtag { background: rgba(255,255,255,.06); color: var(--cream); }

.results-actions { display: flex; justify-content: center; gap: .8rem; margin: 1.6rem 0 .5rem; }
.results-actions .waiting { color: var(--cream-dim); align-self: center; }

@media (max-width: 820px) {
  .room-grid { grid-template-columns: 1fr; }
  .players-panel { order: 2; }
  .stage { order: 1; }
}

/* ================= TOASTS ================= */
.toasts { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 50; align-items: center; }
.toast {
  padding: .6rem 1.1rem; border-radius: 999px;
  font-weight: 600; font-size: .92rem;
  background: #23423a; color: var(--cream);
  box-shadow: 0 8px 22px rgba(0,0,0,.4);
  animation: toastIn .2s ease;
}
.toast.good { background: #1f4a3a; color: #bff0d6; }
.toast.bad { background: #542f2a; color: #f4c8bd; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

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