/* ==========================================================================
   MYRA SUDOKU · 麥麥數獨 — Bespoke Cozy Illustration & Responsive Stylesheet
   ========================================================================== */

:root {
  --bg-page: #fdf7f0;
  --bg-gradient: radial-gradient(circle at 18% 12%, #fff9f2 0%, #faeee2 52%, #f5e3d3 100%);
  --bg-card: rgba(255, 252, 248, 0.92);
  --bg-card-strong: #fffdf9;
  --border-soft: rgba(180, 132, 108, 0.24);
  --border-strong: #8d5b4c;
  --text-main: #3d2822;
  --text-muted: #7d5f54;
  --accent: #d97757;
  --accent-strong: #b85335;
  --accent-soft: rgba(217, 119, 87, 0.16);
  --gold-star: #d99326;
  --cell-bg: #fffefb;
  --cell-peer: #f9efe4;
  --cell-same: #f6d5c1;
  --cell-selected: #f4b393;
  --cell-monogram: #fdf0eb;
  --cell-hint: #fde68a;
  --cell-error: #fecdd3;
  --digit-given: #35221c;
  --digit-user: #b84a27;
  --fog-bg: linear-gradient(135deg, #efe2d3 0%, #e5d2be 100%);
  --thermo-stroke: rgba(236, 114, 151, 0.44);
  --shadow-cozy: 0 12px 32px rgba(92, 55, 38, 0.10);
  --shadow-pop: 0 6px 18px rgba(92, 55, 38, 0.14);
}

body[data-theme="study"] {
  --bg-page: #f5f3ee;
  --bg-gradient: radial-gradient(circle at 20% 10%, #faf9f5 0%, #ebe7de 58%, #dfd9cc 100%);
  --bg-card: rgba(252, 251, 247, 0.94);
  --bg-card-strong: #fcfbf8;
  --border-soft: rgba(100, 92, 79, 0.24);
  --border-strong: #4a443b;
  --text-main: #2c2823;
  --text-muted: #665f54;
  --accent: #5c7467;
  --accent-strong: #3f5549;
  --accent-soft: rgba(92, 116, 103, 0.16);
  --gold-star: #c2852b;
  --cell-bg: #fdfcf9;
  --cell-peer: #efece4;
  --cell-same: #d5e2da;
  --cell-selected: #b7cec1;
  --cell-monogram: #eef4f0;
  --digit-given: #26231e;
  --digit-user: #355c47;
  --fog-bg: linear-gradient(135deg, #e2ded4 0%, #d4cfc2 100%);
}

body[data-theme="cafe"] {
  --bg-page: #f9f2eb;
  --bg-gradient: radial-gradient(circle at 80% 12%, #fff8f1 0%, #f1e2d3 55%, #e5ceb8 100%);
  --bg-card: rgba(255, 250, 245, 0.93);
  --bg-card-strong: #fffcf8;
  --border-soft: rgba(138, 90, 62, 0.25);
  --border-strong: #6b422b;
  --text-main: #382216;
  --text-muted: #785643;
  --accent: #b56546;
  --accent-strong: #8f472b;
  --accent-soft: rgba(181, 101, 70, 0.16);
  --gold-star: #cf8a25;
  --cell-bg: #fffdf9;
  --cell-peer: #f5eadf;
  --cell-same: #f3d1c4;
  --cell-selected: #eca894;
  --cell-monogram: #fdede8;
  --digit-given: #331e13;
  --digit-user: #9e3d22;
  --fog-bg: linear-gradient(135deg, #ead9c9 0%, #dcc4ae 100%);
}

body[data-theme="sakura"] {
  --bg-page: #231f33;
  --bg-gradient: radial-gradient(circle at 22% 14%, #352c4d 0%, #241e38 56%, #191528 100%);
  --bg-card: rgba(44, 37, 66, 0.90);
  --bg-card-strong: #31294a;
  --border-soft: rgba(244, 180, 200, 0.26);
  --border-strong: #e8a5bc;
  --text-main: #fdf4f7;
  --text-muted: #cbbdd6;
  --accent: #ec7ea3;
  --accent-strong: #d95d88;
  --accent-soft: rgba(236, 126, 163, 0.20);
  --gold-star: #fbbf24;
  --cell-bg: #2a2340;
  --cell-peer: #362d52;
  --cell-same: #57385c;
  --cell-selected: #78426d;
  --cell-monogram: #3b2b4a;
  --cell-hint: #6b5324;
  --cell-error: #6e273d;
  --digit-given: #fff5f8;
  --digit-user: #ff9ebb;
  --fog-bg: linear-gradient(135deg, #393056 0%, #2b2342 100%);
  --thermo-stroke: rgba(249, 148, 184, 0.52);
  --shadow-cozy: 0 14px 36px rgba(8, 5, 18, 0.45);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  font-family: "Nunito", "Quicksand", "PingFang TC", "PingFang SC", "Hiragino Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-page);
  background-image: var(--bg-gradient);
  color: var(--text-main);
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
button:active {
  transform: scale(0.96);
}

.hidden {
  display: none !important;
}

.screen {
  display: none;
  min-height: 100dvh;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ======================== FLOATING CELEBRATION PETALS ======================== */
.celebration-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 120;
  overflow: hidden;
}
.petal-spark {
  position: absolute;
  top: -32px;
  font-size: 20px;
  animation: petalFall linear forwards;
  opacity: 0.92;
}
@keyframes petalFall {
  0% {
    transform: translateY(0) rotate(0deg) scale(0.9);
    opacity: 1;
  }
  100% {
    transform: translateY(106dvh) rotate(320deg) scale(1.15);
    opacity: 0;
  }
}

/* ======================== SHARED BUTTONS & PILLS ======================== */
.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.pill-btn:hover {
  border-color: var(--accent);
}
.icon-pill {
  padding: 8px 11px;
}
.cta-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #ffffff;
  font-size: 14.5px;
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(184, 83, 53, 0.28);
}
.cta-primary:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

/* ======================== SCREEN 1: HOME SANCTUARY ======================== */
.home-topbar {
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
}
.brand-avatar {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-pop);
  object-fit: cover;
}
.brand-kicker {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.brand-title {
  margin: 1px 0 0;
  font-size: clamp(18px, 2.4vw, 24px);
  font-weight: 900;
  letter-spacing: -0.01em;
}
.brand-title span {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.86em;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.home-main {
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
  padding: 6px 18px max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.welcome-hero-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-soft);
  border-radius: 26px;
  padding: 18px 22px;
  display: grid;
  grid-template-columns: 168px 1fr;
  align-items: center;
  gap: 22px;
  box-shadow: var(--shadow-cozy);
}
.hero-sticker-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 22px;
  padding: 10px;
  height: 188px;
}
.hero-chibi-img {
  max-width: 100%;
  max-height: 168px;
  object-fit: contain;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.12));
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hero-chibi-img:hover {
  transform: scale(1.05) rotate(-2deg);
}
.hero-greeting-pill {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}
body[data-theme="sakura"] .hero-greeting-pill {
  color: #ffd1e1;
}
.hero-copy h2 {
  margin: 0 0 6px;
  font-size: clamp(18px, 2.3vw, 24px);
  line-height: 1.25;
}
.hero-copy p {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}
.hero-quick-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.sticker-mood-pills {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}
.mood-chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-card-strong);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 800;
}
.mood-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.section-heading-row h3 {
  margin: 0;
  font-size: 17px;
}
.solved-progress-pill {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 11px;
  border-radius: 999px;
}

.chapters-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.chapter-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-soft);
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-cozy);
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: var(--text-main);
}
.chapter-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}
.chapter-art-banner {
  position: relative;
  width: 100%;
  height: 164px;
  overflow: hidden;
  background: #e9dfd5;
}
.chapter-art-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
  transition: transform 0.35s ease;
}
.chapter-art-banner img[src*="pug_coffee"] {
  object-position: center 58%;
}
.chapter-card:hover .chapter-art-banner img {
  transform: scale(1.05);
}
.chapter-status-pill {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(30, 22, 20, 0.76);
  color: #fff8f0;
  font-size: 11px;
  font-weight: 800;
  backdrop-filter: blur(6px);
}
.chapter-status-pill.solved {
  background: rgba(22, 128, 75, 0.88);
  color: #ecfdf5;
}
.chapter-card-body {
  padding: 13px 14px 15px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}
