:root {
  --bg: #0b0d16; --panel: rgba(20, 22, 38, .8); --fg: #f2f3f8; --muted: #8f93ad; --border: rgba(160, 150, 255, .2);
  --rose: #ff5470; --rose-hi: #ffb3c0; --chalk: #e9e4d4; --mint: #5fd39a; --mint-hi: #b9f5d6;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--fg); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
html { background: var(--bg); }
body { display: flex; flex-direction: column; min-height: 100dvh; background: radial-gradient(ellipse at 50% -10%, #2a1630 0%, transparent 55%), radial-gradient(ellipse at 50% 115%, #141c3a 0%, transparent 60%), var(--bg); user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }

.top { position: relative; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 12px; min-height: 56px; }
.top .left, .top .right { display: flex; gap: 8px; align-items: center; }
.top .right { justify-content: flex-end; }
.top h1 { margin: 0; font-size: clamp(18px, 4.6vw, 26px); letter-spacing: .32em; font-weight: 300; color: var(--rose-hi); white-space: nowrap;
  text-shadow: 0 0 6px var(--rose), 0 0 18px rgba(255, 84, 112, .5); }
.icon { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel); font-weight: 700; display: grid; place-items: center; padding: 0; backdrop-filter: blur(6px); }
.icon.off { opacity: .45; }
.chip { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 7px 14px; font-size: 13px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; backdrop-filter: blur(6px); }
.chip.active, .chip.primary { border-color: var(--rose); color: var(--rose-hi); background: rgba(255, 84, 112, .14); box-shadow: 0 0 12px rgba(255, 84, 112, .25); }

.modes { position: relative; z-index: 2; display: flex; justify-content: center; gap: 6px; padding: 4px 6px; flex-wrap: wrap; }
.modes .chip { color: var(--muted); display: inline-flex; align-items: baseline; gap: 6px; }
.modes .chip small { color: var(--muted); font-size: 11px; }
.modes .chip.active { color: var(--rose-hi); }
.modes .chip.active small { color: inherit; opacity: .8; }
.modes .chip.done small { color: var(--mint); }

main { position: relative; z-index: 2; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 8px max(12px, env(safe-area-inset-bottom)); gap: 12px; min-height: 0; }
.hud { display: flex; gap: 16px; justify-content: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; flex-wrap: wrap; text-transform: uppercase; letter-spacing: .08em; }
.hud b { color: var(--fg); font-size: 17px; margin-left: 4px; letter-spacing: 0; text-transform: none; }
.hud b.low { color: var(--rose); }

.gallows { width: min(52vw, calc(100dvh - 470px), 240px); min-width: 130px; aspect-ratio: 1; overflow: visible; }
.gallows .part { stroke: var(--rose-hi); stroke-width: 5; stroke-linecap: round; fill: none; opacity: 0; filter: drop-shadow(0 0 4px var(--rose)); }
.gallows .part.on { opacity: 1; animation: draw .35s ease-out; }
.gallows .frame .part { stroke: var(--chalk); filter: none; }
.gallows .frame .part.on { opacity: .8; animation-name: fade; }
.gallows.lost .man .part { stroke: var(--rose); }
.gallows.won .man .part { stroke: var(--mint-hi); filter: drop-shadow(0 0 5px var(--mint)); }
.gallows.won .man { animation: hop .6s ease 2; }
.gallows.lost .man { transform-origin: 138px 14px; animation: sway 2.4s ease-in-out infinite; }

.word { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(4px, 1.4vw, 10px); max-width: min(96vw, 640px); min-height: 52px; }
.slot { --w: clamp(24px, calc((min(96vw, 640px) - 80px) / var(--len, 8)), 46px); width: var(--w); height: calc(var(--w) * 1.1); display: grid; place-items: end center; line-height: 1; padding-bottom: 3px;
  border-bottom: 3px solid var(--muted); font-size: calc(var(--w) * .78); font-weight: 700; text-transform: uppercase; color: var(--fg); }
.slot.found { border-color: var(--rose-hi); animation: pop .3s cubic-bezier(.2, 1.6, .4, 1); }
.slot.missed { color: var(--rose); border-color: var(--rose); }
.word.won .slot { border-color: var(--mint); color: var(--mint-hi); text-shadow: 0 0 10px var(--mint); }
.word.shake { animation: shake .35s ease; }

.keys { --gap: 6px; display: flex; flex-direction: column; gap: var(--gap); width: min(calc(100vw - 16px), 560px); }
.keys .row { display: flex; gap: var(--gap); justify-content: center; }
.key { flex: 0 0 calc((100% - 9 * var(--gap)) / 10); height: 46px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); font-weight: 700; font-size: 16px; text-transform: uppercase; padding: 0; touch-action: manipulation; backdrop-filter: blur(6px); transition: background .15s, opacity .15s, transform .1s; }
.key:active { transform: scale(.92); }
.key.hit { background: rgba(95, 211, 154, .22); border-color: var(--mint); color: var(--mint-hi); }
.key.miss { opacity: .3; text-decoration: line-through; }
.key:disabled { cursor: default; }

.tools { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: min(calc(100vw - 16px), 560px); }
.tools button { height: 46px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); font-weight: 600; font-size: 14px; white-space: nowrap; padding: 0 4px; touch-action: manipulation; backdrop-filter: blur(6px); }
.tools button:active { background: rgba(255, 84, 112, .18); }
.tools button:disabled { opacity: .35; cursor: default; }

