*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --ink: #35446b;
  --ink-soft: #7183a8;
  --ink-faint: #93a3c4;
  --card: rgba(255, 255, 255, 0.82);
  --card-strong: rgba(255, 255, 255, 0.94);
  --line: #d9e3f8;
  --line-strong: #a8bce3;
  --accent: #7c8cf8;
  --accent-deep: #6274ec;
  --mint: #7fd6c2;
  --peach: #ffb98a;
  --sun: #ffd873;
  --rose: #ff97b0;
  --danger: #dd5f7a;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --shadow-card: 0 18px 40px rgba(74, 96, 148, 0.15), 0 2px 0 rgba(255, 255, 255, 0.85) inset;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-display: "Chalkboard SE", "Comic Sans MS", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--ink);
  background: #e9f1fd;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

h1,
h2,
p {
  margin: 0;
}

button {
  font-family: inherit;
  color: inherit;
}

body.modal-open {
  overflow: hidden;
}

button:focus-visible {
  outline: 3px solid rgba(124, 140, 248, 0.62);
  outline-offset: 2px;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: url("../background.jpg") center / cover no-repeat;
  overflow: hidden;
}

.bg-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(155deg, rgba(247, 251, 255, 0.86) 0%, rgba(226, 241, 255, 0.7) 42%, rgba(255, 246, 236, 0.76) 100%);
}

.bg-bubble {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.5;
}

.bubble-a {
  width: 220px;
  height: 220px;
  left: -70px;
  top: 8%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.9), rgba(180, 218, 255, 0.25));
}

.bubble-b {
  width: 150px;
  height: 150px;
  right: -40px;
  top: 32%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.85), rgba(255, 216, 180, 0.35));
}

.bubble-c {
  width: 260px;
  height: 260px;
  left: 40%;
  bottom: -120px;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.8), rgba(185, 240, 225, 0.3));
}

.app {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(14px, 2.6vw, 30px) clamp(12px, 2.6vw, 30px) 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: clamp(14px, 2.2vw, 24px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 19px;
  color: #fff;
  background: linear-gradient(145deg, #9ad9ff, #7c8cf8);
  box-shadow: 0 12px 22px rgba(92, 122, 220, 0.32), inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.brand-mark svg {
  width: 30px;
  height: 30px;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: clamp(24px, 3.2vw, 34px);
  line-height: 1.1;
  letter-spacing: 1px;
  color: #3a4a74;
}

.tagline {
  margin-top: 3px;
  font-size: clamp(11px, 1.4vw, 13.5px);
  color: var(--ink-soft);
  letter-spacing: 0.5px;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.difficulty {
  display: flex;
  gap: 5px;
  padding: 6px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.72);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 22px rgba(90, 112, 168, 0.12);
}

.diff-btn {
  border: 0;
  background: transparent;
  border-radius: 14px;
  padding: 7px 15px;
  min-width: 70px;
  min-height: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}

.diff-btn span {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1px;
  opacity: 0.75;
}

.diff-btn:hover {
  background: rgba(124, 140, 248, 0.1);
}

.diff-btn:active {
  transform: scale(0.97);
}

.diff-btn[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(155deg, #94a0fb, #6d7df0);
  box-shadow: 0 8px 16px rgba(96, 112, 232, 0.35);
}

.diff-btn[aria-pressed="true"] span {
  opacity: 0.9;
}

.sound-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 0 14px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 8px 18px rgba(90, 112, 168, 0.12);
  transition: color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}

.sound-btn svg {
  width: 21px;
  height: 21px;
}

.sound-btn:hover {
  color: var(--accent-deep);
}

.sound-btn:active {
  transform: scale(0.97);
}

.sound-btn .icon-off {
  display: none;
}

.sound-btn.is-muted {
  color: var(--ink-faint);
  background: rgba(255, 255, 255, 0.6);
}

.sound-btn.is-muted .icon-on {
  display: none;
}

.sound-btn.is-muted .icon-off {
  display: block;
}

.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 336px);
  gap: clamp(14px, 2vw, 22px);
  align-items: start;
}

.board-card,
.panel {
  background: var(--card);
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.board-card {
  padding: clamp(12px, 1.8vw, 20px);
  min-width: 0;
}

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: clamp(10px, 1.4vw, 14px);
}

.level-tag {
  font-family: var(--font-display);
  font-size: clamp(15px, 1.7vw, 18px);
  font-weight: 700;
  color: #4a5c8a;
  padding-left: 2px;
}

.stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: inset 0 0 0 1px #e6ecfb;
  font-size: clamp(12px, 1.4vw, 13.5px);
  font-weight: 700;
  color: #4d5f8c;
  font-variant-numeric: tabular-nums;
}

