/* Word Guess — one-screen game: header, a board that scales to the space left, a keyboard at the bottom. */
:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --fg: #1d2433;
  --muted: #667089;
  --line: #cfd6e4;
  --key: #dfe5f0;
  --key-fg: #1d2433;
  --correct: #3f9a4d;
  --present: #e2b02c;
  --absent: #8a93a6;
  --absent-key: #b9c0ce;
  --on-tile: #ffffff;
  --accent: #3b5bdb;
  --danger: #c92a2a;
  --shadow: 0 1px 0 rgba(29, 36, 51, .18);
  --display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --body: "Nunito", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141822; --surface: #1d2230; --fg: #eef1f7; --muted: #9aa3b8; --line: #3a4256;
    --key: #3a4256; --key-fg: #eef1f7; --correct: #4ea85b; --present: #d4a42a; --absent: #4a5266;
    --absent-key: #262c3a; --accent: #7d97ff; --danger: #ff8787; --shadow: 0 1px 0 rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 16px;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- game page ---------- */
body.game {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  overscroll-behavior: none; overflow: hidden; position: fixed; inset: 0;
}
.app {
  height: 100%; display: flex; flex-direction: column; gap: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px 8px; max-width: 760px; margin: 0 auto;
}
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-family: var(--display); font-weight: 700; font-size: 1.7rem; margin: 0; letter-spacing: .01em; }
.brand .sq { display: inline-block; width: .9em; height: .9em; border-radius: 4px; margin-right: 3px; vertical-align: -0.08em; }
.sq.correct { background: var(--correct); } .sq.present { background: var(--present); }
.status { font-size: .95rem; color: var(--muted); font-weight: 700; text-align: right; min-width: 0; }

.board-wrap { flex: 1 1 auto; min-height: 120px; container-type: size; display: grid; place-items: center; }
.board {
  --gap: 7px;
  --tile: min(calc((100cqw - var(--gap) * (var(--cols) - 1)) / var(--cols)),
              calc((100cqh - var(--gap) * (var(--rows) - 1)) / var(--rows)), 92px);
  display: grid; gap: var(--gap); grid-template-rows: repeat(var(--rows), var(--tile));
}
.row { display: grid; gap: var(--gap); grid-template-columns: repeat(var(--cols), var(--tile)); }
.row.shake { animation: shake .45s; }
.tile {
  display: grid; place-items: center; border: 2px solid var(--line); border-radius: 8px;
  background: var(--surface); font-family: var(--display); font-weight: 700;
  font-size: calc(var(--tile) * .55); line-height: 1; text-transform: uppercase;
}
.tile.filled { border-color: var(--muted); animation: pop .12s; }
.tile.correct, .tile.present, .tile.absent { color: var(--on-tile); border-color: transparent; }
.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent  { background: var(--absent); }
.tile.flip { animation: flip .5s ease both; }
.row.win .tile { animation: hop .5s ease both; }

.keyboard { display: grid; gap: 8px; flex: 0 0 auto; }
.krow { display: flex; gap: 6px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; max-width: 64px; height: clamp(50px, 8.5vh, 68px);
  border: 0; border-radius: 8px; background: var(--key); color: var(--key-fg);
  font-family: var(--display); font-weight: 600; font-size: clamp(1.1rem, 3.2vw, 1.55rem);
  box-shadow: var(--shadow); cursor: pointer; padding: 0; text-transform: uppercase;
  transition: background-color .2s, color .2s, opacity .2s;
}
.key.wide { flex-grow: 1.6; max-width: 104px; font-size: clamp(.85rem, 2.2vw, 1.05rem); letter-spacing: .04em; }
.key:active { transform: translateY(1px); filter: brightness(.92); }
.key.correct { background: var(--correct); color: var(--on-tile); }
.key.present { background: var(--present); color: var(--on-tile); }
.key.absent  { background: var(--absent-key); color: var(--muted); opacity: .55; }

.toast {
  position: fixed; left: 50%; top: calc(70px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  font-weight: 800; font-size: 1.05rem; z-index: 20; pointer-events: none; max-width: calc(100% - 40px); text-align: center;
}
[hidden] { display: none !important; }
.grown { align-self: center; background: none; border: 0; color: var(--muted); font: 700 .8rem var(--body);
  letter-spacing: .06em; text-transform: uppercase; padding: 6px 10px; cursor: pointer; position: relative; }
.grown .fill { position: absolute; left: 10px; right: 10px; bottom: 2px; height: 2px; background: var(--accent);
  transform: scaleX(0); transform-origin: left; }
.grown.holding .fill { transform: scaleX(1); transition: transform 1.2s linear; }

.end { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.end p { margin: 0; font-weight: 800; font-size: 1.1rem; }

canvas#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 25; width: 100%; height: 100%; }

/* ---------- shared controls ---------- */
.btn { font: 800 1rem var(--body); border: 0; border-radius: 10px; padding: 12px 18px; cursor: pointer;
  background: var(--key); color: var(--key-fg); text-decoration: none; display: inline-block; }
.btn.primary { background: var(--accent); color: #fff; }
.key:focus-visible, .btn:focus-visible, .field:focus-visible, .grown:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- admin page ---------- */
body.admin { display: grid; place-items: start center; min-height: 100%;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.panel { background: var(--surface); border-radius: 16px; width: min(460px, 100%); margin-block: 40px;
  padding: 24px; display: grid; gap: 16px; box-shadow: 0 10px 30px rgba(20, 24, 34, .08); }
.panel h2 { font-family: var(--display); margin: 0; font-size: 1.35rem; }
.panel p { margin: 0; color: var(--muted); line-height: 1.45; }
.stack { display: grid; gap: 14px; }
.panel label { font-weight: 800; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: grid; gap: 6px; }
.field { font: 700 1.4rem var(--display); letter-spacing: .2em; text-transform: uppercase; padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); width: 100%; }
.field.plain { letter-spacing: normal; text-transform: none; font: 700 1.1rem var(--body); }
select.field { letter-spacing: 0; font-size: 1.1rem; }
.split { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.current { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--bg); padding: 10px 12px; border-radius: 10px; }
.current b { font-family: var(--display); letter-spacing: .15em; font-size: 1.15rem; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.row-actions form { margin: 0; }
.msg { font-weight: 700; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.msg.err { color: var(--danger) !important; }
.msg.ok { color: var(--correct) !important; }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
@keyframes hop { 40% { transform: translateY(-22%); } 70% { transform: translateY(4%); } }
@media (prefers-reduced-motion: reduce) { .tile, .row, .tile.flip, .row.win .tile { animation: none !important; } }
@media (max-height: 560px) { .brand { font-size: 1.3rem; } .keyboard { gap: 6px; } }
