:root {
  color-scheme: dark;
  --ink: #102b38;
  --ink-soft: #1d4451;
  --sky: #78d6dc;
  --cream: #fff5d8;
  --orange: #f2673a;
  --orange-hot: #ff9b42;
  --moss: #79b83f;
  --gold: #ffd166;
  --glass: #334744;
  --line: rgb(255 243 208 / 26%);
  --shadow: 0 3px 0 #243331, inset 0 1px 0 rgb(255 246 212 / 22%);
  font-family: "Avenir Next", Avenir, "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  touch-action: none;
}

button,
select { font: inherit; }

button:focus-visible,
select:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

#game-shell,
#viewport {
  position: fixed;
  inset: 0;
}

#viewport { cursor: grab; }
#viewport.is-aiming { cursor: grabbing; }
#viewport canvas { display: block; width: 100%; height: 100%; }

#viewport::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: rgb(255 240 186 / 0%);
  mix-blend-mode: screen;
}

#viewport.impact-pop::after { animation: impact-pop 150ms ease-out both; }
@keyframes impact-pop {
  0% { background: rgb(255 240 186 / 22%); }
  36% { background: rgb(255 240 186 / 8%); }
  100% { background: rgb(255 240 186 / 0%); }
}

.poster-copy, .scout-card { display: none; }
@media (max-aspect-ratio: 3/4) and (min-height: 690px) {
  .scout-card {
    display: block; position: fixed; z-index: 10; left: 50%; top: max(120px, 17%); margin: 0;
    width: min(80vw, 330px); overflow: hidden; transform: translateX(-50%); pointer-events: none;
    border: 2px solid #3a4b40; border-radius: 14px; background: #fff0c8; box-shadow: 0 3px #31413a;
    visibility: hidden;
  }
  .scout-card.is-ready { visibility: visible; }
  .scout-card canvas { display: block; width: 100%; aspect-ratio: 2.55; }
  .scout-card figcaption { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px; color: #3c4536; font-size: 11px; }
  .scout-card figcaption span { letter-spacing: .14em; }
  body.poster-mode .scout-card { display: none; }
}

body.poster-mode .hud,
body.poster-mode .bird-rack,
body.poster-mode .ability-card,
body.poster-mode .aim-hint,
body.poster-mode .toast,
body.poster-mode .modal-backdrop { display: none !important; }

body.poster-mode .poster-copy {
  position: fixed;
  z-index: 30;
  top: 72px;
  left: 84px;
  display: block;
  color: var(--cream);
  filter: drop-shadow(0 8px 22px rgb(11 37 48 / 28%));
  pointer-events: none;
}

body.poster-mode .poster-copy span {
  display: block;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .2em;
  text-transform: uppercase;
}

body.poster-mode .poster-copy h2 {
  margin: 8px 0 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: 104px;
  line-height: .88;
  letter-spacing: -.04em;
  transform: skew(-5deg);
}

body.poster-mode .poster-copy p {
  margin: 20px 0 0;
  color: var(--ink);
  font-size: 27px;
  font-weight: 900;
  letter-spacing: .08em;
}

.hud {
  position: fixed;
  z-index: 20;
  top: max(16px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto minmax(170px, 1fr);
  align-items: start;
  gap: 18px;
  pointer-events: none;
}

.brand-panel {
  justify-self: start;
  color: var(--cream);
  filter: drop-shadow(0 2px 0 #354642);
  text-shadow: -1px -1px 0 #354642, 1px -1px 0 #354642, -1px 1px 0 #354642, 1px 1px 0 #354642;
}

.eyebrow,
.modal-kicker,
.rack-label,
.stat-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 10px;
  font-weight: 800;
}

.brand-panel h1 {
  margin: 1px 0 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(30px, 3.5vw, 46px);
  font-weight: 900;
  letter-spacing: -.035em;
  line-height: .9;
  text-transform: uppercase;
  transform: skew(-5deg);
}

.stat-cluster,
.hud-actions,
.bird-rack,
.ability-card {
  border: 2px solid #2d3e39;
  background: var(--glass);
  box-shadow: var(--shadow);
}

.stat-cluster {
  justify-self: center;
  display: flex;
  border-radius: 18px;
  overflow: hidden;
}

.stat {
  min-width: 98px;
  padding: 9px 16px 8px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.stat:last-child { border-right: 0; }
.stat-label { color: rgb(255 245 216 / 60%); }
.stat strong { display: block; margin-top: 1px; color: white; font-size: 18px; font-variant-numeric: tabular-nums; }
.score-stat strong { color: var(--gold); }

.hud-actions {
  justify-self: end;
  display: flex;
  gap: 5px;
  padding: 6px;
  border-radius: 999px;
  pointer-events: auto;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--cream);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

.icon-button:hover { background: rgb(255 255 255 / 12%); transform: translateY(-1px); }
.icon-button[aria-pressed="true"] { color: var(--ink); background: var(--gold); }
.icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.bird-rack {
  position: fixed;
  z-index: 20;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  min-width: 156px;
  padding: 10px 13px 11px;
  color: var(--cream);
  border-radius: 16px;
  pointer-events: none;
}

.rack-label { color: rgb(255 245 216 / 56%); }
.bird-queue { display: flex; align-items: center; gap: 7px; min-height: 31px; margin-top: 5px; }

.bird-chip {
  position: relative;
  width: 32px;
  height: 32px;
  display: inline-flex;
  border-radius: 8px;
  transition: opacity 180ms ease, transform 180ms ease;
}

.bird-chip svg { width: 100%; height: 100%; }
.bird-chip.is-current { background: #f7cf68; outline: 1px solid #ffebb0; }
.bird-chip.is-waiting { background: rgb(255 255 255 / 11%); }
.bird-chip.is-spent { opacity: .25; transform: scale(.82); }

.ability-card {
  position: fixed;
  z-index: 20;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 238px;
  padding: 9px 11px;
  color: var(--cream);
  border-radius: 16px;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.ability-card.is-used { opacity: .70; }
.ability-card.is-armed { border-color: var(--gold); }
.ability-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--ink); background: var(--gold); border-radius: 12px; }
.ability-icon svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.ability-name { display: block; font-size: 13px; font-weight: 900; }
.ability-copy { display: block; margin-top: 1px; color: rgb(255 245 216 / 65%); font-size: 10px; }
kbd { margin-left: auto; padding: 4px 7px; color: rgb(255 245 216 / 70%); background: rgb(255 255 255 / 8%); border: 1px solid var(--line); border-radius: 6px; font: 9px "SFMono-Regular", Consolas, monospace; text-transform: uppercase; }

.aim-hint {
  position: fixed;
  z-index: 15;
  left: 50%;
  bottom: max(27px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 8px 14px;
  background: #334744;
  border-radius: 20px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--cream);
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 2px 8px rgb(0 0 0 / 45%);
  pointer-events: none;
  box-shadow: 0 2px 0 #243331;
}

.aim-hint.is-hidden { opacity: 0; }
.pull-meter { position: fixed; z-index: 40; top: 112px; left: 50%; width: 190px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--glass); color: var(--cream); transform: translateX(-50%); opacity: 0; pointer-events: none; transition: opacity 120ms ease; }
.pull-meter.is-visible { opacity: 1; }
.pull-meter-label { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; margin-bottom: 7px; }
.pull-track { height: 5px; background: rgb(255 255 255 / 18%); border-radius: 4px; overflow: hidden; }
#pull-fill { display: block; height: 100%; width: 100%; transform: scaleX(0); transform-origin: left; background: var(--gold); }
.pull-meter.is-full { border-color: var(--gold); }
@media (max-height: 500px) { .pull-meter { top: 84px; padding: 6px 12px; } }
.gesture-ring { width: 20px; height: 12px; border-left: 3px solid var(--gold); border-bottom: 3px solid var(--gold); transform: rotate(28deg) skewX(-28deg); }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  top: 22%;
  padding: 8px 14px;
  color: var(--cream);
  background: rgb(13 40 50 / 80%);
  border: 1px solid var(--line);
  border-radius: 999px;
  opacity: 0;
  transform: translate(-50%, -10px) scale(.96);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0) scale(1); }

