/* Layouts for each screen: title, select, home (camp), battle, training modal. */

.screen { display: grid; gap: var(--gap); }

/* ── Title ─────────────────────────────────────── */
.title-screen { max-width: 760px; margin: 0 auto; }
.logo { text-align: center; padding-top: 16px; }
.logo h1 {
  margin: 0;
  color: var(--c-yellow);
  letter-spacing: 6px;
  text-shadow: 4px 4px 0 var(--c-red), 8px 8px 0 var(--border);
}
.subtitle { font-family: var(--font-pixel); font-size: 11px; color: var(--c-cyan); margin-top: 14px; }
.feature-list strong { font-family: var(--font-pixel); font-size: 10px; }
.feature-short { display: none; }

/* ── Select ────────────────────────────────────── */
.h-small { font-size: clamp(18px, 4vw, 26px); color: var(--c-yellow); }
.select-screen { max-width: 640px; margin: 0 auto; grid-template-columns: minmax(0, 1fr); } /* the row of slides can't stretch the screen */
.carousel { padding: 10px 10px 8px; overflow: hidden; min-width: 0; }
.carousel-viewport { overflow: hidden; touch-action: pan-y; }
.carousel-track { display: flex; transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: transform; }
.carousel-track.no-anim { transition: none; }
.species-slide { flex: 0 0 100%; min-width: 0; padding: 0 2px; user-select: none; -webkit-user-select: none; }
.species-portrait { background: var(--panel-inset); border: 3px solid var(--border); line-height: 0; }
.species-portrait { position: relative; cursor: pointer; }
.species-portrait canvas { pointer-events: none; }
.portrait-hint { position: absolute; right: 6px; bottom: 4px; font-size: 15px; line-height: 1; color: var(--c-white); text-shadow: 1px 1px 0 var(--c-ink); opacity: 0.75; pointer-events: none; }
.slide-title { display: flex; align-items: center; gap: 8px; margin: 8px 0 2px; }
.slide-title h2 { margin: 0; font-size: 15px; color: var(--c-yellow); }
.species-tagline { color: var(--muted); margin: 0 0 6px; line-height: 1.15; }
.species-bars { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 12px; }
.slide-sub { margin: 6px 0 4px; font-size: 10px; color: var(--c-cyan); }
.move-chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.move-chip { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; padding: 4px 8px; background: var(--panel-inset); border: 2px solid var(--border); color: var(--text); font: inherit; font-size: 18px; line-height: 1.1; text-align: left; cursor: pointer; }
.move-chip small { font-size: 15px; color: var(--c-cyan); flex-shrink: 0; }
.slide-move-info { margin: 4px 0 0; min-height: 2.3em; font-size: 17px; line-height: 1.15; color: var(--text); }
.slide-move-info.more-moves { color: var(--c-yellow); }
.move-chip[aria-pressed='true'] { border-color: var(--c-yellow); }
.slide-facts { margin: 4px 0 0; font-size: 17px; line-height: 1.15; color: var(--muted); }
.slide-facts strong { color: var(--text); font-weight: 400; }
.carousel-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.carousel-arrow { width: 44px; height: 36px; padding: 0; background: var(--panel-inset); border: 3px solid var(--border); color: var(--c-yellow); font-family: var(--font-pixel); font-size: 18px; line-height: 1; cursor: pointer; }
.carousel-dots { display: flex; gap: 8px; }
.carousel-dot { width: 12px; height: 12px; padding: 0; background: var(--c-dark); border: 2px solid var(--border); cursor: pointer; }
.carousel-dot.is-active { background: var(--c-yellow); }

.stats-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }

/* ── Home / camp ───────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--panel);
  border: 4px solid var(--border);
  box-shadow: var(--shadow);
}
.brand { font-family: var(--font-pixel); font-size: 16px; color: var(--c-yellow); text-shadow: 2px 2px 0 var(--c-red); }
.tb-stats { display: flex; gap: 18px; flex-wrap: wrap; }
.tb-coins { color: var(--c-yellow); }
.tb-trophies { color: var(--c-orange); }
/* a tiny pixel cup */
.tb-trophies::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  background:
    linear-gradient(var(--c-orange), var(--c-orange)) 3px 8px / 4px 2px no-repeat,
    linear-gradient(var(--c-orange), var(--c-orange)) 4px 5px / 2px 3px no-repeat,
    linear-gradient(var(--c-orange), var(--c-orange)) 1px 0 / 8px 5px no-repeat;
}
.tb-coins::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  background: var(--c-yellow);
  box-shadow: inset -2px -2px 0 var(--c-orange);
}

