@import url("fonts/clear-sans.css");

:root {
  color-scheme: light;
  --page: #faf8ef;
  --text: #675e55;
  --muted: #746a60;
  --surface: #fffdf7;
  --border: #d6cbbf;
  --board: #bbada0;
  --cell: #cdc1b4;
  --button: #796451;
  --button-hover: #65513f;
  --accent: #74540b;
  --focus: #005fa3;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--page); }
body {
  margin: 0;
  padding: 32px 16px;
  background: var(--page);
  color: var(--text);
  font: 16px/1.6 "Clear Sans", "Helvetica Neue", Arial, sans-serif;
}
body.dark-theme {
  color-scheme: dark;
  --page: #1a1a2e;
  --text: #f1ede7;
  --muted: #bcb7ca;
  --surface: #25253c;
  --border: #525269;
  --board: #2d2d44;
  --cell: #404056;
  --button: #494962;
  --button-hover: #5b5b76;
  --accent: #f4ce69;
  --focus: #69ceff;
}
p { margin: 0 0 12px; }
a { color: var(--accent); text-underline-offset: 3px; }
button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--button);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  cursor: pointer;
}
button:hover { background: var(--button-hover); }
button:disabled { opacity: .55; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.container { width: min(500px, 100%); margin: 0 auto; }
.heading { margin-bottom: 16px; }
h1.title { margin: 0 0 12px; font-size: 64px; line-height: 1.15; }
.hanazar-badge {
  display: inline-block;
  margin-left: 12px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
  vertical-align: middle;
}
.scores-container { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.scores-container > div {
  position: relative;
  min-width: 0;
  padding: 25px 6px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}
.scores-container > div::before {
  position: absolute;
  top: 6px;
  left: 0;
  width: 100%;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.score-container::before { content: "Score"; }
.best-container::before { content: "Best · all"; }
.moves-container::before { content: "Moves"; }
.efficiency-container::before { content: "Pts / move"; }
.timer-container::before { content: "Play time"; }
.best-moves-container::before { content: "Win moves"; }
.game-intro { margin: 0 0 14px; }
.game-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.undo-button { order: 1; }
.ai-toggle { order: 2; }
.restart-button { order: 3; }
.ai-toggle[aria-pressed="true"] { background: #a52f42; }
.grid-size-selector {
  order: 4;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.grid-size-btn { color: var(--text); background: var(--surface); border-color: var(--border); }
.grid-size-btn:hover { background: var(--cell); }
.grid-size-btn.active { color: #fff; background: var(--button); }
.game-container {
  position: relative;
  margin: 18px auto 0;
  width: 500px;
  height: 500px;
  border-radius: 8px;
  background: var(--board);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.grid-container, .tile-container { position: absolute; }
.grid-container { z-index: 1; }
.tile-container { z-index: 2; }
.grid-row { display: flex; }
.grid-row:last-child { margin-bottom: 0; }
.grid-cell { flex: none; border-radius: 4px; background: var(--cell); }
.grid-cell:last-child { margin-right: 0; }
.tile { position: absolute; top: 0; left: 0; }
.tile .tile-inner {
  border-radius: 4px;
  background: #eee4da;
  color: #675e55;
  font-weight: 700;
  text-align: center;
}
.tile.tile-4 .tile-inner { background: #ede0c8; }
.tile.tile-8 .tile-inner { background: #f2b179; color: #593315; }
.tile.tile-16 .tile-inner { background: #f59563; color: #53280f; }
.tile.tile-32 .tile-inner { background: #f67c5f; color: #521c10; }
.tile.tile-64 .tile-inner { background: #c84224; color: #fff; }
.tile.tile-128 .tile-inner { background: #edcf72; color: #51400d; }
.tile.tile-256 .tile-inner { background: #edcc61; color: #51400d; }
.tile.tile-512 .tile-inner { background: #edc850; color: #51400d; }
.tile.tile-1024 .tile-inner { background: #edc53f; color: #493b05; }
.tile.tile-2048 .tile-inner { background: #edc22e; color: #493b05; }
.tile.tile-super .tile-inner { background: #3c3a32; color: #fff; }
.game-message {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  padding: 20px;
  background: var(--surface);
  text-align: center;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}
.game-message.game-won, .game-message.game-over { display: flex; }
.game-message p { margin: 0; font-size: 32px; font-weight: 700; line-height: 1.3; }
.game-message .lower { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.keep-playing-button { display: none; }
.game-won .keep-playing-button { display: inline-block; }
.game-explanation { margin-top: 24px; }
hr { margin: 20px 0; border: 0; border-top: 1px solid var(--border); }
.brand-credit { color: var(--muted); font-size: 13px; text-align: center; }
.daily-challenge-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
}
.daily-label { color: var(--accent); }
.release-notes { display: grid; gap: 8px; margin: 16px 0; }
.release-current, .release-history {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
}
.release-current { display: grid; gap: 6px; }
.release-label { color: var(--accent); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.release-current span:last-child, .release-history p { color: var(--muted); }
.release-history summary { min-height: 28px; cursor: pointer; font-weight: 700; }
.release-history p { margin: 10px 0 0; }
.settings-bar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.settings-bar button { padding: 8px 6px; font-size: 12px; }
.settings-bar [aria-pressed="true"] { border-color: var(--accent); }
.reset-toggle { color: var(--text); background: var(--surface); border-color: var(--border); }
.reset-toggle:hover { color: #fff; background: #a52f42; }
.ui-status { min-height: 24px; margin-top: 10px; color: var(--accent); font-size: 13px; overflow-wrap: anywhere; }
.shortcuts-hint, .version-tag { margin-top: 12px; color: var(--muted); text-align: center; font-size: 12px; }
.shortcuts-hint span { font-weight: 700; }
.game-stats { display: none; padding: 14px; border: 1px solid var(--border); border-radius: 6px; }
.game-stats.stats-visible { display: block; }
.stats-title { margin-bottom: 12px; font-weight: 700; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat-item { text-align: center; }
.stat-val { display: block; font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.stat-label { display: block; font-size: 11px; color: var(--muted); }
.achievements-panel, .stats-panel, .leaderboard-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 101;
  width: min(440px, calc(100vw - 24px));
  max-height: min(80vh, calc(100dvh - 24px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 40px #0005;
}
.panel-open { display: block; }
.panel-visible { overflow: hidden; }
.panel-header, .achievements-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-title, .achievements-title { font-size: 18px; font-weight: 700; }
.panel-close, .achievements-close { flex: none; width: 44px; padding: 0; }
.panel-body, .achievements-list { display: grid; gap: 8px; }
.panel-note { color: var(--muted); font-size: 12px; margin: 12px 0 0; }
.achievement-item, .stats-row, .leaderboard-entry { padding: 10px; border: 1px solid var(--border); border-radius: 6px; }
.achievement-item.unlocked { border-color: var(--accent); }
.achievement-item p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.stats-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.stats-row strong { text-align: right; overflow-wrap: anywhere; }
.leaderboard-header, .leaderboard-row { display: grid; grid-template-columns: 32px minmax(0, 1fr) minmax(40px, .8fr) minmax(40px, .8fr); gap: 6px; align-items: center; font-size: 13px; }
.leaderboard-header { padding: 0 10px; font-size: 11px; color: var(--muted); }
.leaderboard-row span { overflow-wrap: anywhere; }
.leaderboard-context { margin: 6px 0 0; font-size: 11px; color: var(--muted); }
.first-place { font-weight: 700; color: var(--accent); }
.achievements-overlay { position: fixed; inset: 0; z-index: 100; background: #0009; }

@media (max-width: 520px) {
  body { padding: 20px 12px; font-size: 14px; }
  .container { width: min(280px, 100%); }
  h1.title { font-size: 42px; }
  .hanazar-badge { margin-left: 8px; font-size: 9px; }
  .game-actions > button { padding: 8px 4px; font-size: 12px; }
  .scores-container > div { font-size: 20px; }
  .settings-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-message p { font-size: 27px; }
}
