@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --paper: #f5f1ea;
  --ink: #243234;
  --muted: #708080;
  --line: #d9d9d1;
  --board: #d7d2c7;
  --empty: rgba(245, 241, 234, 0.5);
  --accent: #ee765c;
  --accent-dark: #cf5b48;
  --mint: #d8ebe3;
  --tile-light: #fbfaf7;
  --tile-dark: #254148;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  background-image: linear-gradient(rgba(36, 50, 52, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(36, 50, 52, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
}

button { font: inherit; }
button:focus-visible, .board:focus-visible { outline: 3px solid rgba(238, 118, 92, 0.45); outline-offset: 4px; }

.app-shell { width: min(1120px, calc(100% - 56px)); margin: 0 auto; padding: 30px 0 18px; }
.topbar, .intro-row, .game-layout { display: flex; justify-content: space-between; align-items: center; }
.topbar { padding-bottom: 25px; border-bottom: 1px solid var(--line); }
.brand-lockup { display: flex; align-items: center; gap: 16px; }
.brand-mark { display: grid; place-items: center; width: 64px; height: 64px; color: #fff8ed; background: var(--ink); border-radius: 8px; font-size: 24px; font-weight: 800; letter-spacing: -3px; transform: rotate(-4deg); }
.brand-mark em { color: var(--accent); font-style: normal; }
.eyebrow, .kicker { margin: 0; color: var(--muted); font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500; letter-spacing: 0.13em; text-transform: uppercase; }
.brand-lockup h1 { margin: 3px 0 0; font-size: 25px; line-height: 1; letter-spacing: 0.02em; }
.score-cluster { display: flex; gap: 10px; }
.score-box { min-width: 106px; padding: 10px 17px 9px; color: #fff8ed; background: var(--ink); border-radius: 6px; text-align: center; }
.score-box span { display: block; color: #a7b7b2; font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 0.08em; }
.score-box strong { display: block; margin-top: 3px; font-size: 22px; line-height: 1; }
.best-box { background: var(--accent); }
.best-box span { color: #ffe1d8; }

.intro-row { align-items: end; padding: 25px 0 20px; }
.intro-row h2 { margin: 8px 0 5px; font-size: clamp(25px, 3vw, 37px); line-height: 1.14; letter-spacing: -0.04em; }
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }
.action-row { display: flex; align-items: center; gap: 10px; }
.icon-button, .primary-button { border: 0; cursor: pointer; transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease; }
.icon-button:hover, .primary-button:hover { transform: translateY(-2px); }
.icon-button { display: grid; place-items: center; width: 43px; height: 43px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: rgba(255,255,255,0.35); font-size: 25px; line-height: 1; }
.icon-button:disabled { cursor: not-allowed; opacity: 0.38; transform: none; }
.primary-button { min-height: 43px; padding: 0 18px; border-radius: 6px; color: #fff9f0; background: var(--accent); font-size: 13px; font-weight: 700; box-shadow: 0 5px 12px rgba(207, 91, 72, 0.15); }
.primary-button:hover { background: var(--accent-dark); box-shadow: 0 7px 15px rgba(207, 91, 72, 0.22); }
.primary-button span { margin-right: 5px; font-size: 17px; vertical-align: -1px; }

.game-layout { align-items: flex-start; gap: clamp(46px, 8vw, 120px); }
.board-column { flex: 0 1 560px; }
.game-frame { position: relative; width: min(100%, 560px, calc(100vh - 350px)); aspect-ratio: 1; padding: clamp(10px, 1.8vw, 16px); background: var(--board); border-radius: 8px; box-shadow: 0 17px 34px rgba(36, 50, 52, 0.08); }
.board { display: grid; grid-template: repeat(4, 1fr) / repeat(4, 1fr); gap: clamp(7px, 1.35vw, 12px); width: 100%; height: 100%; touch-action: none; user-select: none; }
.cell { display: grid; place-items: center; border-radius: 5px; background: var(--empty); font-size: clamp(27px, 5.8vw, 58px); font-weight: 800; line-height: 1; transition: background 120ms ease, color 120ms ease, transform 120ms ease; }
.cell[data-value="0"] { color: transparent; }
.cell[data-value="2"] { color: var(--ink); background: var(--tile-light); }
.cell[data-value="4"] { color: var(--ink); background: #ece8dc; }
.cell[data-value="8"] { color: #fff9f0; background: #e8a153; }
.cell[data-value="16"] { color: #fff9f0; background: #e77d52; }
.cell[data-value="32"] { color: #fff9f0; background: #df624f; }
.cell[data-value="64"] { color: #fff9f0; background: #c94d4a; }
.cell[data-value="128"] { color: #fff9f0; background: #a48c60; font-size: clamp(22px, 4.3vw, 43px); }
.cell[data-value="256"] { color: #fff9f0; background: #7d9279; font-size: clamp(22px, 4.3vw, 43px); }
.cell[data-value="512"] { color: #fff9f0; background: #618f8b; font-size: clamp(22px, 4.3vw, 43px); }
.cell[data-value="1024"], .cell[data-value="2048"] { color: #fff9f0; background: var(--tile-dark); font-size: clamp(19px, 3.7vw, 37px); }
.cell.is-new { animation: appear 180ms ease-out; }
.cell.is-merged { animation: pop 220ms ease-out; }
@keyframes appear { from { opacity: 0; transform: scale(0.65); } to { opacity: 1; transform: scale(1); } }
@keyframes pop { 45% { transform: scale(1.12); } to { transform: scale(1); } }
.controls-hint { display: flex; align-items: center; justify-content: center; gap: 5px; padding-top: 16px; color: var(--muted); font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 0.04em; }
.keycap { display: inline-grid; place-items: center; width: 21px; height: 21px; border: 1px solid #c5c8c0; border-radius: 4px; color: var(--ink); background: rgba(255,255,255,0.38); font-size: 12px; }
.controls-hint .keycap + .keycap { margin-left: -2px; }
.controls-hint span:last-child { margin-left: 6px; }

.side-panel { width: min(270px, 100%); padding-top: 16px; }
.side-panel-header { padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.side-panel h3 { margin: 8px 0 0; font-size: 19px; }
.rules-list { display: grid; gap: 20px; margin: 24px 0 27px; padding: 0; list-style: none; }
.rules-list li { display: grid; grid-template-columns: 33px 1fr; gap: 12px; align-items: start; }
.rules-list li > span { color: var(--accent); font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500; }
.rules-list p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.rules-list strong { color: var(--ink); }
.tip-box { display: flex; gap: 12px; padding: 17px 16px; border-radius: 6px; background: var(--mint); }
.tip-icon { color: #4f8a7c; font-size: 19px; line-height: 1.3; }
.tip-box p { margin: 0; color: #4d7169; font-size: 11px; line-height: 1.6; }
.tip-box strong { color: #28594f; font-size: 12px; }
.footer-note { display: flex; align-items: center; gap: 7px; padding-top: 36px; color: #97a09b; font-family: 'DM Mono', monospace; font-size: 10px; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: #75b49b; }

.game-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; border-radius: 8px; background: rgba(36, 50, 52, 0.72); }
.game-message[hidden] { display: none; }
.message-card { width: min(310px, 100%); padding: 28px 26px; border-radius: 7px; background: var(--paper); text-align: center; box-shadow: 0 14px 30px rgba(0,0,0,0.16); }
.message-card h3 { margin: 9px 0 7px; font-size: 27px; letter-spacing: -0.04em; }
.message-card > p:not(.kicker) { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 28px, 560px); padding-top: 25px; }
  .topbar { padding-bottom: 28px; }
  .brand-mark { width: 52px; height: 52px; font-size: 19px; }
  .brand-lockup { gap: 12px; }
  .brand-lockup h1 { font-size: 21px; }
  .score-box { min-width: 78px; padding: 8px 9px; }
  .score-box strong { font-size: 18px; }
  .intro-row { align-items: flex-start; gap: 20px; padding: 29px 0 23px; }
  .intro-row h2 { font-size: 25px; }
  .subtitle { font-size: 12px; }
  .action-row { flex-shrink: 0; }
  .primary-button { padding: 0 12px; }
  .game-layout { display: block; }
  .board-column { width: 100%; }
  .game-frame { width: 100%; }
  .side-panel { width: 100%; padding: 34px 2px 0; }
  .side-panel-header { padding-bottom: 13px; }
  .rules-list { grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0 20px; }
  .rules-list li { display: block; }
  .rules-list li > span { display: block; margin-bottom: 6px; }
  .rules-list p { font-size: 11px; line-height: 1.55; }
  .tip-box { padding: 13px 14px; }
  .footer-note { padding-top: 22px; padding-bottom: 10px; }
}

@media (min-width: 761px) {
  body { overflow: hidden; }
}

@media (max-width: 430px) {
  .score-cluster { gap: 5px; }
  .score-box { min-width: 66px; padding-inline: 6px; }
  .score-box span { font-size: 8px; }
  .score-box strong { font-size: 16px; }
  .intro-row { gap: 8px; }
  .intro-row h2 { max-width: 235px; font-size: 22px; }
  .subtitle { max-width: 230px; }
  .action-row { gap: 5px; }
  .icon-button { width: 39px; height: 39px; }
  .primary-button { min-height: 39px; padding-inline: 9px; font-size: 12px; }
}