.home-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--gap); }
.actions-panel { grid-column: 1 / -1; }

.pet-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin: 14px 0 8px; flex-wrap: wrap; }
.pet-name { margin: 0 0 4px; font-size: 18px; color: var(--c-yellow); }
.pet-meta { margin: 0; }

.thought {
  pointer-events: none; /* taps go through to the pet */
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: 60%;
  padding: 6px 10px;
  line-height: 1.1;
  background: var(--c-white);
  color: var(--c-ink);
  border: 3px solid var(--border);
  font-size: 20px;
}
.thought::after {
  content: '';
  position: absolute;
  left: 18px;
  bottom: -9px;
  width: 6px;
  height: 6px;
  background: var(--c-white);
  border: 3px solid var(--border);
  border-top: 0;
  border-left: 0;
}

.panel-note { margin-bottom: 12px; }
.panel-note.is-warn { color: var(--c-orange); }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.action-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 12px;
  background: var(--panel-inset);
  border: 3px solid var(--border);
  cursor: pointer;
}
@media (hover: hover) { .action-card:hover:not(:disabled) { background: var(--c-dark); } }
.action-card:disabled { opacity: 0.55; cursor: not-allowed; }
.action-title { font-family: var(--font-pixel); font-size: 11px; color: var(--c-yellow); }
.action-desc { color: var(--muted); flex: 1; }
.action-status { font-size: 18px; color: var(--c-cyan); }
.action-short { display: none; color: var(--muted); }
.hint-short { display: none; }

