:root {
  --bg: #14112B; --bg2: #1E1A3D; --card: #262150; --card2: #2F2963; --line: #3A3370;
  --ink: #F4F2FF; --soft: #A9A3D6; --brand: #FF5C8A; --brand2: #FFB547; --ok: #2BD99B; --bad: #FF5470; --blue: #4DA3FF;
  --r: 18px; --shadow: 0 8px 24px rgba(0,0,0,.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); min-height: 100%; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); overscroll-behavior-y: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.boot { text-align: center; margin-top: 40vh; font-weight: 800; font-size: 28px; opacity: .6; }
#app { max-width: 720px; margin: 0 auto; padding: 12px 16px 40px; }

/* top bar */
.top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.top h1 { font-size: 22px; margin: 0; flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.top h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { width: 34px; height: 34px; border-radius: 10px; flex: none; }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; background: var(--card); display: grid; place-items: center; font-size: 20px; flex: none; }
.pill { background: var(--card); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 14px; white-space: nowrap; }

/* home */
.hero { background: linear-gradient(135deg, #FF5C8A, #8B5CFF); border-radius: 24px; padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; }
.hero b { font-size: 20px; display: block; }
.hero .go { margin-left: auto; background: #fff; color: #2A1B5C; font-weight: 800; padding: 10px 16px; border-radius: 999px; white-space: nowrap; }
.sec { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--soft); margin: 18px 4px 10px; font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.tile { position: relative; background: var(--card); border-radius: var(--r); padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 132px; box-shadow: var(--shadow); transition: transform .12s; overflow: hidden; }
.tile:active { transform: scale(.97); }
.tile .ic { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 28px; font-weight: 900; }
.tile b { font-size: 17px; }
.tile small { color: var(--soft); font-size: 13px; line-height: 1.3; }
.tile .best { position: absolute; top: 12px; right: 12px; font-size: 12px; color: var(--brand2); font-weight: 700; }
.tile .new { position: absolute; top: 12px; right: 12px; font-size: 11px; background: var(--brand); padding: 2px 8px; border-radius: 99px; font-weight: 800; }
.foot { margin-top: 28px; text-align: center; color: var(--soft); font-size: 13px; }
.foot a { color: var(--soft); }

/* game screen */
.stage { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stats { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.stat { background: var(--card); border-radius: 14px; padding: 6px 14px; text-align: center; min-width: 78px; }
.stat small { display: block; font-size: 11px; color: var(--soft); text-transform: uppercase; letter-spacing: .06em; }
.stat b { font-size: 20px; }
.btn { background: var(--brand); color: #fff; font-weight: 800; padding: 12px 22px; border-radius: 999px; box-shadow: 0 4px 0 rgba(0,0,0,.25); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn.ghost { background: var(--card2); }
.btn.ok { background: var(--ok); color: #082A1E; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.hint { color: var(--soft); font-size: 14px; text-align: center; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip { background: var(--card); padding: 7px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.chip[aria-pressed="true"] { background: var(--blue); color: #fff; }
canvas.game { width: 100%; max-width: 480px; border-radius: 20px; background: var(--bg2); touch-action: none; display: block; }

/* modal */
#overlay:empty { display: none; }
#overlay { position: fixed; inset: 0; background: rgba(8,6,20,.72); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--bg2); border-radius: 26px; padding: 24px 20px; width: min(100%, 380px); text-align: center; box-shadow: var(--shadow); animation: pop .22s ease-out; }
.modal h2 { margin: 4px 0 6px; font-size: 26px; }
.modal .big { font-size: 46px; font-weight: 900; margin: 6px 0; }
.modal p { color: var(--soft); margin: 6px 0 14px; }
.modal .row { margin-top: 10px; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
.toast { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-weight: 700; z-index: 60; animation: pop .18s; }

/* ad slots (empty until ads are switched on) */
.ad-slot { width: 100%; min-height: 0; }

/* 2048 */
.g2048 { --n: 4; width: min(100%, 420px); aspect-ratio: 1; background: #3A3370; border-radius: 16px; padding: 8px; position: relative; touch-action: none; }
.g2048 .cells, .g2048 .tiles { position: absolute; inset: 8px; display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr); gap: 8px; }
.g2048 .cells i { background: rgba(255,255,255,.06); border-radius: 10px; }
.g2048 .t { border-radius: 10px; display: grid; place-items: center; font-weight: 900; font-size: clamp(18px, 7vw, 34px); transition: transform .1s; }
.g2048 .t.pop { animation: pop .15s; }
.g2048 .t.merge { animation: merge .18s; }
@keyframes merge { 50% { transform: scale(1.15); } }

/* word game */
.wboard { display: grid; grid-template-rows: repeat(6, 1fr); gap: 6px; width: min(100%, 330px); }
.wrow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.wrow.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.wcell { aspect-ratio: 1; border: 2px solid var(--line); border-radius: 8px; display: grid; place-items: center; font-weight: 900; font-size: 28px; text-transform: uppercase; }
.wcell.filled { border-color: var(--soft); }
.wcell.g, .key.g { background: #2BB673; border-color: #2BB673; }
.wcell.y, .key.y { background: #E2A63B; border-color: #E2A63B; }
.wcell.x, .key.x { background: #3A3555; border-color: #3A3555; }
.wcell.flip { animation: flip .35s; }
@keyframes flip { 50% { transform: rotateX(90deg); } }
.keys { width: min(100%, 520px); display: flex; flex-direction: column; gap: 6px; }
.krow { display: flex; gap: 5px; justify-content: center; }
.key { flex: 1; max-width: 46px; height: 54px; background: #5A5390; border-radius: 8px; font-weight: 800; text-transform: uppercase; font-size: 15px; }
.key.wide { max-width: 72px; flex: 1.5; font-size: 12px; }

/* sudoku */
.sud { display: grid; grid-template-columns: repeat(9, 1fr); width: min(100%, 440px); aspect-ratio: 1; background: var(--line); gap: 1px; border: 3px solid #8E86D6; border-radius: 8px; overflow: hidden; }
.sud button { background: var(--bg2); font-size: clamp(16px, 5vw, 26px); font-weight: 700; display: grid; place-items: center; }
.sud button.given { color: var(--ink); font-weight: 900; }
.sud button.user { color: var(--blue); }
.sud button.bad { color: var(--bad); }
.sud button.peer { background: #241F49; }
.sud button.same { background: #3B3377; }
.sud button.sel { background: #514799; }
.sud button.c3 { border-right: 2px solid #8E86D6; }
.sud button.r3 { border-bottom: 2px solid #8E86D6; }
.sud button small { font-size: 9px; color: var(--soft); display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; height: 100%; line-height: 1; place-items: center; }
.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; width: min(100%, 440px); }
.pad button { background: var(--card2); border-radius: 10px; height: 50px; font-size: 22px; font-weight: 800; }
.pad button.done { opacity: .3; }

/* ludo & chess */
.board-wrap { width: min(100%, 460px); }
.chess { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 3px solid #8E86D6; }
.chess button { aspect-ratio: 1; display: grid; place-items: center; font-size: clamp(22px, 8vw, 44px); line-height: 1; position: relative; }
.chess .l { background: #E9E3FF; } .chess .d { background: #8E7FD8; }
.chess .sel { box-shadow: inset 0 0 0 4px var(--brand2); }
.chess .last { box-shadow: inset 0 0 0 999px rgba(255,181,71,.35); }
.chess .chk { box-shadow: inset 0 0 0 999px rgba(255,84,112,.6); }
.chess .dot::after { content: ''; width: 28%; height: 28%; border-radius: 50%; background: rgba(20,17,43,.35); position: absolute; }
.chess .cap::after { content: ''; position: absolute; inset: 6%; border-radius: 50%; border: 4px solid rgba(20,17,43,.35); }
.pc { filter: drop-shadow(0 1px 0 rgba(0,0,0,.4)); }
.pc.w { color: #fff; -webkit-text-stroke: 1.2px #1A1440; }
.pc.b { color: #1A1440; }