.stat svg {
  width: 15px;
  height: 15px;
  color: var(--ink-faint);
}

.stat-pips {
  padding: 5px 9px;
}

.pips {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e3eafa;
  transition: background 0.2s ease, transform 0.2s ease;
}

.pip.is-on {
  background: linear-gradient(150deg, #ffb3c4, #ff8ba7);
  transform: scale(1.08);
}

.board-wrap {
  display: grid;
  place-items: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--size, 4), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size, 4), minmax(0, 1fr));
  width: min(100%, 526px, max(240px, calc(100vh - 300px)));
  width: min(100%, 526px, max(240px, calc(100dvh - 300px)));
  min-width: 0;
  aspect-ratio: 1 / 1;
  gap: 2px;
  padding: 7px;
  border-radius: 22px;
  background: #c3d3f0;
  box-shadow: 0 14px 28px rgba(84, 106, 160, 0.18), inset 0 0 0 2px rgba(255, 255, 255, 0.45);
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: #ffffff;
  color: #5a6fe0;
  font-family: var(--font-display);
  font-size: var(--cell-font, 26px);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.cell::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 -1px 0 rgba(31, 45, 90, 0.04);
  pointer-events: none;
}

.cell.bd-right {
  box-shadow: inset -3px 0 0 0 var(--line-strong);
}

.cell.bd-bottom {
  box-shadow: inset 0 -3px 0 0 var(--line-strong);
}

.cell.bd-right.bd-bottom {
  box-shadow: inset -3px 0 0 0 var(--line-strong), inset 0 -3px 0 0 var(--line-strong);
}

.cell.is-given {
  color: #3b4c7c;
  background: #f7faff;
}

.cell.is-peer {
  background: #edf4ff;
}

.cell.is-same {
  background: #fff5d9;
}

.cell.is-hint {
  color: #1f9c86;
  background: #e6faf3;
}

.cell.is-wrong {
  color: var(--danger);
  background: #ffe4ea;
}

.cell.is-selected {
  z-index: 2;
  background: #dbe8ff;
  box-shadow: inset 0 0 0 3px var(--accent);
}

.cell.is-selected.is-wrong {
  background: #ffdce5;
  box-shadow: inset 0 0 0 3px var(--danger);
}

.cell.is-selected.is-hint {
  background: #cdf5e9;
  box-shadow: inset 0 0 0 3px #34b49a;
}

.cell:focus-visible {
  outline: 3px solid rgba(124, 140, 248, 0.7);
  outline-offset: -3px;
}

.cell.pop {
  animation: cellPop 0.3s ease;
}

.cell.shake {
  animation: cellShake 0.4s ease;
}

.cell.sparkle-in {
  animation: hintPop 0.45s ease;
}

@keyframes cellPop {
  0% {
    transform: scale(0.72);
  }
  55% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes hintPop {
  0% {
    transform: scale(0.9);
    filter: brightness(1.4);
  }
  60% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
    filter: none;
  }
}

@keyframes cellShake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(2px);
  }
}

.board-tip {
  margin-top: clamp(10px, 1.4vw, 14px);
  text-align: center;
  font-size: clamp(11.5px, 1.4vw, 13px);
  color: var(--ink-faint);
  letter-spacing: 0.3px;
}

.panel {
  position: sticky;
  top: 18px;
  padding: clamp(14px, 1.8vw, 18px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.theme-picker {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 0 0 1px #e9eefb;
}

.theme-picker-label {
  flex: none;
  padding: 0 4px 0 7px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--ink-faint);
}

.theme-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 40px;
  padding: 5px 6px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.6);
}

.theme-btn:active {
  transform: scale(0.98);
}

.theme-btn[aria-pressed="true"] {
  color: #ffffff;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  box-shadow: 0 6px 12px rgba(96, 112, 232, 0.22);
}

.theme-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.theme-dot-ocean {
  background: #7fd6c2;
}

