/* ==========================================================================
   Learning RPG — styles (mobile/iPad first, touch friendly)
   ========================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #14213d;
  font-family: "Courier New", ui-monospace, monospace;
  color: #f1f3f5;
  overscroll-behavior: none;
  position: fixed;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-canvas {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  image-rendering: pixelated;
  touch-action: none;
}

img { image-rendering: pixelated; }
canvas { image-rendering: pixelated; }

.hidden { display: none !important; }

/* ---------- overlays & panels ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 30, 0.82);
  z-index: 50;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.panel {
  background: #1d2a4d;
  border: 4px solid #f1c40f;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  padding: 22px;
  max-width: 560px;
  width: calc(100% - 28px);
}

/* ---------- start screen ---------- */
#start-screen { background: #2e5cc9; } /* matches the logo background */
.start-panel {
  text-align: center;
  background: transparent;
  border: none;
  box-shadow: none;
}
#game-logo {
  width: min(88vw, 460px);
  image-rendering: pixelated;
  margin-bottom: 4px;
  animation: logo-hover 3.2s ease-in-out infinite;
}
@keyframes logo-hover {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.tagline { color: #dbe6ff; margin-bottom: 22px; text-shadow: 1px 1px 0 rgba(0,0,0,0.25); }
.big-btn {
  display: block; width: 100%;
  font-family: inherit; font-size: 20px; font-weight: bold;
  padding: 16px; margin: 10px 0;
  background: #2f9e44; color: #fff;
  border: 3px solid #1c6b2c; border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 0 #1c6b2c;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1c6b2c; }
.big-btn:disabled { background: #52586b; border-color: #3a3f4e; box-shadow: 0 4px 0 #3a3f4e; opacity: 0.6; }
/* ---------- hero carousel (New Game screen + Profile tab) ---------- */
.hero-carousel {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin: 14px 0 6px;
}
.hero-stage {
  width: 150px; height: 150px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: #16203c; border: 3px solid #52586b; border-radius: 14px;
  touch-action: pan-y;          /* leaves the page scrollable, keeps the swipe */
  user-select: none;
}
.hero-stage-img { width: 92px; height: 92px; transform: scale(1.35); }
.hero-arrow {
  flex: 0 0 auto;
  width: 52px; height: 52px; padding: 0;
  font-family: inherit; font-size: 34px; line-height: 1; font-weight: bold;
  color: #fff; background: #364b83; border: 3px solid #52586b; border-radius: 50%;
  cursor: pointer;
}
.hero-arrow:active { transform: translateY(2px); background: #4a63a8; }
.hero-arrow.mini { width: 34px; height: 34px; font-size: 22px; border-width: 2px; }
.hero-dots {
  display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin: 10px 0 12px;
}
.hero-dot {
  width: 12px; height: 12px; padding: 0;
  border-radius: 50%; border: 2px solid #52586b; background: #16203c;
  cursor: pointer;
}
.hero-dot.on { background: #f1c40f; border-color: #ffe08a; }
.hero-mini { display: flex; align-items: center; gap: 4px; }
#name-input {
  width: 100%; padding: 14px; font-family: inherit; font-size: 20px;
  border: 3px solid #52586b; border-radius: 10px;
  background: #16203c; color: #fff; text-align: center;
  margin-bottom: 8px;
}
#name-input:focus { outline: none; border-color: #f1c40f; }
.secondary-btn { background: #52586b; border-color: #3a3f4e; box-shadow: 0 4px 0 #3a3f4e; }
.secondary-btn:active { box-shadow: 0 1px 0 #3a3f4e; }

/* ---------- start-screen player picker ---------- */
.profile-list { margin: 4px 0 14px; text-align: left; }
.profile-list-head {
  color: #dbe6ff; font-size: 15px; font-weight: bold;
  text-align: center; margin-bottom: 10px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.25);
}
.profile-slot {
  display: flex; align-items: center; gap: 12px;
  background: #16203c; border: 3px solid #4a5980; border-radius: 12px;
  padding: 10px 12px; margin-bottom: 10px; cursor: pointer;
  box-shadow: 0 4px 0 #10182e;
}
.profile-slot:active { transform: translateY(3px); box-shadow: 0 1px 0 #10182e; }
.profile-slot:hover { border-color: #f1c40f; }
.profile-slot-avatar {
  width: 52px; height: 52px; flex-shrink: 0;
  image-rendering: pixelated; transform: scale(1.2);
}
.profile-slot-info { flex: 1; min-width: 0; }
.profile-slot-name { font-size: 19px; font-weight: bold; color: #fff; }
.profile-slot-sub { font-size: 13px; color: #9fb3dd; }
.profile-slot-locked { border-color: #8a4a4a; opacity: 0.7; }
.profile-slot-locked:hover { border-color: #c0392b; }
.profile-slot-locked .profile-slot-sub { color: #e08a8a; }
.profile-slot-del {
  flex-shrink: 0; width: 34px; height: 34px; font-size: 16px;
  background: #52586b; border: 2px solid #3a3f4e; color: #fff;
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hud-top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; justify-content: space-between; align-items: flex-start;
}
#hud-player {
  background: rgba(20, 26, 50, 0.85);
  border: 2px solid #4a5980; border-radius: 12px;
  padding: 10px 12px; min-width: 200px;
  pointer-events: auto;
}
.hud-line { font-weight: bold; font-size: 16px; margin-bottom: 6px; }
.hud-chip {
  background: #f1c40f; color: #14213d;
  border-radius: 8px; padding: 1px 8px; font-size: 13px; margin-left: 4px;
}
.hud-active { font-size: 12px; color: #9fb3dd; margin-top: 5px; display: flex; align-items: center; gap: 5px; }
.hud-active-avatar {
  width: 20px; height: 20px;
  border: 2px solid #f1c40f; border-radius: 5px;
  background: #16203c;
  object-fit: contain;
  flex-shrink: 0;
}
.hud-active-avatar.hidden { display: none; }
#hud-coins-box {
  background: rgba(20, 26, 50, 0.85);
  border: 2px solid #4a5980; border-radius: 12px;
  padding: 8px 14px; font-size: 22px; font-weight: bold;
  display: flex; align-items: center; gap: 8px;
  color: #f1c40f;
}
.coin-icon { width: 32px; height: 32px; border-radius: 50%; }

.bar {
  position: relative; height: 16px;
  background: #0d1327; border: 2px solid #4a5980; border-radius: 8px;
  overflow: hidden; margin: 3px 0;
}
.bar-fill { height: 100%; width: 100%; background: #40c057; transition: width 0.35s; }
.hp-bar .bar-fill.low { background: #e03131; }
.xp-bar { height: 8px; }
.xp-bar .bar-fill { background: #4d9de0; }
.xp-bar.big { height: 18px; }
.bar-text {
  position: absolute; inset: 0;
  font-size: 11px; font-weight: bold; text-align: center; line-height: 13px;
  color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,0.7);
}

#hud-buttons {
  position: absolute;
  right: 12px; bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: auto;
}
.round-btn {
  width: 54px; height: 54px;
  border-radius: 50%;
  font-family: inherit; font-size: 24px; font-weight: bold;
  background: #1d2a4d; color: #fff;
  border: 3px solid #4a5980;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.4);
}
.round-btn:active { transform: translateY(2px); }
.menu-btn { background: #f1c40f; color: #14213d; border-color: #b8860b; }

/* ---------- menu / shop ---------- */
/* fixed height so switching tabs (or menu <-> shop) never resizes the window */
.menu-inner {
  max-width: 640px;
  height: min(86vh, 660px);
  display: flex; flex-direction: column;
}
.menu-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; gap: 10px;
}
.menu-header h2 { color: #f1c40f; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn {
  font-family: inherit; font-size: 14px; font-weight: bold;
  padding: 9px 12px;
  background: #16203c; color: #9fb3dd;
  border: 2px solid #4a5980; border-radius: 10px;
  cursor: pointer;
}
.tab-btn.active { background: #f1c40f; color: #14213d; border-color: #b8860b; }
/* scroll region fills the remaining fixed height */
.tab-page, #shop-list {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-right: 10px;                    /* gap between content and scrollbar */
  scrollbar-width: thin;                  /* Firefox */
  scrollbar-color: #4a5980 rgba(13,19,39,0.5);
}
/* WebKit / Safari / Chrome scrollbar (iPad, desktop) */
.tab-page::-webkit-scrollbar,
#shop-list::-webkit-scrollbar { width: 12px; }
.tab-page::-webkit-scrollbar-track,
#shop-list::-webkit-scrollbar-track {
  background: rgba(13, 19, 39, 0.5);
  border-radius: 8px;
  margin: 2px 0;
}
.tab-page::-webkit-scrollbar-thumb,
#shop-list::-webkit-scrollbar-thumb {
  background: #4a5980;
  border-radius: 8px;
  border: 3px solid transparent;          /* insets the thumb -> padding around it */
  background-clip: padding-box;
}
.tab-page::-webkit-scrollbar-thumb:hover,
#shop-list::-webkit-scrollbar-thumb:hover { background: #f1c40f; }
/* keep tab pages that are toggled off out of the flex flow */
.tab-page.hidden { display: none !important; }
.section-note { color: #9fb3dd; font-size: 14px; margin: 6px 0 10px; }

#logbook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.log-entry {
  background: #16203c; border: 2px solid #303c5e; border-radius: 10px;
  padding: 8px; font-size: 13px;
}
.log-entry.owned { border-color: #f1c40f; }
.log-entry.unknown { opacity: 0.65; }
.log-portrait-wrap {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1;
  background: radial-gradient(circle at 50% 45%, rgba(255,255,255,0.06), rgba(0,0,0,0.18));
  border-radius: 8px; margin-bottom: 6px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.log-portrait {
  width: 100%; height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.log-portrait.grey { filter: grayscale(1) brightness(0.7) contrast(0.9); opacity: 0.8; }
.log-portrait.silhouette { filter: brightness(0); opacity: 0.55; }
.log-name { font-weight: bold; font-size: 14px; }
.type-badge {
  position: absolute;
  top: 5px; right: 5px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 10px; font-weight: bold;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.35);
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.log-sub { font-size: 12px; margin: 2px 0; }
.log-moves { font-size: 11px; color: #8b9dc6; margin-bottom: 6px; }

.mini-btn {
  font-family: inherit; font-size: 13px; font-weight: bold;
  padding: 7px 12px;
  background: #2f9e44; color: #fff;
  border: 2px solid #1c6b2c; border-radius: 8px;
  cursor: pointer;
}
.mini-btn:disabled { background: #52586b; border-color: #3a3f4e; opacity: 0.6; }
.mini-btn.active-btn { background: #f1c40f; color: #14213d; border-color: #b8860b; }
.mini-btn.danger { background: #e03131; border-color: #952020; margin-top: 14px; }

.bag-row {
  display: flex; align-items: center; gap: 12px;
  background: #16203c; border: 2px solid #303c5e; border-radius: 10px;
  padding: 10px; margin-bottom: 8px;
}
.item-icon { width: 36px; height: 36px; border-radius: 8px; border: 2px solid #4a5980; }
.bag-info { flex: 1; }
.bag-name { font-weight: bold; font-size: 15px; }
.bag-desc { font-size: 12px; color: #9fb3dd; }
.empty-note { color: #9fb3dd; text-align: center; padding: 30px 10px; }

/* towns tab (fast travel) */
.town-row {
  display: flex; align-items: center; gap: 12px;
  background: #16203c; border: 2px solid #303c5e; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.town-info { flex: 1; }
.town-name { font-weight: bold; font-size: 16px; }
.town-tier { font-size: 12px; text-transform: capitalize; }
.town-tier.tier-large { color: #f1c40f; }
.town-tier.tier-medium { color: #4d9de0; }
.town-tier.tier-small { color: #69db7c; }

/* online tab (players sharing your room) */
.online-row {
  display: flex; align-items: center; gap: 12px;
  background: #16203c; border: 2px solid #303c5e; border-radius: 10px;
  padding: 8px 12px; margin-bottom: 8px;
}
.online-row.you { border-color: #4dabf7; background: #17264a; }
.online-avatar {
  width: 44px; height: 44px; flex-shrink: 0;
  image-rendering: pixelated; transform: scale(1.2);
}
.online-info { flex: 1; min-width: 0; }
.online-name { font-weight: bold; font-size: 16px; }
.online-you {
  font-size: 11px; font-weight: normal; text-transform: uppercase;
  color: #14213d; background: #4dabf7; border-radius: 6px; padding: 1px 6px;
  vertical-align: middle;
}
.online-sub { font-size: 12px; color: #9fb3dd; }
.online-dot {
  width: 10px; height: 10px; flex-shrink: 0; border-radius: 50%;
  background: #69db7c; box-shadow: 0 0 6px #69db7c;
}

.profile-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.profile-top img { width: 92px; height: 92px; transform: scale(1.2); touch-action: pan-y; }
.profile-name { font-size: 22px; font-weight: bold; color: #f1c40f; }
.profile-stats { margin-top: 12px; line-height: 1.9; font-size: 15px; }
/* leaving and deleting sit together, so the destructive one can't be the only
   button under your thumb — .danger brings its own top margin, hence the reset */
.profile-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.profile-actions .mini-btn.danger { margin-top: 0; }

/* ---------- settings ---------- */
.settings-inner { max-width: 440px; }
#btn-settings-start {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top)); right: calc(14px + env(safe-area-inset-right));
  z-index: 2;
}
.settings-body { padding-top: 6px; }
.setting-row { margin-bottom: 22px; }
.setting-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 16px; font-weight: bold; margin-bottom: 12px;
}
.setting-label span:last-child { color: #f1c40f; font-size: 15px; }
.slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 14px;
  border-radius: 8px;
  background: #0d1327;
  border: 2px solid #4a5980;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #f1c40f;
  border: 3px solid #b8860b;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}
.slider::-moz-range-thumb {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #f1c40f;
  border: 3px solid #b8860b;
  cursor: pointer;
}

/* ---------- settings credit line ---------- */
.made-by {
  margin: 26px 0 2px;
  text-align: center;
  font-size: 11px;
  color: #6b7a9c;
  letter-spacing: 0.3px;
}
/* vertical padding on an inline link grows the tap target without moving
   anything — 11px text is a very small thing to hit with a thumb */
.made-by a { color: #8b9dc6; text-decoration: underline; padding: 8px 3px; }
.made-by a:active { color: #f1c40f; }

/* ---------- dev world editor (localhost only) ---------- */
#dev-row { border-top: 2px solid #4a5980; padding-top: 16px; }
#dev-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
#dev-buttons .mini-btn.danger { margin-top: 0; }
.dev-hint { font-size: 12px; color: #8b9dc6; margin-top: 10px; line-height: 1.5; }
.dev-hint b { color: #f1c40f; }

/* ---------- battle ---------- */
.battle-bg {
  background: #14213d;
  flex-direction: column; justify-content: flex-start; align-items: stretch;
  padding: 0;
}
/* battlefield: the enemy stands here, no player on the field.
   combat.js sets the biome image here (over a gradient fallback). It's
   BOTTOM-anchored + cover, so the ground where the creature fights is always
   visible and only the sky crops off when the frame gets shorter. */
#battle-scene {
  width: 100%; flex: 1; position: relative;
  min-height: 0; overflow: hidden;
  background: linear-gradient(180deg, #1b2b52 0%, #23407a 55%, #2f9e44 55.2%, #237336 100%);
  background-size: cover;
  background-position: center bottom;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}
#battle-scene .fighter.enemy {
  position: absolute;
  top: calc(30% + env(safe-area-inset-top)); right: 5%; z-index: 2;
}
@media (max-width: 780px) {
  #battle-scene .fighter.enemy {
    top:10px;
    left:5%;
    align-items: center;
    display: flex;
    justify-content: center;
  }
}


.fighter-info {
  background: rgba(20, 26, 50, 0.9);
  border: 2px solid #4a5980; border-radius: 10px;
  padding: 8px 10px; min-width: 190px; max-width: 62vw;
}
.fighter-name { font-weight: bold; font-size: 15px; margin-bottom: 5px; }
.fighter-level { font-size: 12px; }
/* big enemy creature image, standing in the arena facing the player.
   wrapper handles position + the flying float; the img handles the hit jitter */
#enemy-battler-wrap {
  position: absolute;
  left: 0; right: 0; bottom: 10%;
  height: 78%;
  display: flex; align-items: flex-end; justify-content: center;
  pointer-events: none;
  max-height: 400px;
}
#battle-scene.flying #enemy-battler-wrap {
  bottom: 12%;                                  /* flyers hover higher... */
  animation: battler-float 3s ease-in-out infinite; /* ...and gently bob */
}
@keyframes battler-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-16px); }
}
#enemy-battler {
  max-height: 100%; max-width: 84%;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,0.45));
}
/* your creature, seen from behind in the near foreground. It sits low enough
   that the footer swallows its lower body — #battle-scene's overflow:hidden
   does the cutting, and the scene's bottom edge IS the top of the footer. The
   blur + dimming push it behind the enemy in depth.

   It stands nearer the camera than the enemy, so it is drawn LARGER. The art is
   a 1024 square whose creature is centred at ~47.5% height, so the Y shift is
   what decides where the footer cuts it: 50% would cut at its waist, and each
   step below that lifts more of the body into view. */
#player-battler-wrap {
  position: absolute;
  left: 26%; bottom: 0;
  height: 144%; max-height: 640px;
  transform: translate(-50%, 38%);   /* ~62% of the sprite stays above the footer */
  display: flex; align-items: flex-end; justify-content: center;
  pointer-events: none; z-index: 3;
}
#player-battler-wrap.hidden { display: none; }
#player-battler {
  max-height: 100%; max-width: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  filter: blur(1.7px) brightness(0.62) saturate(0.92)
          drop-shadow(0 6px 12px rgba(0, 0, 0, 0.55));
}
@media (max-width: 780px) {
  #player-battler-wrap { left: 27%; height: 126%; max-height: 600px; }
}

/* flipbook effect canvases, stacked over the whole battle screen. Positioned
   in JS against #battle's box, so they follow whatever they were aimed at. */
.vfx-canvas {
  position: absolute;
  pointer-events: none;
  z-index: 6;
  image-rendering: pixelated;
}

/* jitter/shake + white flash when the creature is hit */
.hit-flash { animation: battler-hit 0.42s ease-in-out; }
@keyframes battler-hit {
  0%, 100% { transform: translateX(0) rotate(0deg); filter: drop-shadow(0 8px 10px rgba(0,0,0,0.45)); }
  10% { transform: translateX(-9px) rotate(-3deg); filter: brightness(2.6) saturate(0.2); }
  25% { transform: translateX(8px)  rotate(2.5deg); filter: brightness(1.9); }
  40% { transform: translateX(-7px) rotate(-2deg); }
  55% { transform: translateX(6px)  rotate(2deg); }
  70% { transform: translateX(-4px) rotate(-1deg); }
  85% { transform: translateX(2px)  rotate(0.5deg); }
}
.player-hurt { animation: playerhurt 0.45s; }
@keyframes playerhurt {
  0%, 100% { box-shadow: inset 0 0 0 rgba(224,49,49,0); }
  30% { box-shadow: inset 0 0 130px rgba(224,49,49,0.55); }
}

/* black footer: player bar + message + action menu.
   FIXED height so it never jumps as the action content changes. */
#battle-footer {
  width: 100%;
  height: clamp(250px, 42%, 360px);
  background: #0a0d16;
  border-top: 3px solid #f1c40f;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}
/* centred header: the battle log — whose turn it is, what move is happening */
#battle-log {
  flex: 0 0 auto;
  background: rgba(13, 19, 39, 0.55);
  border: 2px solid #2a3352; border-radius: 10px;
  min-height: 42px;
  padding: 12px 16px;               /* top/bottom breathing room */
  font-size: 15px; font-weight: bold;
  text-align: center;
  display: flex; align-items: center; justify-content: center;
}
/* three columns under the header, filling the footer width, centred, not squashed */
#battle-columns {
  flex: 1; min-height: 0;
  width: 100%; max-width: 1100px; margin: 0 auto;
  display: flex; gap: 18px;
  align-items: stretch; justify-content: center;
  overflow-y: auto;
}
.battle-col {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: 10px;
  background: rgba(20, 26, 50, 0.7);
  border: 2px solid #2a3352; border-radius: 12px;
  padding: 10px;
}
.battle-col.hidden { display: none; }
.bcol-head { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.bcol-avatar {
  width: 48px; height: 48px; flex: 0 0 auto;
  border-radius: 50%; object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: #16203c; image-rendering: pixelated;
}
.bcol-id { flex: 1; min-width: 0; }
.bcol-actions { display: flex; flex-direction: column; gap: 8px; }
.bcol-actions > .action-btn { width: 100%; }
.action-btn {
  font-family: inherit; font-weight: bold;
  padding: 11px; border-radius: 10px;
  border: 3px solid rgba(0,0,0,0.35);
  background: #364b83; color: #fff;
  cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 2px;
}
@media (max-width: 780px) {
  .battle-col {
    width:47% !important;
    flex: 1 !important;
    min-width: auto !important;
  }
  #battle-columns {
    flex-wrap: wrap !important;
  }
}
.action-btn:active { transform: translateY(2px); }
.ab-name { font-size: 15px; }
.ab-sub { font-size: 10px; opacity: 0.85; font-weight: normal; }
.el-basic { background: #4a5980; }
.el-item { background: #b06ae0; }
.el-flee { background: #52586b; }
.el-fire { background: #e8590c; } .el-water { background: #1c7ed6; }
.el-grass { background: #2f9e44; } .el-electric { background: #f59f00; }
.el-rock { background: #846358; } .el-ice { background: #3bc9db; }
.el-wind { background: #74b816; } .el-bug { background: #82c91e; }
.el-shadow { background: #5f3dc4; } .el-light { background: #fab005; }

/* items sub-popup (opened from the Items button) */
.battle-popup-overlay {
  position: fixed; inset: 0; z-index: 62;
  background: rgba(8, 12, 26, 0.8);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.battle-popup {
  background: #1d2a4d;
  border: 4px solid #b06ae0; border-radius: 16px;
  width: min(94vw, 460px); max-height: 80vh;
  padding: 18px; display: flex; flex-direction: column; gap: 10px;
}
.battle-popup-title { color: #d0a3f0; font-weight: bold; font-size: 18px; text-align: center; }
.battle-popup-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.battle-item-btn {
  font-family: inherit; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto;
  gap: 1px 12px; align-items: center;
  background: #16203c; color: #fff;
  border: 2px solid #4a5980; border-radius: 10px; padding: 10px;
}
.battle-item-btn img { grid-row: 1 / 3; width: 40px; height: 40px; border-radius: 8px; image-rendering: pixelated; }
.battle-item-btn .bi-name { font-weight: bold; font-size: 15px; }
.battle-item-btn .bi-desc { font-size: 11px; color: #9fb3dd; }
.battle-item-btn:active { transform: translateY(2px); }

#battle-question {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 12, 26, 0.86);
  display: flex; align-items: center; justify-content: center;
}
#bq-card {
  position: relative;
  background: #1d2a4d;
  border: 4px solid #4d9de0; border-radius: 16px;
  width: min(94vw, 520px);
  padding: 22px; text-align: center;
  margin-top: 42px; /* room for the portrait jutting above */
}
#bq-portrait {
  position: absolute;
  top: -46px; left: -18px;
  width: 88px; height: 88px;
  border-radius: 50%;
  object-fit: cover;
  background: #16203c;
  border: 4px solid #4d9de0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  image-rendering: pixelated;
}
#battle-question.defend #bq-card { border-color: #e03131; }
#battle-question.defend #bq-portrait { border-color: #e03131; }
#bq-banner {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin-bottom: 6px;
}
#bq-banner-mode {
  font-size: 18px; font-weight: bold; letter-spacing: 1px;
  color: #4d9de0; text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
}
#battle-question.defend #bq-banner-mode { color: #ff6b6b; }
#bq-banner-move { font-size: 13px; color: #dbe6ff; font-weight: bold; }
#bq-title { color: #9fb3dd; font-size: 15px; font-weight: bold; letter-spacing: 1px; text-transform: uppercase; }
#bq-prompt {
  font-size: clamp(24px, 6vw, 40px);
  font-weight: bold; margin: 14px 0; letter-spacing: 1px;
  line-height: 1.2; overflow-wrap: break-word;
}
#bq-timer {
  height: 14px; border-radius: 7px;
  background: #0d1327; border: 2px solid #4a5980;
  overflow: hidden; margin-bottom: 16px;
}
#bq-timer-fill { height: 100%; width: 100%; background: #40c057; }
/* correct/wrong flash of the whole card on answer */
#battle-question.q-correct #bq-card { border-color: #40c057; box-shadow: 0 0 22px rgba(64,192,87,0.6); }
#battle-question.q-wrong #bq-card { border-color: #e03131; box-shadow: 0 0 22px rgba(224,49,49,0.6); }

/* ===== format A: multiple choice ===== */
#bq-choices.fmt-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-btn {
  font-family: inherit; font-size: 22px; font-weight: bold;
  padding: 16px; border-radius: 12px;
  background: #16203c; color: #fff;
  border: 3px solid #4a5980;
  cursor: pointer;
}
.choice-btn:active { transform: translateY(2px); }
.choice-btn.correct { background: #2f9e44; border-color: #b7f2c3; }
.choice-btn.wrong { background: #e03131; border-color: #ffc9c9; }

/* ===== format B: drag the answer ===== */
#bq-choices.fmt-drag { display: flex; flex-direction: column; gap: 14px; }
.drag-slot {
  min-height: 62px; display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: bold; color: #9fb3dd;
  background: #0d1327; border: 3px dashed #4d9de0; border-radius: 12px;
}
.drag-slot.correct { color: #fff; background: #2f9e44; border-style: solid; border-color: #b7f2c3; }
.drag-slot.wrong { color: #fff; background: #e03131; border-style: solid; border-color: #ffc9c9; }
.drag-tray { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.drag-tile {
  font-family: inherit; font-size: 20px; font-weight: bold;
  padding: 14px 6px; border-radius: 10px;
  background: #364b83; color: #fff; border: 3px solid #4a5980;
  cursor: grab; touch-action: none; user-select: none;
}
.drag-tile.dragging { position: fixed; z-index: 100; cursor: grabbing; opacity: 0.92; box-shadow: 0 6px 16px rgba(0,0,0,0.5); pointer-events: none; }

/* ===== format C: true / false ===== */
#bq-choices.fmt-tf { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tf-btn {
  font-family: inherit; font-size: 22px; font-weight: bold;
  padding: 18px; border-radius: 12px; color: #fff; cursor: pointer;
  border: 3px solid rgba(0,0,0,0.3);
}
.tf-btn.tf-true { background: #2f9e44; }
.tf-btn.tf-false { background: #c0392b; }
.tf-btn:active { transform: translateY(2px); }
.tf-btn.correct { outline: 4px solid #b7f2c3; }
.tf-btn.wrong { outline: 4px solid #ffc9c9; opacity: 0.7; }

/* ---------- mini-game: Number Circle ---------- */
#bq-choices.fmt-circle { display: flex; justify-content: center; }
.circle-ring {
  position: relative; width: min(78vw, 330px); aspect-ratio: 1;
  margin: 2px auto 4px; touch-action: none; user-select: none;
}
.circle-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.circle-line { fill: none; stroke: #f1c40f; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0.92; vector-effect: non-scaling-stroke; }
.circle-center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 33%; aspect-ratio: 1; border-radius: 50%;
  background: #16203c; border: 3px solid #f1c40f;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.cc-label { font-size: 10px; color: #9fb3dd; letter-spacing: 1px; }
.cc-target { font-size: 28px; font-weight: bold; color: #fff; line-height: 1; }
.cc-run { font-size: 12px; color: #f1c40f; min-height: 15px; font-weight: bold; }
.circle-tile {
  position: absolute; transform: translate(-50%, -50%);
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: bold; color: #fff;
  background: #263766; border: 2px solid #4a5980;
  pointer-events: none;
}
.circle-tile.ct-op { background: #3a2a5a; border-color: #7a5cc0; color: #e0d0ff; }
.circle-tile.selected { border-color: #f1c40f; background: #3a4a7a; transform: translate(-50%, -50%) scale(1.1); }
.circle-tile.correct { border-color: #40c057; background: #2f9e44; }
.circle-tile.wrong { border-color: #e03131; background: #a02020; }

/* ---------- mini-game: Falling Tiles ---------- */
#bq-choices.fmt-fall { display: block; }
.fall-area {
  position: relative; width: 100%; height: min(46vh, 300px);
  overflow: hidden; border-radius: 12px; touch-action: none;
  background: linear-gradient(#0d1327, #16203c);
}
.fall-tile {
  position: absolute; width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: bold; color: #fff;
  background: #2f6fd0; border: 2px solid #79b0ff; z-index: 1;
  cursor: grab; user-select: none;
}
.fall-tile.grabbed { z-index: 5; cursor: grabbing; transform: scale(1.08); box-shadow: 0 6px 16px rgba(0,0,0,0.5); }
.fall-eq {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 8px; background: #16203c; border-top: 2px solid #4a5980;
}
.fall-eq-part { font-size: 28px; font-weight: bold; color: #fff; }
.fall-slot {
  width: 56px; height: 56px; border-radius: 12px;
  border: 3px dashed #f1c40f; background: #0d1327;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: bold; color: #f1c40f;
}
.fall-slot.correct { border-style: solid; border-color: #40c057; background: #2f9e44; color: #fff; }
.fall-slot.wrong { border-style: solid; border-color: #e03131; background: #a02020; color: #fff; }

/* ---------- mini-game: Coordinate Lock-On ---------- */
#bq-choices.fmt-grid { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.grid-clue { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.gc-chip {
  background: #16203c; border: 2px solid #4a5980; border-radius: 10px;
  padding: 6px 14px; font-size: 18px; font-weight: bold; color: #fff;
}
.grid-svg {
  width: min(78vw, 320px); aspect-ratio: 1; touch-action: none;
  background: #0d1327; border-radius: 12px; border: 2px solid #4a5980;
}
.grid-line { stroke: #263a63; stroke-width: 0.4; }
.grid-axis { stroke: #5a6f9f; stroke-width: 0.9; }
.grid-label { font-size: 4.4px; fill: #9fb3dd; text-anchor: middle; }
.grid-label-y { text-anchor: end; }
.grid-axis-title { font-size: 5px; fill: #f1c40f; font-weight: bold; text-anchor: middle; }
.grid-pick { fill: rgba(241,196,15,0.25); stroke: #f1c40f; stroke-width: 1.4; }
.grid-pick.correct { fill: rgba(64,192,87,0.3); stroke: #40c057; }
.grid-pick.wrong { fill: rgba(224,49,49,0.3); stroke: #e03131; }
.grid-answer { fill: none; stroke: #40c057; stroke-width: 1.4; stroke-dasharray: 2 1.5; }
.grid-pick.hidden, .grid-answer.hidden { display: none; }

/* ---------- mini-game: Bucket Sort ---------- */
#bq-choices.fmt-bucket { display: block; }
.bucket-area {
  position: relative; width: 100%; height: min(48vh, 320px);
  overflow: hidden; border-radius: 12px; touch-action: none;
  background: linear-gradient(#0d1327, #16203c);
}
.bucket-progress {
  position: absolute; top: 6px; left: 0; right: 0; z-index: 3;
  text-align: center; color: #f1c40f; font-weight: bold; font-size: 16px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
}
.bucket-item {
  position: absolute; padding: 0 14px; height: 44px; min-width: 44px;
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: bold; color: #fff; white-space: nowrap;
  background: #7048c0; border: 2px solid #b79cff; z-index: 1;
  cursor: grab; user-select: none;
}
.bucket-item.grabbed { z-index: 5; cursor: grabbing; transform: scale(1.06); box-shadow: 0 6px 16px rgba(0,0,0,0.5); }
.bucket-row {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  display: flex; gap: 6px; padding: 6px;
}
.bucket {
  flex: 1; height: 64px; border-radius: 12px;
  border: 3px dashed #4a5980; background: #1d2a4d;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: bold; color: #dbe6ff; text-align: center;
}
.bucket.correct-flash { border-style: solid; border-color: #40c057; background: #2f9e44; color: #fff; }
.bucket.wrong-flash { border-style: solid; border-color: #e03131; background: #a02020; color: #fff; }

/* ---------- mini-game: Word Match ---------- */
#bq-choices.fmt-match { display: block; }
.pwm-area {
  position: relative; display: flex; justify-content: space-between;
  gap: 16px; padding: 14px 6px; min-height: 220px; touch-action: none;
}
.pwm-col { display: flex; flex-direction: column; gap: 16px; }
.pwm-left { align-items: flex-start; }
.pwm-right { align-items: flex-end; }
.pwm-anchor {
  display: flex; align-items: center; min-height: 48px;
  background: #16203c; border: 2px solid #4a5980; border-radius: 12px;
  padding: 8px 14px; font-size: 24px; font-weight: bold; color: #fff;
}
.pwm-slot { display: inline-block; min-width: 34px; border-bottom: 3px dashed #f1c40f; margin-left: 3px; }
.pwm-anchor.matched { border-color: #40c057; background: #2f9e44; }
.pwm-anchor.matched .pwm-slot { border-bottom-color: transparent; }
.pwm-anchor.wrong { border-color: #e03131; background: #a02020; }
.pwm-chip {
  background: #7048c0; border: 2px solid #b79cff; border-radius: 12px;
  padding: 8px 16px; font-size: 24px; font-weight: bold; color: #fff;
  cursor: grab; touch-action: none; user-select: none;
}
.pwm-chip.grabbed { cursor: grabbing; box-shadow: 0 6px 16px rgba(0,0,0,0.5); }

/* ---------- mini-game: Letter Drop ---------- */
#bq-choices.fmt-fillin { display: block; }
.ld-area {
  position: relative; width: 100%; height: min(50vh, 340px);
  overflow: hidden; border-radius: 12px; touch-action: none;
  background: linear-gradient(#0d1327, #16203c);
}
.ld-letter {
  position: absolute; width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: bold; color: #fff; text-transform: uppercase;
  background: #2f6fd0; border: 2px solid #79b0ff; z-index: 1;
  cursor: pointer; user-select: none;
}
.ld-letter.dropping { z-index: 4; background: #f1c40f; border-color: #fff3b0; color: #1d2a4d; }
.ld-word {
  position: absolute; left: 0; right: 0; bottom: 10px; z-index: 2;
  display: flex; justify-content: center; align-items: flex-end; gap: 5px;
  padding: 8px; flex-wrap: wrap;
}
.ld-fixed, .ld-slot {
  min-width: 34px; height: 46px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: bold; text-transform: uppercase;
}
.ld-fixed { color: #fff; }
.ld-slot { border: 3px dashed #f1c40f; background: #0d1327; color: #f1c40f; }
.ld-slot.filled { border-style: solid; border-color: #40c057; background: #2f9e44; color: #fff; }
.ld-slot.wrong { border-style: solid; border-color: #e03131; background: #a02020; color: #fff; }

/* ---------- mini-game: Word Ring ---------- */
#bq-choices.fmt-ring { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ring-word {
  font-size: 24px; font-weight: bold; letter-spacing: 3px; min-height: 30px;
  color: #f1c40f; text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
}
.ring-word.good { color: #69db7c; }
.ring-word.bad { color: #ff6b6b; }
.ring-svg { width: min(82vw, 340px); aspect-ratio: 1; touch-action: none; }
.ring-cell { fill: #263766; stroke: #4a5980; stroke-width: 0.8; }
.ring-cell.sel { fill: #3a4a7a; stroke: #f1c40f; stroke-width: 1.4; }
.ring-cell.ok { fill: #2f9e44; stroke: #69db7c; stroke-width: 1.4; }
.ring-cell.bad { fill: #a02020; stroke: #ff6b6b; stroke-width: 1.4; }
.ring-letter { fill: #fff; font-size: 10px; font-weight: bold; text-anchor: middle; dominant-baseline: central; text-transform: uppercase; pointer-events: none; }
.ring-line { fill: none; stroke: #f1c40f; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; vector-effect: non-scaling-stroke; pointer-events: none; }

/* ---------- mini-game: Word Cross ---------- */
#bq-choices.fmt-cross { display: block; }
.cw-area { display: flex; flex-direction: column; align-items: center; gap: 12px; touch-action: none; }
.cw-grid { display: grid; gap: 4px; justify-content: center; }
.cw-cell, .cw-hole, .cw-void {
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; font-weight: bold; text-transform: uppercase;
}
.cw-cell { background: #263766; border: 2px solid #4a5980; color: #dbe6ff; }
.cw-hole { background: #0d1327; border: 3px dashed #f1c40f; color: #f1c40f; }
.cw-hole.done { border-style: solid; border-color: #40c057; background: #2f9e44; color: #fff; }
.cw-hole.bad { border-style: solid; border-color: #e03131; background: #a02020; color: #fff; }
.cw-void { background: transparent; }
.cw-grid.ok .cw-cell { border-color: #40c057; }
.cw-tray {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  padding: 8px; border-radius: 10px; background: rgba(13, 19, 39, 0.6);
}
.cw-tile {
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font-weight: bold; color: #fff; text-transform: uppercase;
  background: #7048c0; border: 2px solid #b79cff; box-shadow: 0 3px 0 rgba(0,0,0,0.35);
  cursor: grab; user-select: none; touch-action: none;
}
.cw-tile.lifted { position: fixed; z-index: 50; margin: 0; cursor: grabbing; transform: scale(1.1); pointer-events: none; }
.cw-tile.spent { visibility: hidden; }
.cw-tile.bad { background: #a02020; border-color: #ff6b6b; }

/* ---------- mini-game: Spell Shot ---------- */
#bq-choices.fmt-shoot { display: block; }
.sl-area {
  position: relative; width: 100%; height: min(52vh, 360px);
  overflow: hidden; border-radius: 12px; touch-action: none;
  background: linear-gradient(#0d1327, #16203c);
}
.sl-row {
  position: absolute; top: 14px; left: 0; right: 0; z-index: 2;
  display: flex; justify-content: center; gap: 5px; pointer-events: none;
}
.sl-tile {
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font-weight: bold; color: #fff; text-transform: uppercase;
  background: #7048c0; border: 2px solid #b79cff; box-shadow: 0 3px 0 rgba(0,0,0,0.35);
}
.sl-tile.boom { position: absolute; animation: sl-boom 200ms ease-out forwards; }
.sl-tile.bad { background: #a02020; border-color: #ff6b6b; }
.sl-row.ok .sl-tile { background: #2f9e44; border-color: #69db7c; }
@keyframes sl-boom { to { transform: scale(1.6) rotate(12deg); opacity: 0; } }
.sl-sling {
  position: absolute; left: 50%; bottom: 8px; width: 46px; height: 34px;
  margin-left: -23px; z-index: 1; border-radius: 0 0 6px 6px;
  border: 4px solid #b07a3a; border-top: none; background: transparent;
}
.sl-sling.pulling { border-color: #f1c40f; }
.sl-ball {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; z-index: 3;
  border-radius: 50%; background: #f1c40f; border: 2px solid #fff59d;
  box-shadow: 0 0 8px rgba(241, 196, 15, 0.6);
}
.sl-dot {
  position: absolute; width: 6px; height: 6px; margin: -3px 0 0 -3px; z-index: 1;
  border-radius: 50%; background: #dbe6ff; opacity: 0.55; pointer-events: none;
}

/* ---------- mini-game: Clock Match ---------- */
#bq-choices.fmt-clock { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.clk-digital {
  font-size: 40px; font-weight: bold; letter-spacing: 4px; color: #f1c40f;
  background: #0d1327; border: 3px solid #4a5980; border-radius: 10px;
  padding: 2px 18px; text-shadow: 0 0 10px rgba(241, 196, 15, 0.45);
}
.clk-svg { width: min(74vw, 290px); aspect-ratio: 1; touch-action: none; cursor: grab; }
.clk-face { fill: #16203c; stroke: #4a5980; stroke-width: 2; }
.clk-tick { stroke: #5a6f9f; stroke-width: 0.7; }
.clk-tick-big { stroke: #9fb0d8; stroke-width: 1.6; }
.clk-num { fill: #dbe6ff; font-size: 8px; font-weight: bold; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.clk-hand { stroke-linecap: round; pointer-events: none; }
.clk-hour { stroke: #fff; stroke-width: 4.5; }
.clk-min { stroke: #f1c40f; stroke-width: 2.8; }
.clk-pin { fill: #dbe6ff; stroke: #16203c; stroke-width: 1; pointer-events: none; }
.clk-grip { stroke-width: 1.4; opacity: 0.85; }
.clk-grip-hour { fill: #7048c0; stroke: #fff; }
.clk-grip-min { fill: #7048c0; stroke: #f1c40f; }
.clk-grip.held { opacity: 1; r: 7.5; }
.clk-svg.ok .clk-face { stroke: #40c057; fill: #17351f; }
.clk-svg.ok .clk-hour, .clk-svg.ok .clk-min { stroke: #69db7c; }
.clk-svg.ok .clk-grip { fill: #2f9e44; stroke: #69db7c; }

/* ---------- mini-game: Number Order ---------- */
#bq-choices.fmt-sort { display: flex; flex-direction: column; gap: 10px; }
.srt-dir { font-size: 13px; font-weight: bold; letter-spacing: 2px; color: #f1c40f; text-align: center; }
.srt-hint { font-size: 11px; color: #6c7fa8; text-align: center; }
/* both rows share a column track so a tile lines up with the slot above it.
   minmax(0,1fr) rather than 1fr: a long value like -100 must not widen its own
   column and knock the two rows out of step */
.srt-slots, .srt-tray { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.srt-slots {
  padding: 7px; border-radius: 12px;
  background: #0d1327; border: 3px solid #4a5980;
}
/* matches the slot row's 7px padding + 3px border, so the columns line up */
.srt-tray { padding: 0 10px; }
.srt-slots.ok { border-color: #40c057; box-shadow: 0 0 22px rgba(64,192,87,0.5); }
.srt-slot, .srt-tile {
  min-height: 54px; display: flex; align-items: center; justify-content: center;
  border-radius: 9px; font-weight: bold; color: #fff;
  /* 6 columns of a 4-character number ("9.95") is the tightest this ever gets,
     and it has to fit on a 375px phone */
  font-size: clamp(11px, 3.5vw, 21px);
}
.srt-slot { background: #16203c; border: 2px dashed #4a5980; }
.srt-slot.active { border-style: solid; border-color: #4d9de0; box-shadow: 0 0 12px rgba(77,157,224,0.55); }
.srt-slot.done { background: #2f9e44; border-style: solid; border-color: #b7f2c3; }
.srt-tile {
  background: #364b83; border: 3px solid #4a5980;
  cursor: grab; touch-action: none; user-select: none;
}
.srt-tile.dragging { position: relative; z-index: 100; cursor: grabbing; opacity: 0.92; box-shadow: 0 6px 16px rgba(0,0,0,0.5); }
/* kept in the layout so the tray doesn't close up mid-round */
.srt-tile.spent { visibility: hidden; }
.srt-tile.bad { background: #7a2727; border-color: #e03131; animation: srt-shake 0.36s; }
@keyframes srt-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---------- mini-game: Money Drop ---------- */
#bq-choices.fmt-money { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.mny-head { text-align: center; }
.mny-ask { font-size: 13px; letter-spacing: 1px; color: #9fb3dd; }
.mny-amount { font-size: 34px; font-weight: bold; color: #f1c40f; line-height: 1.1; }
.mny-sum { display: flex; gap: 22px; justify-content: center; margin-bottom: 2px; }
.mny-k { font-size: 12px; letter-spacing: 1px; color: #9fb3dd; }
.mny-v { font-size: 25px; font-weight: bold; color: #fff; line-height: 1.15; }
.mny-bucket {
  width: 100%; padding: 8px; border-radius: 12px;
  background: #0d1327; border: 3px dashed #4d9de0;
}
.mny-bucket.ok { border-style: solid; border-color: #40c057; box-shadow: 0 0 22px rgba(64,192,87,0.5); }
.mny-drops {
  display: flex; flex-wrap: wrap; gap: 5px;
  justify-content: center; align-content: flex-start;
  min-height: 58px; max-height: 124px; overflow-y: auto;
}
.mny-total { font-size: 26px; font-weight: bold; color: #69db7c; text-align: center; margin-top: 4px; }
.mny-total.over { color: #ff8787; }
.mny-hint { font-size: 11px; color: #6c7fa8; }
.mny-palette { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }

.mny-coin {
  width: var(--d); height: var(--d); flex: none;
  border-radius: 50%; border: 2px solid rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; font-weight: bold; font-size: calc(var(--d) * 0.29);
  color: #2b2b2b; cursor: grab; touch-action: none; user-select: none;
  background: radial-gradient(circle at 34% 28%, #f4f7fb, #aab4c6 68%, #838da1);
}
.mny-gold { color: #4a3505; background: radial-gradient(circle at 34% 28%, #ffeaa9, #e0a92c 68%, #ad7f10); }
/* real Australian diameters (mm x 1.75) — the $2 is the smallest of the lot */
.mny-c5 { --d: 34px; }
.mny-c10 { --d: 41px; }
.mny-c20 { --d: 50px; }
.mny-c50 { --d: 55px; }
.mny-c100 { --d: 44px; }
.mny-c200 { --d: 36px; }
/* the 50c is a flat-topped dodecagon, so clip it to twelve sides */
.mny-c50 {
  border-radius: 0;
  clip-path: polygon(98.3% 62.94%, 85.36% 85.36%, 62.94% 98.3%, 37.06% 98.3%, 14.64% 85.36%, 1.7% 62.94%,
                     1.7% 37.06%, 14.64% 14.64%, 37.06% 1.7%, 62.94% 1.7%, 85.36% 14.64%, 98.3% 37.06%);
}
.mny-dropped { cursor: pointer; }
.mny-ghost { position: fixed; z-index: 100; pointer-events: none; opacity: 0.95; box-shadow: 0 6px 16px rgba(0,0,0,0.55); }

/* ---------- mini-game: Combination Lock ---------- */
#bq-choices.fmt-lock { display: flex; justify-content: center; max-width: 100%; overflow: hidden; }
/* never wraps — a long equation is scaled down to fit instead (see combat.js) */
.lk-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: nowrap; }
.lk-fixed {
  font-size: 34px; font-weight: bold; color: #fff; text-transform: uppercase;
  min-width: 22px; text-align: center;
}
.lk-wheel { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.lk-arrow {
  width: 54px; height: 30px; font-size: 16px; color: #1d2a4d;
  background: #f1c40f; border: none; border-radius: 8px; cursor: pointer;
  font-family: inherit; touch-action: manipulation;
}
.lk-arrow:active { transform: translateY(1px); }
.lk-window {
  width: 54px; height: 108px; overflow: hidden; touch-action: none;
  background: #0d1327; border: 3px solid #4a5980; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: grab; user-select: none;
}
.lk-cell {
  height: 36px; line-height: 36px; font-weight: bold; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center; width: 100%;
}
.lk-cur { font-size: 30px; color: #fff; }
.lk-dim { font-size: 18px; color: #5a6f9f; }
.lk-wheel.ok .lk-window { border-color: #40c057; background: #17351f; }
.lk-wheel.ok .lk-cur { color: #69db7c; }
/* wheels showing totals rather than single digits */
.lk-wide .lk-cur { font-size: 22px; }
.lk-wide .lk-dim { font-size: 14px; }
/* bracketed, multi-step equations: tighter so they stay on one line */
.lk-paren { color: #8fa2cf; }
.lk-row.lk-long { gap: 5px; }
.lk-row.lk-long .lk-fixed { font-size: 24px; min-width: 15px; }
.lk-row.lk-long .lk-paren { min-width: 9px; }
.lk-row.lk-long .lk-window { width: 44px; height: 84px; border-width: 2px; }
.lk-row.lk-long .lk-arrow { width: 44px; height: 24px; font-size: 13px; }
.lk-row.lk-long .lk-cell { height: 28px; line-height: 28px; }
.lk-row.lk-long .lk-cur { font-size: 24px; }
.lk-row.lk-long .lk-dim { font-size: 15px; }
.lk-row.lk-long .lk-wide .lk-cur { font-size: 19px; }
.lk-row.lk-long .lk-wide .lk-dim { font-size: 12px; }

/* ---------- NPC dialog ---------- */
.dialog-inner { max-width: 520px; }
.dialog-header { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
#dialog-portrait {
  width: 72px; height: 72px;
  border: 3px solid #4a5980; border-radius: 12px;
  background: #16203c;
  object-fit: contain;
}
.dialog-name { font-size: 22px; font-weight: bold; color: #69db7c; }
.dialog-text { font-size: 16px; line-height: 1.5; margin-bottom: 14px; }
.dialog-btn { font-size: 17px; padding: 13px; }
.dialog-btn.secondary { background: #52586b; border-color: #3a3f4e; box-shadow: 0 4px 0 #3a3f4e; }
.req-list { margin: 10px 0 4px 22px; line-height: 1.7; }
.reward-line { color: #f1c40f; font-size: 14px; font-weight: bold; margin-top: 6px; }
.hint-line { color: #9fb3dd; font-size: 13px; margin-top: 8px; font-style: italic; }

/* trainer's creature, shown under their challenge line */
.trainer-creature {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px; padding: 8px 10px;
  background: #16203c; border: 2px solid #ff6b6b; border-radius: 12px;
}
.trainer-creature img {
  width: 56px; height: 56px; object-fit: contain;
  background: #0f1730; border-radius: 8px;
}
.trainer-cr-name { font-size: 17px; font-weight: bold; }
.trainer-cr-sub { font-size: 13px; font-weight: bold; margin-top: 2px; }

/* ---------- tutorial ---------- */
.tutorial-inner { max-width: 480px; }
#tutorial-portrait {
  width: 72px; height: 72px;
  border: 3px solid #f1c40f; border-radius: 12px;
  background: #16203c;
  object-fit: cover;
}
.tutorial-welcome { font-size: 18px; line-height: 1.4; margin-bottom: 14px; color: #dbe6ff; }
.tutorial-tips { list-style: none; margin: 0 0 18px; padding: 0; }
.tutorial-tips li {
  display: flex; align-items: flex-start; gap: 12px;
  font-size: 15px; line-height: 1.4;
  padding: 10px 12px; margin-bottom: 8px;
  background: #16203c; border: 2px solid #4a5980; border-radius: 10px;
}
.tutorial-tips b { color: #69db7c; }
.tip-icon { font-size: 22px; line-height: 1; flex-shrink: 0; }

/* ---------- first-catch celebration ---------- */
.firstcatch-inner { max-width: 380px; text-align: center; }
.firstcatch-burst { font-size: 46px; line-height: 1; animation: logo-hover 2.4s ease-in-out infinite; }
.firstcatch-title { color: #f1c40f; font-size: 26px; margin: 6px 0 12px; }
.firstcatch-portrait {
  width: 120px; height: 120px;
  border: 4px solid #f1c40f; border-radius: 16px;
  background: #16203c;
  object-fit: contain;
  margin: 0 auto 12px;
}
.firstcatch-msg { font-size: 16px; line-height: 1.5; color: #dbe6ff; margin-bottom: 18px; }
.firstcatch-msg b { color: #69db7c; }

/* ---------- quests tab ---------- */
.quest-entry {
  background: #16203c; border: 2px solid #303c5e; border-radius: 10px;
  padding: 12px; margin-bottom: 10px;
}
.quest-entry.fulfilled { border-color: #40c057; }
.quest-text { font-size: 14px; font-style: italic; margin-bottom: 8px; }
.quest-req { display: flex; align-items: center; gap: 10px; margin: 4px 0; font-size: 13px; }
.quest-req > span { min-width: 120px; }
.quest-bar { flex: 1; height: 14px; }
.quest-bar .bar-fill { background: #4d9de0; }
.quest-footer { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.quest-footer .mini-btn.danger { margin-top: 0; margin-left: auto; }
.turnin-note { color: #40c057; font-size: 13px; font-weight: bold; }

/* ---------- bag materials ---------- */
.mat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.mat-cell {
  display: flex; align-items: center; gap: 8px;
  background: #16203c; border: 2px solid #303c5e; border-radius: 10px;
  padding: 8px; font-size: 13px; font-weight: bold;
}

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  top: calc(90px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
  width: max-content; max-width: 92vw;
}
.toast {
  background: rgba(13, 19, 39, 0.95);
  border: 2px solid #f1c40f; border-radius: 10px;
  padding: 10px 18px;
  font-weight: bold; font-size: 15px;
  opacity: 0; transform: translateY(-8px);
  transition: all 0.3s;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- player-vs-player duels ---------- */
/* the opponent is a walk-cycle sprite, not battler art — scale it up crisply
   and cap it so it doesn't tower over the scene like a creature would */
#enemy-battler.pvp-battler {
  max-height: 78%;
  max-width: 42%;
  image-rendering: pixelated;
}
/* strip below the battle log while the other player is taking their turn */
#battle-waiting {
  flex: 0 0 auto;
  background: rgba(241, 196, 15, 0.12);
  border: 2px dashed #f1c40f; border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px; font-weight: bold; text-align: center;
  color: #ffe08a;
  animation: waiting-pulse 1.6s ease-in-out infinite;
}
#battle-waiting.hidden { display: none; }
@keyframes waiting-pulse { 0%, 100% { opacity: 0.65; } 50% { opacity: 1; } }

/* the challenge prompt sits above the battle screen, which is also z-index 50 */
#challenge-panel { z-index: 60; }
.challenge-inner { max-width: 420px; text-align: center; position: relative; }
.challenge-swords {
  font-size: 40px; line-height: 1;
  margin-bottom: 4px;
  animation: challenge-shake 2.4s ease-in-out infinite;
}
@keyframes challenge-shake {
  0%, 88%, 100% { transform: rotate(0deg); }
  92% { transform: rotate(-12deg); }
  96% { transform: rotate(12deg); }
}
.challenge-avatar {
  width: 84px; height: 84px;
  object-fit: contain; image-rendering: pixelated;
  border-radius: 50%;
  border: 3px solid #f1c40f;
  background: #16203c;
  margin-bottom: 8px;
}
.challenge-avatar.hidden { display: none; }
.challenge-title { font-size: 19px; font-weight: bold; margin-bottom: 4px; }
.challenge-sub { font-size: 13px; opacity: 0.85; margin-bottom: 10px; }
.challenge-stake {
  display: inline-block;
  background: rgba(241, 196, 15, 0.15);
  border: 2px solid #f1c40f; border-radius: 8px;
  padding: 6px 14px; margin-bottom: 12px;
  font-size: 14px; font-weight: bold; color: #ffe08a;
}
.challenge-stake.hidden { display: none; }
.challenge-timer {
  height: 8px; width: 100%;
  background: rgba(0, 0, 0, 0.4); border-radius: 4px;
  overflow: hidden; margin-bottom: 14px;
}
#challenge-timer-fill { height: 100%; width: 100%; background: #f1c40f; transition: width 0.1s linear; }
.challenge-buttons { display: flex; flex-direction: column; gap: 10px; }
.challenge-buttons .big-btn { margin: 0; }
/* duel button on the Online roster */
.duel-btn { flex: 0 0 auto; white-space: nowrap; }

/* ---------- science: sentence-length prompts and answers ---------- */
/* The default prompt is sized for "7 + 3". A science question is a whole
   sentence, so it drops to reading size and the answers stack. */
#bq-prompt.sci {
  font-size: clamp(15px, 4vw, 21px);
  letter-spacing: 0; margin: 10px 0; line-height: 1.35;
}
#bq-choices.fmt-choice.long { grid-template-columns: 1fr; gap: 8px; }
.fmt-choice.long .choice-btn { font-size: 16px; padding: 12px 14px; line-height: 1.25; }

/* ---------- mini-game: True or False Sort (Bucket Sort, sentences) ---------- */
.bucket-wide .bucket-item {
  height: auto; min-height: 40px; max-width: 74%;
  padding: 8px 12px; font-size: 14px; font-weight: normal;
  line-height: 1.25; white-space: normal; text-align: center;
}
.bucket-wide .bucket { font-size: 17px; }

/* ---------- mini-game: Answer Shot ---------- */
#bq-choices.fmt-scishot { display: block; }
.as-area {
  position: relative; width: 100%; height: min(44vh, 300px);
  overflow: hidden; border-radius: 12px; touch-action: none;
  background: linear-gradient(#0d1327, #16203c);
}
.as-target {
  position: absolute; z-index: 2;
  padding: 7px 10px; border-radius: 9px;
  font-size: 14px; font-weight: bold; line-height: 1.2; text-align: center;
  color: #fff; background: #7048c0; border: 2px solid #b79cff;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
  pointer-events: none; user-select: none;
}
.as-target.hit { background: #2f9e44; border-color: #69db7c; }
.as-target.bad { background: #a02020; border-color: #ff6b6b; }

@media (max-width: 640px) {
  .fighter canvas { width: 120px; height: 114px; }
  .fighter-info { min-width: 130px; }
  #logbook-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
