/* ============================================================
   RiverLab 3D — style.css   Premium dark educational game UI
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:     #020b18;
  --bg-dark:     #0a1628;
  --bg-mid:      #0f2040;
  --bg-card:     #111e35;
  --border:      rgba(99,179,255,0.13);
  --border-soft: rgba(255,255,255,0.06);
  --text-main:   #e2eeff;
  --text-muted:  #6888aa;
  --discharge:   #38bdf8;
  --velocity:    #a78bfa;
  --energy:      #f59e0b;
  --erosion:     #ef4444;
  --transport:   #a78bfa;
  --deposition:  #34d399;
  --radius:      14px;
  --shadow:      0 4px 32px rgba(0,0,0,0.65);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: 'Noto Sans TC', sans-serif;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ══════════════════ INTRO SCREEN ══════════════════ */
#intro-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  background: radial-gradient(ellipse at 35% 55%, #0d2550 0%, #020b18 65%);
  overflow: hidden;
}

#intro-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none; opacity: 0.6;
}

.intro-back-link {
  position: absolute; top: 18px; left: 20px; z-index: 10;
  display: inline-flex; align-items: center; gap: 6px;
  color: rgba(100,160,210,0.75);
  font-size: 13px; font-weight: 600; text-decoration: none;
  padding: 6px 14px; border-radius: 20px;
  border: 1px solid rgba(56,189,248,0.2);
  background: rgba(10,22,50,0.6);
  backdrop-filter: blur(8px);
  transition: all 0.25s;
}
.intro-back-link:hover {
  color: #38bdf8;
  border-color: rgba(56,189,248,0.5);
  background: rgba(14,165,233,0.12);
  transform: translateX(-3px);
}

.intro-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  gap: 22px; text-align: center; padding: 40px 48px;
  max-width: 700px;
}

.intro-badge {
  background: rgba(56,189,248,0.12);
  border: 1px solid rgba(56,189,248,0.28);
  color: var(--discharge);
  font-size: 12px; font-weight: 600;
  padding: 5px 20px; border-radius: 50px; letter-spacing: 1.5px;
  text-transform: uppercase;
}

.intro-title {
  font-size: clamp(32px, 7vw, 82px);
  font-weight: 900; line-height: 1;
  white-space: nowrap;          /* always one line */
  background: linear-gradient(135deg, #38bdf8 0%, #a78bfa 55%, #f59e0b 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 40px rgba(56,189,248,0.25));
}

.intro-tagline {
  font-size: 26px; font-weight: 700; color: var(--text-muted);
  letter-spacing: 4px; margin-top: -10px;
}

.intro-subtitle {
  font-size: 16px; color: var(--text-muted);
  max-width: 500px; line-height: 1.75;
}

/* Formula Box */
.intro-formula-box {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 18px 36px;
  backdrop-filter: blur(10px);
}

.intro-formula-inner {
  display: flex; align-items: center; gap: 14px;
  font-size: 20px; font-weight: 800;
}

.if-label { color: var(--energy); font-size: 18px; }
.if-eq, .if-op { color: var(--text-muted); font-size: 22px; }

.if-var {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px; border-radius: 12px;
  font-size: 18px;
}
.if-var.blue {
  background: rgba(56,189,248,0.15);
  border: 1px solid rgba(56,189,248,0.3);
  color: var(--discharge);
}
.if-var.purple {
  background: rgba(167,139,250,0.15);
  border: 1px solid rgba(167,139,250,0.3);
  color: var(--velocity);
}
.if-icon { font-size: 22px; }

/* Zone preview */
.intro-zones {
  display: flex; align-items: center; gap: 12px;
}

.iz-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 20px; border-radius: 14px;
  border: 1px solid var(--border-soft);
  background: rgba(255,255,255,0.04);
  min-width: 90px;
  transition: transform .3s;
}
.iz-item:hover { transform: translateY(-4px); }
.iz-icon { font-size: 24px; }
.iz-label { font-size: 14px; font-weight: 700; }
.iz-sub { font-size: 11px; color: var(--text-muted); }
.iz-item.red   { border-color: rgba(239,68,68,0.3);  background: rgba(239,68,68,0.08);  }
.iz-item.yellow{ border-color: rgba(167,139,250,0.3);background: rgba(167,139,250,0.08);}
.iz-item.teal  { border-color: rgba(52,211,153,0.3); background: rgba(52,211,153,0.08); }
.iz-arrow { color: var(--text-muted); font-size: 14px; }

