/* ============================================================ Twofold */
:root {
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --radius: 16px;
  --tile-radius: 12%;
  --ease: cubic-bezier(.2, .8, .2, 1);
  /* tile ramp (Midnight) */
  --c2: #e9edf7; --f2: #3a4060;
  --c4: #d1ddfb; --f4: #2c3866;
  --c8: #8fd3ff; --f8: #0d2a42;
  --c16: #58b2ff; --f16: #fff;
  --c32: #4a82ff; --f32: #fff;
  --c64: #6a5cff; --f64: #fff;
  --c128: #9a5cff; --f128: #fff;
  --c256: #c34fe6; --f256: #fff;
  --c512: #ec4fa4; --f512: #fff;
  --c1024: #ff6464; --f1024: #fff;
  --c2048: #ffb627; --f2048: #3a2600;
  --c4096: #2bd4a6; --f4096: #032b21;
  --c8192: #19b7ff; --f8192: #fff;
  --glow2048: rgba(255, 182, 39, .55);
}

[data-theme="dark"] {
  --bg: #0d1020; --bg2: #171b36; --panel: #181c33; --panel2: #20254a; --line: #2a3060;
  --text: #eef1ff; --muted: #8e95c0; --accent: #7c6cff; --accent2: #4cc9f0; --good: #2bd4a6; --bad: #ff6b81;
  --board: #1c2140; --cell: #262c52; --btn: #262c52; --btn-text: #e8ebff; --shadow: 0 10px 30px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #eef1f8; --bg2: #e2e7f5; --panel: #ffffff; --panel2: #f2f4fb; --line: #dde2f0;
  --text: #1d2140; --muted: #6b7193; --accent: #5b4dff; --accent2: #0ea5e9; --good: #10b981; --bad: #e11d48;
  --board: #cfd6ea; --cell: #e1e6f3; --btn: #ffffff; --btn-text: #1d2140; --shadow: 0 10px 30px rgba(40,50,100,.12);
  --c2: #ffffff; --c4: #e6ecff;
}
[data-theme="neon"] {
  --bg: #05050c; --bg2: #0c0a1f; --panel: #0e0c22; --panel2: #15123a; --line: #2b2470;
  --text: #f4f0ff; --muted: #9b93d6; --accent: #ff2bd6; --accent2: #00f0ff; --good: #39ff88; --bad: #ff3864;
  --board: #0a0918; --cell: #131130; --btn: #15123a; --btn-text: #f4f0ff; --shadow: 0 0 30px rgba(255,43,214,.15);
}
[data-theme="sunset"] {
  --bg: #1d0f24; --bg2: #3a1531; --panel: #2a1430; --panel2: #3a1b40; --line: #55264f;
  --text: #fff1ea; --muted: #d3a3b5; --accent: #ff7a59; --accent2: #ffc26b; --good: #7ee0a8; --bad: #ff5e7e;
  --board: #33183a; --cell: #45204b; --btn: #45204b; --btn-text: #fff1ea; --shadow: 0 10px 30px rgba(0,0,0,.4);
  --c2: #fde7dc; --f2: #5a2b3b; --c4: #fbd0b8; --f4: #5a2b3b; --c8: #ffb48a; --f8: #4a1d22; --c16: #ff9466;
  --c32: #ff7158; --c64: #f2545b; --c128: #e04078; --c256: #c43491; --c512: #9b30a8; --c1024: #7136b8;
  --c2048: #ffd166; --f2048: #4a2a00; --c4096: #ff4d8d; --f4096: #fff; --c8192: #5b2bd6;
}
[data-theme="aurora"] {
  --bg: #04161a; --bg2: #072a2e; --panel: #0a2328; --panel2: #0f3137; --line: #1a4a50;
  --text: #e9fffb; --muted: #86b9b2; --accent: #2de0b0; --accent2: #7ad7ff; --good: #2de0b0; --bad: #ff7a90;
  --board: #0c2b31; --cell: #133940; --btn: #133940; --btn-text: #e9fffb; --shadow: 0 10px 30px rgba(0,0,0,.4);
  --c2: #e2fbf5; --f2: #1c4a44; --c4: #c2f4e8; --f4: #1c4a44; --c8: #8debd5; --f8: #083a32; --c16: #4fd8bb; --f16: #053129;
  --c32: #27c0b4; --c64: #1ea2c0; --c128: #2f80d6; --c256: #5468e6; --c512: #7d57e8; --c1024: #a84ddd;
  --c2048: #f6e05e; --f2048: #3b3000; --c4096: #ff8fd1; --f4096: #3a0628; --c8192: #ffffff; --f8192: #0b3b42;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--text); background: var(--bg);
  background-image: radial-gradient(1200px 600px at 50% -10%, var(--bg2), transparent 70%);
  background-attachment: fixed; overscroll-behavior: none; transition: background-color .3s;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

#app { max-width: 560px; margin: 0 auto; min-height: 100%; padding: max(14px, env(safe-area-inset-top)) 16px 24px; }
.screen { display: none; animation: screenIn .28s var(--ease); }
.screen.active { display: block; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- generic controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 14px;
  background: var(--btn); color: var(--btn-text); font-weight: 700; letter-spacing: .01em; transition: transform .12s, filter .15s, opacity .15s;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.18); }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 11px; }
