/* src/ui/styles.css
   Starwind Symphony: felt panels with stitched edges, paper cards, copper rims,
   mint buttons and a mulberry dusk. No webfonts, no images, no network.

   The sizes the screens share (--tap, --pad, --corner and the rest) are written
   onto the root by src/ui/layout.js, and the three shapes of the game (portrait,
   landscape, desktop) are chosen by the data-mode attribute the app sets.
   The named colours below are the art's palette (src/art/sprites.js), under the
   same names; tests/ui/styles.test.mjs holds the two together. */

:root {
  --dusk: #291d30;
  --dusk-soft: #352640;
  --dusk-deep: #241a2b;
  --paper: #fbf1dc;
  --ink: #2b1f33;
  --copper: #b87333;
  --mint: #a7e6ce;
  --honey: #e8c56a;
  --lilac: #dcc2f7;
  --rose: #ffa8b4;
  /* the bold-outline battle HUD: the line, the drop under a chunky piece, how far it presses, and its inks */
  --line: 3px;
  --drop: 4px;
  --press: 3px;
  --edge: #120c17;
  --spent: #d9ccb8;
  --cost: #7a4d14;
  /* a storybook serif for titles, the phone's own system font for the rest (named before the generic system-ui, which some Linux setups map to a monospace); named faces come
     before the generics so no system can fall back to a monospace */
  --display: 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', 'C059', 'Century Schoolbook', 'Georgia', 'Liberation Serif', 'Times New Roman', serif;
  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable', 'Segoe UI', Roboto, 'Adwaita Sans', 'Cantarell', 'Noto Sans', system-ui, 'Liberation Sans', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--dusk);
  color: var(--paper);
  font-family: var(--ui);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

html, body { overscroll-behavior: none; }

/* The note a browser without JavaScript sees (index.html's <noscript>). It is here, not in a style attribute, because
   the page's Content-Security-Policy takes styles only from files (tests/ui/csp.test.mjs). */
.noscript-note { padding: 24px; font: 16px/1.5 Georgia, serif; color: var(--paper); background: var(--dusk); height: 100vh; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid var(--honey); outline-offset: 3px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- the shell ---------- */

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% -20%, #3f2d4d 0%, rgba(63, 45, 77, 0) 60%),
    radial-gradient(90% 60% at 50% 120%, var(--dusk-soft) 0%, rgba(53, 38, 64, 0) 70%),
    var(--dusk);
}

.app[data-large-text='true'] { font-size: 18px; }
html[data-large-text='true'] { font-size: 18px; }

.scene-host { position: absolute; inset: 0; }

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding:
    calc(env(safe-area-inset-top) + var(--pad))
    calc(env(safe-area-inset-right) + var(--pad))
    calc(env(safe-area-inset-bottom) + var(--pad))
    calc(env(safe-area-inset-left) + var(--pad));
  overflow: hidden;
}

/* ---------- felt and paper ---------- */

.felt {
  position: relative;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .022) 0 2px, rgba(0, 0, 0, 0) 2px 5px),
    linear-gradient(160deg, var(--dusk-soft), var(--dusk));
  border-radius: var(--corner);
  box-shadow: 0 18px 44px rgba(10, 6, 14, .55);
}

.felt::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: var(--stitch) dashed rgba(184, 115, 51, .45);
  border-radius: calc(var(--corner) - 6px);
  pointer-events: none;
}

.card {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border: var(--rim) solid var(--copper);
  border-radius: var(--card-corner);
  box-shadow: 0 14px 30px rgba(8, 5, 12, .5), inset 0 0 0 1px rgba(255, 255, 255, .5);
  padding: var(--pad-wide);
}

.card__title {
  margin: 0 0 4px;
  font: normal 1.35rem/1.15 var(--display);
  letter-spacing: -.01em;
}

.card__note {
  margin: 0 0 12px;
  font-size: .95rem;
  line-height: 1.45;
  color: #4b3a55;
}

.card__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card__actions .btn { flex: 1 1 40%; }

/* ---------- buttons ---------- */

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 10px 16px;
  border-radius: 14px;
  border: var(--rim) solid rgba(184, 115, 51, .8);
  background: linear-gradient(180deg, #453357, #33263f);
  color: var(--paper);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .01em;
  transition: transform .12s ease, filter .12s ease;
}

.btn:active:not(:disabled) { transform: translateY(1px); filter: brightness(1.12); }