.theme-dot-minecraft {
  background: #7fb85a;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}

.panel-head h2 {
  font-family: var(--font-display);
  font-size: clamp(17px, 1.9vw, 19px);
  font-weight: 700;
  color: #46588a;
}

.panel-sub {
  font-size: 11.5px;
  color: var(--ink-faint);
}

.pad {
  display: grid;
  grid-template-columns: repeat(var(--pad-cols, 3), minmax(0, 1fr));
  gap: 9px;
}

.digit-btn {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 62px;
  padding: 6px 4px 12px;
  border: 2px solid #eef3ff;
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff, #eef4ff);
  color: #3d4f80;
  font-family: var(--font-display);
  font-size: clamp(23px, 2.6vw, 29px);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 0 #d9e2f7, 0 8px 16px rgba(90, 112, 168, 0.1);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}

.digit-btn:hover {
  background: linear-gradient(180deg, #ffffff, #e4ecff);
}

.digit-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #d9e2f7, 0 3px 8px rgba(90, 112, 168, 0.12);
}

.digit-btn .digit-left {
  position: absolute;
  right: 9px;
  bottom: 5px;
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 700;
  color: #9aa9ca;
  letter-spacing: 0.2px;
}

.digit-btn.is-complete {
  opacity: 0.42;
  cursor: default;
}

.digit-btn.is-complete:active {
  transform: none;
  box-shadow: 0 4px 0 #d9e2f7, 0 8px 16px rgba(90, 112, 168, 0.1);
}

.digit-btn.is-active {
  background: linear-gradient(180deg, #fff8e4, #ffe9b4);
  border-color: #ffe3a1;
  color: #9a6a18;
  box-shadow: 0 4px 0 #f0cf8a, 0 8px 16px rgba(220, 168, 64, 0.16);
}

.digit-btn.is-active .digit-left {
  color: #bb9145;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  padding: 8px 3px;
  border: 2px solid #eaf0fd;
  border-radius: 16px;
  background: #ffffff;
  color: #5b6c98;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 #e8eefb;
  transition: transform 0.12s ease, box-shadow 0.12s ease, color 0.15s ease, border-color 0.15s ease;
}

.ctrl-btn svg {
  width: 22px;
  height: 22px;
}

.ctrl-btn:hover {
  color: var(--accent-deep);
  border-color: #dfe8ff;
}

.ctrl-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.ctrl-btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
  box-shadow: 0 3px 0 #e8eefb;
}

.ctrl-btn.hint-btn {
  color: #2d9f8b;
  border-color: #d9f5ec;
  background: #fbfffd;
  box-shadow: 0 3px 0 #d9f5ec;
}

.ctrl-btn.hint-btn b {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 700;
  color: #55b9a6;
}

.ctrl-btn.new-btn {
  color: #6a7cf0;
  border-color: #e4e8ff;
  background: #fbfcff;
  box-shadow: 0 3px 0 #e4e8ff;
}

.panel-foot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 4px 0;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--ink-faint);
}

.dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.dot-mint {
  background: var(--mint);
  box-shadow: 0 0 0 3px rgba(127, 214, 194, 0.22);
}

.foot {
  margin-top: clamp(14px, 2vw, 20px);
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-soft);
  opacity: 0.85;
}

.toast {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(92vw, 420px);
  padding: 7px 16px 7px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 14px 30px rgba(70, 92, 146, 0.24), inset 0 0 0 1px #eef2fc;
  font-size: 13px;
  font-weight: 700;
  color: #4a5b88;
  opacity: 0;
  transform: translate(-50%, -14px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast-char {
  flex: none;
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff0f4;
  overflow: hidden;
}

.toast.has-char .toast-char {
  display: grid;
  place-items: center;
}

.toast-char svg,
.toast-char .char {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.toast.error {
  color: #b3475f;
}

.toast.success {
  color: #2c9b86;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(56, 70, 106, 0.34);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
}

.modal-layer[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  padding: clamp(18px, 4vw, 28px);
  border-radius: 32px;
  background: #fffdf9;
  box-shadow: 0 30px 70px rgba(50, 66, 110, 0.34), inset 0 0 0 2px #ffffff;
  text-align: center;
  animation: modalIn 0.36s cubic-bezier(0.22, 1.16, 0.4, 1);
}

.modal::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 150px;
  border-radius: 32px 32px 0 0;
  background: radial-gradient(circle at 50% 0%, rgba(255, 233, 201, 0.9), rgba(255, 255, 255, 0) 72%);
  pointer-events: none;
}

.modal-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(132px, 32vw, 180px);
  margin-bottom: 2px;
}

.modal-stage .char {
  width: 100%;
  height: 100%;
}

.modal-stage img.char {
  object-fit: contain;
  filter: drop-shadow(0 12px 16px rgba(80, 96, 140, 0.18));
}

.modal-stage img.pixel {
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 14px rgba(70, 90, 60, 0.2));
}