.icon-btn { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--btn); font-size: 18px; transition: transform .12s; box-shadow: inset 0 -2px 0 rgba(0,0,0,.18); }
.icon-btn:active { transform: scale(.93); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.center { text-align: center; }
.section-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 22px 4px 10px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; background: var(--panel2); font-size: 13px; font-weight: 700; }
.chip.warn { background: color-mix(in srgb, var(--bad) 22%, var(--panel2)); color: var(--text); }
.chip.good { background: color-mix(in srgb, var(--good) 22%, var(--panel2)); }
.seg { display: flex; background: var(--panel2); padding: 4px; border-radius: 14px; gap: 4px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--muted); transition: background .2s, color .2s; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.pills { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.pills button { white-space: nowrap; padding: 7px 13px; border-radius: 999px; background: var(--panel2); font-size: 13px; font-weight: 700; color: var(--muted); }
.pills button.on { background: var(--accent); color: #fff; }
.field { width: 100%; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel2); outline: none; }
.field:focus { border-color: var(--accent); }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar h2 { margin: 0; font-size: 20px; flex: 1; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font-size: 18px; }
.topbar .title small { color: var(--muted); font-weight: 600; }

/* ---------- menu */
.all-games-link { display: inline-block; margin: 0 0 10px -8px; padding: 8px; color: var(--muted); text-decoration: none; font-weight: 700; }
.all-games-link:hover { color: var(--text); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 50px; height: 50px; border-radius: 15px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 5px; background: var(--board); }
.logo i { border-radius: 5px; }
.logo i:nth-child(1) { background: var(--c2048); } .logo i:nth-child(2) { background: var(--c512); }
.logo i:nth-child(3) { background: var(--c64); } .logo i:nth-child(4) { background: var(--c8); }
.brand h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.brand h1 span { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.profile-chip { margin-left: auto; display: flex; align-items: center; gap: 10px; background: var(--panel); padding: 6px 12px 6px 6px; border-radius: 16px; box-shadow: var(--shadow); }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: var(--panel2); flex-shrink: 0; }
.profile-chip .meta { text-align: left; line-height: 1.15; }
.profile-chip .meta b { font-size: 14px; display: block; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-chip .meta small { color: var(--muted); font-size: 12px; font-weight: 700; }
.xpbar { height: 4px; background: var(--panel2); border-radius: 4px; margin-top: 4px; overflow: hidden; width: 90px; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.banner { margin-top: 16px; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 30%, var(--panel)), var(--panel)); box-shadow: var(--shadow); }
.banner .big { font-size: 28px; }
.banner b { display: block; }
.hero { margin-top: 16px; position: relative; overflow: hidden; border-radius: 22px; padding: 22px; color: #fff; text-align: left; width: 100%;
  background: linear-gradient(135deg, var(--c128), var(--c32) 55%, var(--c8)); box-shadow: var(--shadow); transition: transform .15s; }
.hero:active { transform: scale(.985); }
.hero h3 { margin: 0 0 4px; font-size: 26px; }
.hero p { margin: 0; opacity: .9; font-weight: 600; }
.hero .play { margin-top: 16px; display: inline-flex; padding: 10px 18px; border-radius: 12px; background: rgba(255,255,255,.22); font-weight: 800; }
.hero .deco { position: absolute; right: -16px; top: -10px; display: grid; grid-template-columns: repeat(3, 42px); gap: 6px; transform: rotate(14deg); opacity: .5; }
.hero .deco i { height: 42px; border-radius: 10px; background: rgba(255,255,255,.35); }
.hero .deco i:nth-child(3n) { background: rgba(255,255,255,.6); }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode { text-align: left; padding: 15px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); position: relative; transition: transform .14s; min-height: 108px; display: flex; flex-direction: column; }
.mode:active { transform: scale(.97); }
.mode .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 19px; margin-bottom: 10px; color: #fff; }
.mode b { font-size: 16px; }
.mode small { color: var(--muted); font-weight: 600; font-size: 12.5px; margin-top: 2px; }
.mode .badge { position: absolute; top: 12px; right: 12px; }
.navrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.navrow button { background: var(--panel); border-radius: 15px; padding: 14px 6px; box-shadow: var(--shadow); font-weight: 700; font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.navrow button span { font-size: 22px; }
.continue { margin-top: 16px; display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 12px 14px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.continue .mini { width: 64px; flex-shrink: 0; }

/* ---------- game HUD */
.hud { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.stat { background: var(--panel); border-radius: 14px; padding: 9px 10px; text-align: center; position: relative; box-shadow: var(--shadow); }
.stat label { display: block; font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; display: block; line-height: 1.25; }
.stat .gain { position: absolute; left: 0; right: 0; top: 18px; font-style: normal; font-weight: 900; color: var(--good); pointer-events: none; opacity: 0; }
.stat .gain.go { animation: gainUp .7s var(--ease); }
@keyframes gainUp { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-26px); } }
.stat.target b { display: inline-flex; padding: 0 10px; border-radius: 8px; font-size: 18px; margin-top: 2px; }
.hud2 { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 12px 0 8px; min-height: 30px; }
.hud2 .chip { font-variant-numeric: tabular-nums; }
.hud2 .chip.pulse { animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.progress { height: 8px; border-radius: 6px; background: var(--panel2); overflow: hidden; margin: 2px 2px 14px; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .4s var(--ease); border-radius: 6px; }

/* ---------- board */
.board-wrap { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.board { position: relative; width: min(100%, calc(100vh - 270px)); min-width: 260px; aspect-ratio: 1; margin: 0 auto; background: var(--board); border-radius: 18px; box-shadow: var(--shadow); --gap: 10px; --cs: 60px; }
.board .cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), var(--cs)); grid-auto-rows: var(--cs); gap: var(--gap); padding: var(--gap); }
.board .cell, .mini .cell { background: var(--cell); border-radius: var(--tile-radius); }
.board .tiles { position: absolute; inset: 0; }
.tile { position: absolute; left: 0; top: 0; width: var(--cs); height: var(--cs); border-radius: var(--tile-radius); display: grid; place-items: center;
  font-weight: 900; letter-spacing: -.02em; transition: transform 110ms ease-out; will-change: transform; font-variant-numeric: tabular-nums; }