.chapter-kicker {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
}
.chapter-card-body h4 {
  margin: 0;
  font-size: 16px;
}
.chapter-card-body p {
  margin: 2px 0 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
}
.chapter-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--accent-strong);
}
body[data-theme="sakura"] .chapter-badge-row {
  color: #ffb3cb;
}

.endless-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-soft);
  border-radius: 22px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  box-shadow: var(--shadow-cozy);
}
.endless-kicker {
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.endless-info h3 {
  margin: 3px 0 4px;
  font-size: 17px;
}
.endless-info p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 500px;
}
.endless-controls {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.theme-picker-row,
.diff-buttons-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.mini-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  margin-right: 2px;
}
.theme-dot-btn {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-card-strong);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 700;
}
.theme-dot-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.diff-launch-btn {
  padding: 8px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-card-strong);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 800;
}
.diff-launch-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ======================== SCREEN 2: ACTIVE PUZZLE SANCTUARY ======================== */
.game-topbar {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 14px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.game-title-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.puzzle-mode-pill {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
}
#hudPuzzleTitle {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-meta-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.timer-pill {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
}
.tiny-toggle {
  padding: 5px 10px;
  font-size: 11.5px;
}

.game-workspace {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  padding: 6px 16px max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 268px minmax(300px, 520px) 278px;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

/* Companion Mascot + Framed Art */
.companion-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.mascot-bubble-wrap {
  background: var(--bg-card);
  border: 1.5px solid var(--border-soft);
  border-radius: 22px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-cozy);
}
.mascot-live-sticker {
  width: 78px;
  height: 98px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.14));
}
.mascot-speech-card {
  min-width: 0;
  flex: 1;
}
.speech-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}
.speech-header strong {
  font-size: 13px;
  color: var(--accent);
}
.progress-mini-chip {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
}
#mascotSpeechText {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-main);
}