/* Buttons */
.intro-buttons {
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #7c3aed);
  border: none; color: #fff;
  font-size: 17px; font-weight: 700;
  padding: 14px 40px; border-radius: 50px; cursor: pointer;
  box-shadow: 0 0 35px rgba(56,189,248,0.3);
  transition: transform .25s, box-shadow .25s;
  font-family: inherit;
  letter-spacing: 0.5px;
}
.btn-primary:hover {
  transform: scale(1.06); box-shadow: 0 0 55px rgba(56,189,248,0.5);
}

.btn-secondary {
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 15px; font-weight: 600;
  padding: 14px 32px; border-radius: 50px; cursor: pointer;
  transition: background .25s, transform .25s;
  font-family: inherit;
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.12); transform: scale(1.04);
}

.intro-tip {
  font-size: 12px; color: rgba(255,255,255,0.25);
  letter-spacing: 0.5px;
}

/* ══════════════════ GAME SCREEN ══════════════════ */
#game-screen {
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

/* ── Energy Bar (Top Header) ── */
.energy-bar {
  height: 60px; flex-shrink: 0;
  background: rgba(5,15,35,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 14px; gap: 12px;
  z-index: 20;
}

.top-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-size: 12px; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
  font-family: inherit;
  transition: all .2s; white-space: nowrap;
}
.top-btn:hover { color: var(--text-main); background: rgba(255,255,255,0.11); }

/* Formula Display */
.formula-display {
  flex: 1; display: flex; align-items: center;
  justify-content: center; gap: 10px;
}

