/* ==========================================================================
   TiltWorks — Commercial V3 Stylesheet ("Warm Artisan Toy" art direction)
   Premium tactile aesthetic: real PNG art, locally hosted fonts, unified icons.
   ========================================================================== */

/* ---------- CSS Reset & Global Variables ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

:root {
  /* Color Palette */
  --bg-dark: #1f140e;
  --parchment: #faf4e6;
  --parchment-dark: #eee3cb;
  --parchment-deep: #decfa8;

  --oak-light: #ab794b;
  --oak: #8a572c;
  --oak-dark: #5e371a;
  --oak-deep: #381d0b;

  --brass-light: #f5d47a;
  --brass: #c99a24;
  --brass-dark: #826010;

  --ink: #2b1d12;
  --ink-soft: #6d5543;
  --ink-muted: #967d6a;

  --accent-red: #c93b2b;
  --accent-green: #3b8a47;
  --accent-blue: #337ab7;
  --accent-gold: #e5a919;

  /* Typography (locally hosted — see assets/fonts/fonts.css) */
  --font-serif: 'Baloo 2', Georgia, serif;
  --font-sans: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, Monaco, monospace;

  /* Layout & Geometry */
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --shadow-frame: 0 25px 60px rgba(10, 5, 2, 0.6), 0 5px 15px rgba(10, 5, 2, 0.4);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background:
    radial-gradient(ellipse 130% 90% at 50% -10%, #4a2f18 0%, transparent 60%),
    radial-gradient(ellipse 120% 100% at 50% 115%, #180d06 0%, transparent 65%),
    linear-gradient(165deg, #2a1a0e 0%, #170d06 60%, #0d0603 100%);
  color: var(--ink);
}

/* ---------- Master App Wrapper — full-screen, edge to edge ---------- */
#app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

#frame {
  position: relative;
  flex: 1;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  /* notch / home-indicator safe areas — resolves to 0 on devices without them */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  border-radius: 0;
  background: linear-gradient(155deg, var(--oak-light) 0%, var(--oak) 40%, var(--oak-dark) 75%, var(--oak-deep) 100%);
  box-shadow: none;
  display: flex;
  flex-direction: column;
}

/* ---------- Screen Architecture ---------- */
.screen {
  position: absolute;
  inset: 0;
  border-radius: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.985);
  transition: opacity 0.26s ease, transform 0.26s ease;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
  z-index: 2;
}

/* ==========================================================================
   LOADING OVERLAY
   ========================================================================== */
#loadingOverlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background:
    radial-gradient(ellipse at 50% 30%, #3a2413 0%, #24150a 55%, #150b04 100%);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loadingOverlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-logo {
  width: min(320px, 62vw);
  filter: drop-shadow(0 14px 30px rgba(0, 0, 0, 0.55));
  animation: loaderFloat 2.6s ease-in-out infinite;
}

@keyframes loaderFloat {
  0%, 100% { transform: translateY(0) rotate(-1.2deg); }
  50% { transform: translateY(-10px) rotate(1.2deg); }
}

.loader-bar {
  width: min(300px, 60vw);
  height: 14px;
  border-radius: 10px;
  background: rgba(20, 11, 4, 0.65);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(245, 212, 122, 0.35);
  overflow: hidden;
}

.loader-fill {
  height: 100%;
  width: 0%;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--brass-dark), var(--brass-light));
  box-shadow: 0 0 10px rgba(245, 212, 122, 0.55);
  transition: width 0.25s ease;
}

.loader-caption {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: rgba(245, 212, 122, 0.85);
}

/* ==========================================================================
   PNG ICON SYSTEM (unified hand-crafted family)
   ========================================================================== */
.icon-img {
  width: 1.3em;
  height: 1.3em;
  display: inline-block;
  vertical-align: -0.28em;
  flex-shrink: 0;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(40, 20, 5, 0.18));
  pointer-events: none;
}

.icon-img.sm { width: 1.02em; height: 1.02em; }
.icon-img.lg { width: 1.55em; height: 1.55em; }

/* ==========================================================================
   SCREEN 1: MAIN MENU
   ========================================================================== */
