: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;
  /* Full-width bar, but inner content aligned to the same centered 1120px column
     as the screens (matches the Wooden Peg Puzzles layout width). */
  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);
}
.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); }

/* ── 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: 18px 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 24px; }
.set-cards {
  display: grid; gap: clamp(16px, 2vw, 24px); width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.set-card {
  border: none; cursor: pointer; border-radius: var(--radius); padding: 26px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: #fff; box-shadow: var(--shadow); min-height: 168px; justify-content: center;
  transition: transform 0.15s ease;
}
.set-card:active { transform: scale(0.96); }
.set-card-label { font-family: var(--display); font-size: clamp(40px, 8vw, 58px); font-weight: 700; line-height: 1; }
.set-card-title { font-weight: 800; font-size: 18px; }
.set-card-progress { font-weight: 700; background: rgba(255,255,255,0.28); border-radius: 999px; padding: 3px 12px; font-size: 14px; }
.tone-sky  { background: linear-gradient(150deg, #4DB8FF, #3A8DE0); }
.tone-leaf { background: linear-gradient(150deg, #5BC98C, #3FA86E); }
.tone-rose { background: linear-gradient(150deg, #FF6FA5, #E84F8A); }
.text-btn {
  margin: 26px auto 8px; 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); }

/* ── Glyph grid ─────────────────────────────────────────────────────────── */
.glyph-grid {
  display: grid; gap: clamp(12px, 1.2vw, 18px); overflow-y: auto; padding-bottom: 16px;
  width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}
.glyph-cell {
  border: none; cursor: pointer; background: var(--card); border-radius: 18px;
  box-shadow: var(--shadow); min-height: 118px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; padding: 10px;
  transition: transform 0.12s ease;
}
.glyph-cell:active { transform: scale(0.95); }
.glyph-cell.done { background: linear-gradient(160deg, #FFF6E9, #FFE9F1); }
.glyph-cell-char { font-family: var(--display); font-size: 46px; font-weight: 700; line-height: 1; }
.glyph-cell-stars { color: var(--sun); font-size: 13px; letter-spacing: 1px; }

/* ── Practice ───────────────────────────────────────────────────────────── */
.practice-char {
  font-family: var(--display); font-size: 32px; font-weight: 700;
  min-width: 44px; text-align: center;
}
.mode-tabs { display: flex; gap: 6px; margin-left: auto; background: #fff; padding: 5px; border-radius: 16px; box-shadow: var(--shadow); }
.mode-tab {
  border: none; background: transparent; cursor: pointer; font-weight: 800; font-size: 15px;
  padding: 9px 14px; border-radius: 12px; color: #8a8499; min-height: 40px;
}
.mode-tab.active { background: linear-gradient(140deg, var(--coral), var(--rose)); color: #fff; }

.stage {
  position: relative; flex: 1; min-height: 0; margin: 4px auto;
  width: 100%; max-width: 680px;
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#fx-canvas { pointer-events: none; }
.stage-hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 999px;
  font-weight: 700; font-size: 15px; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.stage-hint.show { opacity: 0.96; transform: translateX(-50%) translateY(2px); }

.practice-controls { display: flex; flex-direction: column; gap: 10px; }
.diff-pills { display: flex; gap: 8px; justify-content: center; }
.diff-pill {
  border: none; cursor: pointer; background: #fff; box-shadow: var(--shadow);
  border-radius: 999px; padding: 9px 18px; font-weight: 800; font-size: 14px; color: #8a8499; min-height: 40px;
}
.diff-pill.active { background: var(--leaf); color: #fff; }
.action-row { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.action-btn {
  border: none; cursor: pointer; background: #fff; box-shadow: var(--shadow);
  border-radius: 16px; padding: 14px 18px; font-weight: 800; font-size: 16px; color: var(--ink); min-height: 56px;
}
.action-btn.primary { background: linear-gradient(140deg, var(--coral), var(--rose)); color: #fff; }
.action-btn:active { transform: scale(0.96); }
.round-btn {
  border: none; cursor: pointer; background: #fff; box-shadow: var(--shadow);
  width: 56px; height: 56px; border-radius: 50%; font-size: 28px; color: var(--ink); line-height: 1;
}
.round-btn:active { transform: scale(0.94); }

/* ── Overlays ───────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(46, 42, 58, 0.45); backdrop-filter: blur(4px);
}
.overlay.show { display: flex; }
.complete-card, .sticker-card {
  background: #fff; border-radius: 26px; box-shadow: var(--shadow);
  padding: 28px; width: min(440px, 100%); text-align: center;
}
.sticker-card { width: min(560px, 100%); text-align: left; }
.cm-stars { display: flex; justify-content: center; gap: 8px; font-size: 56px; line-height: 1; }
.cm-star { color: #d8d2e0; }
.cm-star.on { color: var(--sun); }
.cm-message { font-family: var(--display); font-size: 24px; margin: 14px 0 6px; }
.cm-stickers { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.cm-sticker {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: linear-gradient(160deg, #FFF6E9, #FFE9F1); border-radius: 16px; padding: 10px 14px; font-weight: 800; font-size: 12px;
}
.cm-sticker-icon { font-size: 30px; }
.complete-actions { display: flex; gap: 12px; justify-content: center; margin-top: 8px; }

.stickers-grid {
  display: grid; gap: 12px; margin-top: 12px;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}
.sticker {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border-radius: 18px; padding: 16px 10px; text-align: center; font-weight: 800; font-size: 13px;
}
.sticker.earned { background: linear-gradient(160deg, #FFF6E9, #FFE9F1); }
.sticker.locked { background: #f1eef6; color: #b4adc2; }
.sticker-icon { font-size: 38px; }

@media (max-width: 540px) {
  .mode-tabs { width: 100%; margin: 8px 0 0; order: 3; }
  .screen-bar { flex-wrap: wrap; }
  .action-btn { padding: 12px 14px; font-size: 15px; }
  /* Compact header so navigation never crowds the writing stage. */
  .site-game-brand strong,
  .site-game-brand small { display: none; }
  .site-game-actions { gap: 6px; }
  .nav-btn { padding: 7px 10px; font-size: 13px; min-height: 38px; }
  .hud-chip { padding: 5px 9px; font-size: 13px; }
  .icon-btn { min-width: 40px; min-height: 40px; font-size: 18px; }
}
