/**
 * Polar Express Quest Styles
 * Painterly winter aesthetic, animated transit loader, responsive 320/390px.
 */

.polar-quest-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.polar-stage-viewport {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: polarFadeIn 0.4s ease-out;
}

@keyframes polarFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.polar-stage-card-box {
  width: 100%;
  background: linear-gradient(180deg, #102a43 0%, #061320 100%);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(6, 19, 32, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border: 2px solid #243b53;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.polar-hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 14px;
}

.polar-hud-round {
  background: rgba(246, 185, 59, 0.2);
  color: #f6b93b;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 700;
  border: 1px solid rgba(246, 185, 59, 0.4);
}

.polar-hud-goal {
  color: #dff9fb;
  font-weight: 600;
}

.polar-canvas-wrap {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1 / 1;
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.6);
  touch-action: none;
}

.polar-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.polar-help-text {
  margin: 12px 0 4px;
  color: #c7d2fe;
  font-size: 14px;
  text-align: center;
  line-height: 1.4;
}

.polar-bellows-controls,
.polar-firework-btn-wrap {
  margin-top: 14px;
  width: 100%;
  display: flex;
  justify-content: center;
}

.polar-bellows-btn,
.polar-launch-btn {
  width: 100%;
  max-width: 320px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #f6b93b 0%, #e58e26 100%);
  color: #0c2461;
  border: none;
  border-radius: 14px;
  box-shadow: 0 4px 15px rgba(246, 185, 59, 0.4);
  cursor: pointer;
}