.chapter-art-frame {
  background: var(--bg-card);
  border: 1.5px solid var(--border-soft);
  border-radius: 22px;
  padding: 10px;
  box-shadow: var(--shadow-cozy);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.chapter-art-frame img {
  width: 100%;
  height: 250px;
  object-fit: cover;
  object-position: center 20%;
  border-radius: 15px;
}
.chapter-art-frame img[src*="pug_coffee"] {
  object-position: center 56%;
}
.art-frame-caption {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  padding: 0 4px;
}

/* 9x9 Sudoku Grid & Overlays */
.board-stage {
  display: flex;
  align-items: center;
  justify-content: center;
}
.board-outer-frame {
  position: relative;
  width: min(500px, 68dvh, 92vw);
  aspect-ratio: 1 / 1;
  background: var(--border-strong);
  border: 3px solid var(--border-strong);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-cozy);
}
.thermo-svg-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}
.sudoku-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
}

.sudoku-cell {
  position: relative;
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  user-select: none;
  cursor: pointer;
  transition: background 0.14s ease;
}
.sudoku-cell[data-col="2"],
.sudoku-cell[data-col="5"] {
  border-right: 2.5px solid var(--border-strong);
}
.sudoku-cell[data-col="8"] {
  border-right: none;
}
.sudoku-cell[data-row="2"],
.sudoku-cell[data-row="5"] {
  border-bottom: 2.5px solid var(--border-strong);
}
.sudoku-cell[data-row="8"] {
  border-bottom: none;
}