.modal[data-kind="fail"] .modal-stage img.char {
  transform-origin: 50% 92%;
  animation: charFloat 2.8s ease-in-out infinite;
}

.modal[data-kind="win"] .modal-stage img.char {
  transform-origin: 50% 92%;
  animation: photoBounce 1.7s ease-in-out infinite;
}

.char-name {
  position: relative;
  display: inline-block;
  margin-bottom: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: #eef6ff;
  color: #6477a5;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
}

.char-name[hidden] {
  display: none;
}

.modal[data-kind="fail"]::before {
  background: radial-gradient(circle at 50% 0%, rgba(255, 216, 228, 0.95), rgba(255, 255, 255, 0) 72%);
}

.modal[data-kind="win"]::before {
  background: radial-gradient(circle at 50% 0%, rgba(255, 233, 201, 0.95), rgba(255, 255, 255, 0) 72%);
}

.modal h2 {
  position: relative;
  margin-bottom: 6px;
  font-family: var(--font-display);
  font-size: clamp(22px, 4vw, 28px);
  color: #3c4d7c;
}

.modal p {
  position: relative;
  max-width: 300px;
  margin: 0 auto 14px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-soft);
}

.modal-extra {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.modal-extra:empty {
  display: none;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: #f0f5ff;
  font-size: 12.5px;
  font-weight: 700;
  color: #5b6c98;
}

.chip.gold {
  background: #fff1cd;
  color: #a1711c;
}

.modal-actions {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  min-height: 50px;
  padding: 12px 16px;
  border: 0;
  border-radius: 16px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn.primary {
  color: #ffffff;
  background: linear-gradient(150deg, #94a0fb, #6d7df0);
  box-shadow: 0 9px 18px rgba(96, 112, 232, 0.34);
}

.btn.ghost {
  color: #5b6c98;
  background: #f1f5ff;
}

.btn:active {
  transform: translateY(2px);
}

.btn:focus-visible {
  outline: 3px solid rgba(124, 140, 248, 0.55);
  outline-offset: 2px;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  border-radius: 3px;
  animation: confettiFall var(--dur, 2.6s) linear var(--delay, 0s) forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  100% {
    transform: translateY(112vh) rotate(var(--rot, 540deg));
    opacity: 0.9;
  }
}

@keyframes modalIn {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.char {
  overflow: visible;
}

.char-float {
  animation: charFloat 2.8s ease-in-out infinite;
  transform-origin: 50% 92%;
}

.char-bounce {
  animation: charBounce 1.5s ease-in-out infinite;
  transform-origin: 50% 92%;
}

.ear {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: earWiggle 2.4s ease-in-out infinite;
}

.ear-r {
  animation-delay: 0.25s;
}

.sparkle {
  transform-box: fill-box;
  transform-origin: center;
  animation: twinkle 1.8s ease-in-out infinite;
}

.sparkle-b {
  animation-delay: 0.45s;
}

.sparkle-group-c .sparkle {
  animation-delay: 0.8s;
}

.sparkle-c {
  animation-delay: 1.1s;
}

.gold-ingot {
  transform-box: fill-box;
  transform-origin: 60% 20%;
  animation: ingotTilt 3s ease-in-out infinite;
}

.scarf-tail {
  transform-box: fill-box;
  transform-origin: 85% 10%;
  animation: scarfWave 2.4s ease-in-out infinite;
}

.wave-line {
  stroke-dasharray: 14 10;
  animation: waveDash 3.2s linear infinite;
}

@keyframes ingotTilt {
  0%,
  100% {
    transform: rotate(-2deg);
  }
  50% {
    transform: rotate(3deg) translateY(-1px);
  }
}

@keyframes scarfWave {
  0%,
  100% {
    transform: rotate(-2deg);
  }
  50% {
    transform: rotate(2.5deg) translateY(-2px);
  }
}

@keyframes waveDash {
  to {
    stroke-dashoffset: -48;
  }
}

@keyframes charFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes photoBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

@keyframes charBounce {
  0%,
  100% {
    transform: translateY(0) rotate(-1.5deg);
  }
  50% {
    transform: translateY(-9px) rotate(1.5deg);
  }
}

@keyframes earWiggle {
  0%,
  100% {
    transform: rotate(0deg);
  }
  35% {
    transform: rotate(-7deg);
  }
  65% {
    transform: rotate(4deg);
  }
}

@keyframes twinkle {
  0%,
  100% {
    transform: scale(0.7) rotate(0deg);
    opacity: 0.55;
  }
  50% {
    transform: scale(1.1) rotate(18deg);
    opacity: 1;
  }
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 100;
  padding: 14px 18px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(60, 80, 130, 0.2);
  text-align: center;
  color: var(--ink);
}

body[data-theme="minecraft"] {
  --ink: #34432b;
  --ink-soft: #6f7f60;
  --ink-faint: #99a78e;
  --line: #dfe9d2;
  --line-strong: #adc694;
  --accent: #7fb85a;
  --accent-deep: #578d3b;
  --mint: #a5d96f;
  --peach: #d9a45f;
  --sun: #ffd873;
  --rose: #d98a6a;
  --shadow-card: 0 18px 40px rgba(74, 98, 58, 0.16), 0 2px 0 rgba(255, 255, 255, 0.85) inset;
  background: #eef5e7;
}

body[data-theme="minecraft"] .bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../assets/images/minecraft/pattern.png") repeat;
  background-size: 72px 72px;
  image-rendering: pixelated;
  mix-blend-mode: multiply;
  opacity: 0.07;
  pointer-events: none;
}

body[data-theme="minecraft"] .bg-overlay {
  background:
    linear-gradient(155deg, rgba(249, 253, 245, 0.88) 0%, rgba(228, 245, 218, 0.7) 45%, rgba(255, 247, 228, 0.76) 100%);
}

body[data-theme="minecraft"] .brand-mark {
  background: linear-gradient(145deg, #b8e08a, #6cae4f);
  box-shadow: 0 12px 22px rgba(94, 140, 68, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

body[data-theme="minecraft"] .brand-text h1 {
  color: #36462a;
}

body[data-theme="minecraft"] .diff-btn[aria-pressed="true"] {
  background: linear-gradient(155deg, #93ca70, #5c9c43);
  box-shadow: 0 8px 16px rgba(94, 140, 68, 0.32);
}

body[data-theme="minecraft"] .level-tag,
body[data-theme="minecraft"] .panel-head h2 {
  color: #465d36;
}

body[data-theme="minecraft"] .stat {
  color: #4d613d;
}

body[data-theme="minecraft"] .board {
  background: #c8dcb5;
}

body[data-theme="minecraft"] .cell {
  color: #4f7f37;
}

body[data-theme="minecraft"] .cell.is-given {
  color: #3c4a32;
  background: #f8fbf3;
}

body[data-theme="minecraft"] .cell.is-peer {
  background: #f1f8e9;
}

body[data-theme="minecraft"] .cell.is-same {
  background: #fdf3d7;
}

body[data-theme="minecraft"] .cell.is-hint {
  color: #3f8b3a;
  background: #eaf9e1;
}

body[data-theme="minecraft"] .cell.is-selected {
  background: #e2f3d1;
  box-shadow: inset 0 0 0 3px var(--accent);
}

body[data-theme="minecraft"] .cell.is-selected.is-wrong {
  background: #ffe0e6;
  box-shadow: inset 0 0 0 3px var(--danger);
}

body[data-theme="minecraft"] .cell.is-selected.is-hint {
  background: #d8f3c8;
  box-shadow: inset 0 0 0 3px #4e9b3e;
}

body[data-theme="minecraft"] .digit-btn {
  color: #405635;
  background: linear-gradient(180deg, #ffffff, #f1f8e8);
  border-color: #eaf3df;
  box-shadow: 0 4px 0 #dce9cf, 0 8px 16px rgba(86, 122, 64, 0.1);
}

body[data-theme="minecraft"] .digit-btn:hover {
  background: linear-gradient(180deg, #ffffff, #e6f2da);
}

body[data-theme="minecraft"] .digit-btn.is-active {
  color: #8f6a18;
  background: linear-gradient(180deg, #fff9e8, #ffe8af);
  border-color: #ffe0a0;
}

body[data-theme="minecraft"] .digit-btn .digit-left {
  color: #93a284;
}

body[data-theme="minecraft"] .stat {
  box-shadow: inset 0 0 0 1px #e4eed8;
}

body[data-theme="minecraft"] .ctrl-btn {
  color: #5f7050;
  border-color: #e6efdd;
  box-shadow: 0 3px 0 #e6efdd;
}

body[data-theme="minecraft"] .ctrl-btn.new-btn {
  color: #578d3b;
  border-color: #e2eed6;
  background: #fbfdf8;
  box-shadow: 0 3px 0 #e2eed6;
}

body[data-theme="minecraft"] .ctrl-btn.hint-btn {
  color: #3f8b3a;
  border-color: #dcedd1;
  box-shadow: 0 3px 0 #dcedd1;
}

body[data-theme="minecraft"] .btn.primary {
  background: linear-gradient(150deg, #93ca70, #5c9c43);
  box-shadow: 0 9px 18px rgba(94, 140, 68, 0.3);
}

body[data-theme="minecraft"] .theme-picker {
  box-shadow: inset 0 0 0 1px #e5eed9;
}

body[data-theme="minecraft"] .theme-btn[aria-pressed="true"] {
  box-shadow: 0 6px 12px rgba(94, 140, 68, 0.26);
}

@media (max-width: 880px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
  }

  .board-card,
  .panel {
    width: 100%;
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
  }

  .panel {
    position: static;
  }

  .board {
    width: min(100%, 526px);
  }

  .panel-head {
    margin-top: -2px;
  }

  .pad {
    gap: 8px;
  }

  .digit-btn {
    min-height: clamp(54px, 15vw, 68px);
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 10px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 16px;
  }

  .brand-mark svg {
    width: 26px;
    height: 26px;
  }

  .topbar-right {
    width: 100%;
    flex-wrap: nowrap;
  }

  .difficulty {
    flex: 1;
    justify-content: space-between;
  }

  .diff-btn {
    flex: 1;
    min-width: 0;
    padding: 6px 6px;
  }

  .sound-btn {
    flex: none;
    width: 48px;
    min-height: 48px;
    padding: 0;
    justify-content: center;
  }

  .sound-label {
    display: none;
  }

  .board {
    width: min(100%, 526px);
  }

  .board-tip {
    font-size: 11px;
  }

  .panel-sub {
    display: none;
  }

  .panel {
    gap: 12px;
  }
}

@media (max-width: 380px) {
  .cell {
    font-size: var(--cell-font, 20px);
  }

  .diff-btn {
    font-size: 15px;
  }

  .diff-btn span {
    font-size: 9.5px;
    letter-spacing: 0.5px;
  }

  .stat {
    padding: 4px 8px;
    font-size: 11.5px;
  }

  .panel {
    padding: 12px;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .app {
    padding-top: 10px;
  }

  .topbar {
    margin-bottom: 10px;
  }

  .tagline {
    display: none;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .brand-text h1 {
    font-size: 22px;
  }

  .diff-btn {
    min-height: 40px;
    padding: 4px 10px;
  }

  .sound-btn {
    min-height: 40px;
  }

  .game {
    grid-template-columns: minmax(0, 1fr) minmax(250px, 300px);
  }

  .board {
    width: min(100%, calc(100vh - 150px));
    width: min(100%, calc(100dvh - 150px));
  }

  .board-tip {
    display: none;
  }

  .panel {
    position: static;
    gap: 10px;
  }

  .digit-btn {
    min-height: 48px;
    font-size: 23px;
  }

  .ctrl-btn {
    min-height: 52px;
  }

  .panel-foot {
    display: none;
  }
}

@media (max-height: 600px) {
  .modal-layer {
    padding: 10px;
  }

  .modal {
    padding: 14px 20px 18px;
    border-radius: 26px;
  }

  .modal-stage {
    height: 104px;
    margin-bottom: 0;
  }

  .modal h2 {
    font-size: 21px;
  }

  .modal p {
    margin-bottom: 10px;
    font-size: 12.5px;
    line-height: 1.5;
  }

  .modal-extra {
    margin-bottom: 10px;
  }

  .char-name {
    margin-bottom: 4px;
  }

  .modal-actions .btn {
    min-height: 44px;
    padding: 10px 12px;
  }
}

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