/* 藍色の盤に、色ガラスのような5色のタイル。盤は両テーマで同じ深い藍、紙面だけテーマに追従 */
:root {
  --paper: #eceef4;
  --ink: #1a1f33;
  --muted: #5d6481;
  --line: #d3d7e4;
  --board: #1d2747;
  --well: #26325a;
  --accent: #e2a62a;
  --accent-ink: #2a1e05;
  --t0: #e0485a; /* 紅 */
  --t1: #f0b429; /* 山吹 */
  --t2: #46b36b; /* 若竹 */
  --t3: #3c86e0; /* 藍 */
  --t4: #9a6ae0; /* 藤 */
  --font-display: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  --dur: 180ms;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1220; --ink: #e7e9f2; --muted: #9aa1bd; --line: #2a3150;
    --board: #18203d; --well: #222c50; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1220; --ink: #e7e9f2; --muted: #9aa1bd; --line: #2a3150;
  --board: #18203d; --well: #222c50; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 20px 32px;
  display: grid;
  gap: 16px;
}

.top { display: grid; gap: 4px; }
.title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 30px;
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.title span { color: var(--accent); margin-left: 0.15em; font-weight: 700; }
.lede { margin: 0; color: var(--muted); font-size: 14px; text-wrap: balance; }

.hud {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
}
.stat {
  display: grid;
  gap: 2px;
  padding: 8px 12px;
  border-top: 2px solid var(--line);
  min-width: 0;
}
.stat.moves { border-top-color: var(--accent); }
.label { font-size: 11px; letter-spacing: 0.08em; color: var(--muted); }
.value { font-family: var(--font-display); font-variant-numeric: tabular-nums; line-height: 1.1; }
.value b { font-size: 26px; font-weight: 900; }
.value small { font-size: 13px; color: var(--muted); margin-left: 4px; font-weight: 500; }
.meter { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 100%; background: var(--accent); transition: width 300ms ease; }
.stat.low .value b { color: var(--t0); }
.stat.low .meter i { background: var(--t0); }
.bump { animation: bump 500ms ease; }
@keyframes bump { 30% { transform: scale(1.25); } }

.board-wrap { position: relative; }
.board {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  background: var(--board);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  touch-action: manipulation;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06), 0 10px 24px -14px rgb(10 14 30 / 0.6);
}
.board::before {
  /* マス目の溝 */
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(to right, rgb(255 255 255 / 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(255 255 255 / 0.05) 1px, transparent 1px);
  background-size: calc(100% / 6) calc(100% / 6);
  pointer-events: none;
}

.tile {
  position: absolute;
  left: 0; top: 0;
  width: calc(100% / 6);
  height: calc(100% / 6);
  display: block;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
  transition: transform var(--dur) cubic-bezier(.35, 0, .45, 1);
  font: inherit;
  color: inherit;
}
.tile.no-anim { transition: none; }
.face {
  position: absolute;
  inset: 6%;
  display: grid;
  place-items: center;
  border-radius: 24%;
  background: var(--tc);
  box-shadow:
    inset 0 -4px 0 rgb(0 0 0 / 0.22),
    inset 0 3px 0 rgb(255 255 255 / 0.28);
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 200ms ease;
}
.sym {
  font-size: clamp(16px, 6.4vw, 28px);
  line-height: 1;
  color: rgb(255 255 255 / 0.92);
  text-shadow: 0 1px 0 rgb(0 0 0 / 0.25);
  user-select: none;
}
.tile[data-color="0"] { --tc: var(--t0); }
.tile[data-color="1"] { --tc: var(--t1); }
.tile[data-color="1"] .sym { color: rgb(60 35 0 / 0.75); text-shadow: none; }
.tile[data-color="2"] { --tc: var(--t2); }
.tile[data-color="3"] { --tc: var(--t3); }
.tile[data-color="4"] { --tc: var(--t4); }

.tile.bomb .face {
  background:
    radial-gradient(circle at 50% 50%, transparent 52%, rgb(255 255 255 / 0.9) 53% 60%, transparent 61%),
    var(--tc);
}
.tile.bomb .face { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: inset 0 -4px 0 rgb(0 0 0 / 0.22), 0 0 0 3px rgb(255 255 255 / 0.35); } }

.tile:focus-visible { outline: none; }
.tile:focus-visible .face { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--accent); }
.tile.selected .face {
  transform: translateY(-6%) scale(1.06);
  box-shadow: 0 0 0 3px var(--accent), 0 6px 10px rgb(0 0 0 / 0.35);
}
.tile.pop .face { transform: scale(0.2) rotate(25deg); opacity: 0; transition-duration: 220ms; }
.tile.forge .face { animation: forge 380ms ease; }
@keyframes forge { 40% { transform: scale(1.3); } }
.tile.nope .face { animation: nope 300ms ease; }
@keyframes nope { 20%, 60% { transform: translateX(-8%); } 40%, 80% { transform: translateX(8%); } }

.blast {
  position: absolute;
  left: 0; top: 0;
  width: calc(100% / 2);
  height: calc(100% / 2);
  transform: translate(calc((var(--c) - 1) * 100% / 3), calc((var(--r) - 1) * 100% / 3));
  pointer-events: none;
}
.blast::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 20%;
  background: radial-gradient(circle, rgb(255 240 200 / 0.85), rgb(255 200 80 / 0) 70%);
  animation: blast 360ms ease-out forwards;
}
@keyframes blast { from { transform: scale(0.3); opacity: 1; } to { transform: scale(1.1); opacity: 0; } }

.callout {
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 28px;
  color: #fff;
  text-shadow: 0 2px 0 rgb(0 0 0 / 0.35), 0 0 18px rgb(0 0 0 / 0.4);
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
}
.callout.show { animation: callout 900ms ease forwards; }
@keyframes callout {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%); }
}

.over {
  position: absolute; inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  border-radius: 14px;
  background: rgb(14 18 36 / 0.78);
  color: #f3f4fa;
  text-align: center;
  backdrop-filter: blur(2px);
}
.over-title { margin: 0; font-family: var(--font-display); font-weight: 900; font-size: 30px; }
.over-score { margin: 0; font-size: 15px; }
.over-score b { font-family: var(--font-display); font-size: 34px; font-variant-numeric: tabular-nums; margin-left: 6px; color: var(--accent); }

.controls { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.btn {
  font: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }

.rules { border-top: 1px solid var(--line); padding-top: 8px; color: var(--muted); font-size: 14px; }
.rules summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.rules ul { margin: 8px 0 0; padding-left: 1.2em; display: grid; gap: 4px; }

@media (prefers-reduced-motion: reduce) {
  .tile.bomb .face { animation: none; }
}