.sudoku-cell.monogram-tint {
  background: var(--cell-monogram);
}
.sudoku-cell.peer-hl {
  background: var(--cell-peer);
}
.sudoku-cell.same-digit-hl {
  background: var(--cell-same);
}
.sudoku-cell.hint-related-hl {
  background: var(--cell-hint);
}
.sudoku-cell.selected {
  background: var(--cell-selected) !important;
  box-shadow: inset 0 0 0 2.5px var(--accent-strong);
}
.sudoku-cell.conflict {
  background: var(--cell-error) !important;
  animation: gentleShake 0.26s ease;
}
@keyframes gentleShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.cell-digit {
  position: relative;
  z-index: 3;
  font-size: clamp(17px, 3.1vmin, 27px);
  font-weight: 800;
  line-height: 1;
  color: var(--digit-user);
}
.sudoku-cell.given .cell-digit {
  color: var(--digit-given);
  font-weight: 900;
}
.sudoku-cell.pop-anim .cell-digit {
  animation: digitPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes digitPop {
  0% { transform: scale(0.5); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

.keepsake-star-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  z-index: 3;
  font-size: 9.5px;
  color: var(--gold-star);
  opacity: 0.85;
  pointer-events: none;
}

.cell-notes-grid {
  position: relative;
  z-index: 3;
  width: 90%;
  height: 90%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  pointer-events: none;
}
.cell-notes-grid span {
  font-size: clamp(7.5px, 1.15vmin, 10.5px);
  font-weight: 800;
  line-height: 1;
  color: var(--text-muted);
}

/* Morning Mist Fog-of-War Veil */
.sudoku-cell.fogged {
  background: var(--fog-bg) !important;
}
.sudoku-cell.fogged::after {
  content: "☁️";
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(12px, 2vmin, 17px);
  opacity: 0.42;
}
.sudoku-cell.fogged .cell-digit,
.sudoku-cell.fogged .cell-notes-grid,
.sudoku-cell.fogged .keepsake-star-badge {
  opacity: 0;
}

/* Controls & Keypad */
.controls-panel {
  background: var(--bg-card);
  border: 1.5px solid var(--border-soft);
  border-radius: 24px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-cozy);
}
.tool-actions-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.tool-btn {
  padding: 8px 4px;
  border-radius: 13px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-card-strong);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.tool-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}
body[data-theme="sakura"] .tool-btn.active {
  color: #ffc2d6;
}
.hint-tool-btn {
  border-color: rgba(217, 147, 38, 0.45);
}
.tool-ic {
  font-size: 17px;
  line-height: 1;
}
.tool-btn small {
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.num-btn {
  position: relative;
  min-height: 54px;
  border-radius: 15px;
  border: 1.5px solid var(--border-soft);
  border-bottom-width: 3px;
  background: var(--bg-card-strong);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
}
.num-btn:hover {
  border-color: var(--accent);
}
.num-btn.pinned {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.num-btn.completed-digit {
  opacity: 0.42;
}
.num-main {
  font-size: 21px;
  font-weight: 900;
  line-height: 1.05;
}
.num-rem {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
}

.fast-mode-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.fast-pin-pill {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--bg-card-strong);
  color: var(--text-main);
  font-size: 11.5px;
  font-weight: 700;
}
.fast-pin-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.link-subtle-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 700;
  text-decoration: underline;
}