.fd-block {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-soft);
  border-radius: 12px; padding: 6px 14px;
  transition: border-color .4s, box-shadow .4s;
}
.fd-icon { font-size: 20px; }
.fd-label { font-size: 13px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.fd-val {
  font-size: 26px; font-weight: 900; min-width: 30px; text-align: center;
  transition: color .4s;
}
.fd-progress {
  width: 40px; height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px; overflow: hidden;
}
.fd-fill { height: 100%; border-radius: 2px; transition: width .5s cubic-bezier(.25,.8,.25,1); }
.discharge-fill { background: linear-gradient(90deg, #1d5ea3, #38bdf8); }
.velocity-fill  { background: linear-gradient(90deg, #5b21b6, #a78bfa); }

.discharge-fd .fd-val { color: var(--discharge); }
.velocity-fd  .fd-val { color: var(--velocity); }
.energy-fd    .fd-val { color: var(--energy); font-size: 30px; }

.fd-op { font-size: 24px; color: var(--text-muted); font-weight: 300; }

/* Zone glow states */
.zone-erosion-glow    { border-color: rgba(239,68,68,0.5) !important; box-shadow: 0 0 16px rgba(239,68,68,0.2); }
.zone-transport-glow  { border-color: rgba(167,139,250,0.5) !important; box-shadow: 0 0 16px rgba(167,139,250,0.2); }
.zone-deposition-glow { border-color: rgba(52,211,153,0.5) !important; box-shadow: 0 0 16px rgba(52,211,153,0.2); }

/* Energy Zone Badge */
.energy-zone {
  font-size: 15px; font-weight: 800;
  padding: 5px 18px; border-radius: 20px;
  border: 1px solid; white-space: nowrap;
  transition: all .4s; letter-spacing: 0.3px;
}
.zone-erosion    { color:#ef4444; background:rgba(239,68,68,0.12);   border-color:rgba(239,68,68,0.35);   }
.zone-transport  { color:#a78bfa; background:rgba(167,139,250,0.12); border-color:rgba(167,139,250,0.35); }
.zone-deposition { color:#34d399; background:rgba(52,211,153,0.12);  border-color:rgba(52,211,153,0.35);  }

@keyframes celebrate {
  0%,100% { transform: scale(1); }
  20%      { transform: scale(1.25); }
  40%      { transform: scale(0.9); }
  60%      { transform: scale(1.15); }
}
.celebrate { animation: celebrate .6s ease; }

.top-right-btns { display: flex; gap: 6px; }

/* ══════════════════ GAME LAYOUT ══════════════════ */
.game-layout {
  flex: 1; display: grid;
  grid-template-columns: 270px 1fr 270px;
  overflow: hidden; min-height: 0;
}

/* ══════════════════ SIDE PANELS ══════════════════ */
.side-panel {
  background: rgba(6,14,30,0.97);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(99,179,255,0.2) transparent;
}
.left-panel  { border-right: 1px solid var(--border); }
.right-panel { border-left:  1px solid var(--border); }

/* Panel Header */
.panel-header {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  position: sticky; top: 0; z-index: 10;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.discharge-hdr {
  background: linear-gradient(135deg, rgba(56,189,248,0.14) 0%, rgba(6,14,30,0.97) 100%);
}
.velocity-hdr {
  background: linear-gradient(135deg, rgba(167,139,250,0.14) 0%, rgba(6,14,30,0.97) 100%);
}
.ph-icon { font-size: 28px; }
.ph-title { font-size: 18px; font-weight: 800; }
.ph-sub   { font-size: 13px; color: var(--text-muted); margin-top: 1px; }

/* Factor Cards */
.factors { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }

.factor-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px; padding: 11px 12px;
  transition: background .22s, border-color .22s;
}
.factor-card:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.13);
}
.fc-top {
  display: flex; align-items: center; gap: 9px; margin-bottom: 9px;
}
.fc-emoji { font-size: 22px; flex-shrink: 0; }
.fc-name  { font-size: 15px; font-weight: 700; line-height: 1.2; }
.fc-rule  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.fc-num {
  margin-left: auto;
  font-size: 18px; font-weight: 900;
  color: var(--energy);
  background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.2);
  min-width: 34px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 7px; flex-shrink: 0;
}

/* Sliders */
.slider {
  -webkit-appearance: none;
  width: 100%; height: 5px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px; outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
  transition: transform .15s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.3); }
.d-slider::-webkit-slider-thumb { background: var(--discharge); box-shadow: 0 0 10px rgba(56,189,248,0.5); }
.v-slider::-webkit-slider-thumb { background: var(--velocity);  box-shadow: 0 0 10px rgba(167,139,250,0.5); }

.fc-labels {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-muted); margin-top: 4px;
}

/* Action Panel */
.action-panel {
  margin: 6px 10px 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-soft);
  border-radius: 12px; padding: 10px 12px;
  flex-shrink: 0;
}
.ap-title {
  font-size: 12px; font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px; text-transform: uppercase;
  margin-bottom: 8px;
}
.action-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.action-row:last-child { margin-bottom: 0; }
.ar-label {
  font-size: 13px; font-weight: 700; min-width: 58px; white-space: nowrap;
}
.erosion-color   { color: var(--erosion); }
.transport-color { color: var(--transport); }
.deposition-color{ color: var(--deposition); }
.ar-bar-wrap {
  flex: 1; height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px; overflow: hidden;
}
.ar-bar {
  height: 100%; border-radius: 3px; width: 0%;
  transition: width .6s cubic-bezier(.25,.8,.25,1);
}
.erosion-fill    { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.transport-fill  { background: linear-gradient(90deg, #5b21b6, #a78bfa); }
.deposition-fill { background: linear-gradient(90deg, #059669, #34d399); }

/* Mission Panel */
.mission-panel {
  margin: 0 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-soft);
  border-radius: 12px; padding: 10px;
  flex-shrink: 0;
}
.mp-title {
  font-size: 12px; font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px; text-transform: uppercase;
  margin-bottom: 7px;
}
.mission-btn {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-soft);
  color: var(--text-main);
  font-size: 14px; font-weight: 600;
  padding: 9px 11px; border-radius: 9px;
  cursor: pointer; font-family: inherit;
  text-align: left; margin-bottom: 5px;
  transition: background .2s, border-color .2s, transform .15s;
}
.mission-btn:last-child { margin-bottom: 0; }
.mission-btn:hover {
  background: rgba(255,255,255,0.09);
  border-color: rgba(167,139,250,0.4);
  transform: translateX(3px);
}

/* ══════════════════ CANVAS AREA ══════════════════ */
.canvas-area {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, #010d1f 0%, #020b18 100%);
}
#river-canvas { width: 100%; height: 100%; display: block; }

/* Section Panel */
.section-panel {
  position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(6,14,30,0.96);
  border: 1px solid var(--border);
  border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow);
  z-index: 15; backdrop-filter: blur(10px);
  animation: slideDown .3s ease;
}
@keyframes slideDown {
  from { transform: translateX(-50%) translateY(-20px); opacity:0; }
  to   { transform: translateX(-50%) translateY(0);     opacity:1; }
}
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  font-size: 14px; font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}
.section-close-btn {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 14px; width: 26px; height: 26px;
  border-radius: 50%;
  transition: background .2s, color .2s;
}
.section-close-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-main); }
#section-canvas { display: block; }

/* Status Bar */
.status-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(6,14,30,0.92);
  border-top: 1px solid var(--border);
  padding: 9px 18px;
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; backdrop-filter: blur(8px);
  z-index: 10; transition: all .4s;
}
#status-icon { font-size: 20px; flex-shrink: 0; }
#status-text  { transition: color .4s; line-height: 1.4; }

