:root {
  --bg: #faf8ff;
  --card: #ffffff;
  --line: #e6e1f2;
  --line-2: #cfc6e6;
  --ink: #1f1a33;
  --ink-2: #5d5478;
  --ink-3: #958cb0;
  --accent: #6d28d9;
  --accent-2: #5b21b6;
  --correct: #22a06b;
  --present: #e8a317;
  --absent: #8d8aa0;
  --tile-empty: #ffffff;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(60, 30, 120, 0.10);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 1.15rem; margin-bottom: 8px; }
h3 { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-3); margin: 0 0 6px; }
code { font-family: var(--mono); background: #efeaff; border-radius: 5px; padding: 1px 5px; }
.hint { color: var(--ink-3); font-size: 0.8rem; margin: 4px 0 0; line-height: 1.4; }

.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 12px 24px; background: rgba(255, 255, 255, 0.9); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.3rem; letter-spacing: 0.02em; }
.brand p { margin: 0; font-size: 0.78rem; color: var(--ink-3); }
.brand-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 900; font-size: 1.5rem; }
.topbar-actions { display: flex; gap: 4px; margin-left: auto; }

.btn { appearance: none; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; line-height: 1.2; transition: background 0.15s, transform 0.1s; }
.btn:hover { background: #f4f0ff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; border-color: transparent; font-size: 1.05rem; padding: 6px 10px; }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn.toggle[aria-pressed="false"] { opacity: 0.5; }

.page { max-width: 720px; margin: 0 auto; padding: 18px 16px 30px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; }
.seg { display: inline-flex; background: #efeaff; border-radius: 12px; padding: 4px; gap: 2px; }
.seg-btn { border: none; background: none; font: inherit; font-weight: 600; color: var(--ink-2); padding: 7px 14px; border-radius: 9px; cursor: pointer; }
.seg-btn.active { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.subtitle { margin: 0; font-size: 0.85rem; color: var(--ink-3); text-align: center; min-height: 1.3em; }

.board-wrap { width: 100%; display: flex; justify-content: center; overflow-x: auto; padding: 4px; }
.board { display: grid; gap: 6px; --tile: 52px; }
.row { display: grid; gap: 6px; grid-auto-flow: column; }
.row.shake { animation: shake 0.4s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.tile { width: var(--tile); height: var(--tile); display: grid; place-items: center; font-family: var(--mono); font-weight: 800; font-size: calc(var(--tile) * 0.5); border: 2px solid var(--line-2); border-radius: 8px; background: var(--tile-empty); color: var(--ink); transition: transform 0.1s; }
.tile.filled { border-color: var(--ink-3); animation: pop 0.12s ease; }
@keyframes pop { 50% { transform: scale(1.08); } }
.tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.tile.absent { background: var(--absent); border-color: var(--absent); color: #fff; }
.tile.flip { animation: flip 0.5s ease; }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
.tile.ghost { color: var(--ink-3); border-style: dashed; }
.tile.bounce { animation: bounce 0.6s ease; }
@keyframes bounce { 30% { transform: translateY(-10px); } 60% { transform: translateY(2px); } }

.banner { background: var(--card); border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 16px; text-align: center; box-shadow: var(--shadow); animation: fade 0.3s ease; width: 100%; max-width: 520px; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.banner .big { font-size: 1.3rem; font-weight: 800; }
.banner .big.win { color: var(--correct); } .banner .big.lose { color: #c62828; }
.banner p { margin: 4px 0 10px; color: var(--ink-2); }
.banner .answer { font-family: var(--mono); font-weight: 800; letter-spacing: 0.1em; color: var(--ink); }
.banner .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.keypad { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 520px; margin-top: 6px; }
.krow { display: flex; gap: 6px; justify-content: center; }
.key { flex: 1; min-width: 0; height: 52px; border: none; border-radius: 8px; background: #e4def5; color: var(--ink); font: inherit; font-weight: 700; font-size: 1.05rem; cursor: pointer; transition: background 0.15s, transform 0.08s; }
.key:hover { background: #d6cff0; }
.key:active { transform: scale(0.96); }
.key.op { background: #d9cdfa; }
.key.wide { flex: 1.6; font-size: 0.9rem; }
.key.correct { background: var(--correct); color: #fff; } .key.present { background: var(--present); color: #fff; } .key.absent { background: var(--absent); color: #fff; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.helper { width: 100%; max-width: 520px; margin-top: 8px; }
.helper-row { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.helper-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cands { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
.cand-list { margin-top: 10px; font-family: var(--mono); font-size: 0.8rem; color: var(--ink-2); line-height: 1.7; max-height: 140px; overflow: auto; }

.dialog { border: 1px solid var(--line-2); border-radius: 16px; background: var(--card); color: var(--ink); max-width: 480px; width: calc(100% - 32px); padding: 0; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(31, 26, 51, 0.5); }
.dialog form { padding: 22px; }
.dialog p, .dialog li { line-height: 1.5; font-size: 0.92rem; color: var(--ink-2); }
.dialog ul { padding-left: 4px; list-style: none; }
.dialog li { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.sw { display: inline-block; width: 16px; height: 16px; border-radius: 4px; }
.sw.correct { background: var(--correct); } .sw.present { background: var(--present); } .sw.absent { background: var(--absent); }
.example { display: flex; gap: 4px; margin: 10px 0; --tile: 38px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.stat-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 16px; }
.stat-tiles div { text-align: center; }
.stat-tiles b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat-tiles span { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.dist { display: flex; flex-direction: column; gap: 4px; }
.dist div { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: center; font-size: 0.82rem; }
.dist i { display: block; height: 20px; min-width: 22px; background: var(--absent); border-radius: 4px; color: #fff; font-style: normal; font-weight: 700; text-align: right; padding-right: 6px; line-height: 20px; }
.dist i.hl { background: var(--correct); }

.toasts { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 0.9rem; animation: toast-in 0.2s ease; max-width: 360px; text-align: center; }
.toast.out { animation: toast-out 0.3s ease forwards; }
@keyframes toast-in { from { transform: translateY(-10px); opacity: 0; } }
@keyframes toast-out { to { opacity: 0; } }
.footer { text-align: center; font-size: 0.8rem; color: var(--ink-3); padding: 10px 24px 30px; }
[hidden] { display: none !important; }
@media (max-width: 560px) { .board { --tile: 40px; } .brand p { display: none; } .topbar { padding: 10px 12px; } .key { height: 46px; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
