/* TugType: a village tug of war on Independence Day. Warm paper, ink outlines, red and blue teams. */
:root {
  --paper: #F4ECDA;
  --card: #FFFBF1;
  --ink: #241A12;
  --ink-soft: #4A3B2D;
  --muted: #86755F;
  --line: #E4D8BD;
  --line-strong: #D2C29E;
  --red: #C9352B;
  --blue: #2A62B8;
  --gold: #F0B429;
  --green: #2F7D50;
  --shadow: 0 1px 0 rgb(36 26 18 / .06), 0 8px 24px rgb(36 26 18 / .07);
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --radius: 16px;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0; color: var(--ink); font: 500 1rem/1.5 var(--display); min-height: 100vh;
  background:
    radial-gradient(circle at 12% -10%, rgb(255 255 255 / .7), transparent 40%),
    var(--paper);
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

.screen { max-width: 1060px; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; }
.screen.narrow { max-width: 640px; }
.screen.wide { max-width: 1180px; }
.screen:not([hidden]) { animation: screenIn .3s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- type ---------- */
h1 { font-size: clamp(2.6rem, 7vw, 4.6rem); line-height: .98; letter-spacing: -.035em; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 800; letter-spacing: -.01em; }
.lead { color: var(--ink-soft); max-width: 48ch; font-size: 1.08rem; }
.lead.small { font-size: .98rem; color: var(--muted); }
.note { color: var(--muted); font-size: .9rem; }
.eyebrow { font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: .35rem; }
.wordmark { display: inline-flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.5rem; letter-spacing: -.03em; }
.rope-mark {
  width: 34px; height: 20px; border-radius: 10px; position: relative; background: var(--ink);
}
.rope-mark::before, .rope-mark::after { content: ""; position: absolute; top: 4px; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--paper); }
.rope-mark::before { left: 4px; background: var(--red); }
.rope-mark::after { right: 4px; background: var(--blue); }

/* ---------- cards and form controls ---------- */
.card { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 1.35rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; margin: .75rem 0; }
.row.tight { margin: 0; gap: .5rem; }
.row.center { justify-content: center; }
.divider { height: 1.5px; background: var(--line); margin: 1.25rem 0; }
label { font-weight: 700; }

input:not([type=radio]):not([type=checkbox]), select {
  padding: .65rem .85rem; border: 1.5px solid var(--line-strong); border-radius: 10px; background: #fff; min-height: 2.75rem;
}
input:not([type=radio]):not([type=checkbox]):focus, select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 4px rgb(36 26 18 / .1); }
.auth-card input { width: 100%; margin: .3rem 0 .8rem; }
#join-code { width: 7rem; font-family: var(--mono); font-weight: 600; letter-spacing: .25em; text-transform: uppercase; text-align: center; }
#auth-error { color: var(--red); min-height: 1.4rem; font-weight: 700; font-size: .92rem; }

