/* ===========================================================================
   school-pages mobile-first stylesheet.
   Replaces Bootstrap 4 CDN + add.css. No framework dependency, no CDN fetch.
   Theming: CSS variables below, with a dark override via prefers-color-scheme.
   =========================================================================== */

:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f2f6;
  --color-text: #1b1f27;
  --color-text-muted: #6b7280;
  --color-border: #e3e6ec;
  --color-primary: #ff7a3d;
  --color-primary-dark: #e15f22;
  --color-accent: #2f8fff;
  --color-success: #2fb670;
  --color-danger: #e5484d;
  --color-warning: #f5a524;
  --shadow-sm: 0 1px 3px rgba(20, 24, 33, 0.08);
  --shadow-md: 0 4px 16px rgba(20, 24, 33, 0.12);
  --radius: 14px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14161c;
    --color-surface: #1d2029;
    --color-surface-alt: #262a35;
    --color-text: #eef0f4;
    --color-text-muted: #9aa1b1;
    --color-border: #333846;
    --color-primary: #ff8c54;
    --color-primary-dark: #ffa574;
    --color-accent: #5aa5ff;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic",
    "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  display: block;
}

/* --------------------------------------------------------------------- */
/* Header                                                                 */
/* --------------------------------------------------------------------- */
.site-header {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-header-back {
  font-size: 0.85rem;
  white-space: nowrap;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 4px;
}
.site-header-title {
  font-size: 0.95rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: right;
}

/* --------------------------------------------------------------------- */
/* Layout                                                                 */
/* --------------------------------------------------------------------- */
.page-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px;
}
.panel-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.panel-sub {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 4px 0 0;
}
.empty-note {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0;
}
.mb-4 {
  margin-bottom: 1.25rem;
}

/* --------------------------------------------------------------------- */
/* Hero (index page)                                                      */
/* --------------------------------------------------------------------- */
.hero {
  text-align: center;
  padding: 8px 0 4px;
}
.hero-logo {
  max-height: 72px;
  margin: 0 auto 8px;
}
.hero-title {
  font-size: 1.4rem;
  margin: 0 0 6px;
}
.hero-lead {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* --------------------------------------------------------------------- */
/* Game canvas                                                            */
/* --------------------------------------------------------------------- */
.game-canvas {
  width: 100%;
}
.canvas-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, var(--color-surface-alt), var(--color-bg));
  box-shadow: var(--shadow-md);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
/* CSS-drawn fallback "building" shown when the level image 404s, so the
   game never looks broken while art assets are still being produced. */
