/* Junqi Buddy — style sheet. Bright, chunky, kid-friendly, iPad/Safari-first. */

:root {
  --cream: #FBF3E3;
  --paper: #F3E7CC;
  --ink: #2B2320;
  --army-red: #C93C3C;
  --army-red-dark: #A82F2F;
  --accent-blue: #3B6FD4;
  --accent-blue-dark: #2A54A8;
  --success-green: #3FAE58;
  --success-green-dark: #2C8942;
  --star-gold: #F0B429;
  --star-gold-dark: #C98E12;
  --border-thick: 4px;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 20px;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input {
  font-family: inherit;
  font-size: inherit;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------------- Top bar ---------------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  background: var(--cream);
  border-bottom: var(--border-thick) solid var(--ink);
  flex: 0 0 auto;
  z-index: 10;
}

#screen-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  flex: 1;
}

.icon-btn {
  min-width: 64px;
  min-height: 64px;
  font-size: 30px;
  border-radius: var(--radius-md);
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--ink);
}

#star-counter {
  min-width: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  font-weight: 800;
  font-size: 22px;
  background: var(--star-gold);
  border: 3px solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: 0 3px 0 var(--star-gold-dark);
}
.star-emoji { font-size: 24px; }

/* ---------------- Main / screens ---------------- */

#main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  position: relative;
  -webkit-overflow-scrolling: touch;
}

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

.screen-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 16px;
}

/* ---------------- Home ---------------- */

.home-title {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.home-flag { font-size: 56px; }
.home-title h2 { margin: 0; font-size: 30px; }
.home-subtitle { margin: 2px 0 0; font-size: 20px; color: var(--army-red-dark); font-weight: 700; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  grid-auto-rows: minmax(140px, 220px);
  align-content: start;
  gap: 18px;
  flex: 1;
  overflow-y: auto;
}

.home-card {
  position: relative;
  min-width: 140px;
  min-height: 140px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 0 5px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
}
.home-card:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--ink);
}
.home-card .card-icon { font-size: 48px; }
.home-card .card-label { font-weight: 800; font-size: 19px; }
.home-card .card-stars { font-size: 18px; letter-spacing: 2px; }
.home-card .here-badge {
  position: absolute;
  top: -14px;
  right: -10px;
  background: var(--accent-blue);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  animation: bounce-badge 1.4s ease-in-out infinite;
  white-space: nowrap;
}

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

/* ---------------- Generic buttons ---------------- */