/* ======================== MODALS (VICTORY, GALLERY, CUSTOMIZER) ======================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(24, 16, 14, 0.62);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-card {
  position: relative;
  width: min(560px, 95vw);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  background: var(--bg-card-strong);
  color: var(--text-main);
  border: 2px solid var(--border-soft);
  border-radius: 26px;
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
}
.gallery-modal-card {
  width: min(860px, 96vw);
}
.modal-close-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 15px;
  font-weight: 800;
}
.victory-card > .modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
}
.modal-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-top-row h2 {
  margin: 2px 0 0;
  font-size: 20px;
}
.victory-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.victory-sticker {
  width: 82px;
  height: 104px;
  object-fit: contain;
  flex-shrink: 0;
}
.victory-kicker {
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.victory-header h2 {
  margin: 2px 0 4px;
  font-size: 21px;
}
.victory-stats {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.polaroid-showcase {
  background: #fffdf9;
  color: #3d2822;
  border: 1px solid rgba(180, 132, 108, 0.28);
  border-radius: 18px;
  padding: 10px 10px 12px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.10);
  margin-bottom: 12px;
  text-align: center;
}
.polaroid-showcase img {
  width: 100%;
  max-height: 225px;
  object-fit: contain;
  background: #f8efe6;
  border-radius: 12px;
}
.polaroid-showcase p {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 700;
}

.keepsake-cipher-box {
  background: var(--accent-soft);
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 14px;
  text-align: center;
}
.cipher-kicker {
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--gold-star);
  margin-bottom: 8px;
}
.secret-tiles-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.secret-flip-tile {
  background: var(--bg-card-strong);
  border: 1.5px solid rgba(217, 147, 38, 0.45);
  border-radius: 11px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
}
.secret-flip-tile small {
  color: var(--gold-star);
  font-weight: 900;
}
.custom-letter-note {
  margin: 10px 0 2px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}
.modal-actions-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.gallery-polaroid {
  background: var(--bg-card);
  border: 1.5px solid var(--border-soft);
  border-radius: 18px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.gallery-polaroid img {
  width: 100%;
  height: 210px;
  object-fit: cover;
  object-position: center 20%;
  border-radius: 12px;
}
.gallery-polaroid img[src*="pug_coffee"] {
  object-position: center 56%;
}
.gallery-polaroid.locked img {
  filter: blur(5px) grayscale(0.45) brightness(0.86);
}
.gallery-polaroid h4 {
  margin: 2px 0 0;
  font-size: 14.5px;
}
.gallery-polaroid p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Gift Customizer Inputs */
.modal-desc {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  margin: 10px 0 5px;
}
.text-input,
.text-area {
  width: 100%;
  border-radius: 12px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text-main);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
}
.save-feedback {
  margin: 10px 0 0;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--accent);
}

/* ======================== RESPONSIVE 1: TABLET & MEDIUM SCREENS ======================== */
@media (max-width: 1060px) and (orientation: portrait) {
  .chapters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .game-workspace {
    grid-template-columns: 1fr;
    max-width: 560px;
    gap: 10px;
  }
  .chapter-art-frame {
    display: none;
  }
}

/* ======================== RESPONSIVE 2: MOBILE PORTRAIT (360x740 .. 430x932) ======================== */
@media (max-width: 680px) and (orientation: portrait) {
  .hide-xs,
  .hide-mobile-portrait {
    display: none !important;
  }
  .home-topbar {
    padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  }
  .brand-avatar {
    width: 38px;
    height: 38px;
  }
  .brand-title {
    font-size: 17px;
  }
  .pill-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  .home-main {
    padding: 4px 12px 24px;
    gap: 14px;
  }
  .welcome-hero-card {
    grid-template-columns: 1fr;
    padding: 14px;
    gap: 12px;
    text-align: center;
  }
  .hero-sticker-stage {
    height: 138px;
  }
  .hero-chibi-img {
    max-height: 124px;
  }
  .hero-quick-row {
    justify-content: center;
  }
  .chapters-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .chapter-art-banner {
    height: 152px;
  }

  /* Zero-Scroll Mobile Portrait Game Layout */
  #gameScreen {
    height: 100dvh;
    overflow: hidden;
  }
  .game-topbar {
    padding: max(6px, env(safe-area-inset-top)) 10px 4px;
  }
  .puzzle-mode-pill {
    display: none;
  }
  #hudPuzzleTitle {
    font-size: 14px;
  }
  .game-workspace {
    padding: 2px 10px max(8px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 6px;
    min-height: 0;
  }
  .companion-panel {
    width: 100%;
  }
  .mascot-bubble-wrap {
    padding: 7px 10px;
    border-radius: 16px;
    gap: 8px;
  }
  .mascot-live-sticker {
    width: 50px;
    height: 62px;
  }
  #mascotSpeechText {
    font-size: 11.5px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .board-outer-frame {
    width: min(94vw, 49dvh);
    border-radius: 14px;
  }
  .controls-panel {
    width: 100%;
    padding: 9px 10px;
    border-radius: 18px;
    gap: 7px;
  }
  .numpad-grid {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 4px;
  }
  .num-btn {
    min-height: 46px;
    border-radius: 10px;
    padding: 2px 0;
  }
  .num-main {
    font-size: 18px;
  }
  .num-rem {
    font-size: 9px;
  }
  .tool-btn {
    padding: 6px 2px;
    border-radius: 10px;
  }
  .tool-ic {
    font-size: 15px;
  }
  .fast-mode-footer {
    padding-top: 1px;
  }
}

