/* Wordle — 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;
  --correct: #3bb273;
  --present: #ffc93c;
  --present-ink: #1d2452;
  --absent: #3a4270;
  --tile-border: #4a5390;
  --tile-filled: #9aa3dd;
  --key: #4a5390;
  --display: 'Fredoka', 'Nunito', sans-serif;
  --body: 'Nunito', sans-serif;
}
body.cb { --correct: #f5793a; --present: #85c0f9; --present-ink: #10173d; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
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;
  display: flex; flex-direction: column;
  height: 100dvh; overflow: hidden;
}
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, .7);
  flex-shrink: 0;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font: 700 26px var(--display); letter-spacing: .02em; }
.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; }

/* ---------- layout ---------- */
.game {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 540px; margin: 0 auto;
  padding: 10px 8px calc(8px + env(safe-area-inset-bottom, 0px));
}
.modebar { display: flex; flex-direction: column; align-items: center; gap: 5px; flex-shrink: 0; }
.seg { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px; background: rgba(0,0,0,.25); border: 1px solid var(--line); padding: 3px; border-radius: 999px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 7px 16px; font-weight: 800; font-size: .95rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--gold); color: var(--bg); }
.modeinfo { margin: 0; font-size: .9rem; font-weight: 700; color: var(--muted); }

/* ---------- board ---------- */
.board-wrap { flex: 1 1 0; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; width: 100%; padding: 8px 0; }
.board {
  --size: 52px;   /* set to fit the screen by game.js */
  display: grid; grid-template-rows: repeat(6, var(--size)); gap: 6px;
}
.row { display: grid; grid-template-columns: repeat(5, var(--size)); gap: 6px; }
.tile {
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--tile-border); border-radius: 8px;
  font: 700 calc(var(--size) * .55) var(--display); text-transform: uppercase;
  color: var(--ink); background: rgba(0,0,0,.12);
  user-select: none;
}
.tile.filled { border-color: var(--tile-filled); animation: pop .1s ease-out; }
.tile.correct, .tile.present, .tile.absent { border-color: transparent; }
.tile.correct { background: var(--correct); color: #fff; }
.tile.present { background: var(--present); color: var(--present-ink); }
.tile.absent { background: var(--absent); color: #dfe3ff; }
.tile.flip { animation: flip .5s ease-in-out both; }
.tile.hinted { border-style: dashed; border-color: var(--correct); color: var(--correct); }
.row.shake { animation: shake .45s; }
.tile.bounce { animation: bounce .6s ease-in-out both; }
@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 15%, 55% { transform: translateX(-7px); } 35%, 75% { transform: translateX(7px); } 90% { transform: translateX(-2px); } }
@keyframes bounce { 0%, 20% { transform: translateY(0); } 40% { transform: translateY(-26px); } 55% { transform: translateY(4px); } 70% { transform: translateY(-10px); } 85% { transform: translateY(0); } }

/* ---------- clue + letter buttons ---------- */
.helpbar { display: flex; gap: 8px; justify-content: center; flex-shrink: 0; margin-bottom: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: rgba(255,255,255,.06);
  border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: .92rem; cursor: pointer; color: var(--ink);
}
.pill:hover:not(:disabled) { border-color: var(--gold); }
.pill:disabled { opacity: .4; cursor: not-allowed; }
.pill svg { width: 17px; height: 17px; fill: none; stroke: var(--gold); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cluebox {
  flex-shrink: 0; max-width: 500px; width: 100%;
  margin: 0 0 8px; padding: 8px 14px; border-radius: 12px;
  background: rgba(255, 201, 60, .1); border: 1px dashed rgba(255, 201, 60, .55);
  font-size: .98rem; line-height: 1.4; text-align: center;
}
.cluebox b { color: var(--gold); }

/* ---------- keyboard ---------- */
.keyboard { width: 100%; display: flex; flex-direction: column; gap: 7px; flex-shrink: 0; user-select: none; }
.krow { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1; max-width: 46px; height: 54px;
  border: 0; border-radius: 8px;
  background: var(--key); color: var(--ink);
  font: 700 1.15rem var(--display); text-transform: uppercase;
  cursor: pointer; touch-action: manipulation;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
  transition: background .15s, transform .05s;
  display: flex; align-items: center; justify-content: center;
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.key.wide { max-width: 72px; flex: 1.5; font-size: .8rem; letter-spacing: .04em; }
.key svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: var(--present-ink); }
.key.absent { background: #262c55; color: #7a82b5; }
.krow .gap { flex: .5; max-width: 22px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 72px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--bg);
  font-weight: 800; font-size: 1.05rem;
  padding: 10px 18px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  animation: toastIn .15s ease-out;
  transition: opacity .3s;
}
.toast.big { font: 700 1.4rem var(--display); background: var(--gold); }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 14, 40, .72); backdrop-filter: blur(3px);
  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 22px 20px;
  box-shadow: 0 30px 70px rgba(0,0,0,.5);
  animation: cardIn .2s ease-out;
}
@keyframes cardIn { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.card.center { text-align: center; }
.card h2 { margin: 0 0 6px; font: 700 1.9rem var(--display); }
.card h3 { margin: 18px 0 8px; font: 600 1.15rem var(--display); color: var(--gold); }
.card p { line-height: 1.5; margin: 0 0 8px; }
.card .big { font-size: 1.15rem; }
.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);
}
.close:hover { color: var(--ink); background: rgba(255,255,255,.15); }
.steps { padding-left: 20px; margin: 4px 0; line-height: 1.6; font-size: 1.02rem; }
.example { margin-bottom: 10px; }
.mini-row { --size: 40px; display: flex; gap: 5px; margin-bottom: 4px; }
.mini-row .tile { width: var(--size); height: var(--size); font-size: 1.3rem; }
.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: 11px 16px; font-weight: 800; font-size: 1.02rem; cursor: pointer;
}
.btn:hover { background: rgba(255,255,255,.13); }
.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: 16px; }

