/* Fling Wing — UI styles. Touch-friendly, responsive, accessible. */

:root {
  --sky-1: #7ec8ff;
  --sky-2: #cfeaff;
  --gold: #ffd34d;
  --gold-dark: #c98c1c;
  --green: #58c66a;
  --ink: #18324a;
  --ink-soft: #2c4a6a;
  --paper: #fdfaf2;
  --paper-soft: #f3ecd9;
  --danger: #d8584b;
  --shadow: 0 4px 0 rgba(0,0,0,0.18);
  --rad: 16px;
  --tap: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky-1);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  display: block;
  /* respect iOS safe areas */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- Canvas ---------- */
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: linear-gradient(to bottom, var(--sky-1) 0%, var(--sky-2) 60%, #f7f1d6 100%);
}

/* ---------- Generic screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
  text-align: center;
  pointer-events: auto;
}
.screen.overlay {
  background: transparent;
  pointer-events: none;       /* let drags pass through to canvas */
}
.screen.overlay > * { pointer-events: auto; }   /* but child controls (help text, back button) still tap-able */
.screen:not(.overlay) {
  background: linear-gradient(to bottom, rgba(126,200,255,0.92), rgba(207,234,255,0.92));
  backdrop-filter: blur(2px);
}
.hidden { display: none !important; }

.title {
  font-size: clamp(40px, 9vw, 72px);
  margin: 0;
  letter-spacing: 0.5px;
  color: var(--ink);
  text-shadow: 0 3px 0 rgba(255,255,255,0.6);
}
.subtitle {
  font-size: clamp(15px, 3.6vw, 18px);
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.4;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 90%);
  margin-top: 8px;
}

/* Title-screen hero strip — sky panel with the in-game plane sprite,
   a couple of drifting clouds and a floating coin/star. Decorative only. */