button {
  position: relative; cursor: pointer; border: 1.5px solid var(--ink); border-radius: 10px; padding: .6rem 1.1rem; min-height: 2.75rem;
  font-weight: 700; background: var(--card); color: var(--ink);
  transition: transform .12s ease, box-shadow .12s ease, background .12s, color .12s, opacity .12s;
}
button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 3px 0 var(--ink); }
button:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--ink); color: var(--paper); }
button.primary:hover:not(:disabled) { box-shadow: 0 3px 0 var(--red); }
button.ghost { background: transparent; }
button.small { padding: .35rem .8rem; min-height: 2.2rem; font-size: .9rem; }
button.big { padding: .85rem 1.4rem; font-size: 1.05rem; }
button.icon { width: 2.75rem; padding: 0; border-color: var(--line-strong); display: grid; place-items: center; }
button.icon svg { width: 1.25rem; height: 1.25rem; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

button.loading { color: transparent !important; pointer-events: none; }
button.loading::after, .spinner {
  content: ""; width: 1.1rem; height: 1.1rem; border: 3px solid var(--paper); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite;
}
button.loading::after { position: absolute; inset: 0; margin: auto; }
button.ghost.loading::after { border-color: var(--ink); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.segmented { display: inline-flex; flex-wrap: wrap; gap: .3rem; padding: .25rem; background: #EFE4C9; border-radius: 12px; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: .45rem .95rem; border-radius: 9px; font-weight: 700; font-size: .95rem; color: var(--ink-soft); transition: background .12s, color .12s; }
.segmented label:hover span { background: rgb(255 255 255 / .6); }
.segmented input:checked + span { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
.field { margin-bottom: 1.1rem; }
.field-label { display: block; font-weight: 800; font-size: .85rem; margin-bottom: .45rem; }
.field-label em { font-style: normal; font-weight: 500; color: var(--muted); margin-left: .4rem; }

.pill { display: inline-block; padding: .2rem .75rem; border-radius: 999px; background: #EFE4C9; font-weight: 800; font-size: .85rem; }
.pill.live-pill { background: var(--blue); color: #fff; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .85rem; border-radius: 999px; font-weight: 800; font-size: .88rem; background: var(--ink); color: var(--paper); }
.chip.plain { background: #EFE4C9; color: var(--ink); }
.chip.team-a { background: var(--red); color: #fff; }
.chip.team-b { background: var(--blue); color: #fff; }
.switch { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; font-size: .9rem; }
.switch input { width: 1.1rem; height: 1.1rem; accent-color: var(--ink); }

#toast {
  position: fixed; left: 50%; bottom: 1.5rem; z-index: 60; transform: translate(-50%, 150%); transition: transform .2s, opacity .2s, visibility .2s;
  opacity: 0; visibility: hidden; pointer-events: none; background: var(--ink); color: var(--paper); padding: .75rem 1.2rem; border-radius: 12px; max-width: 90vw; font-weight: 700;
}
#toast.visible { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
#reconnecting { position: fixed; top: 0; left: 0; right: 0; z-index: 70; display: flex; gap: .6rem; justify-content: center; align-items: center; padding: .6rem 1rem; background: var(--gold); font-weight: 800; }
#reconnecting .spinner { border-color: var(--ink); border-right-color: transparent; }

/* ---------- log in ---------- */
.auth { display: grid; grid-template-columns: 1.4fr 1fr; gap: 2.5rem; align-items: center; min-height: 100vh; max-width: 1180px; }
.hero { display: grid; gap: 1.25rem; align-content: center; }
.hero-stage { border-radius: var(--radius); overflow: hidden; border: 1.5px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); margin: .5rem 6px 6px 0; background: #CFE7F5; }
#hero-arena { display: block; width: 100%; height: auto; }
.auth-card { align-self: center; }
.auth-card h2 { font-size: 1.6rem; margin-bottom: 1rem; }

/* ---------- lobby ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.me { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.me-text { display: grid; line-height: 1.2; }
.me-text span { color: var(--muted); font-size: .85rem; }
#me-preview { width: 44px; height: 44px; border-radius: 50%; }
.home-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 1.25rem; align-items: start; }
.home-grid .card + .card { margin-top: 0; }
.board { grid-column: 1 / -1; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; margin: 1.25rem 0 .5rem; }
#queue-status { min-height: 1.4rem; margin: .4rem 0; font-weight: 700; }
#queue-status.searching::before { content: ""; display: inline-block; width: .9rem; height: .9rem; margin-right: .5rem; vertical-align: -2px; border: 3px solid var(--blue); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.join label { display: block; font-size: .85rem; font-weight: 800; margin-bottom: .45rem; }

.maker .stage { border-radius: 12px; overflow: hidden; border: 1.5px solid var(--line-strong); background: linear-gradient(#BEE0F2, #F8E7BD 62%, #86B85E 62%); margin-bottom: 1rem; }
#avatar-preview { display: block; width: 100%; height: auto; }
.maker-rows { display: grid; gap: .55rem; margin-bottom: 1rem; }
.maker-row { display: flex; gap: .6rem; align-items: center; }
.maker-row > span { flex: 0 0 5.5rem; }
.maker-row > .stepper, .maker-row > .swatches { flex: 1; }
.maker-row > span { font-size: .82rem; font-weight: 800; color: var(--muted); }
.swatches { display: flex; gap: .4rem; flex-wrap: wrap; }
.swatch { width: 1.9rem; height: 1.9rem; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--ink); }
.swatch:hover:not(:disabled) { transform: scale(1.12); box-shadow: none; }
.swatch[aria-pressed=true] { outline: 3px solid var(--blue); outline-offset: 2px; }
.stepper { display: flex; align-items: center; background: #fff; border: 1.5px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.stepper button { flex: 0 0 2.1rem; border: 0; border-radius: 0; min-height: 2.1rem; padding: 0; background: transparent; font-size: 1.1rem; }
.stepper button:hover:not(:disabled) { background: #EFE4C9; transform: none; box-shadow: none; }
.stepper output { flex: 1; text-align: center; font-weight: 700; font-size: .92rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
td:nth-child(n+4) { font-family: var(--mono); font-weight: 600; }
tr.mine td { background: #F7EBC9; font-weight: 800; }
tbody tr:hover td { background: #FBF3DF; }

/* ---------- room ---------- */
.code-row { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: .85rem; }
.code { display: flex; gap: .45rem; }
.code span { display: grid; place-items: center; width: 3.4rem; height: 4.2rem; border: 2px solid var(--ink); border-radius: 12px; background: var(--card); font: 600 2.4rem var(--mono); box-shadow: 0 3px 0 var(--ink); }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.25rem 0 1rem; }
.team { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 1.1rem; background: var(--card); }
.team-a { border-top: 7px solid var(--red); }
.team-b { border-top: 7px solid var(--blue); }
.team ul { list-style: none; padding: 0; margin: .75rem 0 1rem; min-height: 6.5rem; display: grid; gap: .4rem; align-content: start; }
.team li { display: flex; align-items: center; gap: .6rem; font-weight: 700; }
.team li img { width: 32px; height: 32px; border-radius: 50%; }
#unassigned { min-height: 1.4rem; color: var(--muted); }

/* ---------- tournament ---------- */
.t-head { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; align-items: flex-start; }
.t-head .code span { width: 2.9rem; height: 3.5rem; font-size: 2rem; }
.banner { margin: 1.25rem 0; padding: .9rem 1.2rem; border-radius: 12px; background: var(--ink); color: var(--paper); font-weight: 800; font-size: 1.1rem; }
.banner.out { background: var(--red); }
.banner.champ { background: var(--gold); color: var(--ink); }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .6rem; }
.roster-item { display: flex; align-items: center; gap: .6rem; padding: .45rem .7rem .45rem .45rem; background: #fff; border: 1.5px solid var(--line); border-radius: 999px; font-weight: 700; min-width: 0; }
.roster-item img { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.roster-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-item small { color: var(--muted); font-weight: 600; }
.roster-item.empty { border-style: dashed; color: var(--muted); background: transparent; justify-content: center; padding: .85rem; font-weight: 500; }
#t-hint { margin-top: .9rem; }

.hub { border-color: var(--blue); }
.live-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: .8rem; margin-top: .9rem; }
.live-card { display: grid; gap: .7rem; padding: .9rem; background: #fff; border: 1.5px solid var(--line-strong); border-radius: 14px; }
.live-card .vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem; font-weight: 700; }
.live-card .side { display: grid; justify-items: center; gap: .3rem; min-width: 0; text-align: center; }
.live-card .side img { width: 44px; height: 44px; border-radius: 50%; }
.live-card .side span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.live-card .vs b { color: var(--muted); font-size: .8rem; }
.live-card .foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.live-dot { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 800; color: var(--red); }
.live-dot::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: var(--red); animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }
.live-card .eyes { color: var(--muted); font-size: .82rem; font-weight: 700; }

/* bracket: cards and lines are placed by renderBracket() with plain coordinates */
.bracket { overflow-x: auto; padding: .25rem .25rem 1rem; }
.bracket-inner { position: relative; }
.bracket-lines { position: absolute; left: 0; top: 0; pointer-events: none; }
.round-title { position: absolute; top: 0; margin: 0; width: 214px; font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 800; }
.match { position: absolute; width: 214px; height: 65px; background: #fff; border: 1.5px solid var(--line-strong); border-radius: 10px; }
.match.live { border-color: var(--blue); box-shadow: 0 0 0 3px rgb(42 98 184 / .16); }
.match.mine { border-color: var(--ink); }
.slot { display: flex; align-items: center; gap: .5rem; padding: 0 .6rem; height: 31px; font-weight: 700; font-size: .92rem; }
.slot + .slot { border-top: 1px solid var(--line); }
.slot img { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.slot .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.slot.won { background: #E4F1DA; border-radius: 8px 8px 0 0; }
.slot + .slot.won { border-radius: 0 0 8px 8px; }
.slot.won::after { content: "✓"; color: var(--green); font-weight: 800; }
.slot.lost { color: var(--muted); }
.slot.lost .name { text-decoration: line-through; }
.slot.tbd, .slot.bye { color: var(--muted); font-weight: 500; font-style: italic; }
.slot.you .name { color: var(--red); }
.match.watchable .slot { padding-right: 5.6rem; }
.match .watch-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 5rem; min-height: 1.6rem; padding: 0 .4rem; font-size: .75rem; border-radius: 999px; background: var(--blue); border-color: var(--blue); color: #fff; }
.match .watch-btn:hover:not(:disabled) { transform: translateY(-50%); box-shadow: 0 2px 0 var(--ink); }
.match .watch-btn:active:not(:disabled) { transform: translateY(-50%); }

/* ---------- match ---------- */
.hud { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.arena-panel { position: relative; border-radius: var(--radius); overflow: hidden; border: 1.5px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); margin: 0 6px 6px 0; background: #CFE7F5; }
#arena { display: block; width: 100%; height: auto; }
#timer {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); min-width: 4.2rem; text-align: center; padding: .1rem .9rem;
  font: 600 1.5rem var(--mono); background: var(--ink); color: var(--paper); border-radius: 999px; border: 2px solid var(--paper);
}
#timer:empty { display: none; }
#timer.urgent { background: var(--red); animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.12); } }
#banner { position: absolute; inset: 0; display: grid; place-content: center; opacity: 0; pointer-events: none; font: 800 clamp(4rem, 14vw, 9rem) var(--display); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; letter-spacing: -.03em; }
#banner.zoom-fade { animation: zoomFade .8s ease-out both; }
@keyframes zoomFade { 0% { opacity: 0; transform: scale(.5); } 25% { opacity: 1; transform: scale(1.04); } 100% { opacity: 0; transform: scale(1.5); } }
#overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 1rem; background: rgb(36 26 18 / .45); }
.result-card { background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); padding: 1.4rem 2rem 1.5rem; text-align: center; box-shadow: 0 6px 0 var(--ink); max-width: 30rem; animation: cardIn .35s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.result-card h2 { font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1; letter-spacing: -.03em; font-weight: 800; }
.result-card.win h2 { color: var(--green); }
.result-card.lose h2 { color: var(--red); }
.result-card p:empty { display: none; }
.result-card p { margin-top: .5rem; color: var(--ink-soft); }
#overlay-rank { font: 600 1.1rem var(--mono); color: var(--ink); }
#overlay-mvp { font-weight: 800; }
.result-card .row { margin-bottom: 0; margin-top: 1.1rem; }
.count-pop { animation: countPop .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes countPop { from { opacity: 0; transform: scale(2.2); } }

/* typing: a quiet page of text, the current word underlined */
#wall-wrap { position: relative; margin-top: 1.1rem; }
#wall {
  height: 11rem; overflow: hidden; scroll-behavior: smooth; cursor: text; padding: 1rem 1.3rem 0;
  background: var(--card); border: 1.5px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow);
  font: 500 1.65rem/3.3rem var(--mono); color: var(--ink);
}
/* The real input is invisible and lies over the text, so a tap or click on the text lands on it.
   (A phone only opens its keyboard when the tap hits the input itself.) Font size 16px stops iOS from zooming in. */
#wall-wrap .capture, #wall-wrap .capture:focus {
  min-height: 0; box-shadow: none;
  position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; border-radius: var(--radius);
  background: transparent; color: transparent; caret-color: transparent; font-size: 16px; outline: none; cursor: text;
  -webkit-tap-highlight-color: transparent; -webkit-appearance: none; appearance: none;
}
#wall-wrap .capture:disabled { pointer-events: none; }
.tap-prompt {
  display: none; position: absolute; inset: 0; z-index: 2; place-content: center; justify-items: center; gap: .1rem; text-align: center;
  border-radius: var(--radius); background: rgb(255 251 241 / .82); pointer-events: none;
}
.tap-prompt span { font-weight: 800; font-size: 1.25rem; padding: .3rem 1.1rem; border-radius: 999px; background: var(--ink); color: var(--paper); animation: promptPulse 1.2s ease-in-out infinite alternate; }
.tap-prompt small { color: var(--muted); font-weight: 700; }
@keyframes promptPulse { from { transform: scale(1); } to { transform: scale(1.06); } }
#wall-wrap.active.unfocused .tap-prompt { display: grid; }
#wall .w { display: inline-block; padding: 0 .3rem; margin: 0 .05rem; border-radius: 8px; color: #A99A82; position: relative; }
#wall .done { color: #CDBFA5; }
#wall .done.good { color: #7DAE87; }
#wall .done.skipped { color: var(--red); text-decoration: line-through; text-decoration-thickness: 2px; opacity: .6; }
#wall .current { color: #A99A82; background: #F4E8CB; box-shadow: inset 0 -4px 0 var(--ink); }
#wall .current.ready { background: #E2EFD6; box-shadow: inset 0 -4px 0 var(--green); }
#wall .current.ready::after { content: "space"; position: absolute; top: -.55rem; right: -.1rem; padding: 0 .5rem; border-radius: 99px; background: var(--green); color: #fff; font: 800 .62rem/1.4 var(--display); letter-spacing: .04em; }
#wall .current span { display: inline-block; }
#wall .ok { color: var(--ink); font-weight: 600; }
#wall .ok.fresh { animation: letterPop .14s ease-out; }
#wall .bad { color: #fff; background: var(--red); border-radius: 4px; animation: wobble .18s; }
#wall .next { box-shadow: -2px 0 0 var(--ink); animation: caret 1s steps(1) infinite; }
@keyframes letterPop { 0% { transform: translateY(-3px); } 100% { transform: none; } }
@keyframes wobble { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
@keyframes caret { 50% { box-shadow: -2px 0 0 transparent; } }
#wall-wrap.hit #wall { animation: hit .24s; }
@keyframes hit { 30% { transform: translateX(-4px); border-color: var(--red); } 65% { transform: translateX(3px); } 100% { transform: none; } }
#wall-wrap.over #wall { opacity: .5; transition: opacity .4s; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin-top: .8rem; }
.stats > div { background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: .5rem .85rem; }
.stat-label { display: block; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stats strong { font: 600 1.7rem/1.2 var(--mono); }
.stats small { margin-left: .3rem; color: var(--muted); font-weight: 700; }
#streak-stat.hot { border-color: var(--ink); background: var(--gold); }
#streak-stat[data-tier="2"] { background: #F7A85A; }
#streak-stat[data-tier="3"] { background: #F07A62; }
#streak-stat[data-tier="4"] { background: #CFA0F0; }
#streak-stat[data-tier="5"] { background: #8FD6EE; }
#streak-stat[data-tier="3"] strong, #streak-stat[data-tier="4"] strong, #streak-stat[data-tier="5"] strong { animation: streakHum .5s ease-in-out infinite alternate; }
@keyframes streakHum { from { transform: scale(1); } to { transform: scale(1.12); } }
#streak-stat.hot .stat-label, #streak-stat.hot small { color: var(--ink-soft); }
#streak-stat.pop strong { animation: streakPop .22s ease-out; }
@keyframes streakPop { from { transform: scale(1.35); } }
.hint { text-align: center; margin-top: .8rem; color: var(--muted); font-size: .9rem; }

/* spectators do not type */
.watch { display: none; margin-top: 1.25rem; }
#game.watching #play-ui { display: none; }
#game.watching .watch { display: block; }
.watch-players { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; }
.wp { display: grid; grid-template-columns: 38px 1fr; gap: .1rem .65rem; align-items: center; padding: .55rem .7rem; background: #fff; border: 1.5px solid var(--line); border-radius: 12px; border-left-width: 6px; }
.wp.team-a { border-left-color: var(--red); }
.wp.team-b { border-left-color: var(--blue); }
.wp img { grid-row: 1 / 3; width: 38px; height: 38px; border-radius: 50%; }
.wp b { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wp span { font: 600 .82rem var(--mono); color: var(--muted); }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; min-height: 0; gap: 1.5rem; }
  .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .teams { grid-template-columns: 1fr; }
  .code span { width: 2.9rem; height: 3.6rem; font-size: 2rem; }
  #wall { font-size: 1.2rem; line-height: 2.8rem; height: 9.6rem; padding: .8rem .9rem 0; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .maker-row > span { flex-basis: 4.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}


/* ---------- effects layers ---------- */
#fx-canvas { position: fixed; inset: 0; z-index: 55; width: 100vw; height: 100vh; pointer-events: none; }
#fx-layer { position: fixed; inset: 0; z-index: 60; overflow: hidden; pointer-events: none; }
#edge-glow { position: fixed; inset: 0; z-index: 50; pointer-events: none; opacity: 0; box-shadow: inset 0 0 110px 14px var(--glow, #F0B429); }
#edge-glow.on { animation: edgeGlow .6s ease-out; }
@keyframes edgeGlow { 0% { opacity: 0; } 18% { opacity: calc(.85 * var(--glow-strength, 1)); } 100% { opacity: 0; } }

/* the finished word grows toward you and vanishes */
.word-ghost {
  position: fixed; display: grid; place-items: center; white-space: nowrap; pointer-events: none;
  font-weight: 600; color: var(--ghost-color, var(--green)); text-shadow: 0 0 14px var(--ghost-color, var(--green));
  animation: wordVanish .55s cubic-bezier(.15, .7, .3, 1) forwards;
}
@keyframes wordVanish {
  0% { transform: scale(1); opacity: 1; filter: blur(0); }
  100% { transform: translateY(-14px) scale(2.6); opacity: 0; filter: blur(5px); }
}

/* "x10 GREAT!" over the text */
.combo-pop {
  position: fixed; display: grid; justify-items: center; transform: translate(-50%, -100%); pointer-events: none; white-space: nowrap;
  color: var(--pop-color, var(--gold)); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-align: center;
  animation: comboPop 1s cubic-bezier(.2, 1.4, .4, 1) forwards;
}
.combo-pop b { font: 800 clamp(2.2rem, 7vw, 3.6rem)/1 var(--display); letter-spacing: -.02em; }
.combo-pop span { font: 800 clamp(1rem, 3vw, 1.4rem)/1.2 var(--display); letter-spacing: .08em; }
.combo-pop.lost { color: var(--red); animation-name: comboLost; }
.combo-pop.lost b { font-size: 1.2rem; }
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(.4); }
  25% { opacity: 1; transform: translate(-50%, -110%) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, -120%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}
@keyframes comboLost {
  0% { opacity: 0; transform: translate(-50%, -80%); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -20%); }
}

/* ---------- training, settings and the match header ---------- */
.hud-spacer { flex: 1; }
.hint-touch { display: none; }
.settings { width: min(26rem, calc(100vw - 2rem)); padding: 1.2rem 1.3rem 1.1rem; border: 2px solid var(--ink); border-radius: var(--radius); background: var(--card); color: var(--ink); box-shadow: 0 6px 0 var(--ink); }
.settings::backdrop { background: rgb(36 26 18 / .5); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: .9rem; font-weight: 700; }
.setting-control { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.setting select { max-width: 13rem; }
.setting input[type=range] { width: 11rem; accent-color: var(--ink); }
.setting input[type=checkbox] { width: 1.3rem; height: 1.3rem; accent-color: var(--ink); }
.settings .note { margin-top: 1rem; }

@media (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-touch { display: inline; }
  #game { touch-action: manipulation; }               /* no double-tap zoom while typing */
}
@media (max-width: 560px) {
  .setting { flex-direction: column; align-items: stretch; gap: .35rem; }
  .setting select, .setting input[type=range] { max-width: none; width: 100%; }
  .setting-control select { flex: 1; }
  .setting input[type=checkbox] { align-self: flex-start; }
  .combo-pop b { font-size: 2rem; }
}