/* result */
.answer-row { --size: 46px; display: flex; justify-content: center; gap: 5px; margin: 12px 0 14px; }
.answer-row .tile { width: var(--size); height: var(--size); font-size: 1.5rem; }
.meaning { text-align: left; background: rgba(0,0,0,.18); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.m-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.m-type { font-style: italic; color: var(--muted); font-weight: 700; }
.m-def { font-size: 1.08rem; font-weight: 700; }
.m-ex { color: var(--muted); font-style: italic; margin-bottom: 6px !important; }
.m-ex b { color: var(--ink); font-style: normal; }
.listen { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: rgba(255,255,255,.06); border-radius: 999px; padding: 5px 12px; font-weight: 800; cursor: pointer; }
.listen:hover { border-color: var(--gold); }
.listen svg { width: 17px; height: 17px; fill: none; stroke: var(--gold); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.listen.small { font-size: .85rem; padding: 4px 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.countdown { margin-top: 12px !important; color: var(--muted); font-weight: 700; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-top: 10px; }
.stat-grid div { background: rgba(0,0,0,.18); border-radius: 12px; padding: 10px 4px; }
.stat-grid b { display: block; font: 700 1.8rem var(--display); color: var(--gold); }
.stat-grid span { font-size: .8rem; color: var(--muted); font-weight: 700; }
.dist { display: grid; gap: 5px; }
.dist .bar-row { display: grid; grid-template-columns: 16px 1fr; gap: 8px; align-items: center; font-weight: 800; }
.dist .bar { background: var(--absent); color: #fff; border-radius: 6px; padding: 3px 8px; text-align: right; min-width: 28px; font-size: .9rem; }
.dist .bar.now { background: var(--correct); }
.note { color: var(--muted-2); font-size: .85rem; margin-top: 14px !important; }

/* settings */
.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row > span:first-child { flex: 1; }
.switch-row small { display: block; color: var(--muted); font-size: .88rem; margin-top: 2px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 46px; height: 26px; border-radius: 999px; background: var(--absent); position: relative; flex-shrink: 0; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch-row input:checked + .switch { background: var(--correct); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--gold); outline-offset: 2px; }
.switch-row input:disabled + .switch { opacity: .45; }

/* confetti */
.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); } }

/* ---------- small screens ---------- */
@media (max-width: 480px) {
  .brand .site { display: none; }
  .brand h1 { font-size: 22px; }
  .topbar { padding-inline: 10px; gap: 7px; }
  .iconbtn { width: 34px; height: 34px; }
  .key { height: 52px; font-size: 1.05rem; border-radius: 6px; }
  .krow { gap: 4px; }
  .seg button { padding: 6px 13px; font-size: .9rem; }
  .card { padding: 20px 16px 16px; }
}
@media (max-height: 700px) {
  .key { height: 46px; }
  .keyboard { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