.hero {
  position: relative;
  width: min(360px, 92%);
  height: clamp(140px, 26vw, 180px);
  border-radius: 18px;
  background: linear-gradient(to bottom, #b9e4ff 0%, #e7f4ff 70%, #fff7cf 100%);
  box-shadow: 0 6px 0 rgba(0,0,0,0.10), inset 0 -2px 0 rgba(255,255,255,0.6);
  overflow: hidden;
  margin: 4px 0 2px;
}
.hero-plane {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78%;
  max-width: 280px;
  transform: translate(-50%, -50%) rotate(-8deg);
  filter: drop-shadow(0 6px 4px rgba(0,0,0,0.18));
  animation: hero-bob 3.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes hero-bob {
  0%, 100% { transform: translate(-50%, -52%) rotate(-8deg); }
  50%      { transform: translate(-50%, -48%) rotate(-6deg); }
}
.hero-cloud {
  position: absolute;
  background: rgba(255,255,255,0.85);
  border-radius: 50%;
  box-shadow:
    18px 4px 0 -2px rgba(255,255,255,0.85),
    -18px 4px 0 -2px rgba(255,255,255,0.85),
    32px 0 0 -8px rgba(255,255,255,0.85),
    -32px 0 0 -8px rgba(255,255,255,0.85);
  animation: hero-cloud-drift 14s linear infinite;
}
.hero-cloud-a { top: 14%; left: -10%; width: 36px; height: 18px; animation-duration: 16s; }
.hero-cloud-b { top: 56%; left: -10%; width: 28px; height: 14px; animation-duration: 11s; animation-delay: -3s; opacity: 0.9; }
.hero-cloud-c { top: 30%; left: -10%; width: 44px; height: 22px; animation-duration: 20s; animation-delay: -8s; opacity: 0.95; }
@keyframes hero-cloud-drift {
  from { transform: translateX(0); }
  to   { transform: translateX(440px); }
}
.hero-coin {
  position: absolute;
  font-size: 22px;
  filter: drop-shadow(0 2px 0 rgba(0,0,0,0.15));
  animation: hero-coin-bob 2.4s ease-in-out infinite;
  pointer-events: none;
}
.hero-coin-a { top: 22%; right: 12%; animation-delay: -0.4s; }
.hero-coin-b { top: 64%; left: 14%; font-size: 20px; animation-delay: -1.2s; }
@media (prefers-reduced-motion: reduce) {
  .hero-plane, .hero-cloud, .hero-coin { animation: none; }
}
@keyframes hero-coin-bob {
  0%, 100% { transform: translateY(0)   rotate(-6deg); }
  50%      { transform: translateY(-6px) rotate(6deg); }
}

.btn {
  min-height: var(--tap);
  padding: 0 22px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: var(--rad);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.btn-primary { background: var(--gold); color: #4a2a00; }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: none; }
.btn-ghost:active { background: rgba(255,255,255,0.3); }
.btn-danger { background: var(--danger); color: white; }

.hint {
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 12px;
}

.coin-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(255,255,255,0.6);
  border-radius: 999px;
  font-weight: 700;
}
.coin-pill::before {
  content: "";
  width: 14px; height: 14px;
  background: radial-gradient(circle at 35% 35%, #fff7c2 0%, var(--gold) 50%, var(--gold-dark) 100%);
  border-radius: 50%;
}

/* ---------- Aim screen ---------- */
.aim-help {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.7);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--ink);
}

.icon-btn {
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.7);
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.icon-btn.corner {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}
.hud .icon-btn { pointer-events: auto; width: 44px; height: 44px; font-size: 16px; }
.hud-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.chip {
  background: rgba(255,255,255,0.75);
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  min-width: 60px;
  text-align: center;
}
.chip-coin::before {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  margin-right: 6px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff7c2 0%, var(--gold) 50%, var(--gold-dark) 100%);
  vertical-align: -2px;
}
.meter {
  flex: 1;
  height: 14px;
  background: rgba(255,255,255,0.6);
  border-radius: 7px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(to right, #4ad1ff, #1a89c9);
  transition: width 0.1s linear;
}
.hud-pb {
  align-self: flex-start;
  font-size: 12px;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.55);
  padding: 4px 10px;
  border-radius: 999px;
}

/* ---------- Results ---------- */
#screen-results h2 {
  font-size: clamp(28px, 6vw, 40px);
  margin: 0;
}
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: min(360px, 90%);
  background: rgba(255,255,255,0.65);
  padding: 16px;
  border-radius: var(--rad);
}
.result-grid > div {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.result-label {
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.result-value {
  font-size: 22px;
  font-weight: 800;
}

/* ---------- Upgrades ---------- */
.screen-header {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 0; right: 0;
  display: grid;
  grid-template-columns: var(--tap) 1fr auto;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
}
.screen-header h2 {
  margin: 0;
  font-size: clamp(20px, 5vw, 28px);
  text-align: center;
}
.upgrade-grid {
  width: min(680px, 100%);
  margin-top: 88px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  overflow-y: auto;
  max-height: calc(100% - 100px);
  padding: 4px 12px 16px;
  scrollbar-width: thin;
}
@media (min-width: 540px) {
  .upgrade-grid { grid-template-columns: 1fr 1fr; }
}
.up-card {
  background: var(--paper);
  border-radius: var(--rad);
  padding: 14px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  box-shadow: var(--shadow);
}
.up-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--paper-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.up-meta { text-align: left; }
.up-name { font-weight: 800; font-size: 16px; }
.up-desc { font-size: 12px; color: var(--ink-soft); }
.up-bars {
  display: flex; gap: 3px; margin-top: 6px;
}
.up-bar {
  width: 18px; height: 6px; border-radius: 3px;
  background: var(--paper-soft);
}
.up-bar.on { background: var(--gold); }
.up-buy {
  min-height: 48px;
  border: none;
  border-radius: 12px;
  padding: 0 14px;
  background: var(--gold);
  color: #4a2a00;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.up-buy:disabled {
  background: var(--paper-soft);
  color: var(--ink-soft);
  box-shadow: none;
  cursor: not-allowed;
}
.up-buy:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.up-buy.maxed { background: var(--green); color: white; }

/* ---------- Evolution screen ---------- */
#screen-evolution h2 {
  font-size: clamp(28px, 6vw, 44px);
  margin: 0;
}
.evo-stage {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-soft);
}
#evo-canvas {
  width: min(320px, 80%);
  height: auto;
  background: rgba(255,255,255,0.5);
  border-radius: var(--rad);
}

/* ---------- Settings ---------- */
.settings-list {
  width: min(420px, 92%);
  background: rgba(255,255,255,0.65);
  padding: 12px;
  border-radius: var(--rad);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 88px;
}
.settings-list .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--paper);
  border-radius: 12px;
  font-weight: 600;
  gap: 12px;
}
.settings-list .row input[type="range"] { width: 50%; }
.settings-list .row input[type="checkbox"] { width: 26px; height: 26px; }
.footnote {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  margin: 8px 0 0;
}

