:root {
  --bg: #faf8ef; --ink: #3c3a32; --muted: #776e65; --board: #bbada0; --cell: #cdc1b4;
  --accent: #8f7a66; --accent-ink: #f9f6f2; --ok: #2e7d32; --err: #b3261e;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.wrap { max-width: 480px; margin: 0 auto; padding: 16px; }
.wide { max-width: 1100px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 56px; margin: 0; letter-spacing: -1px; }
h2 { margin: 0 0 8px; }
.scores { display: flex; gap: 8px; }
.score { background: var(--board); color: #fff; border-radius: 6px; padding: 6px 14px; text-align: center; min-width: 72px; }
.score span { display: block; font-size: 12px; text-transform: uppercase; color: #eee4da; }
.score b { font-size: 20px; }
.intro, .help, .foot { color: var(--muted); }
.foot { font-size: 13px; margin-top: 24px; }
a { color: var(--accent); }
.bar { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.status { color: var(--muted); font-size: 14px; }
button { font: inherit; border: 0; border-radius: 6px; padding: 9px 16px; cursor: pointer;
  background: #e3dacd; color: var(--ink); }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button:disabled { opacity: .6; cursor: wait; }
.small-btn { padding: 6px 12px; font-size: 14px; }
input[type=text], input[type=password] { font: inherit; padding: 9px 10px; border: 2px solid #d8cfc3;
  border-radius: 6px; width: 100%; background: #fff; color: var(--ink); }
.bar input { width: auto; flex: 1; min-width: 160px; }

.board-wrap { position: relative; }
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 12px;
  background: var(--board); border-radius: 8px; aspect-ratio: 1; touch-action: none; user-select: none; outline: none; }
.cell { background: var(--cell); border-radius: 5px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: clamp(22px, 8vw, 44px); color: var(--ink); }
.cell.small { font-size: clamp(16px, 6vw, 32px); }
.t-2 { background: #eee4da; } .t-4 { background: #ede0c8; }
.t-8 { background: #f2b179; color: #f9f6f2; } .t-16 { background: #f59563; color: #f9f6f2; }
.t-32 { background: #f67c5f; color: #f9f6f2; } .t-64 { background: #f65e3b; color: #f9f6f2; }
.t-128 { background: #edcf72; color: #f9f6f2; } .t-256 { background: #edcc61; color: #f9f6f2; }
.t-512 { background: #edc850; color: #f9f6f2; } .t-1024 { background: #edc53f; color: #f9f6f2; }
.t-2048 { background: #edc22e; color: #f9f6f2; box-shadow: 0 0 24px 6px rgba(243, 215, 116, .6); }
.t-big { background: #3c3a32; color: #f9f6f2; }
.pop { animation: pop .15s ease-out; }
.merge { animation: merge .15s ease-out; }
@keyframes pop { from { transform: scale(.2); } to { transform: scale(1); } }
@keyframes merge { 50% { transform: scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .pop, .merge { animation: none; } }

.overlay { position: absolute; inset: 0; background: rgba(250, 248, 239, .82); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 12px; }
.panel { background: #fff; border-radius: 10px; padding: 18px; width: 100%; max-width: 380px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15); }
.panel label { display: block; font-weight: 600; margin: 10px 0 4px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0; }
.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.msg { font-size: 14px; min-height: 1.2em; }
.code { font: 700 30px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 2px;
  background: var(--bg); border: 2px dashed var(--accent); border-radius: 8px; padding: 10px; text-align: center; margin: 8px 0; }
.hidden { display: none !important; }

/* admin */
table { border-collapse: collapse; width: 100%; font-size: 14px; background: #fff; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid #eee4da; vertical-align: top; }
th { background: #f3eee4; position: sticky; top: 0; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
tr.paid td { color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.ok { background: #e3f3e4; color: var(--ok); } .pill.wait { background: #fff1d6; color: #8a5a00; }
.note { width: 160px !important; padding: 5px 7px !important; font-size: 13px !important; }
.err { color: var(--err); }
select { font: inherit; padding: 8px; border-radius: 6px; border: 2px solid #d8cfc3; background: #fff; }
.table-scroll { overflow-x: auto; }
td.mono.nowrap { white-space: nowrap; word-break: normal; }