.toast { position: fixed; top: 120px; left: 50%; transform: translateX(-50%); background: rgba(255, 179, 192, .95); color: #22070d; font-weight: 700; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 5; box-shadow: 0 0 24px rgba(255, 84, 112, .5); }
.toast.show { opacity: 1; }

.dlg { background: rgba(16, 17, 32, .96); color: var(--fg); border: 1px solid var(--border); border-radius: 16px; padding: 22px 24px; width: min(92vw, 420px); box-shadow: 0 30px 90px rgba(0, 0, 0, .6), 0 0 40px rgba(255, 84, 112, .08); }
.dlg::backdrop { background: rgba(2, 4, 12, .65); backdrop-filter: blur(3px); }
.dlg h2 { margin: 0 0 10px; font-weight: 600; letter-spacing: .02em; }
.dlg p, .dlg li { color: #cfd1e2; font-size: 15px; line-height: 1.45; }
.dlg .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.result { text-align: center; }
.result h2 { color: var(--rose-hi); font-size: 30px; letter-spacing: .12em; text-transform: uppercase; text-shadow: 0 0 14px rgba(255, 84, 112, .7); }
.result.won h2 { color: var(--mint-hi); text-shadow: 0 0 14px rgba(95, 211, 154, .7); }
.result .reveal { font-size: 26px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: var(--fg); margin: 6px 0; }
.result .reveal small { display: block; font-size: 12px; letter-spacing: .08em; color: var(--muted); font-weight: 500; }
.result .actions { justify-content: center; }
.stars { display: flex; justify-content: center; gap: 10px; font-size: 44px; margin: 6px 0; min-height: 0; }
.stars span { color: #2c2f4a; transform: scale(.4); opacity: 0; animation: starpop .45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
.stars span.got { color: var(--rose-hi); text-shadow: 0 0 10px var(--rose), 0 0 26px rgba(255, 84, 112, .6); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin: 8px 0 14px; }
.stats b { display: block; font-size: 24px; color: var(--rose-hi); }
.stats span { color: var(--muted); font-size: 12px; }
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.stats-table th, .stats-table td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--border); }
.stats-table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
.stats-table td:not(:first-child) { color: var(--rose-hi); }
.dlg .note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

@keyframes draw { from { opacity: 0; transform: scale(.8); transform-origin: 138px 60px; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { 0% { transform: scale(.4); } 100% { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes hop { 50% { transform: translateY(-8px); } }
@keyframes sway { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
@keyframes starpop { to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } .stars span { opacity: 1; transform: none; } }
@media (max-width: 480px) { .top { padding: 8px; gap: 6px; } .top h1 { font-size: 16px; letter-spacing: .2em; } .keys { --gap: 4px; } .key { height: 44px; font-size: 15px; } .hud { gap: 12px; font-size: 12px; } }
