:root {
  --bg: #121213; --fg: #f3f3f3; --muted: #9a9a9e; --tile: #3a3a3c; --border: #565758;
  --key: #818384; --c: #4caf50; --p: #c9a227; --a: #3a3a3c; --accent: #4caf50;
  --tile-size: clamp(44px, 11vw, 62px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { display: flex; flex-direction: column; min-height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; }

.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 12px; border-bottom: 1px solid #2a2a2c; }
.top .right { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.icon { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: transparent; font-weight: 700; }
.chip { border: 1px solid var(--border); background: #1e1e20; border-radius: 999px; padding: 6px 12px; font-size: 13px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { margin: 0; display: flex; gap: 3px; font-size: 0; }
.logo .t, .demo .t { width: 26px; height: 26px; font-size: 16px; }

.t { display: inline-grid; place-items: center; width: var(--tile-size); height: var(--tile-size); border: 2px solid var(--tile); font-weight: 800; font-size: calc(var(--tile-size) * 0.5); text-transform: uppercase; color: var(--fg); user-select: none; }
.t.filled { border-color: var(--border); animation: pop .09s ease; }
.t.c, .t.p, .t.a { border-color: transparent; }
.t.c { background: var(--c); } .t.p { background: var(--p); } .t.a { background: var(--a); }

.modes { display: flex; justify-content: center; gap: 6px; padding: 10px 0 2px; }
.mode { background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; color: var(--muted); font-size: 14px; }
.mode.active { color: var(--fg); border-color: var(--accent); background: rgba(76,175,80,.12); }

main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 8px 0 max(10px, env(safe-area-inset-bottom)); gap: 8px; }
.board { display: grid; grid-template-rows: repeat(6, var(--tile-size)); gap: 5px; margin: auto 0; }
.row5 { display: grid; grid-template-columns: repeat(5, var(--tile-size)); gap: 5px; }
.row5.shake { animation: shake .4s; }
.row5.win .t { animation: bounce .6s ease; }
.row5.win .t:nth-child(2) { animation-delay: .08s } .row5.win .t:nth-child(3) { animation-delay: .16s }
.row5.win .t:nth-child(4) { animation-delay: .24s } .row5.win .t:nth-child(5) { animation-delay: .32s }
.t.flip { animation: flip .5s ease forwards; }

.toast { position: fixed; top: 110px; left: 50%; transform: translateX(-50%); background: #f3f3f3; color: #121213; font-weight: 700; padding: 10px 16px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 5; }
.toast.show { opacity: 1; }

.keyboard { display: flex; flex-direction: column; gap: 6px; width: min(100vw - 12px, 500px); padding: 0 4px; }
.krow { display: flex; justify-content: center; gap: 5px; }
.key { flex: 1; height: 56px; max-width: 46px; border: 0; border-radius: 5px; background: var(--key); color: #fff; font-weight: 700; font-size: 15px; text-transform: uppercase; display: grid; place-items: center; }
.key.wide { flex: 1.6; max-width: 76px; font-size: 12px; }
.key.c { background: var(--c); } .key.p { background: var(--p); } .key.a { background: #27272a; color: #8a8a8e; }
.key:active { filter: brightness(1.2); }

.dlg { background: #1b1b1d; color: var(--fg); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; width: min(92vw, 420px); }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg h2 { margin: 0 0 10px; } .dlg h3 { margin: 16px 0 6px; font-size: 15px; }
.dlg p { line-height: 1.45; margin: 8px 0; }
.demo { display: flex; gap: 4px; margin: 10px 0 2px; }
.demo .t { width: 34px; height: 34px; font-size: 18px; }
.btn { background: var(--accent); color: #0b0b0c; border: 0; border-radius: 8px; padding: 10px 18px; font-weight: 700; }
.btn.alt { background: #2c2c2f; color: var(--fg); }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 6px 0 0; }
.row { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 14px; }
.answer { font-size: 28px; font-weight: 800; letter-spacing: .25em; text-transform: uppercase; margin: 6px 0 0 !important; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; }
.stats b { display: block; font-size: 28px; } .stats span { font-size: 12px; color: var(--muted); }
.dist { display: grid; gap: 4px; }
.dbar { display: grid; grid-template-columns: 14px 1fr; gap: 6px; align-items: center; font-size: 13px; }
.dbar i { display: block; background: var(--tile); color: #fff; font-style: normal; font-weight: 700; padding: 2px 6px; text-align: right; min-width: 22px; border-radius: 2px; }
.dbar.hi i { background: var(--c); }

@keyframes pop { from { transform: scale(.85) } to { transform: scale(1) } }
@keyframes shake { 10%,90% { transform: translateX(-2px) } 20%,80% { transform: translateX(4px) } 30%,50%,70% { transform: translateX(-6px) } 40%,60% { transform: translateX(6px) } }
@keyframes flip { 0% { transform: rotateX(0) } 50% { transform: rotateX(-90deg) } 100% { transform: rotateX(0) } }
@keyframes bounce { 0%,20% { transform: translateY(0) } 40% { transform: translateY(-22px) } 60% { transform: translateY(4px) } 80% { transform: translateY(-6px) } 100% { transform: translateY(0) } }
@media (max-height: 640px) { :root { --tile-size: clamp(36px, 9vw, 48px); } .key { height: 46px; } }