/* ======================== RESPONSIVE 3: MOBILE HORIZONTAL / LANDSCAPE (740x360 .. 932x430) ======================== */
@media (max-height: 540px) and (orientation: landscape) {
  .hide-compact-ls {
    display: none !important;
  }
  .home-topbar {
    padding: 6px 14px 4px;
  }
  .welcome-hero-card {
    grid-template-columns: 124px 1fr;
    padding: 10px 14px;
    gap: 14px;
  }
  .hero-sticker-stage {
    height: 126px;
  }
  .hero-chibi-img {
    max-height: 112px;
  }
  .hero-copy h2 {
    font-size: 16px;
  }
  .hero-copy p {
    font-size: 12px;
    margin-bottom: 8px;
  }
  .chapters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  /* Dedicated Side-by-Side Horizontal Game Arena (Zero Clipping at 360px-430px Height!) */
  #gameScreen {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  .game-topbar {
    padding: 4px max(12px, env(safe-area-inset-right)) 3px max(12px, env(safe-area-inset-left));
    min-height: 34px;
  }
  .game-topbar .pill-btn {
    padding: 4px 9px;
    font-size: 11.5px;
  }
  .timer-pill {
    padding: 3px 8px;
    font-size: 11.5px;
  }
  .game-workspace {
    height: calc(100dvh - 38px);
    max-height: calc(100dvh - 38px);
    padding: 3px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
    display: grid;
    grid-template-columns: auto minmax(260px, 380px);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "board companion"
      "board controls";
    align-items: stretch;
    justify-content: center;
    column-gap: 14px;
    row-gap: 6px;
  }
  .board-stage {
    grid-area: board;
    align-items: center;
  }
  .board-outer-frame {
    width: min(calc(100dvh - 48px), 46vw);
    height: min(calc(100dvh - 48px), 46vw);
    border-radius: 13px;
    border-width: 2.5px;
  }
  .companion-panel {
    grid-area: companion;
  }
  .chapter-art-frame {
    display: none;
  }
  .mascot-bubble-wrap {
    padding: 5px 9px;
    border-radius: 14px;
    gap: 8px;
  }
  .mascot-live-sticker {
    width: 42px;
    height: 52px;
  }
  .speech-header strong {
    font-size: 11.5px;
  }
  #mascotSpeechText {
    font-size: 11px;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .controls-panel {
    grid-area: controls;
    padding: 7px 9px;
    border-radius: 16px;
    gap: 5px;
    justify-content: space-between;
    min-height: 0;
  }
  .tool-actions-bar {
    gap: 4px;
  }
  .tool-btn {
    padding: 4px 2px;
    border-radius: 9px;
    gap: 1px;
  }
  .tool-ic {
    font-size: 13.5px;
  }
  .tool-btn small {
    font-size: 9px;
  }
  .numpad-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    flex: 1;
    min-height: 0;
  }
  .num-btn {
    min-height: 34px;
    border-radius: 10px;
    border-bottom-width: 2px;
    flex-direction: row;
    gap: 5px;
    padding: 2px 6px;
  }
  .num-main {
    font-size: 16px;
  }
  .num-rem {
    font-size: 9.5px;
  }
  .fast-mode-footer {
    padding: 0;
  }
  .fast-pin-pill {
    padding: 3px 8px;
    font-size: 10px;
  }
  .link-subtle-btn {
    font-size: 10px;
  }
}

/* ======================== PRINTABLE KEEPSAKE CARD ======================== */
@media print {
  body {
    background: #ffffff !important;
    color: #111111 !important;
  }
  #homeScreen,
  .game-topbar button,
  .controls-panel,
  .modal-backdrop {
    display: none !important;
  }
  #gameScreen {
    display: block !important;
  }
  .game-workspace {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 18px !important;
  }
  .board-outer-frame {
    width: 460px !important;
    height: 460px !important;
    border: 3px solid #111 !important;
  }
  .sudoku-cell.fogged::after {
    display: none !important;
  }
  .sudoku-cell.fogged .cell-digit {
    opacity: 1 !important;
  }
}