.cam-hint {
  position: absolute; top: 10px; right: 14px;
  font-size: 12px; color: rgba(255,255,255,0.22);
  pointer-events: none; letter-spacing: 0.3px;
}

/* ══════════════════ OVERLAYS ══════════════════ */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(6px);
}

.overlay-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px; padding: 32px;
  max-width: 560px; width: 92%;
  box-shadow: 0 24px 80px rgba(0,0,0,0.75);
  animation: slideUp .3s ease;
  position: relative;
}
@keyframes slideUp {
  from { transform: translateY(28px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.overlay-card h3 {
  font-size: 22px; font-weight: 800; margin-bottom: 12px;
}

.overlay-desc {
  font-size: 15px; color: var(--text-muted);
  line-height: 1.75; margin-bottom: 14px;
}

.overlay-hint {
  background: rgba(167,139,250,0.08);
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: 10px; padding: 10px 14px;
  font-size: 14px; color: #c4b5fd;
  line-height: 1.7; margin-bottom: 16px;
}

.overlay-status {
  font-size: 15px; font-weight: 700;
  padding: 10px 14px; border-radius: 10px;
  margin-bottom: 16px; text-align: center;
}
.overlay-status.in-progress {
  background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.3);
  color: var(--energy);
}
.overlay-status.complete {
  background: rgba(52,211,153,0.12);
  border: 1px solid rgba(52,211,153,0.35);
  color: var(--deposition);
  animation: glow .8s ease;
}
@keyframes glow {
  0%   { box-shadow: 0 0 0 rgba(52,211,153,0); }
  50%  { box-shadow: 0 0 30px rgba(52,211,153,0.4); }
  100% { box-shadow: 0 0 0 rgba(52,211,153,0); }
}

/* Info Modal */
.info-card {
  max-width: 620px;
}
.modal-close-btn {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.08); border: none;
  color: var(--text-muted);
  width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; font-size: 14px;
  transition: all .2s;
}
.modal-close-btn:hover { background: rgba(255,255,255,0.15); color: var(--text-main); }

.info-card h3 { margin-bottom: 18px; }

.info-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.info-item {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-soft);
  border-radius: 14px; padding: 16px;
}
.ii-icon {
  font-size: 26px; margin-bottom: 8px;
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.erosion-bg   { background: rgba(239,68,68,0.15); }
.transport-bg { background: rgba(167,139,250,0.15); }
.deposition-bg{ background: rgba(52,211,153,0.15); }
.wetted-bg    { background: rgba(56,189,248,0.15); }

.info-item h4 {
  font-size: 13px; font-weight: 800; margin-bottom: 6px; color: var(--text-main);
}
.info-item p {
  font-size: 12px; color: var(--text-muted); line-height: 1.7;
}

/* ══════════════════ CANVAS ZONE GLOW BORDERS ══════════════════ */
/* Pulsing border that shows the active river action zone */
.canvas-area {
  transition: box-shadow .5s ease;
}

@keyframes erosion-pulse {
  0%, 100% { box-shadow: inset 0 0 0 3px rgba(239,68,68,0.35),
                          0 0 40px rgba(239,68,68,0.12); }
  50%       { box-shadow: inset 0 0 0 3px rgba(239,68,68,0.80),
                          0 0 70px rgba(239,68,68,0.30); }
}
@keyframes transport-glow {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(167,139,250,0.20); }
  50%       { box-shadow: inset 0 0 0 2px rgba(167,139,250,0.45); }
}
@keyframes deposition-glow {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(52,211,153,0.20); }
  50%       { box-shadow: inset 0 0 0 2px rgba(52,211,153,0.40); }
}