.food-list, .train-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.food-row, .train-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  background: var(--panel-inset);
  border: 3px solid var(--border);
}
.train-row { grid-template-columns: auto minmax(0, 1fr) auto; }
.station-btn { position: relative; display: grid; place-items: center; width: 48px; height: 40px; padding: 0; background: var(--c-ink); border: 2px solid var(--border); cursor: pointer; }
.station-icon { display: block; image-rendering: pixelated; max-width: 36px; max-height: 30px; }
.station-title, .mini-bars, .station-star, .station-ready { display: none; }
.train-row.is-blocked .station-icon { opacity: 0.45; }
.mini-bar { display: block; height: 4px; background: linear-gradient(var(--c), var(--c)) 0 0 / var(--p, 0%) 100% no-repeat, var(--c-dark); }
@keyframes ready-pulse { 50% { transform: scale(1.35); } }
.food-icon-btn { position: relative; display: grid; place-items: center; width: 48px; height: 40px; padding: 0; background: var(--c-ink); border: 2px solid var(--border); cursor: pointer; }
.food-row.is-empty .food-icon { opacity: 0.35; filter: grayscale(0.7); }
.food-title { display: none; }
.food-panel, .train-panel, .stats-panel { position: relative; } /* popovers are placed inside */
.popover {
  position: absolute;
  z-index: 25;
  width: min(280px, 100%);
  padding: 10px 12px;
  background: var(--panel);
  border: 3px solid var(--c-yellow);
  box-shadow: var(--shadow);
  font-size: 19px;
  line-height: 1.15;
}
.popover[hidden] { display: none; }
/* the little pointer towards the tile */
.popover::after {
  content: '';
  position: absolute;
  left: calc(var(--arrow-x, 50%) - 6px);
  bottom: -9px;
  width: 12px;
  height: 12px;
  background: var(--panel);
  border-right: 3px solid var(--c-yellow);
  border-bottom: 3px solid var(--c-yellow);
  transform: rotate(45deg);
}
.popover.is-below::after { bottom: auto; top: -9px; transform: rotate(-135deg); }
.popover-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-right: 24px; color: var(--c-yellow); }
.popover-head canvas { max-width: 30px; max-height: 26px; image-rendering: pixelated; }
.popover p { margin: 6px 0 0; }
.food-pop-pref--favorite { color: var(--c-lime); }
.food-pop-pref--disliked { color: var(--c-orange); }
.popover-muted, .food-pop-pref--neutral { color: var(--muted); }
.popover-fx { color: var(--c-cyan); }
.popover-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.popover-actions .btn { flex: 1; }
.popover-close { position: absolute; top: 4px; right: 6px; padding: 2px 6px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.food-icon { display: block; image-rendering: pixelated; max-width: 36px; max-height: 30px; }
.food-mark { display: none; }
.food-name, .train-name { color: var(--text); }
.food-desc { color: var(--muted); font-size: 19px; }
.food-owned { font-family: var(--font-pixel); font-size: 10px; color: var(--c-yellow); min-width: 34px; text-align: right; }
.food-actions { display: flex; gap: 6px; }
.train-reason { color: var(--c-orange); font-size: 18px; }

.opponent-card {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  margin-top: 4px;
  padding: 12px;
  background: var(--panel-inset);
  border: 3px solid var(--border);
}
.opponent-portrait { border: 3px solid var(--border); background: var(--c-dark); line-height: 0; }
.opponent-portrait { position: relative; }
.mystery-mark { position: absolute; top: 2px; right: 4px; font-family: var(--font-pixel); font-size: 14px; line-height: 1; color: var(--c-yellow); text-shadow: 2px 2px 0 var(--c-ink); animation: ready-pulse 0.8s steps(2) infinite; }
.is-mystery .opponent-info h3 { color: var(--c-yellow); }
/* the enemy card flashes when the mystery opponent is revealed */
@keyframes reveal-flash { 0% { background: var(--c-white); } 100% { background: var(--panel); } }
.fighter.is-revealed { animation: reveal-flash 0.5s ease-out; }
.opponent-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.opponent-info h3 { font-size: 12px; margin-bottom: 6px; }
.opponent-info p { margin: 0 0 4px; }
.reward { color: var(--c-lime); }

.stat-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.stat-table th, .stat-table td { text-align: left; padding: 4px 6px; border-bottom: 2px solid var(--c-dark); }
.stat-table thead th { color: var(--muted); font-weight: 400; }
.num-good { color: var(--c-lime); }
.danger-zone { margin-top: 16px; padding-top: 14px; border-top: 3px dashed var(--c-dark); }
.stats-compact { display: none; }
.stat-chips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.stat-chip { display: grid; justify-items: center; padding: 3px 2px; background: var(--panel-inset); border: 2px solid var(--border); line-height: 1.05; }
.stat-chip small { font-size: 15px; color: var(--muted); }
.stat-chip strong { font-size: 19px; color: var(--c-yellow); font-weight: 400; }
.loadout-head { margin: 6px 0 3px; font-size: 17px; color: var(--muted); }
.loadout-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.loadout-slot { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; min-height: 34px; padding: 4px 8px; text-align: left; background: var(--panel-inset); border: 3px solid var(--border); color: var(--text); font: inherit; font-size: 18px; line-height: 1.05; cursor: pointer; }
.loadout-slot span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.loadout-slot small { flex-shrink: 0; font-size: 15px; color: var(--c-cyan); }
.loadout-slot.is-empty { justify-content: center; color: var(--muted); border-style: dashed; }
.stats-buttons { margin-top: 6px; flex-wrap: nowrap; gap: 6px; }
.stats-buttons .btn { flex: 1; }
.stats-sheet h2 { color: var(--c-yellow); }
.stats-sheet .btn-row { justify-content: center; margin-top: 12px; }

/* ── Battle ────────────────────────────────────── */
.battle-screen { max-width: 720px; margin: 0 auto; gap: 12px; grid-template-columns: minmax(0, 1fr); } /* one wide row can't stretch the screen */
/* 576px canvas (+8px border) = exactly 3× the 192px arena, so pixels stay crisp */
.arena-frame { width: 100%; max-width: 584px; margin: 0 auto; }
.battle-head { display: flex; align-items: center; gap: 14px; }
.battle-head h2 { margin: 0; color: var(--c-orange); font-size: 18px; }
.round-label { flex: 1; font-family: var(--font-pixel); font-size: 10px; color: var(--muted); }
.fighters { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: start; }
.fighter { padding: 10px 12px; background: var(--panel); border: 4px solid var(--border); box-shadow: var(--shadow); }
.fighter--enemy { text-align: right; }
.fighter--enemy .bar-head { flex-direction: row-reverse; }
.fighter--enemy .chips { justify-content: flex-end; }
.fighter-name { margin-bottom: 6px; }
.effect-chips { min-height: 24px; }
.vs { font-family: var(--font-pixel); font-size: 14px; color: var(--c-orange); align-self: center; }
.mood-note { margin: 0; }

.ability-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.battle-screen .panel { padding: 12px; }
.battle-screen .fighter { padding: 8px 10px; }
.ability-btn {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 8px;
  text-align: left;
  background: var(--c-blue);
  border: 3px solid var(--border);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.3), inset 3px 3px 0 rgba(255, 255, 255, 0.2);
  cursor: pointer;
}
@media (hover: hover) { .ability-btn:hover:not(:disabled) { background: var(--c-sky); } }
.ability-btn:active:not(:disabled) { transform: translateY(2px); background: var(--c-sky); }
.ability-btn, .action-card { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.ability-btn:disabled { filter: grayscale(0.8) brightness(0.6); cursor: not-allowed; }
.ability-btn-name { font-family: var(--font-pixel); font-size: 9px; line-height: 1.5; color: var(--c-white); }
.ability-cd { font-size: 18px; color: var(--c-cyan); }
.ability-info { margin: 12px 0 0; min-height: 2.4em; }

.battle-log { list-style: none; margin: 0; padding: 0; max-height: 170px; overflow-y: auto; }
.log { padding: 2px 0; }
.log--round { color: var(--c-slate); font-family: var(--font-pixel); font-size: 9px; padding-top: 10px; }
.log--use { color: var(--c-white); }
.log--hit, .log--dot { color: var(--c-orange); }
.log--crit { color: var(--c-yellow); }
.log--miss { color: var(--muted); }
.log--heal { color: var(--c-lime); }
.log--status { color: var(--c-cyan); }
.log--faint, .log--end { color: var(--c-yellow); font-family: var(--font-pixel); font-size: 10px; padding-top: 6px; }

.result { text-align: center; }
.result h2 { font-size: 22px; }
.result--win h2 { color: var(--c-lime); }
.result--loss h2 { color: var(--c-orange); }
.tier-unlock { font-family: var(--font-pixel); font-size: 12px; color: var(--c-yellow); margin: 4px 0; }
.result .result-list { display: inline-block; text-align: left; margin: 8px 0 18px; }

/* ── Training simulator ────────────────────────── */
.training-sim h2 { color: var(--c-yellow); }
.training-sim .stage-frame { margin: 8px 0 16px; box-shadow: none; }
.sim-pips { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.sim-pip { width: 18px; height: 18px; border: 3px solid var(--border); background: var(--c-dark); }
.sim-pip.is-perfect { background: var(--c-lime); }
.sim-pip.is-good { background: var(--c-teal); }
.sim-pip.is-miss { background: var(--c-red); }
.sim-feedback { text-align: center; min-height: 1.4em; font-size: 26px; }
.sim-feedback[data-grade='perfect'] { color: var(--c-lime); }
.sim-feedback[data-grade='miss'] { color: var(--c-orange); }
.train-learn { display: flex; flex-wrap: wrap; gap: 6px; }
.train-learn:not(:empty) { margin-top: 6px; }
.breakthrough { margin: 12px auto 0; padding: 10px 12px; max-width: 440px; text-align: left; font-size: 20px; border: 3px solid var(--c-yellow); background: var(--c-dark); }
.breakthrough strong { color: var(--c-yellow); }
.breakthrough p { margin: 4px 0; }
.sim-feedback strong { display: block; }
.sim-feedback .result-list { text-align: left; display: inline-block; margin: 6px 0 0; font-size: 22px; }
.training-sim .btn-row { justify-content: center; }
.diff-picker { justify-content: center; margin: 0 0 4px; }
.diff-note { text-align: center; margin: 0; }
.game-hud { display: flex; justify-content: space-between; font-size: 24px; color: var(--c-cyan); margin: -6px 0 4px; }
.game-clock.is-low { color: var(--c-orange); }
.game-meter { position: relative; height: 16px; background: var(--c-ink); border: 3px solid var(--border); overflow: hidden; }
.game-meter-fill { position: absolute; inset: 0 auto 0 0; background: var(--c-lime); }
.game-meter i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--c-white); opacity: 0.6; }
.game-meter--balance { background: linear-gradient(90deg, var(--c-red) 0 12%, var(--c-ink) 12% 88%, var(--c-red) 88%); }
.game-meter-safe { position: absolute; top: 0; bottom: 0; left: 35%; width: 30%; background: var(--c-teal); }
.game-meter-needle { position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px; background: var(--c-white); box-shadow: 0 0 0 2px var(--border); }
.game-meter.is-danger { animation: meter-alarm 0.3s steps(2) infinite; }
@keyframes meter-alarm { 50% { border-color: var(--c-orange); } }
.swipe-pad {
  display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; height: 120px;
  font-family: var(--font-pixel); font-size: 10px; color: var(--muted); background: var(--c-dark);
  border: 4px dashed var(--border); touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.swipe-pad:active { cursor: grabbing; border-color: var(--c-cyan); color: var(--text); }
.swipe-pad--balance { justify-content: space-between; padding: 0 16px; }
.chop-pad { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.chop-side {
  height: 120px; font-family: var(--font-pixel); font-size: 12px; color: var(--c-white); cursor: pointer;
  background: var(--c-dark); border: 4px solid var(--border); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chop-side:active { background: var(--c-blue); transform: translateY(2px); }
.quiz-equation { text-align: center; font-family: var(--font-pixel); font-size: 22px; color: var(--c-yellow); margin: 0 0 10px; }
.quiz-timer .game-meter-fill { background: var(--c-cyan); }
.quiz-timer .game-meter-fill.is-low { background: var(--c-orange); }
.quiz-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.quiz-choice { font-size: 14px; min-height: 52px; justify-content: center; }
@media (hover: hover) and (pointer: fine) { .quiz-choice::before { content: attr(data-key) '. '; color: var(--muted); } }
@media (prefers-reduced-motion: reduce) { .game-meter.is-danger { animation: none; border-color: var(--c-orange); } }
.care-hud { display: flex; justify-content: space-between; margin: 8px 0 0; font-size: 22px; color: var(--c-cyan); }
.care-game .stage-frame { margin-bottom: 8px; }

/* ── Responsive ────────────────────────────────── */
@media (max-width: 860px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ability-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phones: app-style layout with a bottom tab bar on the camp screen. */
@media (max-width: 640px) {
  :root { --gap: 12px; --nav-h: 64px; }
  body { font-size: 20px; }
  h1 { font-size: 40px; }
  .panel { padding: 12px; }

  .topbar { padding: 8px 10px; }
  .brand { font-size: 13px; }
  .tb-stats { gap: 12px; font-size: 19px; }

  /* Needs as a compact two-column grid so the tabs stay close to the pet */
  .needs-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 12px; }
  .needs-panel h3, .needs-panel .chips { grid-column: 1 / -1; }
  .needs-panel h3 { margin-bottom: 6px; }
  .needs-panel .bar-row { margin-bottom: 6px; }
  .needs-panel .bar { height: 12px; border-width: 2px; }
  .pet-heading { margin: 10px 0 6px; }
  .pet-name { font-size: 15px; }

  /* Bottom tab bar */
  .home-screen { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .home-screen .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    gap: 0;
    flex-wrap: nowrap;
    padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    background: var(--panel);
    border-top: 4px solid var(--border);
    box-shadow: 0 -4px 0 rgba(0, 0, 0, 0.3);
  }
  .home-screen .tab { flex: 1 1 0; min-width: 0; min-height: 48px; padding: 8px 2px; font-size: 9px; border-width: 2px; }
  .actions-panel { scroll-margin-top: 12px; }
  .toast-host { bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); }

  /* Title fits on one screen: smaller logo, and "About" becomes three feature tiles */
  .title-screen { gap: 10px; align-content: center; min-height: calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); } /* centred on tall phones */
  .logo { padding-top: 4px; }
  .logo h1 { font-size: 36px; letter-spacing: 4px; text-shadow: 3px 3px 0 var(--c-red), 6px 6px 0 var(--border); }
  .subtitle { margin-top: 8px; font-size: 10px; }
  .start-panel h2 { font-size: 13px; margin-bottom: 6px; }
  .start-panel p { margin: 0 0 8px; line-height: 1.15; }
  .about h2 { font-size: 12px; margin-bottom: 8px; }
  .about-desc, .about-species, .feature-long { display: none; }
  .feature-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0; }
  .feature-list li { margin: 0; display: grid; gap: 4px; align-content: start; padding: 6px; background: var(--panel-inset); border: 2px solid var(--border); font-size: 17px; line-height: 1.1; }
  .feature-list strong { color: var(--c-yellow); font-size: 9px; }
  .feature-short { display: block; color: var(--muted); }

  /* Care tab fits on one screen: compact top bar, pet heading, needs and cards */
  .home-screen .tb-user { display: none; }
  .home-screen .topbar { flex-wrap: nowrap; gap: 8px; }
  .home-screen .tb-stats { gap: 10px; flex-wrap: nowrap; white-space: nowrap; }
  .home-screen .sound-toggle { min-height: 32px; padding: 4px 6px; font-size: 7px; }
  .home-screen .pet-heading { flex-wrap: nowrap; align-items: center; margin: 8px 0 2px; }
  .home-screen .pet-heading > div { min-width: 0; }
  .home-screen .pet-name { display: inline; margin: 0 8px 0 0; }
  .home-screen .pet-heading > div { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .home-screen .pet-meta { display: inline; font-size: 17px; }
  .home-screen .xp-row { margin-bottom: 0; }
  .home-screen .xp-row .bar-head { font-size: 17px; margin-bottom: 1px; }
  .home-screen .xp-row .bar { height: 10px; border-width: 2px; }
  .needs-panel h3 { display: none; }
  .needs-panel .bar-row { margin-bottom: 4px; }
  .needs-panel .bar-head { font-size: 18px; margin-bottom: 1px; }
  .needs-panel .bar { height: 10px; }
  .care-hint { font-size: 17px; line-height: 1.15; margin-bottom: 8px; }
  .card-grid { gap: 8px; }
  .action-card { padding: 8px; gap: 2px; min-height: 76px; }

  /* Battle tab fits on one screen: trophy bar, tiers, and a compact opponent card */
  .battle-status { display: none; margin: 0 0 4px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .battle-status.is-warn { display: block; } /* the mood is already next to the pet's name */
  .trophy-note { display: none; }
  .battle-panel .bar-row { margin: 0 0 6px; }
  .battle-panel .seg-group { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin-bottom: 6px; }
  .battle-panel .seg { min-height: 36px; padding: 3px 2px; font-size: 8px; line-height: 1.3; }
  .seg-lock { display: block; font-size: 7px; }
  .opponent-card .reward { font-size: 16px; white-space: nowrap; }
  .reward-trophies { font-size: 0; }
  .reward-trophies::after { content: '🏆'; font-size: 13px; }
  .opponent-card { grid-template-columns: 56px minmax(0, 1fr); gap: 4px 10px; padding: 6px; margin: 0; font-size: 18px; line-height: 1.1; }
  .opponent-card .opponent-info h3 { font-size: 10px; margin-bottom: 2px; }
  .opponent-card .opponent-info p { margin: 0 0 2px; }
  .opponent-tagline, .opponent-cost { display: none; }
  .opponent-actions { grid-column: 1 / -1; flex-direction: row; }
  .opponent-actions .btn { flex: 1; min-height: 36px; padding: 4px; font-size: 10px; }

  /* Stats tab fits on one screen: a summary; the long lists open as sheets */
  .stats-compact { display: block; }
  .stats-full { display: none; }

  /* Train tab fits on one screen: stations as a 3×2 grid of tiles (tap for details + Train) */
  .train-status { margin: 0 0 6px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .train-cost { display: none; }
  .train-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .train-row { display: block; padding: 3px; }
  .train-row > .train-info, .train-row > .btn { display: none; }
  .station-btn { width: 100%; height: auto; min-height: 74px; padding: 5px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
  .station-title { display: block; font-family: var(--font-pixel); font-size: 8px; line-height: 1.2; color: var(--text); }
  .mini-bars { display: grid; gap: 2px; width: 100%; }
  .station-star { display: block; position: absolute; top: 1px; left: 3px; font-size: 16px; line-height: 1; color: var(--c-lime); }
  .station-ready { display: block; position: absolute; top: 1px; right: 4px; font-size: 16px; line-height: 1; color: var(--c-yellow); animation: ready-pulse 1s steps(2) infinite; }
  .station-ready[hidden] { display: none; }
  .train-row.is-blocked .station-title { color: var(--muted); }

  /* Feed tab fits on one screen: foods as a 4×2 grid of tiles (tap the picture to feed) */
  .food-note { margin: 0 0 6px; font-size: 17px; line-height: 1.15; color: var(--muted); }
  .food-note .hint-long { display: none; }
  .food-note .hint-short { display: inline; }
  .food-list { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .food-row { position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 4px; }
  .food-row .food-info, .food-actions > .btn:first-child, .buy-word { display: none; }
  .food-icon-btn { width: 100%; height: auto; min-height: 58px; padding: 4px 2px 3px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
  .food-title { display: block; font-family: var(--font-pixel); font-size: 8px; line-height: 1.2; color: var(--text); /* VT323's narrow M read as N at this size */ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .food-row.is-empty .food-title { color: var(--muted); }
  .food-actions { display: none !important; }
  .food-owned { position: absolute; top: 6px; right: 6px; min-width: 0; font-size: 8px; pointer-events: none; text-shadow: 1px 1px 0 var(--c-ink); }
  .food-mark { display: block; position: absolute; top: 1px; left: 3px; font-size: 16px; line-height: 1; }
  .food-mark--favorite { color: var(--c-lime); }
  .food-mark--disliked { color: var(--c-orange); }

  .action-desc { display: none; }
  .action-short { display: block; flex: 1; font-size: 18px; line-height: 1.1; }
  .action-status { font-size: 17px; }

  /* Select: sticky adopt bar */
  /* Get an animal fits on one screen */
  .app:has(.select-screen) { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .select-screen { gap: 8px; }
  .select-screen .screen-head p { display: none; }
  .select-screen .h-small { margin: 0; }
  .species-portrait canvas.stage { width: auto; height: min(calc((100vw - 60px) * 0.475), 110px); margin: 0 auto; }
  .species-portrait { background: var(--c-ink); }
  .species-tagline { font-size: 17px; margin-bottom: 4px; }
  .species-bars { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 8px; }
  .species-bars .bar-head { font-size: 15px; }
  .slide-title h2 { font-size: 13px; }
  .carousel { padding: 8px 8px 6px; }
  .carousel-nav { margin-top: 6px; }
  .adopt-panel .field-label { display: none; }
  .adopt-panel .input-row { flex-wrap: nowrap; }
  .adopt-panel .input { flex: 1; min-width: 0; }
  .adopt-which { display: none; }
  .adopt-panel {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin: 0 -4px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  /* Battle: fighters side by side, compact */
  .battle-screen { gap: 8px; }
  .battle-head { gap: 6px; }
  .battle-head h2 { font-size: 13px; }
  .round-label { min-width: 0; font-size: 8px; line-height: 1.3; }
  .battle-head .sound-toggle, .battle-head .btn-small { min-height: 32px; padding: 4px 6px; font-size: 7px; }
  .fighters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .vs { display: none; }
  .fighter-name { font-size: 18px; line-height: 1.05; overflow: hidden; text-overflow: ellipsis; }
  .fighter .bar-head { font-size: 17px; }
  .effect-chips { min-height: 0; }
  .chip { font-size: 7px; padding: 4px 5px; }
  .ability-btn { min-height: 64px; }
  .log-panel h3 { margin-bottom: 6px; }
  /* the arena fills exactly one screen; the log takes what's left and scrolls inside */
  .app:has(.battle-screen) { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .battle-screen { display: flex; flex-direction: column; height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom))); }
  .battle-screen > * { flex-shrink: 0; }
  .battle-screen .log-panel { flex: 1 1 0; min-height: 72px; display: flex; flex-direction: column; }
  .battle-log { flex: 1; min-height: 0; max-height: none; font-size: 19px; }
  .mood-note { margin: 0; font-size: 17px; line-height: 1.1; }
  .ability-info { font-size: 17px; margin-top: 6px; line-height: 1.1; }
}

/* Phones: the training modal fits on one screen without scrolling */
@media (max-width: 640px) {
  .modal-backdrop:has(.training-sim) { padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .modal:has(.training-sim) { padding: 10px; max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .training-sim h2 { font-size: 13px; margin: 0 0 4px; }
  .train-desc { font-size: 16px; line-height: 1.15; margin: 0 0 4px; }
  .training-sim .stage-frame { margin: 4px 0 8px; background: var(--c-ink); }
  .training-sim canvas.stage { width: auto; height: min(calc((100vw - 52px) * 0.4583), 26vh); margin: 0 auto; }
  .game-hud { font-size: 19px; margin: 0 0 2px; }
  .game-meter { height: 12px; }
  .swipe-pad { height: 96px; margin-top: 8px; }
  .chop-pad { margin-top: 8px; gap: 8px; }
  .chop-side { height: 96px; font-size: 11px; }
  .quiz-equation { font-size: 18px; margin-bottom: 6px; }
  .quiz-choices { gap: 8px; margin-top: 8px; }
  .quiz-choice { min-height: 46px; }
  .sim-pips { margin: 8px 0; }
  .sim-pip { width: 14px; height: 14px; }
  .sim-feedback { font-size: 19px; line-height: 1.15; margin: 0 0 8px; }
  .sim-feedback .result-list { font-size: 18px; margin-top: 4px; }
  .sim-feedback .result-list li { margin: 0; }
  .breakthrough { font-size: 17px; padding: 8px; margin-top: 8px; }
  .diff-note { font-size: 16px; }
}

/* Short phones: shrink the pet scene so the care tab still fits above the tab bar */
@media (max-width: 640px) and (max-height: 780px) {
  .species-portrait canvas.stage { height: 80px; }
  .species-tagline { display: none; }
  .slide-facts { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .arena-frame canvas.stage { width: auto; height: min(calc((100vw - 40px) * 0.5417), 25vh); margin: 0 auto; }
  .arena-frame { background: var(--c-ink); }
  .ability-btn { min-height: 50px; padding: 6px 8px; }
  .ability-grid { gap: 6px; }
  .battle-screen .fighter { padding: 6px 8px; }
  .fighter .bar-row { margin-bottom: 2px; }
  .ability-info { min-height: 1.1em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .log-panel h3 { display: none; }
  .battle-screen .panel { padding: 8px 10px; }
  .home-screen { gap: 8px; }
  .home-grid { gap: 8px; }
  .pet-panel canvas.stage { width: auto; height: min(calc((100vw - 56px) * 0.625), 22vh); margin: 0 auto; }
  .pet-panel .stage-frame { background: var(--c-ink); }
  .needs-panel { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 8px; }
  .needs-panel .bar-head { font-size: 16px; }
  .hint-long { display: none; }
  .hint-short { display: inline; }
  .action-card { min-height: 0; }
  .food-note, .train-status { display: none; }
  .stat-chip { display: flex; justify-content: center; align-items: baseline; gap: 4px; padding: 2px; }
  .loadout-slot { min-height: 30px; padding: 2px 6px; }
  .loadout-head { margin: 4px 0 2px; }
  .battle-panel .bar-row { display: none; } /* the locked tiers still show their trophy targets */
  .battle-panel .seg { min-height: 32px; }
  .opponent-actions .btn { min-height: 32px; }
  .station-btn { min-height: 0; padding: 3px 5px; gap: 2px; }
  .station-icon { max-height: 22px; }
  .mini-bar { height: 3px; }
  .train-list { gap: 4px; }
  .food-row { padding: 3px; gap: 3px; }
  .food-icon-btn { min-height: 52px; }
}

@media (max-width: 640px) and (max-height: 700px) {
  .train-desc { display: none; }
  .training-sim canvas.stage { height: 22vh; }
  .sim-feedback .result-list, .breakthrough { font-size: 16px; }
  .pet-panel canvas.stage { height: 19vh; }
  .home-screen .topbar { padding: 4px 8px; }
  .panel { padding: 10px; }
  .food-icon-btn { min-height: 44px; gap: 1px; }
  .stat-chip strong { font-size: 17px; }
  .loadout-slot { min-height: 26px; font-size: 17px; }
  .stats-buttons .btn { min-height: 32px; padding: 4px 8px; }
  .opponent-card { grid-template-columns: 48px minmax(0, 1fr); padding: 4px 6px; }
  .opponent-actions .btn { min-height: 28px; }
  .loadout-grid, .stat-chips { gap: 3px; }
  .loadout-head { margin: 2px 0 1px; font-size: 16px; }
  .stats-buttons { margin-top: 4px; }
  .stat-chip { padding: 1px 2px; }
  .station-icon { max-height: 18px; }
  .food-list { gap: 4px; }
}

@media (max-width: 560px) {
  .stats-cols { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .thought { font-size: 17px; max-width: 75%; }
  .stat-table th, .stat-table td { padding: 4px 3px; }
}

@media (max-width: 360px) {
  .home-screen .tab { font-size: 8px; }
}