/* --- ANIMATED TRANSIT LOADER --- */
.polar-transit-loader {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: radial-gradient(circle at top, #1b3a4b 0%, #061320 85%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 20px;
  padding: 24px 16px;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.polar-transit-loader.active {
  opacity: 1;
}

.polar-transit-loader.fade-out {
  opacity: 0;
}

.polar-loader-backdrop {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.polar-loader-aurora {
  position: absolute;
  top: -20px;
  width: 100%;
  height: 60px;
  background: radial-gradient(ellipse at 50% 0%, rgba(46, 213, 115, 0.35) 0%, transparent 70%);
  filter: blur(14px);
  pointer-events: none;
}

.polar-train-scene {
  position: relative;
  width: 180px;
  height: 100px;
  margin-bottom: 20px;
}

.polar-train-steam-box {
  position: absolute;
  top: 6px;
  right: 36px;
  width: 60px;
  height: 40px;
  pointer-events: none;
}

.steam-puff {
  position: absolute;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  animation: puffRise 1.4s infinite ease-out;
}

.puff-1 { width: 14px; height: 14px; left: 10px; animation-delay: 0s; }
.puff-2 { width: 18px; height: 18px; left: 24px; animation-delay: 0.4s; }
.puff-3 { width: 22px; height: 22px; left: 40px; animation-delay: 0.8s; }

@keyframes puffRise {
  0% { transform: scale(0.4) translateY(10px); opacity: 0.8; }
  100% { transform: scale(2.2) translateY(-30px); opacity: 0; }
}

.polar-headlight-beam {
  position: absolute;
  right: -70px;
  top: 42px;
  width: 90px;
  height: 35px;
  background: linear-gradient(90deg, rgba(255, 234, 167, 0.8) 0%, transparent 100%);
  clip-path: polygon(0% 40%, 100% 0%, 100% 100%, 0% 60%);
  pointer-events: none;
}

.polar-loco-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}

.polar-loader-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.polar-loader-badge {
  font-size: 11px;
  letter-spacing: 1.5px;
  color: #f6b93b;
  font-weight: 800;
  margin-bottom: 6px;
}

.polar-loader-title {
  margin: 0 0 8px;
  font-size: 20px;
  color: #ffffff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.polar-loader-hint {
  margin: 0 0 16px;
  font-size: 14px;
  color: #dff9fb;
  max-width: 280px;
  line-height: 1.35;
}

.polar-progress-track {
  width: 200px;
  height: 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.polar-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f6b93b, #2ed573);
  border-radius: 4px;
  animation: progressFill 1.2s forwards ease-in-out;
}

@keyframes progressFill {
  0% { width: 0%; }
  100% { width: 100%; }
}

/* DEV Mode Dialog and Episode Cards */
.polar-episodes-dialog {
  max-width: 440px;
}

.polar-card-icon {
  font-size: 26px;
  margin-right: 12px;
}

.polar-dev-banner {
  background: #1e3799;
  color: #ffeaa7;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #f6b93b;
}

.polar-dev-jump-btn {
  background: #f6b93b;
  color: #0c2461;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
}

/* Logical scene ratio is preserved on Retina and narrow phones. */
.polar-quest-wrapper { min-height: 390px; max-width: 540px; }
.polar-stage-card-box { padding: 10px; }
.polar-canvas-wrap { max-width: 480px; aspect-ratio: 360 / 400; }
.polar-hud { flex-wrap: wrap; gap: 7px; line-height: 1.35; }
.polar-hud-round { white-space: nowrap; }
.polar-hud-goal { flex: 1 1 140px; text-align: right; }
.polar-help-text { min-height: 2.8em; font-size: 15px; }
.polar-repeat { min-height: 44px; padding: 8px 20px; border-radius: 14px; background: #f5dc98; color: #183d40; font: inherit; font-weight: 700; border: 0; }
@media (prefers-reduced-motion: reduce) { .polar-stage-viewport { animation: none; } }
.polar-sensor { min-height: 48px; margin: 6px 0; padding: 10px 20px; background: #f5dc98; color: #183d40; border: 0; border-radius: 14px; font: inherit; font-weight: 700; }
.polar-pressure { width: 100%; height: 10px; margin: 0 0 4px; }
.polar-painted-train { display: block; width: 160px; height: 100px; background: url('assets/polar-props.webp') 0 100% / 400% 200% no-repeat; }
.game-card:has(.polar-quest-wrapper) > .instruction,
.game-card:has(.polar-quest-wrapper) > .game-note { display: none; }
/* Fit the fixed quest viewport: never clip microphone/tilt controls below the board. */
.quest-app .game-board:has(.polar-quest-wrapper) { padding: 0; gap: 0; }
.quest-app .polar-quest-wrapper { height: 100%; min-height: 0; flex-shrink: 0; }
.quest-app .polar-stage-card-box { height: 100%; min-height: 0; }
.quest-app .polar-hud, .quest-app .polar-help-text, .quest-app .polar-sensor,
.quest-app .polar-repeat, .quest-app .polar-pressure { flex-shrink: 0; }
.quest-app .polar-canvas-wrap { flex: 1 1 0; min-height: 0; aspect-ratio: auto; max-width: none; container-type: size; display: grid; place-items: center; box-shadow: none; }
.quest-app .polar-canvas { width: min(100cqw,90cqh); height: min(100cqh,111.111cqw); border-radius: 14px; }
.quest-app .polar-help-text { margin: 7px 0 4px; font-size: 13px; }

/* Pressure is painted into the boiler scene; keep the accessible value without a duplicate bar. */
.polar-pressure { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); margin:0; }

/* Use only the height the painting and controls need, without letterbox bands. */
.quest-app .polar-stage-card-box { height: auto; max-height: 100%; }
.quest-app .polar-canvas-wrap { flex: 0 1 auto; height: min(480px,calc((100vw - 64px)*1.111111)); }
.quest-app .game-card:has(.polar-quest-wrapper) { background: transparent; border-color: transparent; box-shadow: none; }

/* Reuse the shared pre-stage task card with Polar's painted cover. */
.polar-briefing .aurora-brief-art{background-image:url('assets/polarexpress.webp');background-position:center 35%}

/* Garland: reserve a solid high-contrast instruction strip outside the painting. */
.quest-app .polar-garland-card {padding:7px;gap:4px;}
.quest-app .polar-garland-card .polar-hud {margin-bottom:3px;}
.quest-app .polar-garland-card .polar-help-text {width:100%;box-sizing:border-box;background:#fff3d7;color:#173e49;border:1px solid #edcf8b;border-radius:12px;font-size:15px;font-weight:700;line-height:1.4;text-align:left;padding:10px 12px;margin:3px 0 0;min-height:0;}
.quest-app .polar-garland-card .polar-canvas-wrap {height:min(520px,calc((100vw - 48px)*1.111111));}

.quest-app .polar-garland-card .polar-help-text {height:86px;min-height:86px;display:flex;align-items:center;overflow:auto;}
/* Polar Express illustrated map and DEV stage picker. */
.map-view.polarexpress{display:grid;grid-template-rows:auto minmax(0,1fr) auto;background:#132e47;color:#fff5de}.map-view.polarexpress:has(.wind-map-tools button){grid-template-rows:auto auto minmax(0,1fr) auto}.map-view.polarexpress .map-top{position:relative;min-width:0;padding:max(12px,env(safe-area-inset-top)) 12px 8px;background:#18364af5;gap:7px}.map-view.polarexpress .map-top>div:first-child{min-width:0;flex:1}.map-view.polarexpress .map-top h2{font-size:clamp(15px,4vw,20px);color:#fff3d0}.map-view.polarexpress .map-top .eyebrow,.map-view.polarexpress .map-top .narration-tools{display:none}.map-view.polarexpress .map-top .menu-exit{white-space:nowrap;min-height:44px}.map-view.polarexpress .wind-map-tools{position:relative;padding:5px 12px 8px;background:#18364af5}.map-view.polarexpress .wind-map-tools:empty{display:none}.map-view.polarexpress .wind-map-tools .wind-button{width:auto;min-height:44px;border:1px solid #f4c873;background:#fff3d2;color:#173b4b;border-radius:13px;padding:8px 14px;font-weight:900}.map-view.polarexpress .map-scroll{height:100%;min-height:0;position:relative;padding:20px 0;overflow:auto}.map-view.polarexpress .map-inner{width:min(calc(100% - 20px),560px);aspect-ratio:2/3;background-size:100% 100%;border-radius:18px;overflow:visible}.map-view.polarexpress .map-svg,.map-view.polarexpress .map-decoration{display:none}.map-view.polarexpress .map-node{width:36px;height:36px}.map-view.polarexpress .map-node .island{width:36px;height:36px;border-width:2px;font-size:16px}.map-view.polarexpress .map-node p{position:absolute;top:50%;width:max-content;max-width:min(118px,30vw);margin:0;padding:4px 6px;transform:translateY(-50%);font-size:clamp(9px,2.6vw,11px);line-height:1.1;white-space:normal;overflow-wrap:normal;word-break:normal;hyphens:none;background:#fff7e9ed;color:#183b47;border:1px solid #e6bd79;border-radius:8px;box-shadow:0 2px 6px #10283855}.map-view.polarexpress .map-node-1 p,.map-view.polarexpress .map-node-2 p,.map-view.polarexpress .map-node-4 p,.map-view.polarexpress .map-node-6 p,.map-view.polarexpress .map-node-8 p{right:calc(50% + 22px)}.map-view.polarexpress .map-node-3 p,.map-view.polarexpress .map-node-5 p,.map-view.polarexpress .map-node-7 p{left:calc(50% + 22px)}.map-view.polarexpress .map-boat{font-size:22px;width:30px;height:30px}.map-view.polarexpress .map-bottom{position:relative;padding:8px 12px calc(8px + env(safe-area-inset-bottom));background:#18364af5;gap:8px}.map-view.polarexpress .map-bottom .mascot{display:none}.map-view.polarexpress .map-bottom p{min-width:0;flex:1;font-size:11px;line-height:1.2;color:#fff1d7}.map-view.polarexpress .map-bottom .btn{min-height:44px;padding:9px 13px;font-size:12px;white-space:nowrap}.polar-briefing .aurora-brief-art{background-image:url('assets/polarexpress-cover-v2.webp')}
