/* Word Chain — English Room Games */

:root {
  --bg: #1d2452;
  --bg-2: #252d63;
  --ink: #fff8e7;
  --muted: #b9c0ea;
  --muted-2: #8790c4;
  --line: rgba(255, 255, 255, .14);
  --gold: #ffc93c;
  --gold-dark: #c99a1c;
  --red: #ef6461;
  --red-dark: #b8393a;
  --yellow: #ffc93c;
  --yellow-dark: #c99a1c;
  --blue: #2f6fd8;
  --blue-dark: #1d4ea3;
  --display: 'Fredoka', 'Nunito', sans-serif;
  --body: 'Nunito', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body); color: var(--ink); background-color: var(--bg);
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.03) 75%),
    linear-gradient(45deg, rgba(255,255,255,.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.03) 75%);
  background-size: 64px 64px; background-position: 0 0, 32px 32px;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); border-bottom: 1px solid var(--line); background: rgba(20, 26, 64, .8); }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font: 700 26px var(--display); white-space: nowrap; }
.brand .site { font-size: 11.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); text-decoration: none; white-space: nowrap; }
.brand .site:hover { color: var(--gold); }
.spacer { flex: 1; }
.iconbtn { width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.05); color: var(--muted); cursor: pointer; text-decoration: none; }
.iconbtn:hover { color: var(--ink); border-color: var(--gold); }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn[aria-pressed="false"] .wave { display: none; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: rgba(255,255,255,.07); border-radius: 12px; padding: 10px 16px; font-weight: 800; font-size: 1rem; cursor: pointer; min-height: 44px; }
.btn:hover:not(:disabled) { background: rgba(255,255,255,.13); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--gold); color: var(--bg); border-color: transparent; box-shadow: 0 4px 0 var(--gold-dark); font-family: var(--display); font-weight: 600; font-size: 1.12rem; }
.btn.primary:hover { background: #ffd35e; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }
.btn.wide { width: 100%; margin-top: 8px; }
.tip { margin: 0; color: var(--muted-2); font-size: .9rem; text-align: center; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(10, 14, 40, .75); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 14px; }
.card { position: relative; width: min(480px, 100%); max-height: calc(100dvh - 28px); overflow: auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: 0 30px 70px rgba(0,0,0,.5); }
.card h2 { margin: 0 0 6px; font: 700 2rem var(--display); }
.card h3 { margin: 16px 0 6px; font: 600 1.15rem var(--display); color: var(--gold); }
.card p { line-height: 1.5; margin: 0 0 12px; }
.card .big { font-size: 1.08rem; }
.kicker { font: 600 .8rem var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.kicker a { color: inherit; text-decoration: none; }
.close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(255,255,255,.08); font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); }
.field { margin-bottom: 14px; }
.label { display: flex; align-items: center; gap: 6px; font: 600 .8rem var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.red { background: var(--red); } .dot.yellow { background: var(--yellow); }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice button { text-align: left; padding: 11px 14px; border-radius: 14px; cursor: pointer; border: 2px solid var(--line); background: rgba(0,0,0,.25); }
.choice button b { display: block; font-size: 1.05rem; }
.choice button span { color: var(--muted); font-size: .88rem; }
.choice button[aria-pressed="true"] { border-color: var(--gold); background: rgba(255, 201, 60, .1); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.names input { width: 100%; font: 700 1rem var(--body); color: var(--ink); background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.names input:focus { outline: none; border-color: var(--gold); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 800; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--gold); color: var(--bg); }
.steps { padding-left: 20px; margin: 4px 0; line-height: 1.55; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 150; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 520px) {
  .brand .site { display: none; }
  .brand h1 { font-size: 22px; }
  .names { grid-template-columns: 1fr; }
  .card { padding: 18px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- Word Chain ---------- */
:root { --p0: #5b8def; --p1: #ef6461; }
.layout { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 14px 12px 22px; max-width: 760px; margin: 0 auto; width: 100%; }
.players { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line); background: rgba(0,0,0,.2); min-width: 0; transition: border-color .2s, box-shadow .2s; }
.player.p1 { justify-content: flex-end; }
.player .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.player .score { font: 700 1.35rem var(--display); color: var(--gold); }
.player.p0 .score { margin-left: auto; }
.player.p1 .score { margin-right: auto; }
.player.turn.p0 { border-color: var(--p0); box-shadow: 0 0 0 4px rgba(91,141,239,.22); }
.player.turn.p1 { border-color: var(--p1); box-shadow: 0 0 0 4px rgba(239,100,97,.22); }
.hearts { display: flex; gap: 2px; }
.hearts svg { width: 18px; height: 18px; }
.hearts svg path { fill: #ef6461; }
.hearts svg.lost path { fill: rgba(255,255,255,.15); }
.hearts svg.pop { animation: heartpop .6s; }
@keyframes heartpop { 30% { transform: scale(1.6); } }

.chain-box { position: relative; width: 100%; background: rgba(0,0,0,.22); border: 1px solid var(--line); border-radius: 18px; padding: 14px; min-height: 140px; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 6px; max-height: min(34dvh, 300px); overflow-y: auto; padding: 2px; }
.chain .empty { color: var(--muted-2); font-weight: 700; width: 100%; text-align: center; padding: 30px 0; }
.chip { display: inline-flex; align-items: baseline; padding: 6px 12px; border-radius: 12px; font: 600 1.15rem var(--display); background: rgba(255,255,255,.08); border: 2px solid transparent; animation: chipin .35s ease-out; }
.chip.p0 { border-color: rgba(91,141,239,.6); }
.chip.p1 { border-color: rgba(239,100,97,.6); }
.chip .last { color: var(--gold); text-decoration: underline; text-underline-offset: 3px; }
.chip.latest { background: rgba(255,201,60,.14); }
.arrow { color: var(--muted-2); font-weight: 800; }
.break { width: 100%; display: flex; align-items: center; gap: 10px; color: var(--muted-2); font-size: .82rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.break::before, .break::after { content: ''; flex: 1; border-top: 1px dashed var(--line); }
@keyframes chipin { from { transform: translateY(8px) scale(.9); opacity: 0; } }
.chain-count { position: absolute; right: 12px; bottom: 8px; font-size: .8rem; font-weight: 800; color: var(--muted-2); }

.turn-panel { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.timer { width: min(460px, 100%); height: 10px; border-radius: 99px; background: rgba(255,255,255,.1); overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: #3bb273; border-radius: 99px; transform-origin: left; }
.timer-fill.warn { background: var(--gold); } .timer-fill.danger { background: var(--red); }
.prompt { font: 600 1.3rem var(--display); text-align: center; min-height: 1.6em; }
.prompt b { color: var(--gold); font-size: 1.6rem; text-transform: uppercase; }
.entry { display: flex; align-items: stretch; gap: 8px; width: min(460px, 100%); }
.entry .first { display: grid; place-items: center; width: 56px; flex-shrink: 0; border-radius: 14px; background: var(--gold); color: var(--bg); font: 700 2rem var(--display); text-transform: lowercase; box-shadow: 0 4px 0 var(--gold-dark); }
.entry input { flex: 1; min-width: 0; font: 600 1.6rem var(--display); color: var(--ink); background: rgba(0,0,0,.3); border: 2px solid var(--line); border-radius: 14px; padding: 8px 14px; text-transform: lowercase; }
.entry input:focus { outline: none; border-color: var(--gold); }
.entry input::placeholder { color: var(--muted-2); font-size: 1.1rem; font-family: var(--body); }
.entry.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
.entry.disabled { opacity: .45; pointer-events: none; }
.msg { min-height: 1.4em; font-weight: 800; text-align: center; color: var(--muted); }
.msg.good { color: #6ee7a8; } .msg.bad { color: var(--red); } .msg.hint { color: var(--gold); letter-spacing: .06em; }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--gold); color: var(--bg); font-size: .8rem; }
.thinking { display: inline-flex; gap: 4px; }
.thinking i { width: 8px; height: 8px; border-radius: 50%; background: var(--p1); animation: think 1s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes think { 50% { transform: translateY(-6px); opacity: .5; } }

.example { display: block; margin-top: 8px; font-family: var(--display); color: var(--muted); }
.example b { color: var(--gold); }
.seg.four { grid-template-columns: repeat(4, 1fr); }
.card.center { text-align: center; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 14px; }
.stats div { background: rgba(0,0,0,.25); border-radius: 12px; padding: 10px 6px; }
.stats b { display: block; font: 700 1.4rem var(--display); color: var(--gold); word-break: break-word; }
.stats span { font-size: .8rem; color: var(--muted); font-weight: 800; }

@media (max-width: 520px) {
  .player { padding: 6px 10px; gap: 6px; }
  .hearts svg { width: 15px; height: 15px; }
  .chip { font-size: 1rem; padding: 5px 9px; }
  .entry .first { width: 48px; font-size: 1.7rem; }
  .entry input { font-size: 1.35rem; }
}
