/* ==========================================================================
   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; }
.char-row { display: flex; gap: 16px; justify-content: center; margin: 18px 0; }
.char-card {
  background: #16203c; border: 3px solid #52586b; border-radius: 12px;
  padding: 14px 22px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-size: 18px; font-weight: bold;
}
.char-card img { width: 92px; height: 92px; transform: scale(1.2); }
.char-card.selected { border-color: #f1c40f; background: #263766; }
#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-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; }

.profile-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.profile-top img { width: 92px; height: 92px; transform: scale(1.2); }
.profile-name { font-size: 22px; font-weight: bold; color: #f1c40f; }
.profile-stats { margin-top: 12px; line-height: 1.9; font-size: 15px; }

/* ---------- 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;
}

/* ---------- 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));
}
/* 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: number keypad ===== */
#bq-choices.fmt-keypad { display: flex; flex-direction: column; gap: 10px; }
.kp-display {
  font-size: 32px; font-weight: bold; letter-spacing: 2px;
  background: #0d1327; border: 3px solid #4a5980; border-radius: 10px;
  padding: 10px; min-height: 54px;
}
.kp-display.correct { color: #69db7c; border-color: #40c057; }
.kp-display.wrong { color: #ff8787; border-color: #e03131; }
.kp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kp-key {
  font-family: inherit; font-size: 24px; font-weight: bold;
  padding: 14px; border-radius: 10px;
  background: #16203c; color: #fff; border: 3px solid #4a5980; cursor: pointer;
}
.kp-key:active { transform: translateY(2px); }
.kp-key.kp-ok { background: #2f9e44; border-color: #1c6b2c; }
.kp-key.kp-del { background: #52586b; border-color: #3a3f4e; }

/* ===== format C: 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 D: 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: Combination Lock ---------- */
#bq-choices.fmt-lock { display: flex; justify-content: center; }
.lk-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.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; }

/* ---------- 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; }

/* ---------- 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); }

@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)); }
}