.canvas-frame::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 12%;
  width: 34%;
  height: 46%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, var(--color-primary), var(--color-primary-dark));
  border-radius: 6px 6px 0 0;
  opacity: 0.35;
  z-index: 0;
}
.building-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10%;
  z-index: 1;
  transition: transform 0.25s ease;
}
.building-img.img-fallback {
  display: none;
}
.sprite {
  position: absolute;
  width: 18%;
  z-index: 2;
  pointer-events: none;
}
.sprite-dog {
  left: 6%;
  bottom: 8%;
}
.sprite-cat {
  right: 6%;
  bottom: 8%;
}
.float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}
.float-text {
  position: absolute;
  left: 50%;
  bottom: 40%;
  transform: translateX(-50%);
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--color-primary);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  animation: float-up 900ms ease-out forwards;
}
@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.8);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, -6px) scale(1.05);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -70px) scale(1);
  }
}
.levelup-flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0);
  pointer-events: none;
  font-weight: 800;
  font-size: 1.6rem;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.levelup-flash.active {
  animation: level-flash 900ms ease-out;
}
@keyframes level-flash {
  0% {
    background: rgba(255, 255, 255, 0);
    opacity: 0;
  }
  20% {
    background: rgba(255, 200, 80, 0.85);
    opacity: 1;
  }
  100% {
    background: rgba(255, 200, 80, 0);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .float-text,
  .levelup-flash.active,
  .building-img {
    animation: none !important;
    transition: none !important;
  }
}

/* --------------------------------------------------------------------- */
/* Level / XP bar                                                         */
/* --------------------------------------------------------------------- */
.level-panel {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 10px 14px;
}
.level-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.level-badge {
  font-weight: 800;
  font-size: 1rem;
  color: var(--color-primary);
}
.level-next {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
.bar {
  height: 8px;
  border-radius: 5px;
  background: var(--color-surface-alt);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: 5px;
  transition: width 400ms ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .bar-fill {
    transition: none;
  }
}

/* --------------------------------------------------------------------- */
/* Count-up action                                                        */
/* --------------------------------------------------------------------- */
.count-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.count-up-btn {
  width: 80%;
  min-height: 64px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 120ms ease;
}
.count-up-btn:active {
  transform: scale(0.96);
}
.count-up-btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.count-up-value {
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}
.count-up-hint {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* --------------------------------------------------------------------- */
/* Buttons (generic)                                                      */
/* --------------------------------------------------------------------- */
.btn-secondary {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:active {
  background: var(--color-border);
}

/* --------------------------------------------------------------------- */
/* Quiz                                                                   */
/* --------------------------------------------------------------------- */
.quiz-root {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-start-btn {
  align-self: center;
  min-width: 60%;
}
.quiz-question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
.quiz-category-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-surface-alt);
  font-size: 0.7rem;
  font-weight: 700;
}
.quiz-timerbar {
  height: 6px;
  border-radius: 4px;
  background: var(--color-surface-alt);
  overflow: hidden;
}
.quiz-timerbar-fill {
  height: 100%;
  background: var(--color-accent);
  width: 100%;
  transform-origin: left;
}
.quiz-question-text {
  font-size: 1.02rem;
  font-weight: 700;
  margin: 2px 0 0;
}
.quiz-choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.quiz-choice {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.quiz-choice:disabled {
  cursor: default;
}
.quiz-choice.is-correct {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
}
.quiz-choice.is-wrong {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: #fff;
}
.quiz-progress-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-align: right;
}
.quiz-result {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.quiz-result-points {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--color-primary);
}
.quiz-result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  text-align: center;
  margin: 4px 0;
}
.quiz-result-cell {
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  padding: 8px;
}
.quiz-result-cell .v {
  font-weight: 800;
  font-size: 1.1rem;
}
.quiz-result-cell .l {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

/* --------------------------------------------------------------------- */
/* Stats grid                                                             */
/* --------------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 420px) {
  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
.stat-cell {
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  padding: 10px;
}
.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-name {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

/* --------------------------------------------------------------------- */
/* Items / achievements                                                   */
/* --------------------------------------------------------------------- */
.item-grid,
.achievement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}
.item-form {
  margin: 0;
}
.item-btn {
  position: relative;
  width: 100%;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.item-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-success);
  color: #fff;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}
.item-label,
.achievement-label {
  font-size: 0.65rem;
  color: var(--color-text-muted);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.achievement-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
}
.achievement-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

/* --------------------------------------------------------------------- */
/* Login bonus                                                            */
/* --------------------------------------------------------------------- */
.bonus-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
@media (min-width: 420px) {
  .bonus-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}
.bonus-card {
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  padding: 6px 4px;
  text-align: center;
}
.bonus-date {
  font-size: 0.65rem;
  color: var(--color-text-muted);
  margin: 0 0 2px;
}
.bonus-mark {
  font-size: 0.8rem;
  font-weight: 700;
  margin: 0;
}

/* --------------------------------------------------------------------- */
/* Notices / history                                                      */
/* --------------------------------------------------------------------- */
.notice-card {
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 0.85rem;
}
.notice-card:last-child {
  margin-bottom: 0;
}
.notice-sub {
  display: block;
  font-size: 0.7rem;
  color: var(--color-text-muted);
}
.history-row {
  font-size: 0.8rem;
  margin: 0 0 6px;
}
.history-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.65rem;
  margin-right: 4px;
}
.history-date {
  color: var(--color-text-muted);
  font-size: 0.7rem;
  margin-left: 4px;
}

/* --------------------------------------------------------------------- */
/* Ranking table                                                          */
/* --------------------------------------------------------------------- */
.table-scroll {
  overflow-x: auto;
}
.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.rank-table th,
.rank-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.rank-cell {
  width: 2.5em;
  color: var(--color-text-muted);
}
.num-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------- */
/* Region / school lists (index, regions page)                            */
/* --------------------------------------------------------------------- */
.region-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 480px) {
  .region-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
.region-card {
  padding: 12px;
}
.region-top {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--color-text-muted);
}
.pref-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.pref-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px;
  min-height: 44px;
  border-top: 1px solid var(--color-border);
  flex-wrap: wrap;
}
.pref-link {
  font-weight: 600;
}
.pref-top {
  font-size: 0.72rem;
  color: var(--color-text-muted);
}
.school-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.school-list li {
  border-top: 1px solid var(--color-border);
}
.school-link {
  display: block;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 6px 4px;
}