.btn {
  min-height: 64px;
  padding: 12px 24px;
  font-size: 22px;
  font-weight: 800;
  border-radius: var(--radius-md);
  border: 3px solid var(--ink);
  background: #fff;
  box-shadow: 0 4px 0 var(--ink);
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.btn-primary { background: var(--accent-blue); color: #fff; box-shadow: 0 4px 0 var(--accent-blue-dark); }
.btn-primary:active { box-shadow: 0 0 0 var(--accent-blue-dark); }
.btn-success { background: var(--success-green); color: #fff; box-shadow: 0 4px 0 var(--success-green-dark); }
.btn-success:active { box-shadow: 0 0 0 var(--success-green-dark); }
.btn-gold { background: var(--star-gold); box-shadow: 0 4px 0 var(--star-gold-dark); }
.btn-gold:active { box-shadow: 0 0 0 var(--star-gold-dark); }
.btn:disabled { opacity: 0.45; }

.btn-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------------- Piece tile (reused: flashcards, ladder, arena, match, test) ---------------- */

.piece-tile {
  background: var(--army-red);
  color: var(--cream);
  border-radius: var(--radius-md);
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--army-red-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  line-height: 1.05;
  gap: 4px;
}
.piece-tile.selectable:active { transform: translateY(4px); box-shadow: 0 0 0 var(--army-red-dark); }

.piece-tile--lg { width: min(56vw, 320px); height: min(56vw, 320px); }
.piece-tile--lg .tile-hanzi { font-size: 96px; }

.piece-tile--md { width: 160px; height: 160px; }
.piece-tile--md .tile-hanzi { font-size: 52px; }

.piece-tile--sm { width: 96px; height: 96px; }
.piece-tile--sm .tile-hanzi { font-size: 34px; }

.tile-hanzi .zhang-char { color: #FFE38A; }

.tile-emoji { font-size: 1.4em; }

/* ---------------- Confetti / feedback ---------------- */

.confetti-piece {
  position: fixed;
  top: -20px;
  font-size: 26px;
  pointer-events: none;
  animation: confetti-fall 1.6s linear forwards;
  z-index: 999;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.9; }
}

@keyframes pulse-green {
  0% { box-shadow: 0 0 0 0 rgba(63,174,88,0.6); }
  70% { box-shadow: 0 0 0 22px rgba(63,174,88,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,174,88,0); }
}
.correct-pulse { animation: pulse-green 0.7s ease-out; }

@keyframes hop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-22px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}
.tile-hop { animation: hop 0.6s ease; }

@keyframes fade-lose {
  to { opacity: 0.18; transform: scale(0.92); }
}
.tile-fade { animation: fade-lose 0.6s ease forwards; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}
.tile-shake { animation: shake 0.5s ease; }

@keyframes slide-in-left {
  from { transform: translateX(-120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slide-in-right {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.slide-left { animation: slide-in-left 0.5s ease; }
.slide-right { animation: slide-in-right 0.5s ease; }

/* ---------------- Misc shared ---------------- */

.card-panel {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 0 5px 0 var(--ink);
  padding: 20px;
}

.tip-bubble {
  background: #FFF6D8;
  border: 3px solid var(--star-gold-dark);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 18px;
  font-weight: 600;
  position: relative;
}
.tip-bubble .close-tip {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 22px;
  font-weight: 800;
  min-width: 40px;
  min-height: 40px;
}

.center-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  text-align: center;
}

.row-gap {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.speak-btn {
  font-size: 30px;
  min-width: 64px;
  min-height: 64px;
  border-radius: 50%;
  background: var(--accent-blue);
  color: #fff;
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--accent-blue-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}
.speak-btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--accent-blue-dark); }

.progress-dots { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.progress-dots .dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #ddd; border: 2px solid var(--ink);
}
.progress-dots .dot.seen { background: var(--star-gold); }
.progress-dots .dot.current { background: var(--army-red); }

.arrow-btn {
  font-size: 40px;
  min-width: 64px;
  min-height: 64px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
}
.arrow-btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }

.star-row { font-size: 20px; letter-spacing: 2px; color: var(--star-gold-dark); }

.pinyin-row { font-size: 30px; font-weight: 800; }
.en-row { font-size: 24px; font-weight: 700; color: var(--accent-blue-dark); }
.tagline-row { font-size: 19px; font-style: italic; max-width: 480px; }

.pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  font-weight: 700;
  font-size: 15px;
  background: #fff;
}

.result-banner {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 3px solid var(--ink);
}
.result-banner.good { background: #DFF5E3; }
.result-banner.meh { background: #FFF2D6; }

@media (orientation: portrait) {
  .home-flag { font-size: 44px; }
  .piece-tile--lg { width: min(70vw, 280px); height: min(70vw, 280px); }
  .piece-tile--lg .tile-hanzi { font-size: 78px; }
}

/* ================= Screen 2: Rank Ladder ================= */

.ladder-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.ladder-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 260px;
}

.ladder-rung {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 16px 6px 6px;
  box-shadow: 0 3px 0 var(--ink);
  align-self: flex-start;
  min-width: 220px;
  transition: box-shadow 0.2s;
}
.ladder-rung:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.ladder-rung .rung-label { font-weight: 800; font-size: 17px; }
.ladder-rung .rung-stars { font-size: 13px; color: var(--star-gold-dark); margin-left: auto; letter-spacing: 1px; }
.ladder-rung.quiz-highlight {
  animation: pulse-green 0.9s ease-out 2;
  border-color: var(--accent-blue);
}

.specials-col {
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.specials-title { font-weight: 700; font-size: 15px; color: var(--army-red-dark); }
.specials-row { display: flex; flex-direction: column; gap: 10px; }
.special-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 3px dashed var(--ink);
  border-radius: var(--radius-md);
  padding: 6px 12px;
}
.special-chip-label { font-weight: 700; font-size: 15px; }

.quiz-prompt { font-size: 22px; font-weight: 800; }

/* ================= Screen 3: Battle Arena (+ shared quiz UI) ================= */

.arena-prompt { font-size: 24px; font-weight: 800; }

.arena-tiles-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.arena-both-btn {
  font-size: 16px;
  line-height: 1.3;
  padding: 10px 18px;
  background: var(--army-red);
  color: var(--cream);
  box-shadow: 0 4px 0 var(--army-red-dark);
}
.arena-both-btn:active { box-shadow: 0 0 0 var(--army-red-dark); }

.option-grid, .answer-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  max-width: 640px;
}
.answer-btn { min-width: 140px; }

/* ================= Screen 4: Special Powers ================= */

.powers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  grid-auto-rows: minmax(140px, 200px);
  align-content: start;
  gap: 18px;
}

.lesson-text { font-size: 22px; font-weight: 700; max-width: 520px; }

.lesson-anim-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  min-height: 140px;
  width: min(90vw, 460px);
  position: relative;
}

