:root {
  --paper: #f4efe6;
  --ink: #2a2622;
  --muted: #7a7268;
  --line: #3a342e;
  --box: #c45c26;
  --ok: #2f7d4a;
  --bad: #c43c2e;
  --given: #1f1c19;
  --user: #245a8e;
  --pad: #fffdf8;
  --locked: #d8d0c4;
  --safe: env(safe-area-inset-bottom, 0px);
  --top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 12%, rgba(196, 92, 38, 0.07), transparent 28%),
    radial-gradient(circle at 88% 84%, rgba(36, 90, 142, 0.06), transparent 30%),
    var(--paper);
  color: var(--ink);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(12px + var(--top)) 16px calc(12px + var(--safe));
}

h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1;
  letter-spacing: 0.18em;
  font-weight: 700;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 480px;
}
.screen.hidden { display: none; }

#select-screen {
  position: relative;
  justify-content: center;
  isolation: isolate;
  padding: 4px 0 8px;
}
.sound-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid rgba(47, 125, 74, 0.38);
  color: #2f6e46;
  background: rgba(238, 247, 240, 0.92);
  font-family: "Hiragino Sans", sans-serif;
  cursor: pointer;
}
.sound-toggle.is-muted {
  color: var(--muted);
  border-color: rgba(42, 38, 34, 0.24);
  background: rgba(235, 231, 224, 0.9);
}
.sound-icon {
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
}
.menu-sound {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 3;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 11px;
  box-shadow: 0 3px 10px rgba(42, 38, 34, 0.08);
}

.menu-decoration {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  color: rgba(42, 38, 34, 0.055);
  font-size: 66px;
  font-weight: 700;
}
.menu-decoration span { position: absolute; }
.menu-decoration span:nth-child(1) { left: -18px; top: 7%; transform: rotate(-12deg); }
.menu-decoration span:nth-child(2) { right: -10px; top: 20%; transform: rotate(10deg); }
.menu-decoration span:nth-child(3) { left: 12px; bottom: 10%; transform: rotate(7deg); }
.menu-decoration span:nth-child(4) { right: 6px; bottom: 2%; transform: rotate(-9deg); }

.menu-hero {
  text-align: center;
}
.menu-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
}
.app-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0;
  border-radius: 18px;
  color: #fffdf8;
  background: #c45c26;
  box-shadow: 0 8px 22px rgba(113, 54, 25, 0.22);
  transform: rotate(-3deg);
  transform-origin: center;
  animation: mark-turn 8s cubic-bezier(.4, 0, .2, 1) infinite;
  will-change: transform;
}
.app-mark::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(255, 253, 248, 0.62);
  border-radius: 13px;
}
.app-mark span {
  font-size: 33px;
  font-weight: 700;
  transform: rotate(3deg);
}
@keyframes mark-turn {
  0%, 68% { transform: rotate(-3deg) scale(1); }
  72% { transform: rotate(7deg) scale(1.04); }
  76% { transform: rotate(-9deg) scale(0.98); }
  90% { transform: rotate(357deg) scale(1.05); }
  94%, 100% { transform: rotate(357deg) scale(1); }
}
.menu-kicker,
.menu-lead,
.menu-rule {
  font-family: "Hiragino Sans", sans-serif;
}
.menu-kicker {
  margin: 0 0 7px;
  color: #a34b22;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
}
.menu-lead {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.levels {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  width: 100%;
}

.level-btn {
  appearance: none;
  position: relative;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 13px;
  overflow: hidden;
  border: 1px solid rgba(42, 38, 34, 0.24);
  background: rgba(255, 253, 248, 0.9);
  color: var(--ink);
  font: inherit;
  padding: 12px 14px 12px 12px;
  border-radius: 17px;
  min-height: 88px;
  text-align: left;
  box-shadow: 0 5px 0 rgba(42, 38, 34, 0.11), 0 12px 28px rgba(42, 38, 34, 0.05);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.level-btn::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--level-color);
}
.level-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(42, 38, 34, 0.11);
}
.level-easy { --level-color: #2f7d4a; --level-soft: #e1efe4; }
.level-medium { --level-color: #c45c26; --level-soft: #f7e4d5; }
.level-hard { --level-color: #245a8e; --level-soft: #dfeaf3; }
.level-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 15px;
  color: var(--level-color);
  background: var(--level-soft);
  font-size: 24px;
  font-weight: 700;
}
.level-copy {
  min-width: 0;
}
.level-copy strong {
  display: block;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0.05em;
}
.level-arrow {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #fffdf8;
  background: var(--level-color);
  font-family: "Hiragino Sans", sans-serif;
  font-size: 14px;
}

.level-btn small {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  font-family: "Hiragino Sans", sans-serif;
}
.level-btn .level-rec {
  color: var(--level-color);
  font-size: 12px;
  font-weight: 700;
  margin-top: 5px;
}
.menu-rule {
  margin: 18px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}
.menu-rule span {
  color: #c45c26;
  margin-right: 4px;
}
.level-btn:focus-visible,
.topbar button:focus-visible,
.pad button:focus-visible,
.sound-toggle:focus-visible {
  outline: 3px solid #e0a13b;
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-family: "Hiragino Sans", sans-serif;
}

.topbar button {
  appearance: none;
  border: 1px solid rgba(42, 38, 34, 0.35);
  background: rgba(255, 253, 248, 0.88);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 11px;
  min-height: 40px;
  box-shadow: 0 3px 0 rgba(42, 38, 34, 0.1);
}
.topbar button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(42, 38, 34, 0.1);
}
#btn-hint {
  color: #245a8e;
  border-color: rgba(36, 90, 142, 0.5);
  background: #edf4f9;
}
#btn-new {
  color: #9d461f;
  border-color: rgba(196, 92, 38, 0.48);
  background: #f9eee5;
}
.topbar .sound-toggle {
  flex: 0 0 40px;
  width: 40px;
  padding: 8px 6px;
}
.topbar .sound-label { display: none; }