.zone-erosion-canvas    { animation: erosion-pulse   1.2s ease-in-out infinite; }
.zone-transport-canvas  { animation: transport-glow  2.5s ease-in-out infinite; }
.zone-deposition-canvas { animation: deposition-glow 3.0s ease-in-out infinite; }

/* ══════════════════ SCROLLBARS ══════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(99,179,255,0.2); border-radius: 2px;
}

/* ══════════════════════════════════════════════════
   RESPONSIVE LAYOUT
   ─ Desktop  ( > 1100px )  : 3-column grid (current)
   ─ Tablet L ( 901-1100px ): narrower panels
   ─ Tablet P ( ≤ 900px )  : full-width canvas + slide-in drawers
   ─ Mobile   ( ≤ 480px )  : compact energy bar + bottom drawers
══════════════════════════════════════════════════ */

/* ── Tablet Landscape  ─────────────────────────── */
@media (max-width: 1100px) {
  .game-layout {
    grid-template-columns: 215px 1fr 215px;
  }
  .ph-title      { font-size: 15px; }
  .ph-sub        { font-size: 11px; }
  .factor-card   { padding: 8px 10px; gap: 7px; }
  .fc-name       { font-size: 13px; }
  .fc-rule       { font-size: 10.5px; }
  .fc-labels     { font-size: 10.5px; }
  .slider        { height: 5px; }
  .ar-label      { font-size: 11.5px; }
  .energy-formula{ gap: 10px; }
  .fd-val        { font-size: 22px; }
  .energy-fd .fd-val { font-size: 26px; }
  .fd-label      { font-size: 11px; }
  .fd-op         { font-size: 21px; }
  .energy-zone   { font-size: 13px; }
  .top-btn       { font-size: 12px; padding: 5px 9px; }
  .mission-btn   { font-size: 12px; }
  .status-bar    { font-size: 13px; }
}