.score-fx-layer {
  position: fixed;
  inset: 0;
  z-index: 42;
  overflow: hidden;
  pointer-events: none;
}

.score-pop {
  position: absolute;
  min-width: 72px;
  color: white;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1;
  letter-spacing: .02em;
  text-align: center;
  text-shadow: 0 3px 0 rgb(16 43 56 / 90%), 0 7px 20px rgb(16 43 56 / 38%);
  transform: translate(-50%, -50%);
  animation: score-rise 720ms cubic-bezier(.16,.78,.22,1) both;
}

.score-pop.is-target { color: #fff1a8; font-size: clamp(32px, 4vw, 52px); }
@keyframes score-rise {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(.45) rotate(-4deg); }
  20% { opacity: 1; transform: translate(-50%, -65%) scale(1.18) rotate(2deg); }
  70% { opacity: 1; transform: translate(-50%, -135%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -185%) scale(.86); }
}

.streak-badge {
  position: fixed;
  z-index: 43;
  left: 50%;
  top: 30%;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 15px;
  color: var(--cream);
  background: rgb(16 43 56 / 86%);
  border: 1px solid rgb(255 209 102 / 44%);
  border-radius: 999px;
  opacity: 0;
  transform: translate(-50%, 12px) scale(.72);
  transition: opacity 120ms ease, transform 180ms cubic-bezier(.15,.86,.25,1.35);
  pointer-events: none;
}

