:root {
  color-scheme: light;
  --paper: #f2f5ed;
  --ink: #202923;
  --muted: #68736a;
  --line: #d7ded4;
  --green: #b8ef46;
  --green-dark: #46751e;
  --mint: #e2ebdc;
  --coral: #f0784d;
  --gold: #ffd833;
  --wall: #25332d;
  --white: #fffefa;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }

html, body { min-width: 320px; min-height: 100%; margin: 0; }

body {
  background-color: var(--paper);
  background-image: radial-gradient(#dce4d7 0.7px, transparent 0.7px);
  background-size: 18px 18px;
  overscroll-behavior: none;
}

button { font: inherit; }

.app-shell {
  width: min(100% - 48px, 1000px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 20px 0 18px;
  display: flex;
  flex-direction: column;
}

.masthead {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-weight: 850; font-size: 19px; }
.brand-mark { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 8px 8px 8px 2px; background: var(--green); font-size: 16px; }
.masthead-note, .version-tag, .score-label, .section-kicker, .result-kicker { font-size: 10px; font-weight: 800; letter-spacing: 1.25px; }
.masthead-note { margin: 0; color: var(--muted); }
.version-tag { color: var(--green-dark); padding: 7px 9px; border: 1px solid #c9dca9; border-radius: 4px; }
.header-tools { display: flex; align-items: center; gap: 8px; }
.language-select { width: 150px; max-width: 100%; min-height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--white); color: var(--ink); font: inherit; font-size: 12px; }

.scoreboard {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 21px 0 17px;
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 254, 250, 0.86);
  box-shadow: 0 3px 12px rgba(32, 41, 35, 0.035);
}

.score-item { min-width: 114px; padding: 0 20px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--line); }
.score-primary { min-width: 142px; padding-left: 21px; }
.score-label { color: var(--muted); }
.score-item strong { font-size: 25px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-primary strong { color: var(--green-dark); }
.timer-item { margin-left: auto; border: 0; align-items: flex-end; }
.timer-item strong { min-width: 45px; text-align: right; }
.seconds-unit { margin-left: 3px; font-size: 12px; font-weight: 700; color: var(--muted); }
.timer-item.is-low strong { color: #c94f31; }
.icon-button { display: grid; place-items: center; width: 42px; height: 42px; margin: 0 15px 0 5px; border: 1px solid var(--line); border-radius: 7px; background: var(--white); color: var(--ink); font-size: 19px; cursor: pointer; transition: background 140ms ease, transform 140ms ease; }
.icon-button:not(:disabled):hover { background: var(--green); transform: translateY(-1px); }
.icon-button:disabled { opacity: .42; cursor: not-allowed; }

.game-layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 276px; align-items: center; gap: 30px; }
.board-column { min-width: 0; }
.board-shell { position: relative; width: min(100%, 610px); margin: 0 auto; aspect-ratio: 1; padding: 11px; border: 1px solid #aab8a8; border-radius: 10px; background: #d8e2d4; box-shadow: 0 9px 22px rgba(32, 41, 35, .08), inset 0 1px 0 rgba(255,255,255,.65); }
#gameCanvas { display: block; width: 100%; height: 100%; border-radius: 5px; touch-action: none; }
.board-caption { width: min(100%, 610px); margin: 11px auto 0; display: flex; justify-content: center; gap: 20px; color: var(--muted); font-size: 11px; font-weight: 650; }
.board-caption > span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-dot { display: inline-grid; place-items: center; width: 12px; height: 12px; border-radius: 3px; font-size: 9px; font-style: normal; }
.player-dot { background: var(--coral); border: 2px solid var(--white); box-shadow: 0 0 0 1px var(--coral); }
.star-dot { color: #ad8210; background: var(--gold); }
.pending-dot { border: 2px solid #e6763f; background: #ffc779; }
.wall-dot { background: var(--wall); }

.control-column { align-self: stretch; min-height: 0; display: flex; flex-direction: column; justify-content: center; padding: 13px 0; }
.control-heading { display: flex; justify-content: space-between; align-items: center; }
.section-kicker { color: var(--green-dark); }
.control-heading h2 { margin: 4px 0 0; font-size: 21px; line-height: 1.1; }
.move-rate { padding: 7px 9px; color: var(--green-dark); background: #e6f2d4; border-radius: 5px; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.move-rate span { margin-left: 2px; font-size: 9px; }
.control-instruction { max-width: 240px; margin: 12px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.direction-pad { position: relative; width: 188px; height: 188px; margin: 0 auto; overflow: hidden; border: 1px solid #bdcbb9; border-radius: 50%; background: #e7eee2; box-shadow: inset 0 3px 7px rgba(40, 65, 40, .07); touch-action: none; user-select: none; -webkit-user-select: none; }
.pad-track { position: absolute; z-index: 0; display: block; background: #dce6d6; }
.pad-track-vertical { width: 53px; height: 100%; left: calc(50% - 26.5px); top: 0; }
.pad-track-horizontal { height: 53px; width: 100%; top: calc(50% - 26.5px); left: 0; }
.pad-key { position: absolute; z-index: 1; display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 1px solid #c5d2bf; border-radius: 13px; background: var(--white); color: #395139; font-size: 23px; line-height: 1; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.pad-key:active, .pad-key.is-selected { background: var(--green); border-color: #a2ce4d; }
.pad-up { top: 9px; left: calc(50% - 24px); }
.pad-right { right: 9px; top: calc(50% - 24px); }
.pad-down { bottom: 9px; left: calc(50% - 24px); }
.pad-left { left: 9px; top: calc(50% - 24px); }
.pad-center { position: absolute; z-index: 2; top: calc(50% - 15px); left: calc(50% - 15px); display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid #bdcbb9; border-radius: 50%; background: #e7eee2; pointer-events: none; }
.pad-center span { width: 7px; height: 7px; border-radius: 50%; background: var(--green-dark); }
.pad-hint { display: flex; justify-content: center; align-items: center; gap: 7px; margin: 10px 0 19px; color: var(--muted); font-size: 11px; }
.hint-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green-dark); box-shadow: 0 0 0 3px #deedc8; }
.rule-note { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-left: 3px solid #f2a451; background: rgba(255, 248, 225, .8); }
.rule-note p { margin: 0; color: #665438; font-size: 11px; line-height: 1.45; }
.rule-icon { flex: 0 0 21px; display: grid; place-items: center; width: 21px; height: 21px; border-radius: 50%; background: #f5c36e; color: #503c20; font-size: 13px; font-weight: 900; }
.keyboard-note { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 17px; }
.keycap { display: grid; place-items: center; width: 21px; height: 21px; border: 1px solid #cad3c7; border-bottom-width: 2px; border-radius: 4px; background: #fffefa; color: #59645a; font-size: 9px; font-weight: 750; }
.key-divider { margin: 0 4px; color: #89938a; font-size: 10px; }

.page-footer { display: flex; justify-content: space-between; margin-top: 15px; padding-top: 12px; border-top: 1px solid var(--line); color: #7d877e; font-size: 10px; }
.page-footer span:first-child { color: var(--green-dark); font-weight: 800; }

.screen-overlay { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: 22px; border-radius: 9px; background: rgba(28, 39, 32, .32); backdrop-filter: blur(3px); }
.screen-overlay[hidden] { display: none; }
.dialog { width: min(100%, 390px); padding: 29px 30px 25px; border: 1px solid rgba(255,255,255,.82); border-radius: 10px; background: var(--white); box-shadow: 0 16px 48px rgba(19, 32, 24, .2); animation: dialog-in 220ms ease-out both; }
.dialog-kicker { display: flex; align-items: center; gap: 7px; color: var(--green-dark); font-size: 9px; font-weight: 850; letter-spacing: .9px; }
.sparkle { color: #e0ad22; font-size: 14px; }
.start-dialog h1 { margin: 13px 0 9px; font-size: 50px; line-height: .98; font-weight: 900; }
.start-dialog h1 span { color: var(--green-dark); }
.dialog-rule { max-width: 290px; margin: 0; font-size: 17px; font-weight: 750; line-height: 1.35; }
.dialog-help { margin: 13px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.primary-button { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 48px; padding: 0 16px; border: 0; border-radius: 6px; background: var(--green); color: #23301f; font-size: 14px; font-weight: 850; cursor: pointer; transition: transform 130ms ease, background 130ms ease; }
.primary-button:hover { background: #a9e333; transform: translateY(-1px); }
.primary-button span { font-size: 20px; font-weight: 500; }
.dialog-footnote { margin: 12px 0 0; color: #7d877e; text-align: center; font-size: 10px; font-weight: 650; }
.compact-dialog { width: min(100%, 330px); padding: 26px; text-align: center; }
.dialog-symbol { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #e8f0e1; color: var(--green-dark); font-size: 20px; font-weight: 800; }
.compact-dialog h2 { margin: 12px 0 6px; font-size: 22px; }
.compact-dialog > p { margin: 0 0 21px; color: var(--muted); font-size: 12px; }
.result-kicker { color: var(--green-dark); }
.result-dialog h2 { margin-top: 7px; }
.result-scores { display: flex; justify-content: center; gap: 32px; margin: 19px 0 22px; }
.result-scores div { display: flex; flex-direction: column; gap: 3px; }
.result-scores span { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: 1px; }
.result-scores strong { font-size: 27px; font-variant-numeric: tabular-nums; }

.score-primary.is-bumping strong { animation: score-pop 300ms ease-out; }
.board-shell.is-flashing::after { position: absolute; inset: 11px; border: 3px solid rgba(255, 216, 51, .9); border-radius: 5px; content: ""; pointer-events: none; animation: collect-flash 360ms ease-out both; }

@keyframes dialog-in { from { opacity: 0; transform: translateY(7px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes score-pop { 50% { transform: scale(1.25); color: #cf6b28; } }
@keyframes collect-flash { from { opacity: .85; } to { opacity: 0; } }

@media (min-width: 900px) and (min-height: 760px) {
  .board-shell { width: min(100%, calc(100svh - 215px)); }
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 28px, 560px); padding-top: 12px; }
  .masthead { height: auto; min-height: 60px; display: grid; grid-template-columns: auto 1fr; grid-template-rows: 34px 20px; gap: 0 8px; }
  .brand { grid-column: 1; grid-row: 1; }
  .header-tools { grid-column: 2; grid-row: 1; justify-self: end; gap: 6px; }
  .language-select { width: 138px; min-height: 30px; font-size: 11px; }
  .masthead-note { grid-column: 1 / -1; grid-row: 2; justify-self: center; font-size: 8px; letter-spacing: .7px; }
  .version-tag { padding: 6px 7px; font-size: 8px; }
  .scoreboard { margin: 14px 0 13px; min-height: 59px; }
  .score-item { min-width: 78px; padding: 0 12px; }
  .score-primary { min-width: 92px; padding-left: 14px; }
  .score-item strong { font-size: 22px; }
  .score-label { font-size: 9px; }
  .icon-button { width: 37px; height: 37px; margin: 0 9px 0 0; }
  .game-layout { display: flex; flex-direction: column; align-items: stretch; gap: 17px; }
  .board-shell { width: min(100%, max(260px, calc(100svh - 390px))); min-width: 0; padding: 8px; }
  .board-caption { flex-wrap: wrap; gap: 7px 15px; margin-top: 8px; font-size: 10px; }
  .control-column { display: grid; grid-template-columns: minmax(0, 1fr) 170px; grid-template-rows: auto auto 1fr; column-gap: 10px; padding: 0 2px; }
  .control-heading { grid-column: 1; align-self: end; }
  .control-heading h2 { font-size: 18px; }
  .move-rate { padding: 5px 7px; font-size: 11px; }
  .control-instruction { grid-column: 1; grid-row: 2; max-width: 180px; margin: 7px 0 0; font-size: 11px; }
  .direction-pad { grid-column: 2; grid-row: 1 / span 3; width: min(100%, 166px); height: auto; aspect-ratio: 1; }
  .pad-track-vertical { width: 46px; left: calc(50% - 23px); }
  .pad-track-horizontal { height: 46px; top: calc(50% - 23px); }
  .pad-key { width: 41px; height: 41px; border-radius: 11px; font-size: 20px; }
  .pad-up { top: 8px; left: calc(50% - 20.5px); }
  .pad-right { right: 8px; top: calc(50% - 20.5px); }
  .pad-down { bottom: 8px; left: calc(50% - 20.5px); }
  .pad-left { left: 8px; top: calc(50% - 20.5px); }
  .pad-center { width: 26px; height: 26px; top: calc(50% - 13px); left: calc(50% - 13px); }
  .pad-hint { grid-column: 2; grid-row: 4; margin: 6px 0 0; font-size: 9px; white-space: nowrap; }
  .rule-note, .keyboard-note { display: none; }
  .page-footer { margin-top: auto; padding-top: 10px; }
  .screen-overlay { position: fixed; inset: 0; z-index: 20; border-radius: 0; overflow-y: auto; }
  .dialog { max-height: calc(100svh - 32px); overflow-y: auto; }
}

@media (max-width: 390px) {
  .app-shell { width: calc(100% - 20px); }
  .language-select { width: 128px; }
  .version-tag { display: none; }
  .score-item { min-width: 68px; padding: 0 9px; }
  .score-primary { min-width: 80px; padding-left: 11px; }
  .timer-item { min-width: 69px; }
  .board-shell { width: min(100%, max(260px, calc(100svh - 360px))); padding: 6px; }
  .screen-overlay { padding: 12px; }
  .dialog { padding: 22px; }
  .start-dialog h1 { font-size: 42px; }
  .dialog-rule { font-size: 15px; }
  .control-column { grid-template-columns: minmax(0, 1fr) 145px; }
  .direction-pad { width: min(100%, 145px); }
  .pad-key { width: 37px; height: 37px; }
  .pad-up { left: calc(50% - 18.5px); }
  .pad-right { top: calc(50% - 18.5px); }
  .pad-down { left: calc(50% - 18.5px); }
  .pad-left { top: calc(50% - 18.5px); }
  .pad-hint { font-size: 8px; }
}

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