:root {
  --coral:  #FF8A5B;
  --sky:    #4DB8FF;
  --leaf:   #5BC98C;
  --rose:   #FF6FA5;
  --sun:    #FFD166;
  --lav:    #9C8CFF;
  --ink:    #2E2A3A;
  --paper:  #FFFDF6;
  --card:   #FFFFFF;
  --shadow: 0 10px 30px rgba(46, 42, 58, 0.12);
  --radius: 22px;
  --font:   'Nunito', system-ui, sans-serif;
  --display:'Fredoka', 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, #FFF3E6 0%, #FDF7FF 55%, #EAF6FF 100%);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100;
}
.skip-link:focus { left: 12px; top: 12px; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-game-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, calc((100% - 1120px) / 2));
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(46, 42, 58, 0.08);
}
.site-game-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.site-game-mark {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--coral), var(--rose)); color: #fff;
  font-family: var(--display); font-weight: 700; font-size: 22px;
}
.site-game-brand strong { font-family: var(--display); display: block; font-size: 16px; line-height: 1.1; }
.site-game-brand small { color: #7a7488; font-size: 12px; }
.site-game-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.nav-btn {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 40px; padding: 8px 14px; border: none; border-radius: 12px;
  background: #fff; box-shadow: var(--shadow); cursor: pointer;
  font-family: var(--font); font-weight: 800; font-size: 14px; color: var(--ink); text-decoration: none;
}
.nav-btn:active { transform: scale(0.95); }
.nav-btn[hidden] { display: none; }
.hud-chip {
  font-weight: 800; font-size: 15px; background: #fff; border-radius: 999px;
  padding: 6px 12px; box-shadow: var(--shadow); white-space: nowrap;
}
.icon-btn {
  min-width: 44px; min-height: 44px; border: none; border-radius: 14px;
  background: #fff; box-shadow: var(--shadow); font-size: 20px; cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }
.nav-btn .nav-label { white-space: nowrap; }

/* Compact header for phones: the brand is just the home icon, so the whole
   header stays on a single row with the actions pushed to the right. */
@media (max-width: 560px) {
  .site-game-header { flex-wrap: nowrap; padding: 7px 12px; gap: 8px; }
  .site-game-brand { gap: 8px; flex: 0 0 auto; min-width: 0; }
  .site-game-mark { width: 32px; height: 32px; border-radius: 10px; font-size: 18px; }
  .site-game-actions { flex: 0 1 auto; gap: 6px; justify-content: flex-end; }
  .nav-btn { min-height: 36px; padding: 6px 10px; font-size: 13px; gap: 3px; }
  .hud-chip { font-size: 13px; padding: 5px 9px; }
  .icon-btn { min-width: 38px; min-height: 38px; border-radius: 12px; font-size: 18px; }
}

/* Very narrow phones: collapse the longer nav button to its icon only. */
@media (max-width: 430px) {
  #nav-game-home .nav-label { display: none; }
  .nav-btn { padding: 6px 9px; }
}

/* ── Screens ────────────────────────────────────────────────────────────── */
#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen {
  display: none; flex: 1; flex-direction: column; min-height: 0;
  padding: clamp(16px, 3vw, 32px) max(clamp(16px, 3vw, 32px), calc((100% - 1120px) / 2));
}
.screen.active { display: flex; }

.screen-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.screen-bar h2 { font-family: var(--display); margin: 0; font-size: clamp(20px, 3vw, 26px); }
.back-btn {
  min-width: 48px; min-height: 48px; border: none; border-radius: 16px;
  background: #fff; box-shadow: var(--shadow); font-size: 24px; cursor: pointer; color: var(--ink);
}
.back-btn:active { transform: scale(0.94); }

/* ── Home ───────────────────────────────────────────────────────────────── */
.home-title {
  font-family: var(--display); font-weight: 700; text-align: center;
  font-size: clamp(30px, 7vw, 52px); margin: 14px 0 4px;
  background: linear-gradient(120deg, var(--coral), var(--rose), var(--lav));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.home-sub { text-align: center; font-size: clamp(15px, 2.6vw, 19px); color: #6c6680; margin: 0 0 18px; }

.chooser { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.chooser-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chooser-label { font-weight: 800; font-family: var(--display); min-width: 52px; color: #6c6680; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: none; cursor: pointer; min-height: 44px; padding: 8px 16px; border-radius: 999px;
  background: #fff; box-shadow: var(--shadow); font-family: var(--font); font-weight: 800;
  font-size: 15px; color: var(--ink);
}
.pill.active { background: linear-gradient(140deg, var(--coral), var(--rose)); color: #fff; }
.pill:active { transform: scale(0.95); }

.theme-grid {
  display: grid; gap: clamp(12px, 2vw, 20px); width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
}
.theme-card {
  border: none; cursor: pointer; border-radius: var(--radius); padding: 20px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; color: #fff;
  box-shadow: var(--shadow); min-height: 130px; justify-content: center; transition: transform 0.15s ease;
}
.theme-card:active { transform: scale(0.96); }
.theme-emoji { font-size: clamp(38px, 7vw, 52px); line-height: 1; }
.theme-name { font-weight: 800; font-size: 16px; }
.tone-sky  { background: linear-gradient(150deg, #4DB8FF, #3A8DE0); }
.tone-leaf { background: linear-gradient(150deg, #5BC98C, #3FA86E); }
.tone-rose { background: linear-gradient(150deg, #FF6FA5, #E84F8A); }
.tone-lav  { background: linear-gradient(150deg, #9C8CFF, #7C6CE0); }

.home-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.text-btn {
  border: none; background: #fff; box-shadow: var(--shadow);
  border-radius: 999px; padding: 14px 26px; font-weight: 800; font-size: 16px; cursor: pointer; color: var(--ink);
}
.text-btn:active { transform: scale(0.96); }
.options { display: flex; gap: 8px; flex-wrap: wrap; }
.opt-btn {
  border: none; cursor: pointer; min-height: 44px; padding: 8px 14px; border-radius: 999px;
  background: #fff; box-shadow: var(--shadow); font-weight: 700; font-size: 14px; color: var(--ink);
}
.opt-btn.on { background: linear-gradient(140deg, var(--leaf), #3FA86E); color: #fff; }
.opt-btn:active { transform: scale(0.95); }

/* ── Play ───────────────────────────────────────────────────────────────── */
.play-bar { gap: 10px; justify-content: space-between; }
.play-label { display: none; }  /* mode name hidden to keep the play bar on one aligned row */
.play-hud { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.play-hud .hud-chip { font-size: 14px; padding: 5px 10px; }
.key-chip.got { background: linear-gradient(140deg, var(--leaf), #3FA86E); color: #fff; }

.stage {
  position: relative; flex: 1; min-height: clamp(200px, 40vh, 520px); width: 100%;
  border-radius: var(--radius); overflow: hidden; touch-action: none;
  background: var(--card); box-shadow: var(--shadow);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#fx-canvas { pointer-events: none; }

.play-controls {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin-top: 12px; flex-wrap: wrap;
}
.dpad {
  display: grid; gap: 5px; width: 150px; height: 150px; flex: 0 0 auto;
  grid-template-areas: ". up ." "left . right" ". down .";
  grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr;
}
.dbtn {
  border: none; cursor: pointer; border-radius: 14px; background: #fff; box-shadow: var(--shadow);
  font-size: 20px; color: var(--ink); display: grid; place-items: center; min-width: 46px; min-height: 46px;
}
.dbtn:active { transform: scale(0.92); background: var(--sun); }
.dbtn-up { grid-area: up; } .dbtn-left { grid-area: left; }
.dbtn-right { grid-area: right; } .dbtn-down { grid-area: down; }

.action-col { display: flex; flex-direction: column; gap: 8px; flex: 1 1 150px; min-width: 140px; max-width: 320px; }
.action-btn {
  border: none; cursor: pointer; min-height: 48px; padding: 10px 16px; border-radius: 14px;
  background: #fff; box-shadow: var(--shadow); font-family: var(--font); font-weight: 800;
  font-size: 15px; color: var(--ink);
}
.action-btn:active { transform: scale(0.96); }
.action-btn.primary { background: linear-gradient(140deg, var(--coral), var(--rose)); color: #fff; }

/* ── Overlays ───────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 80; display: none; place-items: center;
  background: rgba(46, 42, 58, 0.45); padding: 20px;
}
.overlay.show { display: grid; }
.complete-card, .sticker-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px 22px; max-width: 460px; width: 100%; text-align: center;
}
.cm-stars { display: flex; justify-content: center; gap: 8px; font-size: 44px; margin-bottom: 8px; }
.cm-star { filter: grayscale(1) opacity(0.35); }
.cm-star.on { filter: none; }
.cm-message { font-family: var(--display); font-weight: 700; font-size: 24px; margin: 6px 0; }
.cm-coins { font-weight: 800; font-size: 18px; color: var(--coral); margin: 0 0 8px; }
.cm-badges { display: flex; justify-content: center; gap: 10px; font-size: 30px; min-height: 36px; margin-bottom: 8px; }
.complete-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
.complete-actions .action-btn { flex: 1; min-width: 110px; }
.fail-emoji { font-size: 52px; margin-bottom: 6px; }

.sticker-card { max-width: 560px; text-align: left; }
.sticker-card .screen-bar { justify-content: space-between; }
.badges-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); margin-top: 8px; }
.badge-cell {
  background: #FBF8FF; border-radius: 16px; padding: 14px 8px; text-align: center;
  display: flex; flex-direction: column; gap: 6px; opacity: 0.55;
}
.badge-cell.got { opacity: 1; background: linear-gradient(150deg, #FFF6E6, #FFEAF3); }
.badge-emoji { font-size: 34px; }
.badge-name { font-weight: 800; font-size: 13px; }

@media (max-width: 540px) {
  .play-controls { justify-content: center; }
  .action-col { width: 100%; }
}