/* --------------------------------------------------------------------- */
/* Weather strip (small, bottom)                                          */
/* --------------------------------------------------------------------- */
.weather-strip {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 8px 12px;
  font-size: 0.72rem;
  color: var(--color-text-muted);
}
.weather-summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}
.weather-summary::-webkit-details-marker {
  display: none;
}
.weather-summary .wi {
  font-size: 1rem;
  color: var(--color-primary);
}
.weather-detail {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.weather-day {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}
.weather-day .wi {
  font-size: 1.1rem;
  color: var(--color-primary);
}
.temp-high {
  color: var(--color-danger);
}
.temp-low {
  color: var(--color-accent);
}
.weather-attribution {
  margin: 6px 0 0;
  font-size: 0.62rem;
  opacity: 0.8;
}
.weather-attribution a {
  color: inherit;
}

/* --------------------------------------------------------------------- */
/* Disclaimer (tiny, bottom)                                              */
/* --------------------------------------------------------------------- */
.disclaimer-tiny {
  font-size: 0.62rem;
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.6;
  margin: 4px 0 0;
}
.disclaimer-tiny a {
  color: var(--color-text-muted);
  text-decoration: underline;
}

/* --------------------------------------------------------------------- */
/* About page                                                             */
/* --------------------------------------------------------------------- */
.about-page {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow-sm);
}
.about-title {
  font-size: 1.2rem;
  margin: 0 0 12px;
}
.about-page h4 {
  font-size: 0.95rem;
  margin: 0 0 4px;
}
.about-page p {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* ===========================================================================
   GAME SHELL (/id/:pageId only)
   ---------------------------------------------------------------------------
   Everything below is scoped to .game-body / .app so the top page, the region
   lists and /about keep the light-and-dark card styling above untouched.

   The game page is a fixed-height shell rather than a document: HUD on top, a
   full-bleed tap stage in the middle, a tab sheet at the bottom that scrolls
   internally. The page itself never scrolls, so the counter and the thing you
   tap are always on screen together.
   =========================================================================== */

:root {
  --game-bg: #17130d;
  --game-bg-2: #241c12;
  --game-panel: #2b2015;
  --game-panel-2: #352818;
  --game-line: #4a3a26;
  --game-gold: #ffd15c;
  --game-gold-dim: #b8912f;
  --game-text: #f3e9d6;
  --game-muted: #a9977a;
  --game-green: #6ddf7a;
  --game-red: #ff5a4d;
  --sheet-h: 38dvh;
}

body.game-body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--game-bg);
  color: var(--game-text);
}

/* Re-point the shared component variables at the game palette. Reused pieces
   (quiz, rank table, achievement badges, bonus cards) then theme themselves
   with no per-component overrides, and stay dark regardless of the OS setting
   because the clicker's whole look depends on it. */
