:root {
    --g-paper: #f4f0e7;
    --g-surface: #fcfaf5;
    --g-ink: #3d352c;
    --g-muted: #73685c;
    --g-line: #d7cbbb;
    --g-accent: #8c482d;
    --g-board: #b6a48b;
    --g-empty: #cabcaa;
    --g-tile-2: #f1eadf;
    --g-tile-4: #e8ddc7;
    --g-tile-8: #d5ae78;
    --g-tile-16: #bf8b55;
    --g-tile-32: #a8663e;
    --g-tile-64: #934b32;
    --g-tile-128: #877642;
    --g-tile-256: #786735;
    --g-tile-512: #65572c;
    --g-tile-1024: #554a2e;
    --g-tile-2048: #423d29;
    --g-tile-more: #34342b;
    --g-light: #fffaf0;
    --g-overlay: rgb(252 250 245 / 95%);
    --g-backdrop: rgb(61 53 44 / 35%);
    --g-shadow: rgb(61 53 44 / 12%);
}

* { box-sizing: border-box; }
body.arcade-game {
    margin: 0;
    background: var(--arcade-bg, var(--g-paper));
    color: var(--arcade-ink, var(--g-ink));
    font-family: "Times New Roman", "SimSun", "宋体", serif;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
[hidden] { display: none !important; }
.game-shell { width: min(1080px, calc(100% - 64px)); margin: 0 auto; }
.game-shell .arcade-topbar {
    min-height: 84px; display: flex; align-items: center; justify-content: space-between;
    gap: 16px; border-bottom: 1px solid var(--arcade-line, var(--g-line));
}
.arcade-brand { color: inherit; text-decoration: none; padding: 12px 0; font-weight: bold; }
.edition, .game-footer { color: var(--arcade-muted, var(--g-muted)); font-size: 12px; letter-spacing: 0.08em; }
.game-layout { display: grid; grid-template-columns: 1fr 460px; gap: clamp(32px, 7vw, 100px); padding: 46px 0 40px; align-items: start; }
.game-intro { padding-top: 7px; }
.game-intro .arcade-kicker { margin: 0 0 16px; color: var(--arcade-muted, var(--g-muted)); font-size: 14px; }
.game-intro .game-title { margin: 0 0 10px; font-size: clamp(76px, 9vw, 124px); line-height: 0.95; font-weight: normal; letter-spacing: -0.055em; }
.title-dot { color: var(--arcade-accent, var(--g-accent)); }
.game-subtitle { font-size: 27px; margin: 22px 0 16px; line-height: 1.5; }
.game-intro .arcade-description { font-size: 15px; line-height: 1.9; color: var(--arcade-muted, var(--g-muted)); margin: 0; }
.game-rules { margin-top: 40px; padding-top: 23px; border-top: 1px solid var(--arcade-line, var(--g-line)); max-width: 340px; }
.game-rules h2 { font-size: 16px; margin: 0 0 16px; font-weight: normal; }
.game-rules p { font-size: 14px; line-height: 1.9; color: var(--arcade-muted, var(--g-muted)); margin: 0 0 13px; }
.game-rules strong { color: var(--arcade-ink, var(--g-ink)); font-weight: normal; }
kbd { font: inherit; border: 1px solid var(--arcade-line, var(--g-line)); padding: 0 4px; border-radius: 3px; }
.quiet-note { font-size: 13px; color: var(--arcade-muted, var(--g-muted)); margin-top: 28px; }
.play-area { min-width: 0; }
.scoreboard { display: grid; grid-template-columns: 1fr 1fr 0.8fr; margin-bottom: 20px; }
.score-item { padding: 0 14px; border-left: 1px solid var(--arcade-line, var(--g-line)); min-width: 0; }
.score-item:first-child { border-left: 0; padding-left: 0; }
.score-item > span { display: block; font-size: 13px; color: var(--arcade-muted, var(--g-muted)); margin-bottom: 5px; }
.score-item > strong { display: block; font-size: 30px; font-weight: normal; overflow-wrap: anywhere; }
.score-goal { text-align: right; padding-right: 0; }
.score-goal strong { color: var(--arcade-accent, var(--g-accent)); }
.board-frame { position: relative; border-radius: 8px; }
.board { background: var(--g-board); padding: 12px; border-radius: 8px; display: grid; grid-template-rows: repeat(4, minmax(0, 1fr)); gap: 10px; aspect-ratio: 1; touch-action: none; user-select: none; }
.board-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; min-height: 0; }
.tile { display: grid; place-items: center; border-radius: 5px; background: var(--g-empty); color: var(--g-ink); line-height: 1; font-weight: bold; font-size: 47px; min-width: 0; }
.tile[data-value="2"] { background: var(--g-tile-2); }
.tile[data-value="4"] { background: var(--g-tile-4); }
.tile[data-value="8"] { background: var(--g-tile-8); }
.tile[data-value="16"] { background: var(--g-tile-16); color: var(--g-ink); }
.tile[data-value="32"] { background: var(--g-tile-32); color: var(--g-light); }
.tile[data-value="64"] { background: var(--g-tile-64); color: var(--g-light); }
.tile[data-value="128"] { background: var(--g-tile-128); color: var(--g-light); }
.tile[data-value="256"] { background: var(--g-tile-256); color: var(--g-light); }
.tile[data-value="512"] { background: var(--g-tile-512); color: var(--g-light); }
.tile[data-value="1024"] { background: var(--g-tile-1024); color: var(--g-light); }
.tile[data-value="2048"] { background: var(--g-tile-2048); color: var(--g-light); }
.tile[data-large="true"] { background: var(--g-tile-more); color: var(--g-light); }
.tile[data-digits="3"] { font-size: 39px; }
.tile[data-digits="4"] { font-size: 32px; }
.tile[data-digits="5"] { font-size: 25px; }
.tile[data-digits="6"] { font-size: 19px; }
.tile[data-digits="many"] { font-size: 12px; }
.tile.is-spawned { animation: tile-appear 150ms ease-out; }
.tile.is-merged { animation: tile-merge 180ms ease-out; }
@keyframes tile-appear { from { transform: scale(0.72); opacity: 0.5; } to { transform: scale(1); opacity: 1; } }
@keyframes tile-merge { 0% { transform: scale(1); } 45% { transform: scale(1.08); } 100% { transform: scale(1); } }
.board-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; text-align: center; border-radius: 8px; background: var(--g-overlay); }
.overlay-mark { font-size: 54px; margin: 0 0 20px; line-height: 1; color: var(--arcade-accent, var(--g-accent)); }
.board-overlay h2 { font-weight: normal; font-size: 28px; margin: 0 0 13px; }
.board-overlay p:not(.overlay-mark) { font-size: 15px; line-height: 1.7; color: var(--arcade-muted, var(--g-muted)); margin: 0 0 24px; }
.game-status { min-height: 24px; font-size: 14px; margin: 16px 0 12px; color: var(--arcade-muted, var(--g-muted)); }
.game-controls { display: grid; grid-template-columns: 1fr 0.8fr 1.1fr; gap: 9px; }
.game-shell .arcade-button, .restart-dialog .arcade-button {
    border: 1px solid var(--arcade-line, var(--g-line)); border-radius: 5px;
    padding: 10px 14px; min-height: 44px; cursor: pointer; font-size: 14px;
    white-space: nowrap; color: var(--arcade-ink, var(--g-ink)); background: var(--arcade-surface, var(--g-surface));
    transition: background-color 120ms, transform 120ms;
}
.game-shell .arcade-button--primary, .restart-dialog .arcade-button--primary { background: var(--arcade-accent, var(--g-accent)); color: var(--g-light); border-color: var(--arcade-accent, var(--g-accent)); }
.arcade-button:hover:not(:disabled) { filter: brightness(0.94); }
.arcade-button:active:not(:disabled), .arcade-brand:active { transform: scale(0.97); }
.arcade-button:disabled { opacity: 0.42; cursor: not-allowed; }
.arcade-button:focus-visible, .arcade-brand:focus-visible, .board:focus-visible { outline: 3px solid var(--arcade-accent, var(--g-accent)); outline-offset: 4px; }
.arcade-brand:hover { color: var(--arcade-accent, var(--g-accent)); }
.direction-controls { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
.game-shell .direction-button { width: 48px; padding: 4px; font-size: 24px; }
.storage-status { margin: 15px 0 0; font-size: 12px; text-align: center; line-height: 1.6; color: var(--arcade-muted, var(--g-muted)); }
.game-footer { border-top: 1px solid var(--arcade-line, var(--g-line)); padding: 22px 0; display: flex; justify-content: space-between; gap: 15px; }
.restart-dialog { background: var(--arcade-surface, var(--g-surface)); color: var(--arcade-ink, var(--g-ink)); border: 1px solid var(--arcade-line, var(--g-line)); border-radius: 8px; padding: 28px; max-width: min(420px, calc(100% - 32px)); box-shadow: 0 16px 48px var(--g-shadow); font: inherit; }
.restart-dialog::backdrop { background: var(--g-backdrop); }
.restart-dialog h2 { font-size: 24px; font-weight: normal; margin: 0 0 12px; }
.restart-dialog p { line-height: 1.8; color: var(--arcade-muted, var(--g-muted)); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.no-script { text-align: center; padding: 24px; }
@media (max-width: 840px) {
    .game-shell { width: min(480px, calc(100% - 32px)); }
    .game-shell .arcade-topbar { min-height: 62px; }
    .edition { font-size: 10px; letter-spacing: 0.02em; }
    .game-layout { grid-template-columns: minmax(0, 1fr); gap: 22px; padding: 25px 0 28px; }
    .game-intro { display: grid; grid-template-columns: auto 1fr; align-items: end; gap: 8px 18px; padding: 0; }
    .game-intro .arcade-kicker { grid-column: 1 / -1; margin: 0 0 4px; font-size: 12px; }
    .game-intro .game-title { font-size: 72px; margin: 0; }
    .game-subtitle { font-size: 17px; margin: 0 0 3px; }
    .game-intro .arcade-description, .quiet-note { display: none; }
    .game-rules { grid-column: 1 / -1; grid-row: 3; margin: 6px 0 0; padding: 0; border: 0; max-width: none; }
    .game-rules h2, .game-rules p:not(:first-of-type) { display: none; }
    .game-rules p { font-size: 12px; line-height: 1.6; margin: 0; }
    .scoreboard { margin-bottom: 13px; }
    .score-item > strong { font-size: 26px; }
    .score-item > span { font-size: 12px; }
    .board { padding: 9px; gap: 8px; }
    .board-row { gap: 8px; }
    .tile { font-size: clamp(32px, 10vw, 47px); }
    .tile[data-digits="3"] { font-size: clamp(28px, 8vw, 39px); }
    .tile[data-digits="4"] { font-size: clamp(22px, 6.8vw, 32px); }
    .tile[data-digits="5"] { font-size: clamp(18px, 5.2vw, 25px); }
    .tile[data-digits="6"] { font-size: 15px; }
    .tile[data-digits="many"] { font-size: 10px; }
    .tile.is-spawned, .tile.is-merged { animation-duration: 120ms; }
    .game-footer { font-size: 10px; }
}
@media (max-width: 350px) {
    .game-shell { width: calc(100% - 24px); }
    .game-intro .game-title { font-size: 60px; }
    .game-subtitle { font-size: 15px; }
    .game-shell .arcade-button { padding-inline: 8px; }
    .game-footer { flex-direction: column; gap: 7px; }
}
@media (prefers-reduced-motion: reduce) {
    .tile.is-spawned, .tile.is-merged { animation: none; }
    .arcade-button { transition: none !important; }
    .arcade-button:active, .arcade-brand:active { transform: none; }
}