/* ── Tablet Portrait (panels become slide-in drawers) ── */
@media (max-width: 900px) {

  /* Energy bar: 2 rows on narrow screens */
  .energy-bar {
    height: auto;
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 6px;
    row-gap: 4px;
  }
  .energy-formula     { order: 1; flex: 1 1 100%; justify-content: center; }
  .top-right-btns     { order: 2; flex: 0 0 auto; }
  .energy-zone-wrap   { order: 3; flex: 1 1 100%; justify-content: center; }

  /* Action bars row: hide on tablet to save space, kept in panel only */
  .action-bars-section { display: none; }

  /* Game layout: single-column so canvas fills the row */
  .game-layout {
    grid-template-columns: 1fr;
    position: relative;        /* anchor for absolute drawers */
    overflow: visible;         /* let drawers overflow */
  }

  /* ── Side panels become absolute slide-in drawers ── */
  .side-panel {
    position: absolute;
    top: 0; bottom: 0;
    width: min(295px, 85vw);
    z-index: 30;
    border-radius: 0;
    overflow-y: auto;
    transition: transform 0.32s cubic-bezier(0.25, 0.8, 0.25, 1),
                box-shadow 0.32s ease;
  }
  .left-panel {
    left: 0;
    transform: translateX(-102%);
    box-shadow: none;
    border-right: 1px solid var(--border);
    border-radius: 0 var(--radius) var(--radius) 0;
  }
  .right-panel {
    right: 0;
    transform: translateX(102%);
    box-shadow: none;
    border-left: 1px solid var(--border);
    border-radius: var(--radius) 0 0 var(--radius);
  }
  .left-panel.panel-open  { transform: translateX(0); box-shadow: 6px 0 30px rgba(0,0,0,0.6); }
  .right-panel.panel-open { transform: translateX(0); box-shadow: -6px 0 30px rgba(0,0,0,0.6); }

  /* Canvas fills the full column width */
  .canvas-area {
    min-height: 55vh;
    grid-column: 1;
  }

  /* Mobile toggle buttons: visible on tablet/mobile */
  .mobile-panel-toggles {
    display: flex !important;     /* override the default none from below */
  }

  /* Scrim overlay when a panel is open */
  .panel-scrim {
    display: block;
  }

  /* Intro adjustments */
  .intro-content { padding: 28px 22px; max-width: 95vw; }
  .game-title    { font-size: clamp(22px, 6vw, 44px); }
  .game-subtitle { font-size: clamp(11px, 3vw, 16px); }
  .intro-formula { gap: 10px; flex-wrap: wrap; justify-content: center; }
  .zone-preview  { flex-direction: row; flex-wrap: wrap; gap: 6px; justify-content: center; }
  .zone-item     { font-size: 12px; padding: 5px 10px; }
  .intro-buttons { flex-direction: column; align-items: stretch; }
  .intro-btn     { text-align: center; }
}

/* ── Mobile Portrait ( ≤ 480px ) ─────────────────── */
@media (max-width: 480px) {

  html, body { overflow: hidden; }

  /* Even more compact energy bar */
  .energy-bar      { padding: 5px 8px; gap: 4px; }
  .fd-val          { font-size: 18px; }
  .fd-label        { font-size: 9px; }
  .fd-op           { font-size: 16px; }
  .energy-zone     { font-size: 11px; padding: 3px 8px; }
  .top-btn         { font-size: 10px; padding: 4px 7px; }
  .top-btn span    { display: none; }   /* icon only on tiny screens */

  /* Canvas: use remaining height after bar */
  .canvas-area { min-height: 52vh; }

  /* Wider drawers on phones */
  .side-panel { width: min(310px, 92vw); }

  /* Factor cards: 2-column grid inside drawer */
  .factors     { gap: 5px; }
  .factor-card { padding: 7px 8px; gap: 6px; }
  .fc-name     { font-size: 11px; }
  .fc-rule     { font-size: 9.5px; }
  .fc-val      { font-size: 13px; min-width: 18px; }

  /* Status bar smaller */
  .status-bar  { font-size: 11px; padding: 5px 10px; }
  .cam-hint    { font-size: 9px; }

  /* Mission panel: hide inside drawer, use intro only */
  .mission-panel { display: none; }

  /* Intro page */
  .intro-content { padding: 20px 16px; }
  .game-title    { font-size: clamp(20px, 7vw, 36px); }
  .energy-formula-intro { gap: 8px; }
}

/* ── Mobile panel toggle buttons (base style hidden on desktop) ── */
.mobile-panel-toggles {
  display: none;    /* hidden by default; overridden above at ≤900px */
  position: absolute;
  bottom: 52px;     /* above status bar */
  left: 50%;
  transform: translateX(-50%);
  gap: 8px;
  z-index: 20;
  pointer-events: auto;
}

.mpt-btn {
  background: rgba(10, 22, 50, 0.88);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-family: 'Noto Sans TC', sans-serif;
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  white-space: nowrap;
}
.mpt-btn:hover { background: rgba(30,60,120,0.9); border-color: rgba(99,179,255,0.4); }
.mpt-btn:active { transform: scale(0.95); }
.mpt-btn.active {
  background: rgba(56,189,248,0.18);
  border-color: var(--discharge);
  color: var(--discharge);
}

/* ── Panel scrim (dark overlay behind open drawer) ── */
.panel-scrim {
  display: none;    /* shown via JS class toggle */
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 29;
  cursor: pointer;
}