.app {
  --color-bg: var(--game-bg);
  --color-surface: var(--game-panel);
  --color-surface-alt: var(--game-panel-2);
  --color-text: var(--game-text);
  --color-text-muted: var(--game-muted);
  --color-border: var(--game-line);
  --color-primary: var(--game-gold);
  --color-primary-dark: var(--game-gold-dim);
  --color-accent: #ffd98f;
  --color-success: var(--game-green);
  --color-danger: var(--game-red);

  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 80% at 50% 0%, var(--game-bg-2) 0%, var(--game-bg) 60%);
}

/* --------------------------------------------------------------------- */
/* HUD                                                                     */
/* --------------------------------------------------------------------- */
.hud {
  flex: none;
  padding: max(6px, env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(180deg, #201a11 0%, rgba(32, 26, 17, 0.82) 100%);
  border-bottom: 1px solid var(--game-line);
}
.hud-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--game-muted);
}
.hud-back {
  color: var(--game-muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px 2px 0;
  text-decoration: none;
}
.hud-school {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--game-text);
  font-weight: 600;
}
.hud-rank {
  flex: none;
  color: var(--game-gold-dim);
  font-weight: 700;
}

.hud-count {
  font-size: clamp(30px, 10.5vw, 54px);
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  /* Proportional digits make a fast-climbing counter jitter horizontally. */
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--game-gold);
  text-shadow: 0 2px 0 #6b4f16, 0 0 24px rgba(255, 209, 92, 0.35);
}
.hud-count.is-frenzy {
  color: #ff9d4d;
  text-shadow: 0 2px 0 #7a2f0c, 0 0 28px rgba(255, 120, 40, 0.6);
}

.hud-sub {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 13px;
  color: var(--game-muted);
  font-variant-numeric: tabular-nums;
}
.hud-rate {
  color: var(--game-green);
  font-weight: 700;
}
.hud-bank b {
  color: var(--game-text);
  font-weight: 700;
}

.hud-level {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--game-muted);
}
.lv-badge {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--game-gold);
  color: #3a2a08;
  font-weight: 800;
  font-size: 11px;
}
.lv-bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: #3a2d1c;
  overflow: hidden;
}
.lv-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--game-gold-dim), var(--game-gold));
  transition: width 320ms ease-out;
}
.lv-next {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.frenzy-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 8px;
  background: linear-gradient(90deg, #6b2a0c, #b4501a);
  color: #ffe6c2;
  font-size: 12px;
  font-weight: 800;
}
.frenzy-strip[hidden] {
  display: none;
}
.frenzy-bar {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.frenzy-fill {
  height: 100%;
  width: 100%;
  background: #ffd15c;
}

/* --------------------------------------------------------------------- */
/* Stage - the whole area is the tap target                                */
/* --------------------------------------------------------------------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  /* Kill double-tap zoom, text selection and the grey tap flash, all of which
     make rapid tapping feel broken on mobile. */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.stage-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(45% 40% at 50% 45%, rgba(255, 209, 92, 0.16), transparent 70%);
  pointer-events: none;
}
.stage.is-frenzy .stage-glow {
  background: radial-gradient(55% 50% at 50% 45%, rgba(255, 120, 40, 0.3), transparent 70%);
  animation: frenzy-pulse 900ms ease-in-out infinite alternate;
}
@keyframes frenzy-pulse {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

.stage-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.stage-inner .slot-building {
  width: min(62vw, 46dvh);
  height: min(62vw, 46dvh);
  transition: transform 120ms ease-out;
}
.stage.is-tapping .slot-building {
  transform: scale(0.94);
}
.slot-building img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.55));
}

.sprite {
  position: absolute;
  width: 52px;
  height: auto;
}
.sprite[hidden] {
  display: none;
}
.sprite-dog { left: 8%; bottom: 12%; }
.sprite-cat { right: 8%; bottom: 12%; }