.tile span { display: block; border-radius: inherit; width: 100%; height: 100%; display: grid; place-items: center; box-shadow: inset 0 -4px 0 rgba(0,0,0,.12), 0 3px 8px rgba(0,0,0,.18); }
.no-anim .tile { transition: none !important; }
.tile.spawn span { animation: spawn .18s var(--ease); }
.tile.pop span { animation: pop .2s var(--ease); }
.tile.smash span { animation: smash .26s ease-in forwards; }
@keyframes spawn { from { transform: scale(0); opacity: 0; } }
@keyframes pop { 0% { transform: scale(.7); } 55% { transform: scale(1.16); } 100% { transform: scale(1); } }
@keyframes smash { 30% { transform: scale(1.15) rotate(-6deg); } 100% { transform: scale(0) rotate(20deg); opacity: 0; } }
.board.selecting .tile span { animation: wiggle .5s infinite alternate; cursor: pointer; }
.board.selecting .tile.picked span { outline: 4px solid var(--accent2); outline-offset: 2px; animation: none; transform: scale(.92); }
@keyframes wiggle { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }

.v2 span { background: var(--c2); color: var(--f2); } .v4 span { background: var(--c4); color: var(--f4); }
.v8 span { background: var(--c8); color: var(--f8); } .v16 span { background: var(--c16); color: var(--f16); }
.v32 span { background: var(--c32); color: var(--f32); } .v64 span { background: var(--c64); color: var(--f64); }
.v128 span { background: var(--c128); color: var(--f128); box-shadow: 0 0 14px color-mix(in srgb, var(--c128) 45%, transparent), inset 0 -4px 0 rgba(0,0,0,.12); }
.v256 span { background: var(--c256); color: var(--f256); box-shadow: 0 0 16px color-mix(in srgb, var(--c256) 50%, transparent), inset 0 -4px 0 rgba(0,0,0,.12); }
.v512 span { background: var(--c512); color: var(--f512); box-shadow: 0 0 18px color-mix(in srgb, var(--c512) 55%, transparent), inset 0 -4px 0 rgba(0,0,0,.12); }
.v1024 span { background: var(--c1024); color: var(--f1024); box-shadow: 0 0 22px color-mix(in srgb, var(--c1024) 60%, transparent), inset 0 -4px 0 rgba(0,0,0,.12); }
.v2048 span { background: var(--c2048); color: var(--f2048); box-shadow: 0 0 26px var(--glow2048), inset 0 -4px 0 rgba(0,0,0,.12); }
.v4096 span, .v8192 span, .vsuper span { color: #fff; background-size: 300% 300%; animation: shimmer 3s linear infinite; text-shadow: 0 1px 6px rgba(0,0,0,.35); }
.v4096 span { background-image: linear-gradient(120deg, var(--c4096), #9cf6dc, var(--c4096), #18a07c); color: var(--f4096); box-shadow: 0 0 26px color-mix(in srgb, var(--c4096) 60%, transparent); }
.v8192 span { background-image: linear-gradient(120deg, var(--c8192), #8a5cff, var(--c8192), #ff5ca8); color: var(--f8192); box-shadow: 0 0 30px color-mix(in srgb, var(--c8192) 60%, transparent); }
.vsuper span { background-image: linear-gradient(120deg, #ff5ca8, #ffd166, #2bd4a6, #4c84ff, #b388ff, #ff5ca8); box-shadow: 0 0 34px rgba(255,255,255,.45); }
@keyframes shimmer { to { background-position: 300% 0; } }

[data-theme="neon"] .tile span { background: #0d0b20 !important; border: 2px solid var(--nc, #fff); color: var(--nc, #fff) !important;
  text-shadow: 0 0 8px var(--nc); box-shadow: 0 0 12px var(--nc), inset 0 0 12px color-mix(in srgb, var(--nc) 35%, transparent) !important; animation-name: none; }
[data-theme="neon"] .tile.spawn span { animation: spawn .18s var(--ease); }
[data-theme="neon"] .tile.pop span { animation: pop .2s var(--ease); }
[data-theme="neon"] .v2 { --nc: #8a8fff; } [data-theme="neon"] .v4 { --nc: #5ec8ff; } [data-theme="neon"] .v8 { --nc: #00f0ff; }
[data-theme="neon"] .v16 { --nc: #00ffa3; } [data-theme="neon"] .v32 { --nc: #b6ff00; } [data-theme="neon"] .v64 { --nc: #ffe600; }
[data-theme="neon"] .v128 { --nc: #ffa600; } [data-theme="neon"] .v256 { --nc: #ff5e00; } [data-theme="neon"] .v512 { --nc: #ff2d55; }
[data-theme="neon"] .v1024 { --nc: #ff2bd6; } [data-theme="neon"] .v2048 { --nc: #c04bff; } [data-theme="neon"] .v4096,
[data-theme="neon"] .v8192, [data-theme="neon"] .vsuper { --nc: #ffffff; }

.board-overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.countdown { font-size: 96px; font-weight: 900; color: #fff; text-shadow: 0 6px 30px rgba(0,0,0,.5); animation: pop .4s var(--ease); }
.paused-veil { position: absolute; inset: 0; border-radius: 18px; backdrop-filter: blur(14px); background: color-mix(in srgb, var(--bg) 55%, transparent); display: grid; place-items: center; font-weight: 900; font-size: 22px; letter-spacing: .1em; pointer-events: auto; }

.powerbar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 16px; }
.pw { position: relative; aspect-ratio: 1; max-height: 58px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 20px; transition: transform .12s, opacity .2s; }
.pw:active { transform: scale(.92); }
.pw:disabled { opacity: .35; pointer-events: none; }
.pw.on { outline: 3px solid var(--accent2); }
.pw .n { position: absolute; top: -5px; right: -5px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.pw .n.zero { background: var(--muted); }
.pw-label { text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; margin-top: 8px; min-height: 18px; }
.selhint { text-align: center; margin-top: 10px; font-weight: 700; }

/* opponents */
.opps { display: grid; gap: 10px; margin-bottom: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.opp { background: var(--panel); border-radius: 14px; padding: 8px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); }
.opp .mini { width: 58px; flex-shrink: 0; }
.opp .info { min-width: 0; }
.opp .info b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp .info .sc { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.opp.lead { outline: 2px solid var(--c2048); }
.opp.done { opacity: .6; }
.mini { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 2px; padding: 2px; background: var(--board); border-radius: 7px; aspect-ratio: 1; }
.mini > div { aspect-ratio: 1; border-radius: 3px; display: grid; place-items: center; font-size: 0; }
.mini .tile { position: static; width: auto; height: auto; transition: none; }
.mini .tile span { box-shadow: none; }
.spectate .opps { grid-template-columns: 1fr 1fr; }
.spectate .opp { flex-direction: column; align-items: stretch; }
.spectate .opp .mini { width: 100%; }
.spectate .opp .mini > div { font-size: 11px; font-weight: 900; }
.spectate #g-boardwrap, .spectate #powerbar, .spectate .pw-label { display: none; }

/* ---------- lists / leaderboard */
.list { display: flex; flex-direction: column; gap: 8px; }
.lrow { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--panel); text-align: left; width: 100%; box-shadow: var(--shadow); }
.lrow .rk { width: 28px; text-align: center; font-weight: 900; color: var(--muted); font-variant-numeric: tabular-nums; }
.lrow .rk.top1 { color: #ffc531; } .lrow .rk.top2 { color: #c8d0e0; } .lrow .rk.top3 { color: #e0965a; }
.lrow .nm { flex: 1; min-width: 0; }
.lrow .nm b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lrow .nm small { color: var(--muted); font-weight: 600; }
.lrow .val { font-weight: 900; font-variant-numeric: tabular-nums; text-align: right; }
.lrow .val small { display: block; color: var(--muted); font-weight: 700; font-size: 11px; }
.lrow.me { outline: 2px solid var(--accent); }
.sticky-me { position: sticky; bottom: 10px; margin-top: 12px; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* levels */
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.lvl { aspect-ratio: 1; border-radius: 15px; background: var(--panel); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; font-weight: 900; font-size: 20px; transition: transform .12s; }
.lvl:active { transform: scale(.94); }
.lvl small { font-size: 10px; color: var(--muted); font-weight: 800; }
.lvl .stars { font-size: 10px; letter-spacing: 1px; color: #ffc531; min-height: 12px; }
.lvl.locked { opacity: .4; }
.lvl.current { outline: 3px solid var(--accent); }

/* achievements */
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ach { background: var(--panel); border-radius: 18px; padding: 16px 12px; text-align: center; box-shadow: var(--shadow); }
.ach .medal { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; font-size: 30px;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c2048) 60%, #fff), var(--c2048)); box-shadow: 0 6px 18px var(--glow2048); }
.ach.locked .medal { background: var(--panel2); box-shadow: none; filter: grayscale(1); opacity: .55; }
.ach b { display: block; font-size: 14px; }
.ach p { margin: 4px 0 8px; font-size: 12px; color: var(--muted); min-height: 30px; }
.ach .rw { font-size: 11px; font-weight: 800; color: var(--accent2); }
.shop { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.shop-item { background: var(--panel); border-radius: 16px; padding: 12px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); }
.shop-item .ic { font-size: 24px; }
.shop-item .nm { flex: 1; min-width: 0; font-size: 13px; }
.shop-item .nm b { display: block; font-size: 14px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 74px; text-align: center; font-size: 12px; font-weight: 700; }
.swatch i { display: block; height: 52px; border-radius: 14px; margin-bottom: 4px; border: 3px solid transparent; }
.swatch.on i { border-color: var(--accent2); }
.swatch.locked { opacity: .45; }
.avatars { display: flex; flex-wrap: wrap; gap: 8px; }
.avatars button { width: 46px; height: 46px; border-radius: 14px; background: var(--panel2); font-size: 24px; }
.avatars button.on { outline: 3px solid var(--accent); }
.avatars button:disabled { opacity: .3; }

/* lobby */
.code { font-size: 44px; letter-spacing: .18em; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; }
.player-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: var(--panel2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); }
.dot.off { background: var(--muted); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--panel2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5, 7, 20, .55); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border-radius: 24px; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: sheetIn .3s var(--ease); }
@keyframes sheetIn { from { transform: translateY(24px) scale(.97); opacity: 0; } }
.sheet h2 { margin: 0 0 6px; font-size: 26px; }
.headline { font-size: 40px; font-weight: 900; letter-spacing: -.02em; text-align: center; margin: 4px 0; }
.headline.win { background: linear-gradient(90deg, var(--c2048), var(--c512)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.stats-grid div { background: var(--panel2); border-radius: 14px; padding: 10px 12px; }
.stats-grid div.wide { grid-column: span 2; }
.stats-grid label { display: block; font-size: 11px; color: var(--muted); font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.stats-grid b { font-size: 22px; font-variant-numeric: tabular-nums; }
.pb { text-align: center; font-weight: 800; padding: 10px; border-radius: 12px; background: var(--panel2); }
.pb.new { background: color-mix(in srgb, var(--good) 25%, var(--panel2)); }
.verify { text-align: center; font-size: 13px; color: var(--muted); font-weight: 700; margin-top: 10px; min-height: 18px; }
.actions { display: grid; gap: 10px; margin-top: 16px; }
.actions.two { grid-template-columns: 1fr 1fr; }
.stars-big { text-align: center; font-size: 40px; letter-spacing: 6px; color: #ffc531; }
.stars-big .off { color: var(--panel2); }
.howto ol { padding-left: 20px; line-height: 1.6; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; font-weight: 700; }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--panel2); position: relative; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }

#toasts { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(420px, 92vw); }
.toast { background: var(--panel); color: var(--text); padding: 10px 16px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.35); font-weight: 700; display: flex; gap: 10px; align-items: center; animation: toastIn .3s var(--ease); }
.toast.out { animation: toastOut .3s forwards; }
.toast .ic { font-size: 22px; }
.toast small { display: block; color: var(--muted); font-weight: 600; }
@keyframes toastIn { from { transform: translateY(-20px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-20px); opacity: 0; } }

@media (min-width: 900px) {
  #app { max-width: 600px; padding-top: 28px; }
  .modes { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-height: 700px) { .board { width: min(100%, calc(100vh - 240px)); } }
@media (prefers-reduced-motion: reduce) { .tile { transition-duration: 60ms; } .screen { animation: none; } }