#status {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: #675e54;
  text-align: center;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-wrap {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  width: 100%;
}
.board-wrap::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: min(100%, 100%);
  max-height: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.62);
  box-shadow: 0 14px 36px rgba(59, 45, 34, 0.16);
}

#board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: min(100%, 100%);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border: 3px solid var(--line);
  background: var(--line);
  gap: 1px;
  box-shadow: 0 2px 0 #fffdf8, 0 0 0 6px rgba(255, 253, 248, 0.72);
}

#board.board-enter {
  animation: board-enter 0.62s cubic-bezier(.2,.8,.2,1) both;
}
#board.board-enter .cell {
  animation: cell-enter 0.42s cubic-bezier(.2,.75,.25,1) both;
  animation-delay: var(--start-delay, 0ms);
}
#play-screen.game-enter .topbar {
  animation: toolbar-enter 0.45s ease-out both;
}
#play-screen.game-enter .pad {
  animation: pad-enter 0.5s ease-out 0.16s both;
}
@keyframes board-enter {
  from { opacity: 0.25; transform: translateY(8px) scale(0.975); box-shadow: 0 0 0 rgba(42, 38, 34, 0); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cell-enter {
  from { opacity: 0; transform: scale(0.72) rotate(-2deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes toolbar-enter {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pad-enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.cell {
  background: #fffdf8;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  font-size: clamp(14px, 4.8vmin, 26px);
  font-weight: 600;
}
.cell.tone { background: #fbf5ea; }

.cell.box-r { border-right: 2px solid var(--line); }
.cell.box-b { border-bottom: 2px solid var(--line); }
.cell.given {
  color: #1a1814;
  background: #e7dfd2;
  font-weight: 700;
}
.cell.tone.given { background: #ded8cc; }
.cell.user { color: #1b5ea8; }
.cell.sure {
  color: #1a6b3c;
  background: #d7eddc;
  font-weight: 700;
}
.cell.confirmed {
  z-index: 4;
  animation: number-confirm 0.72s cubic-bezier(.18,.89,.32,1.28) both;
}
.cell.confirmed::after {
  content: "✓";
  position: absolute;
  right: 2px;
  top: 2px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: #fffdf8;
  background: #2f7d4a;
  font-family: "Hiragino Sans", sans-serif;
  font-size: 10px;
  font-weight: 800;
  box-shadow: 0 2px 7px rgba(31, 92, 52, 0.32);
  animation: confirm-mark 0.72s cubic-bezier(.18,.89,.32,1.35) both;
}
@keyframes number-confirm {
  0% { transform: scale(0.78); background: #f8d878; box-shadow: inset 0 0 0 0 rgba(47, 125, 74, 0); }
  55% { transform: scale(1.09); background: #cbe8d2; box-shadow: inset 0 0 0 3px rgba(47, 125, 74, 0.72); }
  100% { transform: scale(1); background: #d7eddc; box-shadow: inset 0 0 0 0 rgba(47, 125, 74, 0); }
}
@keyframes confirm-mark {
  0% { opacity: 0; transform: scale(0) rotate(-18deg); }
  58% { opacity: 1; transform: scale(1.22) rotate(5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
.cell.forced { background: #e7f4ea; }
.cell.hint-target {
  z-index: 3;
  background: #ffe39a;
  box-shadow: inset 0 0 0 3px #c45c26, 0 0 16px rgba(224, 161, 59, 0.48);
  animation: hint-breathe 1.05s ease-in-out infinite;
}
.cell.hint-pulse {
  animation: hint-pulse 0.7s cubic-bezier(.18,.89,.32,1.35) both;
}
@keyframes hint-breathe {
  0%, 100% { box-shadow: inset 0 0 0 3px #c45c26, 0 0 8px rgba(224, 161, 59, 0.28); }
  50% { box-shadow: inset 0 0 0 3px #e0a13b, 0 0 21px rgba(224, 161, 59, 0.72); }
}
@keyframes hint-pulse {
  0% { transform: scale(0.86); }
  55% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.cell.sel {
  background: #ffe7c2;
  box-shadow: inset 0 0 0 3px #c45c26;
  animation: selblink 0.7s ease-in-out infinite;
  z-index: 1;
}
.cell.given.sel { background: #edd9b4; }
.cell.sure.sel { background: #d7eddc; }
.cell.forced.sel { background: #e7f4ea; }
.cell.bad.sel { background: #f8d8d4; }
@keyframes selblink {
  0%, 100% { box-shadow: inset 0 0 0 3px #c45c26; }
  50% { box-shadow: inset 0 0 0 3px rgba(196, 92, 38, 0.12); }
}
.cell.same { background: #efe4d4; }
.cell.given.same { background: #e0d5c4; }
.cell.sure.same { background: #d0e6d6; }
.cell.bad { color: var(--bad); background: #f8d8d4; }
.cell.bad.sel { background: #f8d8d4; }
.cell.bad.same { background: #f3cfc8; }
.cell.locked {
  background: var(--locked);
  color: transparent;
}
.cell.locked::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(-45deg, #cfc6b8 0 6px, #d8d0c4 6px 12px);
}
.cell.unlocking { animation: openbox 0.45s ease; }
@keyframes openbox {
  from { transform: scale(0.92); background: #f3c9a4; }
  to { transform: scale(1); }
}

.pad {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
  width: 100%;
  flex: 0 0 auto;
  position: relative;
  z-index: 6;
  font-family: "Hiragino Sans", sans-serif;
}

.pad button {
  appearance: none;
  border: 1.5px solid rgba(42, 38, 34, 0.68);
  background: linear-gradient(#fffdf8, #f8f2e8);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  min-width: 0;
  min-height: 44px;
  border-radius: 10px;
  box-shadow: 0 3px 0 rgba(42, 38, 34, 0.14);
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
}
.pad button:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(42, 38, 34, 0.14);
}
.pad button:disabled {
  opacity: 0.3;
  box-shadow: none;
}

.pad button.wide {
  grid-column: span 4;
  font-size: 15px;
  background: #e9e2d7;
}
.pad button.wide:last-child { grid-column: span 5; }

@media (orientation: portrait) {
  body {
    padding-left: 8px;
    padding-right: 8px;
  }
  #play-screen { max-width: 720px; }
  .pad {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 7px;
    margin-top: 12px;
  }

  .pad button[data-n] {
    grid-column: span 2;
    min-height: 54px;
    font-size: 24px;
    border-width: 2px;
  }

  .pad button.wide,
  .pad button.wide:last-child {
    grid-column: span 3;
    min-height: 48px;
    font-size: 16px;
  }
}

@media (orientation: portrait) and (max-width: 699px) {
  body {
    padding-left: 4px;
    padding-right: 4px;
  }

  .pad {
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 6px;
    margin-top: 10px;
  }

  .pad button[data-n] {
    grid-column: span 2;
    min-height: 56px;
    font-size: 25px;
  }

  .pad button[data-n]:nth-of-type(6) {
    grid-column: 2 / span 2;
  }

  .pad button.wide,
  .pad button.wide:last-child {
    grid-column: span 5;
    min-height: 48px;
  }

  #board,
  .board-wrap::before {
    width: 100%;
    max-height: none;
  }
}

@media (orientation: portrait) and (min-width: 700px) {
  .pad {
    grid-template-columns: repeat(18, minmax(0, 1fr));
    gap: 9px;
    margin-top: 14px;
  }
  .pad button[data-n] {
    grid-column: span 2;
    min-height: 76px;
    font-size: 30px;
  }
  .pad button.wide,
  .pad button.wide:last-child {
    grid-column: span 9;
    min-height: 60px;
    font-size: 18px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .screen { max-width: 820px; }
  #select-screen {
    display: grid;
    grid-template-columns: minmax(180px, 0.75fr) minmax(360px, 1.4fr);
    grid-template-rows: 1fr auto;
    column-gap: 28px;
    padding: 0;
  }
  #select-screen.hidden { display: none; }
  .menu-hero { grid-column: 1; grid-row: 1; }
  .app-mark {
    width: 52px;
    height: 52px;
  }
  .app-mark span { font-size: 28px; }
  .menu-hero h1 { font-size: 34px; }
  .menu-lead { font-size: 12px; }
  .levels {
    grid-column: 2;
    grid-row: 1;
    gap: 7px;
    margin: 0;
  }
  .level-btn {
    grid-template-columns: 44px minmax(0, 1fr) 24px;
    gap: 10px;
    min-height: 68px;
    padding: 8px 12px 8px 9px;
    border-radius: 14px;
  }
  .level-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 20px;
  }
  .level-copy strong { font-size: 17px; }
  .level-btn small { margin-top: 2px; font-size: 11px; }
  .level-btn .level-rec { margin-top: 2px; font-size: 10px; }
  .menu-rule {
    grid-column: 1 / -1;
    grid-row: 2;
    margin: 4px 0 0;
  }
  .pad {
    grid-template-columns: repeat(13, minmax(0, 1fr));
    gap: 4px;
    margin-top: 7px;
  }
  .pad button.wide,
  .pad button.wide:last-child {
    grid-column: span 2;
  }
  #board,
  .board-wrap::before {
    width: min(100%, calc(100dvh - 125px));
    max-height: none;
  }
}

@media (hover: hover) {
  .level-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 rgba(42, 38, 34, 0.1), 0 16px 30px rgba(42, 38, 34, 0.08);
  }
  .topbar button:hover,
  .pad button:not(:disabled):hover { filter: brightness(0.97); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(254px + var(--safe));
  z-index: 35;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 999px;
  font-family: "Hiragino Sans", sans-serif;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

@media (orientation: landscape) {
  .toast { bottom: calc(68px + var(--safe)); }
}

#clear-fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
#fw-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}
.reward-rays {
  position: absolute;
  left: 50%;
  top: 40%;
  z-index: 0;
  width: min(120vmin, 720px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: repeating-conic-gradient(from 4deg, rgba(240, 183, 66, 0.28) 0 4deg, transparent 4deg 12deg);
  mask-image: radial-gradient(circle, transparent 0 18%, #000 21% 48%, transparent 70%);
  -webkit-mask-image: radial-gradient(circle, transparent 0 18%, #000 21% 48%, transparent 70%);
  animation: reward-rays 2.8s ease-out both;
}
.clear-banner {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 100vw;
  display: grid;
  gap: 2px;
  text-align: center;
  color: #fffdf8;
  white-space: nowrap;
  text-shadow: 0 3px 18px rgba(42, 38, 34, 0.5);
  z-index: 2;
  animation: clear-pop 2.4s cubic-bezier(.18,.89,.32,1.16) both;
}
.clear-banner.set-banner {
  animation: set-clear-pop 2.8s cubic-bezier(.18,.89,.32,1.18) both;
}
.clear-banner.set-banner strong {
  color: #fff5cf;
  font-size: clamp(48px, 14vw, 82px);
  text-shadow: 0 4px 0 #a44720, 0 9px 32px rgba(42, 38, 34, 0.55);
}
.clear-banner small {
  font-family: "Hiragino Sans", sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.42em;
}
.clear-banner strong {
  display: block;
  width: 100%;
  font-size: clamp(58px, 17vw, 94px);
  line-height: 1;
  letter-spacing: 0.015em;
  text-align: center;
}
.clear-banner:not(.set-banner) strong {
  padding-left: 0.18em;
}
.clear-banner:not(.set-banner) strong span {
  display: inline-block;
  animation: clear-char 0.78s cubic-bezier(.18,.89,.32,1.35) both;
}
.clear-banner:not(.set-banner) strong span:nth-child(1) { animation-delay: 0.4s; }
.clear-banner:not(.set-banner) strong span:nth-child(2) { animation-delay: 0.56s; }
.clear-banner:not(.set-banner) strong span:nth-child(3) { animation-delay: 0.72s; }
.clear-banner:not(.set-banner)::after {
  content: "";
  justify-self: center;
  width: 108px;
  height: 4px;
  margin-top: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #f0b742 18% 82%, transparent);
  animation: clear-underline 0.68s ease-out 0.96s both;
}
@keyframes clear-pop {
  0% { transform: translate(-50%, -38%) scale(0.82); opacity: 0; filter: blur(7px); }
  18%, 80% { transform: translate(-50%, -50%) scale(1); opacity: 1; filter: blur(0); }
  100% { transform: translate(-50%, -58%) scale(1.06); opacity: 0; }
}
@keyframes clear-char {
  0% { opacity: 0; transform: translateY(20px) scale(0.62) rotate(-7deg); }
  68% { opacity: 1; transform: translateY(-6px) scale(1.12) rotate(2deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}
@keyframes clear-underline {
  from { opacity: 0; transform: scaleX(0); }
  to { opacity: 1; transform: scaleX(1); }
}
@keyframes set-clear-pop {
  0% { transform: translate(-50%, -40%) scale(0.52) rotate(-4deg); opacity: 0; filter: blur(9px); }
  22% { transform: translate(-50%, -50%) scale(1.12) rotate(2deg); opacity: 1; filter: blur(0); }
  38%, 76% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -58%) scale(1.08); opacity: 0; }
}
@keyframes reward-rays {
  from { transform: translate(-50%, -50%) scale(0.4) rotate(-18deg); opacity: 0; }
  30%, 72% { opacity: 1; }
  to { transform: translate(-50%, -50%) scale(1.25) rotate(12deg); opacity: 0; }
}
#board.board-cleared {
  animation: board-victory 0.85s ease-out both;
}
#board.board-cleared .cell {
  animation: cell-victory 0.58s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: var(--clear-delay, 0ms);
}
@keyframes board-victory {
  0%, 100% { box-shadow: 0 0 0 rgba(196, 92, 38, 0); }
  42% { box-shadow: 0 0 0 7px rgba(196, 92, 38, 0.22), 0 16px 42px rgba(42, 38, 34, 0.22); }
}
@keyframes cell-victory {
  0%, 100% { transform: scale(1); }
  48% { transform: scale(0.9); background: #f8d878; color: #5c351e; }
}

.congrats {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(42, 38, 34, 0.66);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  padding: 24px;
  animation: veil-in 0.28s ease-out both;
}
.congrats.hidden { display: none; }
.congrats-card {
  --reward-color: #c45c26;
  --reward-dark: #8c3e19;
  --reward-soft: #f7e4d5;
  position: relative;
  background: var(--pad);
  border: 1px solid rgba(42, 38, 34, 0.28);
  border-radius: 24px;
  padding: 48px 26px 24px;
  text-align: center;
  width: min(88vw, 360px);
  box-shadow: 0 24px 70px rgba(20, 16, 12, 0.34), inset 0 0 0 6px #f4efe6;
  animation: card-in 0.55s cubic-bezier(.18,.89,.32,1.18) both;
}
.congrats-card.reward-vermilion { --reward-color: #c45c26; --reward-dark: #8c3e19; --reward-soft: #f7e4d5; }
.congrats-card.reward-indigo { --reward-color: #315f91; --reward-dark: #20456d; --reward-soft: #e2ebf4; }
.congrats-card.reward-green { --reward-color: #3f7a55; --reward-dark: #28563a; --reward-soft: #e1eee5; }
.congrats-card.reward-gold { --reward-color: #b27b22; --reward-dark: #805614; --reward-soft: #f6ecd2; }
.congrats-card.reward-plum { --reward-color: #8b4864; --reward-dark: #623146; --reward-soft: #f1e3e9; }
.congrats-card::before,
.congrats-card::after {
  content: "";
  position: absolute;
  top: 20px;
  width: 42px;
  height: 1px;
  background: #d8c6a7;
}
.congrats-card::before { left: 24px; }
.congrats-card::after { right: 24px; }
.victory-seal {
  position: absolute;
  left: 50%;
  top: 0;
  width: 68px;
  height: 68px;
  translate: -50% -42%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fffdf8;
  background: var(--reward-color);
  border: 5px solid var(--pad);
  box-shadow: 0 6px 18px rgba(94, 47, 24, 0.28);
}
.victory-seal::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255, 253, 248, 0.65);
  border-radius: inherit;
}
.victory-seal span {
  font-family: "Hiragino Sans", sans-serif;
  font-size: 30px;
  font-weight: 800;
  transform: rotate(-7deg);
}
.congrats-kicker {
  margin: 0;
  font-family: "Hiragino Sans", sans-serif;
  font-size: 13px;
  color: var(--reward-color);
  font-weight: 700;
  letter-spacing: 0.12em;
}
.congrats-card h2 {
  margin: 7px 0 8px;
  font-size: 32px;
  letter-spacing: 0.09em;
}
.congrats-sub {
  margin: 0 0 20px;
  font-family: "Hiragino Sans", sans-serif;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
}
.set-progress {
  margin: 0 0 22px;
  padding: 13px 14px 14px;
  border-radius: 12px;
  background: #f4efe6;
  font-family: "Hiragino Sans", sans-serif;
}
.set-progress-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}
.set-progress-label strong {
  color: var(--ink);
  font-size: 14px;
}
.set-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ddd3c4;
}
.set-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--reward-color), #e0a13b);
  transition: width 0.8s cubic-bezier(.2,.8,.2,1) 0.3s;
}
.reward-note {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -9px 0 20px;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--reward-color) 28%, transparent);
  border-radius: 13px;
  text-align: left;
  background: var(--reward-soft);
  font-family: "Hiragino Sans", sans-serif;
  animation: reward-note-in 0.55s cubic-bezier(.18,.89,.32,1.18) 0.25s both;
}
.reward-note.hidden { display: none; }
.reward-glyph {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fffdf8;
  background: var(--reward-color);
  font-size: 21px;
  font-weight: 700;
}
.reward-copy { min-width: 0; }
.reward-copy small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
}
.reward-copy strong {
  display: block;
  margin-top: 2px;
  color: var(--reward-color);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 18px;
  letter-spacing: 0.07em;
}
.congrats-card button {
  appearance: none;
  width: 100%;
  border: 0;
  background: var(--reward-color);
  color: #fffdf8;
  font: inherit;
  font-family: "Hiragino Sans", sans-serif;
  font-size: 18px;
  padding: 12px 22px;
  border-radius: 13px;
  min-height: 52px;
  box-shadow: 0 5px 0 var(--reward-dark);
  cursor: pointer;
}
.congrats-card button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--reward-dark);
}
.congrats-card button:focus-visible {
  outline: 3px solid #f0b742;
  outline-offset: 4px;
}
@keyframes veil-in { from { opacity: 0; } }
@keyframes card-in {
  from { opacity: 0; transform: translateY(24px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes reward-note-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .clear-banner, .clear-banner strong span, .clear-banner::after,
  #board.board-cleared, #board.board-cleared .cell, .congrats, .congrats-card,
  #board.board-enter, #board.board-enter .cell, #play-screen.game-enter .topbar, #play-screen.game-enter .pad,
  .reward-rays, .reward-note, .cell.confirmed, .cell.confirmed::after, .app-mark,
  .cell.hint-target, .cell.hint-pulse {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
  }
  .set-progress-track span { transition: none; }
}