.float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  font-size: 20px;
  color: var(--game-gold);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
  opacity: 0;
  white-space: nowrap;
}
.float-text.is-live {
  animation: float-up 900ms ease-out forwards;
}
@keyframes float-up {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, calc(-50% - 64px)) scale(0.9); }
}

.golden-badge {
  position: absolute;
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff2c4, #ffcc44 45%, #b8862a);
  box-shadow: 0 0 26px rgba(255, 209, 92, 0.85), 0 6px 16px rgba(0, 0, 0, 0.5);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  z-index: 6;
  animation: golden-bob 2.4s ease-in-out infinite alternate;
}
.golden-badge[hidden] {
  display: none;
}
@keyframes golden-bob {
  from { transform: translateY(-6px) rotate(-8deg); }
  to { transform: translateY(6px) rotate(8deg); }
}

.levelup-flash {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(28px, 9vw, 46px);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff6da;
  text-shadow: 0 0 30px rgba(255, 209, 92, 0.9);
  background: radial-gradient(circle, rgba(255, 209, 92, 0.35), transparent 65%);
  opacity: 0;
  pointer-events: none;
  z-index: 7;
}
.levelup-flash.is-active {
  animation: levelup 950ms ease-out;
}
@keyframes levelup {
  0% { opacity: 0; transform: scale(0.7); }
  25% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(1.25); }
}

.stage-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 26px;
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--game-muted);
  pointer-events: none;
}

/* Non-official-fan-page notice. Deliberately tiny, but it must stay visible
   without scrolling on every school page - see /about. Do not remove. */
.stage-legal {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  margin: 0;
  text-align: center;
  font-size: 10px;
  line-height: 1.4;
  color: #7d6f5a;
}
.stage-legal a {
  color: #9c8a6d;
  margin-left: 4px;
  text-decoration: underline;
}