.mini-emoji { font-size: 40px; }

.mini-rail {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 6px;
  transform: translateY(-50%);
  background: repeating-linear-gradient(90deg, var(--ink) 0 10px, transparent 10px 16px);
}
.rail-runner { animation: rail-slide 1.6s ease-in-out infinite; position: relative; z-index: 1; }
@keyframes rail-slide {
  0% { transform: translateX(-120px); }
  45% { transform: translateX(120px); }
  55% { transform: translateX(120px) translateY(-40px); }
  100% { transform: translateX(120px) translateY(-40px); }
}

.approach-runner { animation: approach 1.1s ease-in-out infinite; }
@keyframes approach {
  0%, 15% { transform: translateX(-70px); }
  50%, 70% { transform: translateX(0); }
  100% { transform: translateX(-70px); }
}

.tile-shake-loop { animation: shake 0.6s ease-in-out infinite; }
.idle-pulse { animation: idle-pulse 1.6s ease-in-out infinite; }
@keyframes idle-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.pop-vanish { animation: pop-vanish 0.4s ease forwards; }
@keyframes pop-vanish {
  to { transform: scale(1.6); opacity: 0; }
}

.shake-on-hit { animation: shake 0.5s ease-in-out infinite; }

.fade-both { animation: fade-lose 0.5s ease forwards; }

.boom-pop { animation: boom-pop 1.1s ease-in-out infinite; }
@keyframes boom-pop {
  0%, 100% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
}

.mini-hq {
  border: 3px dashed var(--accent-blue-dark);
  border-radius: var(--radius-md);
  padding: 10px;
}

.trophy-pop { animation: trophy-pop 1.2s ease-in-out infinite; }
@keyframes trophy-pop {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-10px) scale(1.15); }
}

/* ================= Screen 5: Board Explorer ================= */

.board-explorer { display: flex; flex-direction: column; align-items: center; gap: 14px; flex: 1; }
.board-svg-holder { width: min(92vw, 460px); }
.board-svg { width: 100%; height: auto; display: block; }
.board-caption { font-size: 19px; font-weight: 700; text-align: center; min-height: 28px; }
.board-tour-row .btn { font-size: 17px; padding: 10px 16px; min-height: 54px; }

.road-line { stroke: #8a7a5c; stroke-width: 2; }
.diagonal-line { stroke: #8a7a5c; stroke-width: 1.5; stroke-dasharray: 3 3; }
.rail-line { stroke: var(--ink); stroke-width: 5; }
.mountain-blob { font-size: 26px; }

.node-plain { fill: #fff; stroke: var(--ink); stroke-width: 2; }
.node-camp { fill: #FFF2D6; stroke: var(--ink); stroke-width: 2.5; }
.node-hq { fill: #D8E4FF; stroke: var(--accent-blue-dark); stroke-width: 3; }

.tour-highlight {
  animation: node-pulse 0.8s ease-in-out infinite;
}
@keyframes node-pulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(59,111,212,0)); }
  50% { filter: drop-shadow(0 0 8px rgba(59,111,212,0.9)); }
}
line.tour-highlight { stroke: var(--accent-blue) !important; }

/* ================= Screen 6: Match Game ================= */

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 560px;
}
.memory-card {
  width: 100%;
  aspect-ratio: 1;
  background: var(--army-red);
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
  box-shadow: 0 3px 0 var(--army-red-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cream);
  font-size: 30px;
  font-weight: 800;
}
.memory-card.face-up { background: #fff; color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.memory-card.matched { opacity: 0.45; }
.memory-hanzi { font-size: 30px; color: var(--army-red); font-weight: 800; }
.memory-en { font-size: 13px; font-weight: 800; text-align: center; padding: 4px; }
.memory-back { font-size: 30px; }

/* ================= Screen 7: Big Test / Certificate ================= */

.name-input {
  font-size: 24px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 3px solid var(--ink);
  text-align: center;
  min-width: 260px;
}

.certificate {
  border: 6px double var(--star-gold-dark);
  border-radius: var(--radius-lg);
  background: #FFFBEF;
  padding: 32px;
  gap: 14px;
}
.cert-flag { font-size: 56px; }
.cert-title { font-size: 26px; font-weight: 800; max-width: 560px; }
.cert-date { font-size: 18px; color: var(--army-red-dark); font-weight: 700; }
.marching-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.marching-tile { animation: marching 0.9s ease infinite; }
@keyframes marching {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