#screen-menu {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(20, 11, 4, 0.32) 0%, rgba(20, 11, 4, 0.05) 30%, rgba(20, 11, 4, 0.05) 62%, rgba(20, 11, 4, 0.42) 100%),
    radial-gradient(ellipse 90% 78% at 50% 46%, rgba(250, 244, 230, 0.88) 0%, rgba(250, 244, 230, 0.55) 55%, rgba(250, 244, 230, 0.12) 100%),
    url('../assets/img/menu-bg.png') center / cover no-repeat;
}

.menu-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
}

.brand-logo {
  width: min(400px, 68vw, 46dvh);
  max-height: 42dvh;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px rgba(30, 15, 4, 0.35));
  animation: brandSway 3.6s ease-in-out infinite;
  transform-origin: 50% 20%;
}

@keyframes brandSway {
  0%, 100% { transform: rotate(-1deg); }
  50% { transform: rotate(1deg); }
}

.brand-sub {
  font-family: var(--font-sans);
  font-size: clamp(0.8rem, 2vw, 1rem);
  font-weight: 900;
  color: var(--ink-soft);
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-top: 10px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.brand-sub::before, .brand-sub::after {
  content: '✦';
  color: var(--brass);
  font-size: 0.7em;
  margin: 0 8px;
  vertical-align: middle;
}

.menu-stats-row {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.stat-chip {
  background: linear-gradient(180deg, var(--oak-light), var(--oak-dark));
  color: #fff9ed;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 8px 18px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 3px 0 var(--oak-deep), 0 5px 12px rgba(60, 30, 10, 0.3);
}

.menu-buttons {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  width: min(330px, 82vw);
}

.corner-btn {
  position: absolute;
  top: 16px;
  z-index: 10;
  background: linear-gradient(180deg, #fffdf8, var(--parchment-dark));
  border: 1.5px solid #d8c79c;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 3px 0 #c0b085, 0 6px 12px rgba(80, 50, 20, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease;
}

.corner-btn .icon-img {
  width: 22px;
  height: 22px;
}

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

#menuSoundToggle { right: 18px; }
#menuMusicToggle { right: 68px; }
#settingsBtnMenu { left: 18px; }

.menu-footer {
  position: absolute;
  bottom: 12px;
  font-size: 0.74rem;
  font-weight: 800;
  color: #fff3dd;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(30, 15, 4, 0.65);
}

/* ==========================================================================
   SCREEN 2: LEVEL SELECT
   ========================================================================== */
#screen-levels {
  padding: 20px 24px;
  background: linear-gradient(180deg, #fffefb, var(--parchment) 60%);
}

.levels-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.levels-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.levels-progress-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--brass-dark);
  background: rgba(255, 235, 160, 0.4);
  border: 1px solid var(--brass);
  padding: 6px 12px;
  border-radius: 16px;
}

.panel-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chapters-scroll {
  flex: 1;
  overflow-y: auto;
  padding-right: 6px;
}

.chapter-card {
  background: linear-gradient(180deg, #fffdf8, var(--parchment-dark));
  border: 1.5px solid #ddcd9f;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: 0 3px 8px rgba(80, 50, 20, 0.08);
}

.chapter-card.locked {
  opacity: 0.55;
  filter: saturate(0.4);
}

.chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}

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

.chapter-thumb {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid #d8c79c;
  box-shadow: 0 3px 6px rgba(70, 45, 15, 0.22);
  flex-shrink: 0;
}

.chapter-pill {
  color: #ffffff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.76rem;
  padding: 4px 10px;
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.chapter-name {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.chapter-sub {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 2px;
}

.chapter-stars-pill {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--brass-dark);
  background: rgba(255, 235, 160, 0.4);
  border: 1px solid var(--brass);
  padding: 4px 10px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

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

.lvl-btn {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1.5px solid #d4c295;
  background: linear-gradient(180deg, #fffcf5, var(--parchment-dark));
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 3px 0 #c2b184, 0 4px 8px rgba(70, 45, 15, 0.1);
  transition: transform 0.08s ease;
}

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

.lvl-btn.locked {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.lvl-btn .icon-img {
  width: 18px;
  height: 18px;
  vertical-align: middle;
}

.lvl-btn.current {
  background: linear-gradient(180deg, #fff8e1, #ffecb3);
  border-color: var(--brass);
  box-shadow: 0 3px 0 var(--brass-dark), 0 0 0 2px rgba(201, 154, 36, 0.35);
}

.lvl-btn.signature {
  border-color: var(--brass);
  position: relative;
}

.lvl-btn.signature::after {
  content: '';
  position: absolute;
  top: -6px;
  right: -5px;
  width: 15px;
  height: 15px;
  background: url('../assets/img/ui/icon-star-gold.png') center / contain no-repeat;
  filter: drop-shadow(0 1px 1px rgba(40, 20, 5, 0.3));
}

.lvl-stars-row {
  display: flex;
  gap: 1px;
  margin-top: 2px;
  height: 8px;
}

.lvl-stars-row .icon-img {
  width: 8px;
  height: 8px;
  vertical-align: baseline;
  filter: none;
}

/* ==========================================================================
   SCREEN 3: HOW TO PLAY
   ========================================================================== */
#screen-howto {
  padding: 24px;
  background: linear-gradient(180deg, #fffefb, var(--parchment) 60%);
}

.howto-scroll {
  flex: 1;
  overflow-y: auto;
  padding-right: 6px;
}

.howto-goal {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(180deg, #fff8e1, #ffecb3);
  border: 1.5px solid var(--brass);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  margin-bottom: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.45;
  box-shadow: 0 3px 8px rgba(201, 154, 36, 0.22);
}

.howto-goal b {
  color: var(--oak-dark);
}

.howto-card {
  display: flex;
  gap: 16px;
  align-items: center;
  background: linear-gradient(180deg, #fffdf8, var(--parchment-dark));
  border: 1.5px solid #ded0a6;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(80, 50, 20, 0.06);
}

.howto-num {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff9ed;
  background: linear-gradient(180deg, var(--oak-light), var(--oak-dark));
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 0 var(--oak-deep);
}

.howto-illo {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 16px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 8px rgba(60, 35, 10, 0.22));
}

.howto-text {
  font-size: 0.92rem;
  color: var(--ink);
  line-height: 1.5;
  min-width: 0;
}

.howto-text b {
  display: block;
  color: var(--oak-dark);
  margin-bottom: 2px;
}

/* ==========================================================================
   SCREEN 4: GAMEPLAY
   ========================================================================== */
#screen-game {
  padding: 10px 12px;
  background: linear-gradient(180deg, #ece1c5, #decfa7);
}

#canvasContainer {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 0 2px #d8c79c, 0 4px 14px rgba(60, 35, 10, 0.15);
  touch-action: none;
  overflow: hidden;
  /* matches the gameplay backdrop — never black, never visible behind the canvas */
  background: #ece1c5;
}

/* Managed by GameEngine.fitCanvas() — fills the container edge to edge;
   the 900x620 playfield is uniformly scaled inside it (no distortion) */
#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* HUD Controls */
#gameHud {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 4px 4px 4px;
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-info {
  min-width: 0;
  flex: 0 1 auto;
}

.hud-title {
  max-width: min(30vw, 240px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-chip {
  background: linear-gradient(180deg, #fffdf8, var(--parchment-dark));
  border: 1.5px solid #d8c79c;
  border-radius: 24px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 5px rgba(80, 50, 20, 0.1);
  white-space: nowrap;
}

.hud-chip.badge {
  background: linear-gradient(180deg, var(--oak-light), var(--oak-dark));
  color: #fff9ed;
  border: none;
  box-shadow: 0 2px 5px rgba(60, 30, 10, 0.35);
}

#hudMoves.goal-met {
  background: linear-gradient(180deg, #e6f6e9, #cdeed4);
  border-color: var(--accent-green);
  color: #22612c;
}

.icon-btn {
  background: linear-gradient(180deg, #fffdf8, var(--parchment-dark));
  border: 1.5px solid #d8c79c;
  border-radius: 24px;
  padding: 8px 12px;
  min-width: 42px;
  min-height: 42px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 #c2b184, 0 4px 8px rgba(70, 45, 15, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform 0.08s ease;
}

.icon-btn .icon-img {
  width: 20px;
  height: 20px;
}

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

.icon-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
  box-shadow: none;
  transform: translateY(2px);
}

.icon-btn.power {
  background: linear-gradient(180deg, #fff8e1, #ffecb3);
  border-color: var(--brass);
  box-shadow: 0 3px 0 var(--brass-dark), 0 4px 10px rgba(201, 154, 36, 0.25);
}

.power-count {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ==========================================================================
   BUTTON DESIGN SYSTEM
   ========================================================================== */
.btn {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.05rem;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  position: relative;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #fff9ed;
  transition: transform 0.08s ease, filter 0.15s ease;
  overflow: hidden;
}

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

/* HERO (Play) — the strongest element on the menu */
.btn-hero {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 800;
  padding: 18px 26px;
  border-radius: 18px;
  background: linear-gradient(180deg, #ffe08a 0%, var(--brass-light) 22%, var(--brass) 60%, #a87c14 100%);
  color: var(--oak-deep);
  text-shadow: 0 1px 0 rgba(255, 244, 214, 0.55);
  box-shadow: 0 6px 0 #6e500c, 0 12px 26px rgba(90, 60, 10, 0.45), inset 0 2px 2px rgba(255, 255, 255, 0.55);
  letter-spacing: 0.5px;
}

.btn-hero::after {
  content: '';
  position: absolute;
  top: 0;
  left: -70%;
  width: 45%;
  height: 100%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  transform: skewX(-20deg);
  animation: heroShine 3.2s ease-in-out infinite;
}

@keyframes heroShine {
  0%, 55% { left: -70%; }
  85%, 100% { left: 130%; }
}

.btn-hero:active {
  box-shadow: 0 3px 0 #6e500c, 0 6px 14px rgba(90, 60, 10, 0.4);
}

.btn-hero .icon-img {
  width: 1.35em;
  height: 1.35em;
}

.btn-primary {
  background: linear-gradient(180deg, var(--oak-light), var(--oak) 55%, var(--oak-dark));
  box-shadow: 0 5px 0 var(--oak-deep), 0 8px 18px rgba(50, 25, 10, 0.35);
}

.btn-primary:active {
  box-shadow: 0 2px 0 var(--oak-deep);
}

.btn-secondary {
  background: linear-gradient(180deg, var(--brass-light), var(--brass) 60%, var(--brass-dark));
  color: var(--oak-deep);
  box-shadow: 0 5px 0 #6e500c, 0 8px 18px rgba(110, 80, 15, 0.3);
}

.btn-secondary:active {
  box-shadow: 0 2px 0 #6e500c;
}

.btn-ghost {
  background: linear-gradient(180deg, #fffdf8, var(--parchment-dark));
  color: var(--ink);
  border: 1.5px solid #d4c295;
  box-shadow: 0 5px 0 #c2b184, 0 6px 14px rgba(70, 45, 15, 0.12);
}

.btn-ghost:active {
  box-shadow: 0 2px 0 #c2b184;
}

.btn-small {
  padding: 10px 18px;
  font-size: 0.88rem;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   MODAL OVERLAYS
   ========================================================================== */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 35%, rgba(40, 25, 10, 0.65), rgba(15, 8, 3, 0.82));
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  border-radius: 0;
}

.modal-overlay.show {
  display: flex;
  animation: modalFade 0.22s ease forwards;
}

@keyframes modalFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: linear-gradient(180deg, #fffefb, var(--parchment));
  border-radius: var(--radius-lg);
  padding: 26px 34px 28px;
  text-align: center;
  max-width: 88%;
  width: 440px;
  box-shadow: 0 24px 50px rgba(10, 5, 2, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 0 0 1.5px #ded0a6;
  animation: cardPop 0.28s cubic-bezier(0.2, 1.3, 0.4, 1) forwards;
}

@keyframes cardPop {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-card h2 {
  font-family: var(--font-serif);
  color: var(--ink);
  font-size: 1.85rem;
  margin-bottom: 8px;
}

.modal-card p {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin-bottom: 18px;
  line-height: 1.5;
  font-weight: 600;
}

.modal-sub {
  margin-bottom: 6px !important;
  font-size: 0.82rem !important;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ink-muted) !important;
}

.win-move-summary {
  margin-bottom: 18px !important;
  font-family: var(--font-mono);
  font-size: 0.82rem !important;
  color: var(--brass-dark) !important;
}

.chapter-name-intro {
  font-size: 1.2rem !important;
  font-weight: 800 !important;
  color: var(--oak-dark) !important;
}

.btn-danger {
  background: linear-gradient(180deg, #e06a5a, var(--accent-red) 60%, #8f2317);
}

.btn-reset {
  padding: 4px 10px;
  font-size: 0.78rem;
}

.modal-trophy {
  width: 108px;
  height: 108px;
  object-fit: contain;
  margin: -6px auto 2px;
  display: block;
  filter: drop-shadow(0 8px 16px rgba(140, 90, 10, 0.35));
  animation: trophyPop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) 0.1s both;
}

@keyframes trophyPop {
  from { transform: scale(0) rotate(-18deg); }
  to { transform: scale(1) rotate(0deg); }
}

.modal-art {
  width: 130px;
  height: 130px;
  object-fit: contain;
  margin: -4px auto 6px;
  display: block;
  filter: drop-shadow(0 8px 16px rgba(60, 35, 10, 0.3));
}

.chapter-intro-art {
  width: 190px;
  height: 130px;
  border-radius: 14px;
  border: 2px solid #d8c79c;
  box-shadow: 0 6px 14px rgba(70, 45, 15, 0.25);
}

.modal-stars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-stars .icon-img {
  width: 44px;
  height: 44px;
  vertical-align: middle;
  filter: none;
}

.modal-stars .icon-img.pop {
  animation: starPop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.modal-stars .icon-img.pop:nth-child(2) { animation-delay: 0.14s; }
.modal-stars .icon-img.pop:nth-child(3) { animation-delay: 0.28s; }

@keyframes starPop {
  from { transform: scale(0) rotate(-40deg); }
  to { transform: scale(1) rotate(0deg); }
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Settings List */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0 22px 0;
  text-align: left;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid #ded0a6;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
}

.settings-label {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ink);
}

.toggle-btn {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--brass);
  background: var(--brass-light);
  color: var(--oak-deep);
  cursor: pointer;
}

/* Toast System */
.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: linear-gradient(180deg, var(--oak-light), var(--oak-dark));
  color: #fff9ed;
  font-weight: 800;
  font-size: 0.84rem;
  padding: 8px 20px;
  border-radius: 24px;
  opacity: 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.toast.good {
  background: linear-gradient(180deg, var(--accent-green), #2c6835);
}

.toast .icon-img {
  width: 18px;
  height: 18px;
  vertical-align: middle;
}

/* ==========================================================================
   RESPONSIVE DESIGN (mobile-first adaptivity — phones → tablets → desktop)
   The app fills 100vw x 100dvh edge-to-edge on every device; playfield
   proportions are kept via uniform world scaling in game.js.
   Every tappable control stays >= 40px on touch screens.
   ========================================================================== */

/* --- Phones: compact controls, everything stays touch-friendly --- */
@media (max-width: 580px) {
  .brand-logo { width: min(280px, 72vw); }
  .menu-buttons { width: min(300px, 88vw); gap: 11px; }
  .btn-hero { font-size: 1.12rem; padding: 14px 20px; }
  .menu-footer { font-size: 0.62rem; }
  .corner-btn { width: 40px; height: 40px; }
  #menuSoundToggle { right: 14px; }
  #menuMusicToggle { right: 62px; }
  #settingsBtnMenu { left: 14px; }

  #screen-levels, #screen-howto { padding: 14px 14px 18px; }
  .panel-title { font-size: 1.3rem; }
  .levels-header-actions { gap: 8px; }
  .level-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
  .chapter-thumb { width: 48px; height: 48px; }
  .chapter-name { font-size: 1rem; }
  .chapter-sub { font-size: 0.7rem; }
  .chapter-pill { font-size: 0.66rem; padding: 3px 8px; }
  .chapter-stars-pill { font-size: 0.72rem; }

  .howto-card { padding: 11px 13px; gap: 12px; }
  .howto-illo { width: 62px; height: 62px; border-radius: 13px; }
  .howto-num { width: 30px; height: 30px; font-size: 1rem; }
  .howto-text { font-size: 0.85rem; }
  .howto-goal { font-size: 0.85rem; padding: 10px 14px; }

  #screen-game { padding: 8px; }
  #gameHud { padding: 8px 0 2px 0; gap: 6px; }
  .hud-row { gap: 6px; }
  .hud-chip { font-size: 0.72rem; padding: 5px 10px; }
  .hud-title { max-width: 42vw; }
  .icon-btn { min-width: 40px; min-height: 40px; padding: 6px 8px; }
  .icon-btn .icon-img { width: 19px; height: 19px; }

  .modal-card { padding: 20px 18px 22px; width: min(92%, 340px); }
  .modal-card h2 { font-size: 1.5rem; }
  .modal-trophy { width: 84px; height: 84px; }
  .modal-stars .icon-img { width: 36px; height: 36px; }
  .modal-art { width: 100px; height: 100px; }
  .chapter-intro-art { width: 150px; height: 104px; }
  .modal-actions { gap: 9px; }
  .btn-small { padding: 10px 14px; font-size: 0.82rem; }
}

/* --- Short landscape phones (e.g. 740×360): HUD becomes a side rail so the
       playfield gets the full screen height --- */
@media (max-height: 480px) and (orientation: landscape) {
  .brand-logo { max-height: 26dvh; width: min(230px, 34vw); }
  .brand-sub { margin-top: 4px; font-size: 0.7rem; }
  .menu-stats-row { margin-top: 8px; }
  .stat-chip { padding: 5px 12px; font-size: 0.78rem; }
  .menu-buttons { margin-top: 10px; gap: 8px; width: min(260px, 42vw); }
  .btn { padding: 9px 14px; font-size: 0.85rem; }
  .btn-hero { font-size: 0.95rem; padding: 11px 16px; }
  .menu-footer { display: none; }
  .corner-btn { width: 36px; height: 36px; }

  #screen-game { padding: 5px 8px; flex-direction: row; }
  #canvasContainer { min-width: 0; }
  #gameHud {
    flex-direction: column;
    justify-content: flex-end;
    width: 104px;
    flex: 0 0 104px;
    padding: 4px 0 4px 6px;
    gap: 6px;
  }
  .hud-row { flex-direction: column; gap: 6px; align-items: stretch; }
  .hud-info { flex-wrap: wrap; gap: 5px; justify-content: center; }
  .hud-actions { flex-wrap: wrap; gap: 5px; justify-content: center; }
  .hud-chip { font-size: 0.64rem; padding: 4px 8px; }
  .hud-chip.badge { padding: 4px 9px; }
  .hud-title { display: none; }
  .icon-btn { min-width: 36px; min-height: 36px; padding: 4px 5px; }
  .icon-btn .icon-img { width: 17px; height: 17px; }
  .power-count { font-size: 0.72rem; }

  .modal-card { padding: 14px 18px 16px; }
  .modal-card h2 { font-size: 1.25rem; margin-bottom: 4px; }
  .modal-card p { margin-bottom: 10px; font-size: 0.82rem; }
  .modal-trophy { width: 64px; height: 64px; }
  .modal-stars .icon-img { width: 30px; height: 30px; }
  .modal-art { width: 78px; height: 78px; }
  .chapter-intro-art { width: 130px; height: 90px; }
}

/* --- Large phones / small tablets (portrait) --- */
@media (min-width: 581px) and (max-width: 900px) {
  .level-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .hud-title { max-width: 30vw; }
}

/* --- Tall phone portrait: give the playfield room, HUD wraps in 2 rows --- */
@media (max-width: 580px) and (min-height: 640px) and (orientation: portrait) {
  #gameHud { flex-direction: row; flex-wrap: wrap; }
  .hud-row { flex-basis: 100%; }
  .hud-info { justify-content: flex-start; }
  .hud-actions { justify-content: center; }
}

/* --- Desktop: frame can grow slightly, crisper HUD --- */
@media (min-width: 1180px) and (min-height: 800px) {
  .level-grid { gap: 9px; }
  .hud-chip { font-size: 0.86rem; }
}

/* --- Very small legacy phones (<= 360px) --- */
@media (max-width: 360px) {
  .hud-chip { font-size: 0.66rem; padding: 4px 8px; }
  .icon-btn { min-width: 38px; min-height: 38px; }
  .menu-buttons { width: 92vw; }
  .brand-logo { width: 88vw; }
  .modal-card { width: 94%; }
}

/* --- Touch affordances: lift every control to >= 40px on coarse pointers --- */
@media (pointer: coarse) {
  .icon-btn, .corner-btn, .toggle-btn { min-width: 40px; min-height: 40px; }
  .btn-small { min-height: 40px; }
  .lvl-btn { min-height: 44px; }
}

/* --- Reduced-motion accessibility: soften decorative animations --- */
@media (prefers-reduced-motion: reduce) {
  .loader-logo, .brand-logo, .btn-hero::after { animation: none; }
}