/* --------------------------------------------------------------------- */
/* Bottom sheet                                                            */
/* --------------------------------------------------------------------- */
.sheet {
  flex: none;
  height: var(--sheet-h);
  min-height: 200px;
  display: flex;
  flex-direction: column;
  background: var(--game-panel);
  border-top: 1px solid var(--game-line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs {
  flex: none;
  display: flex;
  border-bottom: 1px solid var(--game-line);
  background: #241b11;
}
.tab {
  flex: 1;
  padding: 9px 2px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--game-muted);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab.is-active {
  color: var(--game-gold);
  border-bottom-color: var(--game-gold);
}
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px 12px 16px;
}
.tabpanel {
  display: none;
}
.tabpanel.is-active {
  display: block;
}
.sheet-body .panel-title {
  margin: 10px 0 4px;
  font-size: 13px;
}
.sheet-body .panel-title:first-child {
  margin-top: 0;
}

/* --------------------------------------------------------------------- */
/* Shop                                                                    */
/* --------------------------------------------------------------------- */
.buy-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--game-muted);
}
.buy-toggle-label {
  margin-right: auto;
}
.buy-qty {
  padding: 3px 10px;
  border: 1px solid var(--game-line);
  border-radius: 999px;
  background: transparent;
  color: var(--game-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.buy-qty.is-active {
  background: var(--game-gold);
  border-color: var(--game-gold);
  color: #3a2a08;
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.shop-section-title {
  margin: 8px 0 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--game-gold-dim);
}
.shop-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--game-line);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--game-panel-2), #2c2116);
  color: var(--game-text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* The affordable/unaffordable split is the whole engine of the shop, so make
   it loud: buyable rows are lit and gold-edged, the rest recede. */
.shop-row.is-affordable {
  border-color: var(--game-gold);
  box-shadow: 0 0 0 1px rgba(255, 209, 92, 0.25), 0 0 16px rgba(255, 209, 92, 0.18);
}
.shop-row.is-affordable .shop-cost {
  color: var(--game-gold);
}
.shop-row:not(.is-affordable) {
  opacity: 0.42;
  cursor: not-allowed;
}
.shop-row.is-locked {
  opacity: 0.28;
  cursor: default;
  border-style: dashed;
}
.shop-row.just-bought {
  animation: bought-flash 420ms ease-out;
}
@keyframes bought-flash {
  0% { background: rgba(255, 209, 92, 0.55); }
  100% { background: linear-gradient(180deg, var(--game-panel-2), #2c2116); }
}
.shop-main {
  min-width: 0;
}
.shop-name {
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shop-desc {
  font-size: 11px;
  color: var(--game-muted);
}
.shop-cost {
  font-size: 12px;
  font-weight: 700;
  color: var(--game-gold-dim);
  font-variant-numeric: tabular-nums;
}
.shop-eta {
  font-size: 10px;
  color: #8a7a60;
  margin-left: 6px;
}
.shop-owned {
  font-size: 22px;
  font-weight: 800;
  color: rgba(255, 209, 92, 0.28);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------- */
/* Image placeholder slots. Until real art exists the emoji in data-glyph
   stands in; the <img> removes itself on error and reveals it.            */
/* --------------------------------------------------------------------- */
.slot {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 10px;
  overflow: hidden;
}
.slot::before {
  content: attr(data-glyph);
  font-size: 22px;
  line-height: 1;
}
.slot > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: inherit;
}
.slot-building {
  background: none;
}
.slot-building::before {
  font-size: clamp(64px, 26vw, 150px);
}
.slot-sm {
  width: 40px;
  height: 40px;
}
.shop-row .slot {
  width: 42px;
  height: 42px;
  background: radial-gradient(circle at 40% 35%, #45341f, #241b11);
}

/* --------------------------------------------------------------------- */
/* Items                                                                   */
/* --------------------------------------------------------------------- */
.item-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.item-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  min-width: 74px;
  border: 1px solid var(--game-line);
  border-radius: 10px;
  background: var(--game-panel-2);
  color: var(--game-text);
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
}
.item-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--game-gold);
  color: #3a2a08;
  font-size: 10px;
  font-weight: 800;
}

/* --------------------------------------------------------------------- */
/* Toasts                                                                  */
/* --------------------------------------------------------------------- */
.toasts {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
  z-index: 40;
}
.toast {
  max-width: 90%;
  padding: 7px 12px;
  border: 1px solid var(--game-gold-dim);
  border-radius: 999px;
  background: rgba(43, 32, 21, 0.96);
  color: var(--game-text);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
  animation: toast-in 220ms ease-out;
}
.toast.is-out {
  animation: toast-out 260ms ease-in forwards;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(24px); }
}

/* --------------------------------------------------------------------- */
/* Wide screens: stage on the left, sheet as a right-hand column            */
/* --------------------------------------------------------------------- */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 1fr 400px;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "hud   sheet"
      "stage sheet";
  }
  .hud { grid-area: hud; }
  .stage { grid-area: stage; }
  .sheet {
    grid-area: sheet;
    height: 100dvh;
    border-top: none;
    border-left: 1px solid var(--game-line);
  }
  .stage-inner .slot-building {
    width: min(40vw, 52dvh);
    height: min(40vw, 52dvh);
  }
}

/* --------------------------------------------------------------------- */
/* Reduced motion: keep the numbers, drop the theatre                      */
/* --------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .float-text.is-live,
  .levelup-flash.is-active,
  .golden-badge,
  .stage.is-frenzy .stage-glow,
  .shop-row.just-bought,
  .toast,
  .toast.is-out {
    animation: none;
  }
  .float-text.is-live { opacity: 1; }
  .toast.is-out { opacity: 0; }
  .stage.is-tapping .slot-building { transform: none; }
  .lv-fill { transition: none; }
}

/* Shop row internals are spans (they live inside a <button>), so they need to
   be told to stack. */
.shop-main > span {
  display: block;
}