.streak-badge.is-visible { opacity: 1; transform: translate(-50%, 0) scale(1); }
.streak-badge span { font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.streak-badge strong { color: var(--gold); font-family: Impact, sans-serif; font-size: 27px; }

body.is-celebrating #viewport canvas { filter: saturate(1.08) brightness(1.05); }
body.is-defeated #viewport canvas { filter: saturate(.82) brightness(.92); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(31 48 42 / 40%);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease;
}
.modal-backdrop.is-visible { opacity: 1; visibility: visible; pointer-events: auto; }

.modal-card {
  width: min(620px, 100%);
  padding: clamp(24px, 5vw, 46px);
  color: var(--cream);
  max-height: 100%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  background: linear-gradient(145deg, #385249, #283935);
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 28px;
  box-shadow: 0 35px 100px rgb(0 0 0 / 42%);
  transform: translateY(16px) scale(.97);
  transition: transform 240ms cubic-bezier(.2,.8,.2,1);
}
.is-visible .modal-card { transform: translateY(0) scale(1); }
.compact-card { width: min(460px, 100%); text-align: center; }
.modal-kicker { color: var(--gold); }
.modal-card h2 { margin: 8px 0 12px; font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: clamp(34px, 7vw, 62px); line-height: .95; letter-spacing: -.025em; text-transform: uppercase; }
.modal-card p { color: rgb(255 245 216 / 72%); line-height: 1.65; }

.tutorial-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 24px 0; }
.tutorial-grid > div { position: relative; min-height: 132px; padding: 17px 14px 14px; background: rgb(255 255 255 / 6%); border: 1px solid rgb(255 255 255 / 10%); border-radius: 16px; }
.tutorial-number { position: absolute; top: 9px; right: 11px; color: rgb(255 255 255 / 12%); font-size: 36px; font-weight: 900; }
.tutorial-grid strong { position: relative; display: block; margin-top: 29px; font-size: 13px; }
.tutorial-grid small { position: relative; display: block; margin-top: 5px; color: rgb(255 245 216 / 60%); line-height: 1.5; }

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 22px;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}
.primary-button { color: var(--ink); background: linear-gradient(180deg, var(--gold), #ffad42); border: 0; box-shadow: 0 8px 24px rgb(255 177 58 / 24%); }
.secondary-button { color: var(--cream); background: rgb(255 255 255 / 7%); border: 1px solid var(--line); }
.primary-button:hover,
.secondary-button:hover { transform: translateY(-2px); filter: brightness(1.05); }
.intro-card > .primary-button { width: 100%; }
.button-row { display: flex; justify-content: center; gap: 10px; margin-top: 22px; }

.star-row { display: flex; justify-content: center; gap: 10px; min-height: 54px; margin: 18px 0; }
.star { width: 46px; height: 46px; color: rgb(255 255 255 / 12%); filter: drop-shadow(0 6px 12px rgb(0 0 0 / 20%)); }
.star.is-earned { color: var(--gold); animation: star-pop 420ms cubic-bezier(.2,.8,.2,1) both; }
.star svg { width: 100%; height: 100%; fill: currentColor; }
@keyframes star-pop { from { transform: scale(.2) rotate(-30deg); } to { transform: scale(1) rotate(0); } }

.result-card { text-align: center; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 16px; }
.result-stats > div { padding: 13px 8px; border-right: 1px solid var(--line); }
.result-stats > div:last-child { border-right: 0; }
.result-stats span { display: block; color: rgb(255 245 216 / 52%); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.result-stats strong { display: block; margin-top: 3px; font-size: 19px; font-variant-numeric: tabular-nums; }

@media (max-width: 820px) {
  .hud { grid-template-columns: 1fr auto; }
  .stat-cluster { position: fixed; top: 86px; left: 50%; transform: translateX(-50%); }
  .brand-panel h1 { font-size: 34px; }
  .ability-card { min-width: 0; }
  .ability-card kbd,
  .ability-copy { display: none; }
}

@media (max-width: 620px), (max-height: 560px) {
  .hud { top: 8px; left: 9px; right: 9px; }
  .brand-panel .eyebrow { display: none; }
  .brand-panel h1 { font-size: 26px; }
  .hud-actions { padding: 3px; }
  .icon-button { width: 36px; height: 36px; }
  .stat-cluster { top: 54px; }
  .stat { min-width: 74px; padding: 6px 8px; }
  .stat strong { font-size: 14px; }
  .stat-label { font-size: 8px; }
  .bird-rack { left: 8px; bottom: 8px; min-width: 122px; padding: 7px 9px; }
  .ability-card { right: 8px; bottom: 8px; padding: 6px 8px; }
  .ability-card > div:nth-child(2) { display: none; }
  .ability-icon { width: 34px; height: 34px; }
  .aim-hint { left: 12%; font-size: 10px; }
  .score-pop { font-size: 23px; }
  .score-pop.is-target { font-size: 31px; }
  .streak-badge { top: 25%; }
  .tutorial-grid { grid-template-columns: 1fr; max-height: 260px; overflow-y: auto; }
  .tutorial-grid > div { min-height: 82px; }
  .tutorial-grid strong { margin-top: 8px; }
  .modal-card { padding: 22px; border-radius: 20px; }
  .result-stats { grid-template-columns: 1fr 1fr; }
  .result-stats > div:last-child { grid-column: 1 / -1; border-top: 1px solid var(--line); }
}

/* The handbook reads like a printed field plate. The same die cuts label the queue. */
.intro-card {
  position: relative; isolation: isolate; text-align: center; color: #352e27;
  border: 3px solid #3f4233; border-radius: 18px; background: radial-gradient(ellipse at 50% 23%, #fff9df 10%, #faefcc 70%, #efdbab);
  box-shadow: inset 0 0 0 5px #fffae5, inset 0 0 0 6px #dbc99e, 0 7px 0 #36443b, 0 18px 52px #23342c55;
  padding: clamp(20px, 3.6vh, 36px) clamp(20px, 4vw, 46px);
}
.intro-card .modal-kicker { color: #735535; font-size: 11px; letter-spacing: .19em; }
.cover-portraits { display: flex; align-items: end; justify-content: center; margin: 10px auto 3px; }
.cover-portraits svg { width: 70px; height: 68px; transform: rotate(-9deg); filter: drop-shadow(0 3px 0 #ac8d5844); }
.cover-portraits svg:nth-child(2) { width: 96px; height: 87px; margin: 0 -6px; z-index: 1; transform: translateY(2px); }
.cover-portraits svg:last-child { transform: rotate(9deg); }
.intro-card h2 { color: #af3342; font-weight: 1000; font-size: clamp(46px, 7vw, 72px); letter-spacing: -.055em; transform: skew(-6deg); text-shadow: 0 3px #fff6db, 0 5px #794331; }
.intro-card p { color: #564935; max-width: 31em; margin: 14px auto 0; font-size: 14px; }
.intro-card .tutorial-grid { gap: 0; margin: 18px 0; border-block: 1px dashed #bda882; }
.intro-card .tutorial-grid > div { min-height: 0; padding: 14px 8px; border: 0; border-radius: 0; background: none; }
.intro-card .tutorial-number { position: static; display: inline-block; width: 19px; height: 19px; font-size: 12px; line-height: 19px; background: #445e4b; color: #fff6dc; border-radius: 50%; }
.intro-card .tutorial-grid strong { display: inline; margin-left: 5px; }
.intro-card .tutorial-grid small { color: #65563d; font-size: 12px; }
.route-choice { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; font-size: 13px; font-weight: 800; }
.route-choice[hidden] { display: none; }
.route-choice label { flex: 1; min-width: 0; display: grid; gap: 3px; text-align: left; }
.route-choice select { width: 100%; min-width: 0; min-height: 40px; padding: 4px 10px; color-scheme: light; color: #3d4937; background: #fff8dd; border: 1px solid #ad9973; border-radius: 8px; cursor: pointer; }
.mix-link { background: none; border: 0; padding: 5px 10px; color: inherit; text-decoration: underline; cursor: pointer; font-size: 13px; }
.intro-card .mix-link { margin-bottom: 8px; }
.mix-dialog { width: min(380px, 90vw); max-height: 90dvh; overflow: auto; border: 2px solid #514a33; border-radius: 18px; padding: 24px; color: #344135; background: #fff4d6; color-scheme: light; }
.mix-dialog::backdrop { background: rgb(26 42 36 / 62%); }
.mix-dialog h2 { margin: 4px 0 14px; }
.mix-dialog .modal-kicker { color: #735535; }
.mix-dialog input { accent-color: #377358; }
.mix-dialog p { font-size: 13px; }
.mix-channel { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 16px; font-weight: bold; }
.mix-channel input { grid-column: 1 / -1; width: 100%; margin: 0; height: 30px; }
.mix-dialog form { text-align: right; }
.intro-card .primary-button { border: 2px solid #674927; border-radius: 12px; box-shadow: inset 0 2px #ffe8a1, 0 3px 0 #73502e; }
@media (max-width: 620px) {
  .intro-card .tutorial-grid { grid-template-columns: 1fr; text-align: left; padding-block: 6px; }
  .intro-card .tutorial-grid > div { padding: 4px; }
  .intro-card .tutorial-grid small { display: inline; margin-left: 8px; }
  .aim-hint { left: 50%; bottom: max(88px, calc(env(safe-area-inset-bottom) + 80px)); }
  .bird-chip { width: 26px; height: 26px; }
  .bird-queue { gap: 4px; }
  .bird-rack, .ability-card { bottom: max(8px, env(safe-area-inset-bottom)); }
  .ability-card > div:nth-child(2) { display: block; }
  .ability-name { font-size: 12px; }
}
@media (max-height: 500px) and (min-width: 621px) {
  .intro-card .cover-portraits { display: none; }
  .intro-card .tutorial-grid { grid-template-columns: repeat(3,1fr); margin: 8px 0; }
  .intro-card h2 { font-size: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