/* ---------- Help screen ---------- */
.help-list {
  width: min(720px, 94%);
  margin-top: 88px;
  max-height: calc(100% - 110px);
  overflow-y: auto;
  display: grid;
  gap: 12px;
  padding: 0 12px 24px;
  text-align: left;
}
@media (min-width: 720px) {
  .help-list { grid-template-columns: 1fr 1fr; }
  .help-list > section.help-block:nth-child(1),
  .help-list > section.help-block:nth-child(2) { grid-column: 1 / -1; }
}
.help-block {
  background: var(--paper);
  border-radius: var(--rad);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.help-block h3 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--ink);
}
.help-block ul {
  margin: 4px 0;
  padding-left: 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
}
.help-block ul li { margin: 3px 0; }
.help-block .muted { color: var(--ink-soft); font-weight: 500; font-size: 12px; }
.help-block kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--paper-soft);
  border: 1px solid #c7bfa6;
  box-shadow: 0 1px 0 #c7bfa6;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: #2c4a6a;
}

/* ---------- Pickup counters row (current / personal best per type) ---------- */
.pickup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-soft);
  pointer-events: none;
}
.pickup {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 3px 8px;
  background: rgba(255,255,255,0.55);
  border-radius: 999px;
  letter-spacing: 0.4px;
  transition: transform 0.18s ease, background 0.18s ease;
}
.pickup .pc-cur { color: var(--ink); }
.pickup .pc-best {
  font-size: 10px;
  color: rgba(40,55,80,0.6);
  font-weight: 700;
  margin-left: 2px;
}
.pickup .pc-best::before { content: " / "; color: rgba(40,55,80,0.4); }
.pickup.empty { opacity: 0.55; }
.pickup.record {                 /* current run beats previous best */
  background: rgba(255,224,160,0.95);
  color: #6a3a00;
  transform: scale(1.05);
  box-shadow: 0 0 0 2px rgba(255,180,60,0.55);
}

/* ---------- Active effects strip (above fuel gauge) ---------- */
.effects {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 22px;
  pointer-events: none;
}
.effect-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 8px;
  background: rgba(255,255,255,0.78);
  color: var(--ink);
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.4px;
  position: relative;
  overflow: hidden;
  transition: opacity 0.30s ease, transform 0.20s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.10);
}
.effect-chip.expired { transform: scale(0.92); }
.effect-chip .effect-icon { font-size: 13px; line-height: 1; }
.effect-chip .effect-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px;
  background: currentColor;
  opacity: 0.45;
  transition: width 0.05s linear;
}
.effect-chip.shield  { color: #5b3a8a; box-shadow: 0 0 0 2px rgba(164,127,255,0.55), 0 2px 4px rgba(0,0,0,0.10); }
.effect-chip.fuel    { color: #2c6a32; }
.effect-chip.boost   { color: #11567a; }
.effect-chip.stall   { color: #8a1818; background: rgba(255,200,200,0.82); }
.effect-chip.slowed  { color: #555; }
.effect-chip.slipstream { color: #9c2779; }
.effect-chip.evolved { color: #9c5a00; background: rgba(255,224,160,0.92); }

/* ---------- Combo display ---------- */
.combo {
  position: absolute;
  top: max(58px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(255,255,255,0.45);
  transition: opacity 0.15s linear;
}
.combo.hidden { opacity: 0; }
.combo-mult {
  font-size: clamp(20px, 5vw, 30px);
  color: #ff7a3a;
  letter-spacing: 1px;
  filter: drop-shadow(0 2px 0 rgba(0,0,0,0.18));
}
.combo-mult.tier-2 { color: #ff5e2a; }
.combo-mult.tier-3 { color: #ff3a90; }
.combo-mult.tier-4 { color: #b35ad1; }
.combo-mult.tier-5 { color: #5a86ff; }
.combo-mult.tier-6 { color: #ffd34d; text-shadow: 0 0 10px rgba(255,211,77,0.7); }
.combo-mult.tier-7 { color: #fff281; text-shadow: 0 0 14px rgba(255,242,129,0.9); }
.combo-bar {
  width: 100px; height: 5px;
  background: rgba(0,0,0,0.18);
  border-radius: 3px;
  overflow: hidden;
}
.combo-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(to right, #ff7a3a, #ffd34d);
  transition: width 0.05s linear;
}

/* ---------- Difficulty chip in top HUD row ---------- */
.chip-diff {
  background: rgba(40,55,80,0.80);
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  min-width: 56px;
}

/* ---------- Difficulty toggle on title ---------- */
.diff-toggle {
  display: inline-flex;
  background: rgba(255,255,255,0.55);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
  margin-top: 4px;
}
.diff-pill {
  border: none;
  background: transparent;
  font-weight: 800;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-soft);
  letter-spacing: 0.4px;
}
.diff-pill[aria-pressed="true"] {
  background: var(--ink);
  color: white;
}
.diff-pill.diff-locked { opacity: 0.45; cursor: not-allowed; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .meter-fill { transition: none; }
  .btn { transition: none; }
}
body.reduced-motion .btn,
body.reduced-motion .meter-fill { transition: none; }