.btn--primary {
  background: linear-gradient(180deg, #bdf0da, var(--mint));
  color: var(--ink);
  border-color: #6fbf9d;
}

.btn--honey {
  background: linear-gradient(180deg, #f3d98f, var(--honey));
  color: var(--ink);
  border-color: #c9a24a;
  box-shadow: 0 6px 16px rgba(232, 197, 106, .25);
}

.btn--lavender {
  background: linear-gradient(180deg, #e9dbfa, var(--lilac));
  color: var(--ink);
  border-color: #b79ad6;
}

.btn--ghost { background: rgba(255, 255, 255, .06); }
.btn--danger { border-color: #b4647a; color: #ffd9e0; }
.btn--small { padding: 8px 12px; font-size: .9rem; border-radius: 12px; }
.btn--play { min-height: 56px; font-size: 1.1rem; }

/* ---------- the splash ---------- */

.scene--splash { align-items: center; justify-content: center; text-align: center; }

.splash__sky, .scene__sky {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.splash__inner { position: relative; display: grid; gap: 10px; justify-items: center; }

.splash__mark { width: 140px; height: 140px; margin-bottom: 6px; }

.splash__presents { animation: fade-up .7s ease .9s both; }
.splash__title { animation: shimmer-in 1.4s ease 1.3s both; }
.splash__skip { animation: fade-up .5s ease 2s both; }
.splash--still .splash__presents, .splash--still .splash__title, .splash--still .splash__skip { animation: none; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes shimmer-in {
  0% { opacity: 0; letter-spacing: .08em; filter: blur(4px); text-shadow: 0 0 40px rgba(232, 197, 106, .9); }
  60% { opacity: 1; letter-spacing: -.01em; filter: blur(0); text-shadow: 0 0 36px rgba(232, 197, 106, .7); }
  100% { opacity: 1; letter-spacing: -.02em; text-shadow: 0 0 26px rgba(167, 230, 206, .28); }
}

.splash__presents {
  margin: 0;
  font-size: .8rem;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--mint);
}

.splash__title {
  margin: 0;
  font: normal clamp(2.1rem, 10vw, var(--title-size)) / 1 var(--display);
  color: var(--paper);
  text-shadow: 0 0 26px rgba(167, 230, 206, .28);
}

.splash__skip { margin-top: 18px; }

/* ---------- the title ---------- */

/* the panel centres itself with auto margins, not the box with justify-content, so a panel taller than the screen
   (larger text) starts at the top and scrolls, instead of losing its first line above the top */
.scene--title { align-items: center; overflow-y: auto; }
.scene--title > .title__panel { margin-block: auto; }

.title__panel {
  position: relative;
  width: min(560px, 100%);
  padding: calc(var(--pad-wide) + 8px);
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
}

.title__eyebrow {
  margin: 0;
  font-size: .72rem;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--mint);
}

.title__name {
  margin: 0;
  font: normal clamp(2.1rem, 9vw, var(--title-size)) / 1.02 var(--display);
  letter-spacing: -.02em;
}

.title__sub { margin: 0; font-size: .95rem; color: #d9cbe4; max-width: 34ch; }
.title__notes { margin: 4px 0 0; font-size: .9rem; color: var(--honey); }

.menu { display: grid; gap: 8px; width: min(320px, 100%); margin-top: 14px; }

.menu__item {
  display: grid;
  gap: 1px;
  text-align: center;
  justify-items: center;
  padding: 10px 16px;
  min-height: 52px;
  border-radius: 999px;
  border: var(--rim) solid #b79ad6;
  background: linear-gradient(180deg, #e9dbfa, var(--lilac));
  color: var(--ink);
}

.menu__item:active { filter: brightness(1.06); }
.menu__label { font: 700 1rem/1.2 var(--ui); }
.menu__hint { font-size: .72rem; color: #56405f; }

.menu__item--play {
  min-height: 64px;
  margin-bottom: 6px;
  border-color: #c9a24a;
  background: linear-gradient(180deg, #f3d98f, var(--honey));
  box-shadow: 0 8px 20px rgba(232, 197, 106, .28);
}

.menu__item--play { animation: play-pulse 2.6s ease-in-out infinite; }
.scene--still .menu__item--play { animation: none; }

@keyframes play-pulse {
  0%, 100% { box-shadow: 0 8px 20px rgba(232, 197, 106, .28); }
  50% { box-shadow: 0 8px 30px rgba(232, 197, 106, .6), 0 0 0 4px rgba(232, 197, 106, .18); }
}

.menu__item--play .menu__label { font: normal 1.45rem/1.1 var(--display); }
.menu__item--play .menu__hint { color: #6b5520; }

.title__scene {
  width: min(320px, 100%);
  height: auto;
  display: block;
  margin: 4px auto 0;
  border-radius: 14px;
}

.title__footer { margin: 14px 0 0; font-size: .78rem; color: #b9a9c6; }
.title__link {
  color: var(--mint);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
}

/* ---------- the other screens ---------- */

.scene__panel {
  position: relative;
  width: min(640px, 100%);
  margin: 0 auto;
  padding: calc(var(--pad-wide) + 6px);
  display: grid;
  gap: 8px;
  align-content: start;
  overflow-y: auto;
}

.scene__back { justify-self: start; }
.scene__title { margin: 4px 0 0; font: normal 1.6rem/1.1 var(--display); }
.scene__note { margin: 0 0 6px; font-size: .9rem; color: #d3c4de; }

/* the album: round felt stickers on a paper page */
.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

.sticker {
  background: var(--paper);
  color: var(--ink);
  border: var(--rim) solid var(--copper);
  border-radius: var(--card-corner);
  padding: 12px;
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
  min-height: 150px;
}

.sticker__icon { width: 64px; height: 64px; filter: drop-shadow(0 3px 2px rgba(43, 31, 51, .25)); }
.sticker--new .sticker__icon { animation: wiggle .9s ease .2s 1 both; }
.scene--still .sticker--new .sticker__icon { animation: none; }

@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-9deg) scale(1.08); }
  40% { transform: rotate(8deg) scale(1.08); }
  60% { transform: rotate(-5deg); }
  80% { transform: rotate(4deg); }
}

.sticker__name { margin: 0; font: normal 1.05rem/1.2 var(--display); }
.sticker__hint { margin: 0; font-size: .82rem; color: #56405f; }
.sticker__worth { margin: 0; font-size: .78rem; color: #7a5a2c; }
.sticker--hidden { background: #efe4cd; }
.sticker--hidden .sticker__name { color: #6b5a44; }

/* the workshop */
.shop { display: grid; gap: 10px; }

.shop__item {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border: var(--rim) solid var(--copper);
  border-radius: var(--card-corner);
  padding: 12px;
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  grid-template-areas: 'pic name' 'pic what' 'pic price' 'pic buy';
  column-gap: 12px;
  row-gap: 4px;
  align-items: start;
}

.shop__preview { grid-area: pic; width: 80px; height: 80px; border-radius: 16px; background: rgba(41, 29, 48, .08); }
.shop__name { grid-area: name; margin: 0; font: normal 1.1rem/1.2 var(--display); }
.shop__what { grid-area: what; margin: 0; font-size: .85rem; color: #56405f; }
.shop__price { grid-area: price; margin: 0; font-size: .85rem; color: #7a5a2c; font-weight: 700; }
.shop__item .btn { grid-area: buy; justify-self: start; }
.shop__item--owned { background: #f4ead6; }
.shop__item--owned .shop__price { color: #2b6a4e; }
.shop__item--unwrap .shop__preview { animation: unwrap .8s ease both; }
.scene--still .shop__item--unwrap .shop__preview { animation: none; }

@keyframes unwrap {
  0% { transform: scale(.6) rotate(-8deg); filter: brightness(1.6); }
  55% { transform: scale(1.12) rotate(4deg); filter: brightness(1.2); }
  100% { transform: none; filter: none; }
}

.shop__ribbon {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--ink);
  font-size: .72rem;
  font-weight: 700;
}

.confirm {
  margin-top: 8px;
  padding: 12px;
  border-radius: 14px;
  border: var(--rim) dashed var(--copper);
  background: rgba(251, 241, 220, .1);
  display: grid;
  gap: 8px;
  justify-items: start;
}

.confirm__text { margin: 0; font-size: .92rem; }

/* the music box: a real little box, a pinned cylinder and a comb */
.musicbox { width: 100%; height: auto; display: block; border-radius: 14px; }

.tunes { display: grid; gap: 8px; }
.tunes__stage { margin: 8px 0 0; font: normal 1.05rem/1.2 var(--display); color: var(--honey); }

.tune {
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 12px 14px;
  min-height: var(--tap);
  border-radius: 14px;
  border: var(--rim) solid rgba(184, 115, 51, .5);
  background: rgba(255, 255, 255, .05);
  color: var(--paper);
}

.tune { grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 10px; }
.tune--playing { border-color: var(--honey); background: rgba(232, 197, 106, .12); }
.tune__name { font: normal 1rem/1.2 var(--display); }
.tune__staff { grid-column: 1 / -1; width: 100%; max-width: 260px; height: auto; }
.tune__hint { font-size: .78rem; color: #cbb9d8; }

/* the settings */
.settings { display: grid; gap: 8px; }

.settings__row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .04);
}

.settings__text { min-width: 0; }
.settings__label { margin: 0; font-weight: 700; }
.settings__hint { margin: 2px 0 0; font-size: .8rem; color: #c9b9d6; }

.switch {
  flex: none;
  min-width: 84px;
  min-height: var(--tap);
  padding: 8px 14px;
  border-radius: 999px;
  border: var(--rim) solid rgba(184, 115, 51, .6);
  background: rgba(255, 255, 255, .06);
  color: var(--paper);
  font-weight: 700;
}

.switch--on { background: var(--mint); color: var(--ink); border-color: #6fbf9d; }
.settings__backups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

/* ---------- the star chart: a full night sky ---------- */

.scene--chart { align-items: stretch; gap: 6px; }

.scene__top { position: relative; display: flex; align-items: center; gap: 12px; }
.scene__top .scene__title { margin: 0; }

.sky {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  transition: transform .42s ease;
}

.sky--zoomed { transform: scale(1.12); }
.scene--still .sky { transition: none; }

.sky__stars { position: absolute; inset: 0; }

.star {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 1px;
  min-width: 84px;
  min-height: var(--tap);
  padding: 6px;
  border: 0;
  background: none;
  color: var(--paper);
}

.star__mark {
  font-size: 2.2rem;
  line-height: 1;
  color: var(--honey);
  text-shadow: 0 0 14px rgba(232, 197, 106, .9), 0 0 28px rgba(232, 197, 106, .5);
}
.star__badges { display: flex; gap: 1px; font-size: .78rem; line-height: 1; color: rgba(251, 241, 220, .5); }
.star__badge--earned { color: var(--honey); text-shadow: 0 0 6px rgba(232, 197, 106, .9); }
.star__name {
  font-size: .74rem;
  font-weight: 700;
  color: var(--paper);
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8), 0 0 8px rgba(41, 29, 48, .9);
}
.star--faint { opacity: .5; }
.star--faint .star__mark { color: #cbb9d8; text-shadow: none; }
.star--next .star__mark { animation: star-pulse 1.8s ease-in-out infinite; }
.scene--still .star--next .star__mark { animation: none; }
.star--chosen .star__mark { color: var(--mint); text-shadow: 0 0 14px rgba(167, 230, 206, .9), 0 0 28px rgba(167, 230, 206, .5); }

@keyframes star-pulse {
  0%, 100% { transform: scale(1); text-shadow: 0 0 14px rgba(232, 197, 106, .9), 0 0 28px rgba(232, 197, 106, .5); }
  50% { transform: scale(1.18); text-shadow: 0 0 22px rgba(251, 241, 220, 1), 0 0 44px rgba(232, 197, 106, .8); }
}

.card--stage {
  position: relative;
  flex: none;
  width: min(560px, 100%);
  margin: 0 auto;
  max-height: 62%;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  padding: 14px;
  z-index: 2;
}

.card--rise { animation: card-rise .36s ease both; }
.scene--still .card--rise { animation: none; }

@keyframes card-rise {
  from { opacity: 0; transform: translateY(28px); }
  to { opacity: 1; transform: none; }
}

.stage__head { display: grid; grid-template-columns: 110px minmax(0, 1fr) 64px; gap: 10px; align-items: center; }
.stage__picture { width: 110px; height: auto; border-radius: 12px; border: var(--rim) solid rgba(184, 115, 51, .5); }
.stage__titles { min-width: 0; }
.stage__titles .card__title { font-size: 1.25rem; }
.stage__titles .card__note { margin: 0; font-size: .82rem; }
.stage__stars { margin: 0; font-size: 1.5rem; line-height: 1; color: rgba(43, 32, 51, .25); letter-spacing: .04em; }
.stage__star--earned { color: var(--copper); text-shadow: 0 0 10px rgba(232, 197, 106, .9); }
.stage__soloist { width: 64px; height: 64px; }

.card--stage .card__actions { margin-top: 2px; }
.card--stage .card__actions .btn--lavender { flex: 0 1 auto; }

.picker { display: grid; gap: 4px; }
.picker__label { margin: 0; font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: #6d5a3f; }
.picker__row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 8px 14px;
  border-radius: 999px;
  border: var(--rim) solid rgba(184, 115, 51, .6);
  background: rgba(255, 255, 255, .55);
  color: var(--ink);
  font-weight: 700;
  font-size: .9rem;
}

.chip--on { background: var(--mint); border-color: #6fbf9d; }
.card__play { min-height: 56px; font-size: 1.1rem; }

/* ---------- the results ---------- */

.scene--results { align-items: center; justify-content: center; overflow-y: auto; }

.card--results {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  text-align: center;
  justify-items: center;
}

.bigstars { display: flex; gap: 10px; }
.bigstar { font-size: 2.6rem; line-height: 1; color: var(--copper); text-shadow: 0 0 12px rgba(232, 197, 106, .8); }
.bigstar--empty { color: rgba(43, 32, 51, .25); text-shadow: none; }
.bigstar--waiting { opacity: 0; }
.bigstar--lit { animation: star-land .6s cubic-bezier(.2, 1.4, .4, 1) both; }
.scene--still .bigstar--lit { animation: none; }

@keyframes star-land {
  0% { opacity: 0; transform: translateY(-40px) scale(2.2) rotate(-30deg); }
  60% { opacity: 1; transform: translateY(0) scale(1.15) rotate(6deg); }
  100% { transform: none; }
}

.results__fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }

.gains__item--peel { animation: peel .5s cubic-bezier(.2, 1.4, .4, 1) both; animation-delay: var(--peel-delay, 0ms); }
.scene--still .gains__item--peel { animation: none; }

@keyframes peel {
  0% { opacity: 0; transform: translateY(14px) rotate(-6deg) scale(.7); }
  70% { opacity: 1; transform: translateY(-3px) rotate(2deg) scale(1.06); }
  100% { transform: none; }
}

.gains__sticker { display: inline-flex; align-items: center; gap: 6px; }
.gains__sticker canvas { width: 28px; height: 28px; }

.tune-card {
  width: 100%;
  padding: 10px;
  border-radius: 14px;
  background: #f4e8cf;
  border: var(--rim) solid rgba(184, 115, 51, .45);
}

.tune-card__title { margin: 0 0 4px; font: normal 1rem/1.2 var(--display); color: #6b4f22; }
.tune-card--empty .tune-card__staff { opacity: .35; }
.tune-card__staff { width: 100%; max-width: 260px; height: auto; }

.gains { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.gains__item {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(41, 29, 48, .07);
  border: 1px solid rgba(184, 115, 51, .4); font-size: .95rem; color: #56405f; }
.card--results .card__actions { width: 100%; }
.gains__item--total { background: var(--honey); border-color: #c9a24a; color: var(--ink); font-weight: 700; flex-basis: 100%; }

/* ---------- the battle ---------- */

.scene--battle { padding: 0; }

.battle {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-areas: 'hudA' 'board' 'hudB';
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

[data-mode='landscape'] .battle,
[data-mode='desktop'] .battle {
  grid-template-areas: 'hudA board hudB';
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr);
}

.battle__board {
  grid-area: board;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
  background: var(--dusk-deep);
}

/* ---------- the battle's HUD: bold outlines, flat fills, one drop shadow ----------
   Buttons are chunky and press down on pointerdown. The honey colour is for the one main action (Begin) and the
   heroes on the board, nothing else; the counters are an icon and a number, and their words are still read out. */
.hud {
  display: flex;
  gap: 8px;
  padding: 8px;
  min-width: 0;
  background: var(--dusk-deep);
  border-color: var(--edge);
}

.hud--top { grid-area: hudA; flex-direction: column; border-right: 0; }

.hud--bottom {
  grid-area: hudB;
  border-left: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 8px);
}


[data-mode='landscape'] .hud--top,
[data-mode='desktop'] .hud--top { border-right: var(--line) solid var(--edge); }
[data-mode='landscape'] .hud--bottom,
[data-mode='desktop'] .hud--bottom {
  border-left: var(--line) solid var(--edge);
  align-content: center;
  width: 236px;
  overflow-y: auto;
}

[data-mode='landscape'] .actions,
[data-mode='desktop'] .actions { flex-wrap: wrap; }
[data-mode='landscape'] .dock,
[data-mode='desktop'] .dock { grid-template-columns: repeat(2, minmax(0, 1fr)); }
[data-mode='landscape'] .sheet,
[data-mode='desktop'] .sheet { max-height: calc(100dvh - 24px); width: min(380px, 100vw); }
[data-mode='landscape'] .hud--top { width: 200px; overflow-y: auto; }



[data-mode='desktop'] .hud--top { width: 220px; }

.hud__row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud__row--spawn { justify-content: space-between; }

[data-mode='landscape'] .hud__row,
[data-mode='desktop'] .hud__row { flex-wrap: wrap; }

/* every chunky piece: paper fill, ink line, a hard drop under it */
.plaque, .ribbon, .iconbtn, .dock-head__shut, .hud .btn, .portrait, .ability, .token, .speed, .dock__card {
  border: var(--line) solid var(--edge);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 var(--drop) 0 var(--edge);
  transition: transform .08s ease, box-shadow .08s ease;
}

.hud .btn:active:not(:disabled), .iconbtn:active, .dock-head__shut:active, .portrait:active, .ability:active, .token:active, .speed:active, .dock__card:active {
  transform: translateY(var(--press));
  box-shadow: 0 calc(var(--drop) - var(--press)) 0 var(--edge);
  filter: none;
}

.plaque {
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 0;
  flex: none;
  min-width: 58px;
  min-height: var(--tap);
  padding: 4px 10px 4px 8px;
  text-align: left;
}

.plaque__row { display: flex; align-items: center; gap: 6px; }

.plaque__icon, .token__icon, .call-early__icon { display: block; flex: none; object-fit: contain; }
.plaque__icon { width: 28px; height: 28px; }
.token__icon { width: 26px; height: 22px; }
.call-early__icon { width: 26px; height: 22px; }

.plaque__label { font-size: .62rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink); font-weight: 800; }
.plaque__value { font: 800 1.3rem/1.05 var(--ui); color: var(--ink); }
.plaque--starlight { background: var(--lilac); }
.plaque--stardust { background: var(--mint); }

.ribbon {
  display: grid;
  justify-items: center;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 8px;
  background: var(--dusk-soft);
  color: var(--paper);
}

.ribbon__count { font: 800 1rem/1 var(--ui); color: var(--paper); }
.ribbon__staff { width: 100%; height: auto; }

.iconbtn, .dock-head__shut {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  background: var(--lilac);
  font-size: 1rem;
  font-weight: 900;
}

.hud .btn { font-weight: 800; }
.hud .btn--honey { background: var(--honey); }
.hud .btn:disabled { background: var(--spent); }
.hud .btn--ghost { background: var(--lilac); }
.call-early { white-space: nowrap; flex: none; display: inline-flex; align-items: center; gap: 6px; }

.preview {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: .8rem;
  font-weight: 600;
  color: var(--paper);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle__status {
  margin: 0;
  padding: 6px 8px;
  min-height: 2.2em;
  font-size: .84rem;
  line-height: 1.25;
  font-weight: 600;
  color: var(--paper);
  background: var(--edge);
  border: 2px solid var(--dusk-soft);
  border-radius: 10px;
}

/* the HUD never shifts the board: on a phone held upright the message line is always two lines tall, whatever it says
   (a screen reader still gets all of it) */
[data-mode='portrait'] .battle__status {
  height: calc(2.5em + 16px);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.actions { display: flex; align-items: stretch; gap: 6px; min-width: 0; }

.portrait {
  flex: none;
  width: 60px;
  min-height: 60px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
  padding: 2px;
  overflow: hidden;
}

.portrait__face { width: 40px; height: 40px; }
.portrait__name { font-size: .6rem; font-weight: 800; color: var(--ink); line-height: 1; }
.portrait[aria-pressed='true'] { background: var(--mint); box-shadow: 0 var(--drop) 0 var(--edge), 0 0 0 3px var(--paper); }

.ability {
  flex: none;
  width: 60px;
  min-height: 60px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
  padding: 2px;
}

.ability__mark { font-size: 1.25rem; line-height: 1.1; font-weight: 800; }
.ability__name { font-size: .6rem; font-weight: 800; color: var(--ink); line-height: 1; }
.ability--ready { background: var(--mint); }
.ability[aria-pressed='true'] { box-shadow: 0 var(--drop) 0 var(--edge), 0 0 0 3px var(--paper); }

.token {
  flex: none;
  width: 64px;
  min-height: 60px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  padding: 4px;
}

.token__pips { display: flex; gap: 4px; }
.pip { width: 10px; height: 10px; border-radius: 999px; background: var(--lilac); box-shadow: inset 0 0 0 2px var(--edge); }
.pip--spent { background: var(--paper); box-shadow: inset 0 0 0 2px var(--dusk-soft); }
.token__label { font-size: .6rem; font-weight: 800; color: var(--ink); line-height: 1; }
.token--holding { background: var(--mint); box-shadow: 0 var(--drop) 0 var(--edge), 0 0 0 4px var(--paper); }

.speed {
  flex: none;
  width: 48px;
  min-height: 60px;
  font: 800 1.1rem var(--ui);
}

.begin {
  flex: 1 1 auto;
  min-width: 72px;
  min-height: 60px;
  padding: 6px 8px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
  line-height: 1.1;
}

.begin__main { font-size: 1.05rem; }
.begin__sub { font-size: .7rem; font-weight: 700; }

.dock {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.dock__card {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
  min-height: 86px;
  padding: 4px 2px;
  min-width: 0;
}

.dock__face { width: 52px; height: 52px; }
.dock__name { font-size: .7rem; font-weight: 800; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock__cost { font-size: .74rem; font-weight: 800; color: var(--cost); line-height: 1.2; }
.dock__card--on { background: var(--mint); box-shadow: 0 var(--drop) 0 var(--edge), 0 0 0 3px var(--paper); }
.dock__card--dim { background: var(--spent); }
.dock__card--dim .dock__cost { background: var(--rose); color: var(--ink); border-radius: 8px; padding: 0 6px; }

/* the fx layer: notes flying to the staff, sparkles, the fanfare */
.battle__fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; }

/* the conductor's hold dims the world; the baton keeps a halo */
.battle::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(20, 12, 26, 0);
  pointer-events: none;
  z-index: 3;
  transition: background .5s ease;
}
.battle--holding::before { background: rgba(20, 12, 26, .45); }
.battle--holding .token { position: relative; z-index: 4; box-shadow: 0 0 0 4px rgba(167, 230, 206, .35), 0 0 32px 10px rgba(232, 197, 106, .55); }
.battle--holding .hud { position: relative; z-index: 3; }

/* a boss's entrance: a vignette round the board */
.battle--boss::before { background: radial-gradient(70% 60% at 50% 50%, rgba(20, 12, 26, 0) 40%, rgba(20, 12, 26, .55) 100%); }

/* the wave-clear fanfare */
.banner {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100vw - 40px));
  padding: 12px 16px;
  text-align: center;
  display: grid;
  gap: 6px;
  justify-items: center;
  z-index: 7;
  pointer-events: none;
  border-color: #c9a24a;
  box-shadow: 0 14px 30px rgba(8, 5, 12, .5), 0 0 40px rgba(232, 197, 106, .45);
  animation: banner-in .5s cubic-bezier(.2, 1.4, .4, 1) both;
}
.banner .card__title { font-size: 1.15rem; margin: 0; }
.banner__staff { width: 100%; height: auto; }
.scene--still .banner { animation: none; }

@keyframes banner-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* the overlay: rings and cards */
.overlay { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.overlay > * { pointer-events: auto; }

.ring__yes, .ring__no {
  position: fixed;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  border: var(--rim) solid var(--copper);
  font-size: 1.5rem;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(8, 5, 12, .55);
}

.ring__yes { background: var(--mint); color: var(--ink); }
.ring__no { background: var(--paper); color: var(--ink); }

.overlay__hint {
  position: fixed;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(24, 16, 30, .9);
  border: var(--rim) solid rgba(184, 115, 51, .5);
  font-size: .8rem;
  color: var(--paper);
  text-align: center;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(520px, 100vw);
  max-height: calc(100dvh - var(--hud-top) - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 10px;
  padding: 8px 14px calc(env(safe-area-inset-bottom) + 14px);
  background: var(--paper);
  color: var(--ink);
  border: var(--rim) solid var(--copper);
  border-bottom: 0;
  border-radius: var(--card-corner) var(--card-corner) 0 0;
  box-shadow: 0 -10px 36px rgba(8, 5, 12, .55), inset 0 0 0 1px rgba(255, 255, 255, .5);
  z-index: 6;
  animation: sheet-up .18s cubic-bezier(.2, .8, .2, 1) both;
  touch-action: pan-y;
}
.sheet--drag { animation: none; transition: none; }
.sheet--leaving { transform: translateX(-50%) translateY(100%); transition: transform .14s ease-in; }
.sheet__grab {
  justify-self: center;
  width: 100%;
  height: 22px;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
.sheet__grab::before { content: ''; width: 40px; height: 5px; border-radius: 3px; background: rgba(41, 29, 48, .28); }
@keyframes sheet-up { from { transform: translateX(-50%) translateY(100%); } to { transform: translateX(-50%) translateY(0); } }

.sheet__head { display: grid; grid-template-columns: 64px minmax(0, 1fr) var(--tap); align-items: center; gap: 10px; }
.sheet__face { width: 64px; height: 64px; border-radius: 16px; background: rgba(41, 29, 48, .08); }
.sheet__titles { min-width: 0; }
.sheet__title { margin: 0; font: normal 1.3rem/1.1 var(--display); }
.sheet__sub { margin: 2px 0 0; font-size: .76rem; color: #56405f; }
.sheet__close {
  width: var(--tap);
  height: var(--tap);
  border-radius: 999px;
  border: var(--rim) solid rgba(184, 115, 51, .6);
  background: rgba(255, 255, 255, .6);
  color: var(--ink);
  font-size: 1rem;
}

.chairs { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.chair {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 12px;
  border: 2px dashed rgba(184, 115, 51, .45);
  color: #7a6a86;
}
.chair__figure { font-size: 1.3rem; line-height: 1; }
.chair__label { font-size: .68rem; font-weight: 700; }
.chair--seated { border-style: solid; border-color: var(--copper); background: rgba(232, 197, 106, .35); color: var(--ink); }
.chair--new .chair__figure { display: inline-block; animation: chair-pop .55s cubic-bezier(.2, 1.4, .4, 1) both; }
.scene--still .chair--new .chair__figure { animation: none; }

@keyframes chair-pop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  70% { transform: scale(1.3) rotate(6deg); opacity: 1; }
  100% { transform: none; }
}
.chair--next { border-color: #6fbf9d; background: rgba(167, 230, 206, .3); color: var(--ink); }

.upgrades { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.upgrades__row { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; padding: 4px 8px; border-radius: 8px; background: rgba(41, 29, 48, .06); }
.upgrades__label { color: #56405f; }
.upgrades__value { font-weight: 700; }

.sheet__tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sheet__big { min-height: 56px; font-size: 1.05rem; }

.branches { display: grid; gap: 6px; margin-top: 4px; }
.branches__note { margin: 0; font-size: .8rem; color: #56405f; }

.branch {
  min-height: var(--tap);
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 8px 12px;
  border-radius: 12px;
  border: var(--rim) solid rgba(184, 115, 51, .6);
  background: rgba(255, 255, 255, .6);
  color: var(--ink);
}

.branch__name { font-weight: 700; font-size: .95rem; }
.branch__what { font-size: .76rem; color: #56405f; }

.branch--on { background: var(--mint); border-color: #6fbf9d; }
.branch--flip { animation: flip-in .5s ease both; animation-delay: var(--flip-delay, 0ms); }
.scene--still .branch--flip { animation: none; }

@keyframes flip-in {
  from { opacity: 0; transform: perspective(600px) rotateX(-80deg); }
  to { opacity: 1; transform: none; }
}

.card--wave {
  position: fixed;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  width: min(300px, calc(100vw - 40px));
  padding: 12px 16px;
  text-align: center;
  z-index: 7;
  pointer-events: none;
  /* a solid raised card in the HUD's own colours: it never fades, so its text is always at full contrast */
  background: var(--dusk-soft);
  color: var(--paper);
  border: var(--line) solid var(--edge);
  box-shadow: 0 var(--drop) 0 var(--edge);
  animation: card-drop .32s ease both;
}

.card--wave .card__title { font-size: 1.2rem; }
.card--wave .card__note { font-size: .86rem; margin-bottom: 0; color: var(--paper); }

@keyframes card-drop {
  from { transform: translate(-50%, calc(-50% - 14px)); }
  to { transform: translate(-50%, -50%); }
}

.card--boss { background: var(--ink); color: var(--paper); border-color: var(--copper); animation: boss-slide .6s cubic-bezier(.2, 1.2, .4, 1) both; box-shadow: 0 14px 30px rgba(8, 5, 12, .5), 0 0 40px rgba(220, 194, 247, .35); }
.card--boss .card__note { color: #e4d6ef; }

@keyframes boss-slide {
  from { opacity: 0; transform: translate(-50%, -50%) translateX(-60px) rotate(-3deg); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 14px)); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

/* ---------- the star curtain between scenes ---------- */

.curtain {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  background:
    radial-gradient(2px 2px at 20% 30%, rgba(251, 241, 220, .9), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 70% 20%, rgba(232, 197, 106, .9), rgba(0, 0, 0, 0)),
    radial-gradient(1.5px 1.5px at 40% 70%, rgba(167, 230, 206, .9), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 85% 60%, rgba(251, 241, 220, .9), rgba(0, 0, 0, 0)),
    radial-gradient(1.5px 1.5px at 55% 45%, rgba(251, 241, 220, .8), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 10% 80%, rgba(232, 197, 106, .8), rgba(0, 0, 0, 0)),
    var(--dusk-deep);
  animation: iris-open .42s ease-in both;
}
.curtain--fade { animation: curtain-fade .18s ease-out both; }

@keyframes iris-open {
  0% { clip-path: circle(80% at 50% 50%); opacity: 1; }
  100% { clip-path: circle(0% at 50% 50%); opacity: 1; }
}
@keyframes curtain-fade {
  from { opacity: .7; }
  to { opacity: 0; }
}

/* ---------- the toast ---------- */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  border: var(--rim) solid var(--copper);
  box-shadow: 0 14px 30px rgba(8, 5, 12, .55);
  animation: rise .24s ease both;
}

.toast__text { margin: 0; font-size: .92rem; }
.toast .btn { flex: none; }

/* ---------- left handed, larger text, reduced motion ---------- */

[data-left-handed='true'] .actions { flex-direction: row-reverse; }
[data-left-handed='true'] .dock { direction: rtl; }
[data-left-handed='true'] .dock__card { direction: ltr; }

[data-reduce-motion='true'] *,
[data-reduce-motion='true'] *::before,
[data-reduce-motion='true'] *::after {
  animation: none !important;
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- native feel: touch first ----------
   No text selection or callout from a long press, no tap flash (the press state below answers instead),
   no scrollbars, and the page never rubber-bands. Fields where people type stay selectable. */
.app, .app * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.app input, .app textarea { -webkit-user-select: text; user-select: text; }
.app img, .app canvas { -webkit-user-drag: none; user-drag: none; }
.app, .app * { scrollbar-width: none; }
.app *::-webkit-scrollbar { display: none; }
.app button, .app [role='button'], .app .btn, .app a, .app canvas { touch-action: manipulation; }
.app .dock__card, .app .dock__card * { touch-action: none; }

/* A press answers within a frame: script adds .is-pressed on pointerdown, before any game logic; :active covers the rest. */
.btn, .menu__item, .toggle, button {
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease, background-color .12s ease;
}
.btn:not(:disabled).is-pressed, .menu__item.is-pressed, button.is-pressed:not(:disabled):not(.dock__card):not(.iconbtn):not(.dock-head__shut) {
  transform: scale(.96);
  filter: brightness(1.14);
}
.hud .btn.is-pressed:not(:disabled), .iconbtn.is-pressed, .dock-head__shut.is-pressed, .portrait.is-pressed, .ability.is-pressed, .token.is-pressed, .speed.is-pressed, .dock__card.is-pressed {
  transform: translateY(var(--press));
  box-shadow: 0 calc(var(--drop) - var(--press)) 0 var(--edge);
  filter: brightness(1.08);
}

/* ---------- dragging a section from the dock ---------- */
.dock__card--drag { opacity: .55; }
.drag-chip {
  position: fixed;
  left: 0; top: 0;
  z-index: 30;
  width: 64px; height: 64px;
  margin: -92px 0 0 -32px;
  border-radius: 18px;
  background: var(--paper);
  border: var(--line) solid var(--edge);
  box-shadow: 0 6px 0 var(--edge), 0 12px 24px rgba(8, 5, 12, .5);
  pointer-events: none;
  display: grid; place-items: center;
  transition: background-color .12s ease;
}
.drag-chip--ok { background: var(--mint); }
.drag-chip--no { background: var(--rose); }
.drag-chip canvas { width: 52px; height: 52px; }
.info-card {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + var(--hud-bottom) + 10px);
  width: min(320px, calc(100vw - 24px));
  padding: 12px 14px;
  background: var(--paper);
  color: var(--ink);
  border: var(--rim) solid var(--copper);
  border-radius: 16px;
  box-shadow: 0 14px 30px rgba(8, 5, 12, .55);
  z-index: 7;
  animation: info-in .16s ease both;
}
.info-card h3 { margin: 0; font: normal 1.1rem/1.2 var(--display); }
.info-card p { margin: 4px 0 0; font-size: .85rem; }

.app { height: 100dvh; }
@keyframes info-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%); } }

/* ---------- the pit, held sideways ----------
   A phone held sideways (data-mode='landscape') keeps the board at its own 14 x 9 and puts the whole pit in one rail
   on the thumb side (the right; the left with the left-handed setting): the plaques and pause at the top, the next
   wave and the game's one sentence, then the soloist, Glissando, Conduct and speed, and at the corner the Sections
   button and the honey Begin. Sections opens the dock in the rail in place of the controls. The chair sheet is a side
   sheet on the same side. Upright and desktop keep the layouts above; nothing here changes a rule of the game.
   The rail's width is --rail (layout.js). */
.sections, .dock-head, .sheet__purse { display: none; }
.sheet__col { display: contents; }

[data-mode='landscape'] .battle {
  grid-template-areas: 'board hudA' 'board hudB';
  grid-template-columns: minmax(0, 1fr) var(--rail);
  grid-template-rows: minmax(0, 1fr) auto;
}
[data-mode='landscape'][data-left-handed='true'] .battle {
  grid-template-areas: 'hudA board' 'hudB board';
  grid-template-columns: var(--rail) minmax(0, 1fr);
}

[data-mode='landscape'] .hud--top,
[data-mode='landscape'] .hud--bottom {
  width: auto;
  border-right: 0;
  border-left: var(--line) solid var(--edge);
}
[data-mode='landscape'][data-left-handed='true'] .hud--top,
[data-mode='landscape'][data-left-handed='true'] .hud--bottom {
  border-left: 0;
  border-right: var(--line) solid var(--edge);
}
/* the top of the rail takes what the controls leave and scrolls when the text is larger; the controls and the honey
   Begin keep the bottom corner, always on the screen (the controls scroll themselves if they ever outgrow 70% of it) */
[data-mode='landscape'] .hud--top { gap: 6px; padding: 8px 8px 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
[data-mode='landscape'] .hud--bottom { align-content: end; padding: 6px 8px 8px; max-height: 70dvh; overflow-y: auto; overscroll-behavior: contain; }

/* the top of the rail, in the order a Tab key goes: the two plaques and pause, then the tune ribbon under them */
[data-mode='landscape'] .hud--top .hud__row:not(.hud__row--spawn) {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
/* the plaques share the row and give way to larger text by wrapping, so a number is never cut */
[data-mode='landscape'] .hud--top .plaque { flex: 1 1 5.5rem; min-width: 0; }
[data-mode='landscape'] .hud--top .iconbtn { flex: none; }
[data-mode='landscape'] .ribbon {
  order: 4;
  flex: 1 1 100%;
  grid-auto-flow: column;
  justify-content: space-between;
  align-items: center;
  min-height: var(--tap);
  padding: 2px 8px;
}
[data-mode='landscape'] .ribbon__staff { width: auto; height: 34px; }
[data-mode='landscape'] .hud--top .iconbtn { order: 3; }
[data-mode='landscape'] .plaque--starlight { order: 1; }
[data-mode='landscape'] .plaque--stardust { order: 2; }

[data-mode='landscape'] .hud__row--spawn { flex-wrap: nowrap; justify-content: space-between; align-items: center; gap: 6px; }
[data-mode='landscape'] .preview { font-size: .76rem; line-height: 1.2; white-space: normal; overflow: visible; text-overflow: clip; }
[data-mode='landscape'] .call-early { white-space: normal; max-width: 120px; text-align: left; line-height: 1.1; font-size: .8rem; }
[data-mode='landscape'] .battle__status { min-height: 3.6em; max-height: 6.4em; overflow-y: auto; font-size: .8rem; }

/* the bottom of the rail: four small controls, then Sections and Begin at the corner */
[data-mode='landscape'] .actions { flex-wrap: wrap; gap: 4px; }
[data-mode='landscape'] .portrait { width: 64px; min-height: 56px; }
[data-mode='landscape'] .ability { width: 64px; min-height: 56px; }
[data-mode='landscape'] .token { width: 60px; min-height: 56px; }
[data-mode='landscape'] .speed { width: 44px; min-height: 56px; }
[data-mode='landscape'] .begin { flex: 1 1 120px; min-height: 56px; }
[data-mode='landscape'] .sections {
  display: grid;
  place-items: center;
  flex: 1 1 96px;
  min-height: 56px;
  padding: 4px 8px;
  line-height: 1.1;
  text-align: center;
}
[data-mode='landscape'] .sections--armed { background: var(--mint); box-shadow: 0 var(--drop) 0 var(--edge), 0 0 0 3px var(--paper); }

/* the dock lives in the rail only while Sections is open, and then it takes the controls' place */
[data-mode='landscape'] .dock { display: none; }
[data-mode='landscape'] .battle[data-dock='open'] .dock { display: grid; }
[data-mode='landscape'] .battle[data-dock='open'] .dock-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
[data-mode='landscape'] .battle[data-dock='open'] .actions,
[data-mode='landscape'] .battle[data-dock='open'] .hud__row--spawn { display: none; }
.dock-head__title { margin: 0; font: normal 1.05rem/1.2 var(--display); color: var(--paper); }
/* while the dock is open the sentence is not drawn, but a screen reader still hears every word of it */
[data-mode='landscape'] .battle[data-dock='open'] .battle__status {
  position: absolute;
  width: 1px; height: 1px;
  min-height: 0; max-height: none;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* the chair sheet: a side sheet on the rail's side; it grows a second column when the branches are in it */
[data-mode='landscape'] .sheet {
  left: auto;
  right: 0;
  top: 0;
  bottom: 0;
  transform: none;
  width: min(calc(var(--rail) + env(safe-area-inset-right)), 100vw);
  max-height: none;
  align-content: start;
  gap: 8px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px) 12px;
  border: var(--rim) solid var(--copper);
  border-right: 0;
  border-radius: var(--card-corner) 0 0 var(--card-corner);
  box-shadow: -10px 0 36px rgba(8, 5, 12, .55), inset 0 0 0 1px rgba(255, 255, 255, .5);
  animation: sheet-in-right .18s cubic-bezier(.2, .8, .2, 1) both;
}
[data-mode='landscape'] .sheet[data-side='left'] {
  right: auto;
  left: 0;
  width: min(calc(var(--rail) + env(safe-area-inset-left)), 100vw);
  padding-left: calc(env(safe-area-inset-left) + 12px);
  padding-right: 12px;
  border-right: var(--rim) solid var(--copper);
  border-left: 0;
  border-radius: 0 var(--card-corner) var(--card-corner) 0;
  box-shadow: 10px 0 36px rgba(8, 5, 12, .55), inset 0 0 0 1px rgba(255, 255, 255, .5);
  animation-name: sheet-in-left;
}
[data-mode='landscape'] .sheet:not([data-side='left']) { padding-right: calc(env(safe-area-inset-right) + 12px); }
/* never wider than half the screen less a margin, so that on one side or the other the section stays in view */
[data-mode='landscape'] .sheet--wide { width: min(calc(var(--rail-wide) + env(safe-area-inset-right)), calc(50vw + env(safe-area-inset-right) - 24px)); grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
[data-mode='landscape'] .sheet--wide[data-side='left'] { width: min(calc(var(--rail-wide) + env(safe-area-inset-left)), calc(50vw + env(safe-area-inset-left) - 24px)); }
[data-mode='landscape'] .sheet--wide .sheet__col { display: grid; gap: 8px; align-content: start; min-width: 0; }
[data-mode='landscape'] .sheet__grab { display: none; }
[data-mode='landscape'] .sheet__head { grid-template-columns: 48px minmax(0, 1fr) var(--tap); }
[data-mode='landscape'] .sheet__face { width: 48px; height: 48px; }
[data-mode='landscape'] .sheet__title { font-size: 1.15rem; }
[data-mode='landscape'] .sheet__purse { display: block; margin: 0; text-align: center; font-weight: 800; font-size: .88rem; color: var(--cost); }

@keyframes sheet-in-right { from { transform: translateX(100%); } to { transform: none; } }
@keyframes sheet-in-left { from { transform: translateX(-100%); } to { transform: none; } }

/* the wave card, the boss card and the wave-clear banner take the rail's top, where the plaques are: the board
   stays clear for the few seconds they stay */
[data-mode='landscape'] .card--wave,
[data-mode='landscape'] .banner {
  left: auto;
  right: calc(env(safe-area-inset-right) + 8px);
  top: calc(env(safe-area-inset-top) + 8px);
  transform: none;
  width: min(calc(var(--rail) - 16px), calc(100vw - 16px));
  animation: card-in-side .3s ease both;
}
[data-mode='landscape'][data-left-handed='true'] .card--wave,
[data-mode='landscape'][data-left-handed='true'] .banner {
  right: auto;
  left: calc(env(safe-area-inset-left) + 8px);
}
@keyframes card-in-side { from { transform: translateX(24px); } to { transform: none; } }
[data-mode='landscape'][data-left-handed='true'] .card--wave,
[data-mode='landscape'][data-left-handed='true'] .banner { animation-name: card-in-side-left; }
@keyframes card-in-side-left { from { transform: translateX(-24px); } to { transform: none; } }

/* ---------- the other screens, held sideways ----------
   The title is the painting on the left and the felt menu on the thumb side; the Star Chart keeps its thread on the
   left and puts the stage card beside it instead of under it. */
[data-mode='landscape'] .title__panel {
  width: min(760px, 100%);
  padding: 14px 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 300px);
  column-gap: 18px;
  align-items: center;
}
[data-mode='landscape'] .title__panel > * { grid-column: 1; }
[data-mode='landscape'] .title__panel > .menu { grid-column: 2; grid-row: 1 / span 6; width: 100%; margin-top: 0; grid-template-columns: 1fr 1fr; }
[data-mode='landscape'] .menu__item--play { grid-column: 1 / -1; }
[data-mode='landscape'] .menu__item { padding: 6px 10px; }
[data-mode='landscape'] .title__sub { max-width: none; }
[data-mode='landscape'] .title__scene { width: min(240px, 100%); }

[data-mode='landscape'] .scene--chart {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
}
[data-mode='landscape'] .scene--chart:has(.card--stage:not([hidden])) { grid-template-columns: minmax(0, 1fr) min(380px, 46%); column-gap: 8px; }
[data-mode='landscape'] .scene--chart .scene__top { grid-column: 1 / -1; }
[data-mode='landscape'] .scene--chart .sky { grid-column: 1; grid-row: 2; }
[data-mode='landscape'] .scene--chart .card--stage { grid-column: 2; grid-row: 2; width: 100%; max-height: none; margin: 0; padding: 10px; gap: 6px; }
[data-mode='landscape'] .stage__head { grid-template-columns: 84px minmax(0, 1fr) 48px; }
[data-mode='landscape'] .stage__picture { width: 84px; }
[data-mode='landscape'] .stage__soloist { width: 48px; height: 48px; }

/* the results: the tune and the stars on the left, the haul on the right, the buttons pinned along the bottom */
[data-mode='landscape'] .scene--results { overflow: hidden; }
[data-mode='landscape'] .card--results {
  width: min(780px, 100%);
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  column-gap: 14px;
  padding: 12px 16px;
  gap: 8px 14px;
}
[data-mode='landscape'] .card--results > .card__title { grid-column: 1; grid-row: 1; margin: 0; }
[data-mode='landscape'] .card--results > .bigstars { grid-column: 1; grid-row: 2; }
[data-mode='landscape'] .card--results > .tune-card { grid-column: 1; grid-row: 3; min-height: 0; overflow: hidden; }
[data-mode='landscape'] .card--results > .gains { grid-column: 2; grid-row: 1 / 4; overflow-y: auto; align-content: start; min-height: 0; }
[data-mode='landscape'] .card--results > .card__actions { grid-column: 1 / -1; grid-row: 4; }
[data-mode='landscape'] .bigstar { font-size: 2rem; }

/* the star names sit on a dark backing, so no thread of the constellation runs through a word */
[data-mode='landscape'] .star__name { background: rgba(36, 26, 43, .85); border-radius: 8px; padding: 0 6px; }
[data-mode='landscape'] .card--results .card__actions { flex-wrap: nowrap; }
[data-mode='landscape'] .card--results .card__actions .btn { flex: 1 1 0; }
[data-mode='landscape'] .sheet__sub { font-size: .7rem; line-height: 1.15; }
[data-mode='landscape'] .sheet--wide .sheet__head { grid-template-columns: 40px minmax(0, 1fr) var(--tap); gap: 6px; }
[data-mode='landscape'] .sheet--wide .sheet__face { width: 40px; height: 40px; }
[data-mode='landscape'] .sheet--wide .branch { padding: 6px 10px; }
[data-mode='landscape'] .sheet--wide .branch__what { font-size: .72rem; }
[data-mode='landscape'] .sheet--wide .branches__note { font-size: .74rem; }
/* the card has its own column sideways, so the sky does not zoom toward a star */
[data-mode='landscape'] .sky--zoomed { transform: none; }

/* the shortest phones held sideways (360 tall and the like): the same rail, packed a little tighter so that nothing
   scrolls. The controls keep their 44 px; the ribbon, the sentence and the gaps give way. */
@media (max-height: 380px) {
  [data-mode='landscape'] .hud--top { gap: 4px; padding: 6px 8px 0; }
  [data-mode='landscape'] .hud--top .hud__row:not(.hud__row--spawn) { gap: 4px; }
  [data-mode='landscape'] .ribbon { min-height: 34px; padding: 0 8px; }
  [data-mode='landscape'] .ribbon__staff { height: 24px; }
  [data-mode='landscape'] .battle__status { min-height: 2.8em; padding: 4px 8px; font-size: .74rem; }
  [data-mode='landscape'] .hud--bottom { padding: 4px 8px 6px; gap: 4px; }
  [data-mode='landscape'] .portrait,
  [data-mode='landscape'] .ability,
  [data-mode='landscape'] .token,
  [data-mode='landscape'] .speed,
  [data-mode='landscape'] .begin,
  [data-mode='landscape'] .sections { min-height: 50px; }
  [data-mode='landscape'] .dock__card { min-height: 78px; }
}
/* the small controls' names a little smaller, so the longest ("Trombone", "Glissando") never touch the edge */
[data-mode='landscape'] .portrait__name,
[data-mode='landscape'] .ability__name,
[data-mode='landscape'] .token__label { font-size: .56rem; }
