:root {
  color-scheme: light;
  --page: #f4f1e9;
  --paper: #fffdf8;
  --ink: #202c2a;
  --muted: #6d7771;
  --line: #dcded6;
  --accent: #d9f77a;
  --accent-ink: #203227;
  --board: #d7d9ce;
  --empty: #e9e9e1;
  --shadow: 0 22px 70px rgba(35, 53, 39, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111a1a;
  --paper: #1b2929;
  --ink: #f0f3e9;
  --muted: #a9b8af;
  --line: #354746;
  --accent: #d7f478;
  --accent-ink: #203227;
  --board: #30413f;
  --empty: #3b4c49;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.17);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: radial-gradient(circle at 88% 8%, rgba(216, 246, 119, 0.22), transparent 30%), var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, kbd { font: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid #70a743; outline-offset: 4px; }

.page { max-width: 1240px; margin: 0 auto; padding: 0 42px; }
.topbar { height: 104px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-size: 26px; font-weight: 860; letter-spacing: -0.065em; }
.brand-mark { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 11px; background: var(--accent); color: var(--accent-ink); font-size: 20px; transform: rotate(-9deg); }
.brand-dot { color: #93af44; }
.theme-toggle { display: inline-flex; gap: 12px; align-items: center; padding: 10px 0 10px 12px; border: 0; background: transparent; color: var(--ink); font-size: 13px; font-weight: 720; }
.switch-track { width: 42px; height: 25px; padding: 3px; border: 1px solid var(--line); border-radius: 99px; background: var(--board); transition: background .2s; }
.switch-thumb { display: block; width: 17px; height: 17px; border-radius: 50%; background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.18); transition: transform .2s; }
[data-theme="dark"] .switch-track { background: var(--accent); }
[data-theme="dark"] .switch-thumb { transform: translateX(17px); background: var(--accent-ink); }

.intro { display: flex; align-items: center; justify-content: space-between; gap: 30px; min-height: 360px; padding: 48px 0 42px; }
.intro-copy { max-width: 770px; }
.eyebrow { margin: 0; display: flex; align-items: center; gap: 10px; color: #607e4c; font-size: 11px; font-weight: 850; letter-spacing: .16em; }
[data-theme="dark"] .eyebrow { color: #c0dc81; }
.eyebrow-line { width: 20px; height: 2px; background: currentColor; }
.intro h1 { margin: 22px 0 16px; font-size: clamp(46px, 5.6vw, 80px); line-height: .99; letter-spacing: -.075em; font-weight: 830; }
.intro h1 em { font-style: normal; color: #91ad49; }
[data-theme="dark"] .intro h1 em { color: #d4eb91; }
.intro-description { margin: 0; max-width: 420px; color: var(--muted); font-size: 16px; line-height: 1.6; }
.intro-art { display: flex; align-items: center; flex-shrink: 0; transform: rotate(-9deg); padding-right: 10px; }
.art-tile { display: grid; place-items: center; width: 74px; height: 74px; border-radius: 17px; box-shadow: 0 8px 25px rgba(41, 46, 33, .12); font-size: 33px; font-weight: 850; letter-spacing: -.07em; }
.art-tile-two { background: #f8d8aa; color: #6b4d29; }
.art-tile-four { background: #c9e676; color: #395429; }
.art-tile-offset { transform: translateY(23px) rotate(12deg); }
.art-plus, .art-equals { margin: 0 8px; color: var(--muted); font-size: 27px; font-weight: 400; }
.art-equals { transform: translateY(15px); }

.game-area { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(285px, 1fr); gap: 20px; align-items: stretch; }
.game-main, .game-sidebar { background: var(--paper); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); }
.game-main { min-width: 0; padding: 28px; }
.game-heading { min-height: 79px; margin-bottom: 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.eyebrow.small { font-size: 10px; }
.game-heading h2 { margin: 9px 0 0; font-size: 25px; letter-spacing: -.05em; line-height: 1; }
.scores { display: flex; gap: 8px; }
.score-card { min-width: 96px; min-height: 74px; padding: 12px 14px; border-radius: 13px; background: var(--page); display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; }
.score-card span { color: var(--muted); font-size: 10px; font-weight: 840; letter-spacing: .13em; }
.score-card strong { font-size: 23px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.board-shell { position: relative; overflow: hidden; border-radius: 19px; }
.board-grid { width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: clamp(7px, 1.2vw, 12px); padding: clamp(7px, 1.2vw, 12px); background: var(--board); touch-action: none; user-select: none; container-type: inline-size; }
.cell { min-width: 0; min-height: 0; display: grid; place-items: center; border-radius: clamp(8px, 1.2vw, 13px); background: var(--empty); color: transparent; font-size: clamp(22px, 8cqw, 47px); font-weight: 850; letter-spacing: -.07em; font-variant-numeric: tabular-nums; }
.cell.tile { color: #3b483d; background: #f4ebd8; }
.tile[data-value="4"] { background: #f2dfbf; }
.tile[data-value="8"] { background: #f6c990; color: #633f22; }
.tile[data-value="16"] { background: #f3ad79; color: #583521; }
.tile[data-value="32"] { background: #ee9277; color: #fffaf2; }
.tile[data-value="64"] { background: #e97870; color: #fffaf2; }
.tile[data-value="128"] { background: #d9e989; color: #354326; font-size: clamp(21px, 7cqw, 42px); }
.tile[data-value="256"] { background: #c3e474; color: #30451f; font-size: clamp(21px, 7cqw, 42px); }
.tile[data-value="512"] { background: #a9d969; color: #27421e; font-size: clamp(21px, 7cqw, 42px); }
.tile[data-value="1024"] { background: #83cb85; color: #1e4133; font-size: clamp(19px, 6.1cqw, 37px); }
.tile[data-value="2048"] { background: #d9f77a; color: #243525; box-shadow: inset 0 0 0 3px rgba(255,255,255,.35); font-size: clamp(19px, 6.1cqw, 37px); }
.tile[data-value="super"] { background: #3c8b70; color: #fff; font-size: clamp(17px, 5.4cqw, 33px); }
[data-theme="dark"] .tile[data-value="2"] { background: #586c67; color: #f7f7ec; }
[data-theme="dark"] .tile[data-value="4"] { background: #718378; color: #fff; }
[data-theme="dark"] .tile[data-value="8"] { background: #a68067; color: #fff; }
[data-theme="dark"] .tile[data-value="16"] { background: #b27c63; color: #fff; }
[data-theme="dark"] .tile[data-value="32"] { background: #bd746b; color: #fff; }
[data-theme="dark"] .tile[data-value="64"] { background: #c56863; color: #fff; }
.tile-new { animation: tile-appear .18s ease-out both; }
@keyframes tile-appear { from { transform: scale(.78); opacity: .5; } to { transform: scale(1); opacity: 1; } }
.game-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(18, 28, 26, .57); backdrop-filter: blur(5px); }
.game-overlay[hidden] { display: none; }
.overlay-card { max-width: 355px; padding: 30px; border-radius: 22px; background: var(--paper); color: var(--ink); text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.overlay-sparkle { color: #9fbb4f; font-size: 32px; }
.overlay-card h3 { margin: 10px 0; font-size: 28px; line-height: 1.08; letter-spacing: -.055em; }
.overlay-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.5; }
.board-note { margin: 17px 1px 1px; color: var(--muted); font-size: 12px; }

.game-sidebar { min-width: 0; min-height: 565px; padding: 28px; display: flex; flex-direction: column; }
.sidebar-top { display: flex; justify-content: space-between; align-items: flex-start; }
.side-index { color: var(--muted); font-size: 11px; font-weight: 760; letter-spacing: .12em; }
.side-symbol { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; font-size: 21px; }
.game-sidebar h2 { max-width: 260px; margin: 65px 0 13px; font-size: clamp(32px, 3.4vw, 48px); line-height: 1.04; letter-spacing: -.068em; }
.game-sidebar p { margin: 0; max-width: 280px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.primary-button { min-height: 52px; padding: 14px 20px; border: 0; border-radius: 11px; background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 790; transition: transform .15s, background .15s; }
.primary-button:hover { transform: translateY(-2px); background: #c8ed60; }
.primary-button:active { transform: translateY(0); }
.new-game-button { width: 100%; margin-top: 28px; display: flex; justify-content: space-between; align-items: center; text-align: left; }
.new-game-button span { font-size: 20px; font-weight: 400; }
.sidebar-divider { height: 1px; margin: 30px 0 26px; background: var(--line); }
.guide-title { display: block; margin-bottom: 18px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .14em; }
.guide-row { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.keycaps { display: flex; gap: 3px; }
kbd { display: grid; place-items: center; width: 21px; height: 23px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); font-size: 12px; }
.swipe-mark { width: 92px; color: var(--ink); font-size: 25px; line-height: 1; }
.sidebar-bottom { margin-top: auto; padding-top: 25px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.bottom-dot { width: 7px; height: 7px; border-radius: 50%; background: #96bd53; }
.footer { display: flex; justify-content: space-between; gap: 20px; padding: 33px 0 44px; color: var(--muted); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 920px) {
  .intro-art { transform: scale(.75) rotate(-9deg); transform-origin: right center; margin-left: -80px; }
  .game-area { grid-template-columns: minmax(0, 1fr); }
  .game-main { max-width: 680px; width: 100%; margin: auto; }
  .game-sidebar { min-height: 0; max-width: 680px; width: 100%; margin: auto; }
  .game-sidebar h2 { margin-top: 30px; }
  .sidebar-bottom { margin-top: 24px; }
}

@media (max-width: 640px) {
  .page { padding: 0 16px; }
  .topbar { height: 72px; }
  .brand { font-size: 22px; }
  .brand-mark { width: 34px; height: 34px; font-size: 18px; }
  .theme-toggle { gap: 7px; font-size: 11px; }
  .intro { min-height: 0; padding: 42px 0 36px; }
  .intro h1 { margin-top: 18px; font-size: clamp(47px, 11vw, 72px); }
  .intro-description { font-size: 14px; }
  .intro-art { display: none; }
  .game-area { gap: 14px; }
  .game-main, .game-sidebar { border-radius: 18px; }
  .game-main { padding: 13px; }
  .game-heading { min-height: 76px; margin-bottom: 13px; gap: 6px; }
  .game-heading h2 { font-size: 20px; }
  .scores { gap: 5px; }
  .score-card { min-width: 68px; min-height: 60px; padding: 8px 9px; }
  .score-card span { font-size: 8px; }
  .score-card strong { font-size: 18px; }
  .board-shell { border-radius: 12px; }
  .board-note { font-size: 11px; line-height: 1.4; }
  .game-sidebar { padding: 22px; }
  .game-sidebar h2 { font-size: 36px; }
  .footer { display: block; line-height: 1.8; padding-top: 24px; }
  .footer span { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
