/* Anime-Draft Sketch — tokens and shared components.
   Colours were sampled from the owner-approved mockups (DESIGN.md §Design tokens). */
:root {
  --paper: #fef7ea;
  --paper-2: #fffcf5;
  --graphite: #20232b;
  --ink-2: #51545c;
  --hair: #c7bfb2;
  --coral: #fd6a5c;
  --coral-hot: #fd534e;
  --coral-deep: #e8483c;
  --cobalt: #2a5afd;
  --cobalt-2: #3271fa;
  --cobalt-soft: #dee6fe;
  --green: #91f09f;
  --green-ink: #077f4a;
  --danger: #a53d3d;
  --rail-dark: #1d2024;
  --rail-dark-2: #25292f;
  --f-ui: 'Barlow Condensed', 'Bahnschrift', 'Segoe UI', 'Arial Narrow', system-ui, sans-serif;
  --f-body: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --f-heavy: 'Segoe UI Black', 'Arial Black', 'Bahnschrift', sans-serif;
  --f-cond: 'Impact', 'Franklin Gothic Medium Cond', 'Bahnschrift', 'Arial Narrow', sans-serif;
  --f-brush: 'Permanent Marker', 'Segoe Print', 'Ink Free', 'Comic Sans MS', cursive;
  --f-hand: 'Kalam', 'Ink Free', 'Segoe Print', 'Comic Sans MS', cursive;
  --shadow-btn: 0 3px 0 rgba(32, 35, 43, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--graphite);
  font-family: var(--f-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
img { user-select: none; -webkit-user-drag: none; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.ico { width: 1em; height: 1em; display: inline-block; vertical-align: middle; flex: none; }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; }
.dark :focus-visible { outline-color: #8fb0ff; }

/* ---------------------------------------------------------------- stage
   Every desktop screen is authored at its mockup's native pixel size and scaled to fit
   (contain). The plate is the mockup with live-UI regions erased; real controls sit on top. */
#app { position: fixed; inset: 0; overflow: hidden; background: var(--paper); }
.viewport { position: absolute; inset: 0; overflow: hidden; }
.stage {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  overflow: hidden;
}
.stage > * { position: absolute; }
.stage .flow { position: static; }
.abs { position: absolute; }

/* Mobile flow layout (S14/S15 and reflowed screens). */
.mobile-screen {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  background: var(--paper);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  -webkit-overflow-scrolling: touch;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5em;
  border: 0; border-radius: 12px;
  font-family: var(--f-ui); font-weight: 600; font-stretch: 87.5%;
  letter-spacing: 0.02em; text-transform: uppercase;
  line-height: 1; white-space: nowrap; user-select: none;
  transition: transform 0.08s ease, filter 0.12s ease, box-shadow 0.12s;
  min-height: 44px; min-width: 44px;
}
.btn:not(:disabled):hover { filter: brightness(1.04) saturate(1.05); }
.btn:not(:disabled):active { transform: translateY(2px); }
.btn:disabled { filter: grayscale(0.55) opacity(0.62); }
.btn-coral { background: var(--coral); color: #fff; }
.btn-hot { background: var(--coral-hot); color: #fff; }
.btn-cobalt { background: var(--cobalt); color: #fff; }
.btn-outline { background: transparent; color: var(--graphite); border: 2px solid var(--graphite); }
.btn-ghost { background: rgba(255, 252, 245, 0.85); color: var(--graphite); border: 1.5px solid var(--graphite); }

.chip-btn {
  display: inline-flex; align-items: center; gap: 8px; border-radius: 10px;
  border: 1.5px solid var(--graphite); background: var(--paper-2);
  font-family: var(--f-ui); font-weight: 600; font-size: 16px; padding: 8px 12px; min-height: 44px;
}

/* ---------------------------------------------------------------- fields */
.field {
  display: flex; align-items: center; gap: 14px;
  background: #fffdf8; border: 2px solid var(--graphite); border-radius: 12px;
  padding: 0 18px;
}
.field input {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
  font-family: var(--f-body); font-size: 24px; color: var(--graphite);
}
.field input::placeholder { color: #8e8f95; opacity: 1; }
.field:focus-within { border-color: var(--cobalt); box-shadow: 0 0 0 3px rgba(42, 90, 253, 0.18); }
.field.invalid { border-color: var(--danger); }
.field-error {
  font-family: var(--f-body); font-size: 17px; font-weight: 600; color: var(--danger);
  display: flex; gap: 6px; align-items: flex-start;
}

/* ---------------------------------------------------------------- overlays */
.scrim {
  position: fixed; inset: 0; background: rgba(32, 35, 43, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.dialog {
  background: var(--paper-2); border: 2px solid var(--graphite); border-radius: 16px;
  box-shadow: 0 10px 0 rgba(32, 35, 43, 0.15), 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 24px 26px; max-width: 520px; width: 100%;
  font-family: var(--f-body); font-size: 18px;
}
.dialog h2 { margin: 0 0 10px; font-family: var(--f-ui); font-weight: 700; font-size: 28px; text-transform: uppercase; letter-spacing: 0.02em; }
.dialog p { margin: 0 0 18px; line-height: 1.45; color: var(--ink-2); }
.dialog .row { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.dialog .row .btn { font-size: 20px; padding: 12px 20px; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--graphite); color: #fff; border-radius: 12px; padding: 12px 18px;
  font-family: var(--f-ui); font-weight: 600; font-size: 18px; letter-spacing: 0.01em;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); max-width: min(92vw, 560px); text-align: center;
  animation: toast-in 0.18s ease-out;
}
.toast.warn { background: var(--danger); }
.toast.ok { background: var(--green-ink); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Connection / pause banner (DESIGN.md interaction rule 7). */
.net-banner {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 55;
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 12px;
  background: var(--graphite); color: #fff; font-family: var(--f-ui); font-weight: 600; font-size: 17px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); max-width: min(94vw, 720px);
}
.net-banner .ico { font-size: 22px; color: #ffb3a9; }

/* HUD: one fixed cluster (bottom-right) so controls can never overlap each other. */
.hud { position: fixed; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); z-index: 40; display: flex; gap: 8px; align-items: center; }
.hud-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid rgba(32, 35, 43, 0.35);
  background: rgba(255, 252, 245, 0.92); color: var(--graphite); display: grid; place-items: center;
  font-size: 21px; text-decoration: none; box-shadow: 0 2px 8px rgba(32, 35, 43, 0.12); transition: transform 0.1s;
}
.hud-btn:hover { transform: translateY(-1px); border-color: var(--graphite); }
/* Brand colours: Discord blurple, Ko-fi blue (official logos in icons.svg). */
:root { --discord: #5865f2; --kofi: #29abe0; }
.hud-btn.discord { background: var(--discord); color: #fff; border-color: var(--discord); font-size: 23px; }
.hud-btn.kofi { background: var(--kofi); color: #fff; border-color: var(--kofi); font-size: 25px; }
.hud.mid .hud-btn { opacity: 0.75; }
.hud.mid .hud-btn:hover, .hud.mid .hud-btn:focus-visible { opacity: 1; }
.hud-menu {
  position: fixed; right: 10px; bottom: 64px; z-index: 45; width: 290px; background: var(--paper-2);
  border: 2px solid var(--graphite); border-radius: 14px; padding: 12px; display: grid; gap: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22); font-family: var(--f-ui);
}
.hud-menu hr { border: 0; border-top: 1px solid #e6e1d6; margin: 4px 0; width: 100%; }
.menu-plug { margin: 0 4px 6px; font: 600 15px/1.35 var(--f-body); color: var(--ink-2); }
.menu-item { display: flex; gap: 12px; align-items: center; min-height: 44px; padding: 0 10px; border-radius: 10px; border: 0; background: none; text-decoration: none; color: var(--graphite); font: 600 18px var(--f-ui); text-align: left; }
.menu-item:hover, .menu-item:focus-visible { background: #eef2ff; }
.menu-item .ico { font-size: 22px; }
.menu-legal { display: flex; gap: 14px; padding: 4px 10px; font: 500 15px var(--f-body); }
.menu-legal a { color: var(--ink-2); }
.support-plug { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; font: 600 18px var(--f-body); color: var(--ink-2); }
.sp-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 20px; color: #fff; text-decoration: none; font: 700 17px var(--f-ui); letter-spacing: 0.02em; }
.sp-btn .ico { font-size: 22px; flex: none; }
.sp-btn.kofi { background: var(--kofi); text-shadow: 0 1px 1px rgba(0, 40, 70, 0.35); }
.sp-btn.discord { background: var(--discord); }
.sp-btn:hover { filter: brightness(1.06); }
/* Menu rows: the logo sits in its brand-coloured badge. */
.brand-badge { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; font-size: 19px; }
.brand-badge.kofi { background: var(--kofi); font-size: 21px; }
.brand-badge.discord { background: var(--discord); }
.support-plug.mobile { font-size: 15px; gap: 8px; }
.legal-foot { position: fixed; left: max(12px, env(safe-area-inset-left)); bottom: max(10px, env(safe-area-inset-bottom)); z-index: 39; display: flex; gap: 12px; font: 500 14px var(--f-body); background: rgba(255, 252, 245, 0.85); padding: 6px 10px; border-radius: 10px; }
.legal-foot a { color: var(--ink-2); }

/* Replay */
.replay { position: absolute; inset: 0; background: #fff; }
.replay-canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.replay-btn { position: absolute; right: 10px; top: 10px; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 20px; border: 1.5px solid var(--graphite); background: rgba(255, 252, 245, 0.92); font: 700 16px var(--f-ui); letter-spacing: 0.04em; color: var(--graphite); z-index: 2; }
.replay-btn .ico { font-size: 18px; }
.replay.playing .replay-btn { opacity: 0.5; }

.sound-pop {
  position: fixed; right: 10px; bottom: 64px; z-index: 41; background: var(--paper-2);
  border: 2px solid var(--graphite); border-radius: 14px; padding: 14px 16px; width: 250px;
  font-family: var(--f-ui); font-weight: 600; font-size: 16px; display: grid; gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.sound-pop label { display: grid; grid-template-columns: 70px 1fr 34px; align-items: center; gap: 8px; }
.sound-pop input[type='range'] { width: 100%; accent-color: var(--cobalt); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* Character pool dialog */
.pool-dialog { max-width: 860px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; gap: 10px; }
.pool-dialog h2 { margin: 0; }
.pool-dialog h3 { margin: 0; font: 700 16px var(--f-ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.pool-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pool-segbtn { display: grid; gap: 2px; text-align: left; padding: 10px 14px; border-radius: 12px; border: 2px solid #d9d4c9; background: #fff; min-height: 58px; }
.pool-segbtn b { font: 700 19px var(--f-ui); }
.pool-segbtn small { font: 400 14px var(--f-body); color: var(--ink-2); }
.pool-segbtn.on { border-color: var(--cobalt); background: #eef2ff; }
.pool-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pool-head h3 { margin-right: auto; }
.pool-mini { height: 36px; min-width: 44px; padding: 0 12px; border-radius: 18px; border: 1.5px solid #cfcac0; background: #fff; font: 600 15px var(--f-ui); }
.pool-search { height: 38px; border: 1.5px solid #cfcac0; border-radius: 19px; padding: 0 14px; font: 400 16px var(--f-body); min-width: 0; flex: 1 1 180px; max-width: 280px; }
.pool-verses { display: flex; flex-wrap: wrap; gap: 6px; }
.pool-verse { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 19px; border: 1.5px solid #cfcac0; background: #fff; font: 600 16px var(--f-ui); }
.pool-verse.on { background: var(--graphite); color: #fff; border-color: var(--graphite); }
.pool-list { flex: 1 1 auto; min-height: 140px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; padding: 2px; overscroll-behavior: contain; }
.pool-char { display: grid; grid-template-rows: 84px auto auto; gap: 2px; padding: 6px; border-radius: 10px; border: 1.5px solid #e1dccf; background: #fff; text-align: center; }
.pool-char img { width: 100%; height: 84px; object-fit: cover; object-position: top; border-radius: 6px; background: #f1ece2; }
.pc-name { font: 600 14px/1.15 var(--f-ui); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pc-verse { font: 400 12px var(--f-body); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pool-char.out { opacity: 0.4; border-style: dashed; }
.pool-char.out .pc-name { text-decoration: line-through; }
.pool-more { grid-column: 1 / -1; margin: 6px; color: var(--ink-2); font-size: 15px; }
.pool-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid #e6e1d6; padding-top: 10px; }
.pool-count { flex: 1 1 220px; font: 600 16px var(--f-ui); color: var(--ink-2); }
.pool-count.bad { color: var(--danger); }
.pool-foot .row { margin-left: auto; }

/* Practice */
.prac-dialog h3 { margin: 16px 0 6px; font: 700 16px var(--f-ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.prac-summary { font: 600 17px var(--f-ui); margin-bottom: 8px; }
.prac-dialog .btn { font-size: 18px; padding: 0 16px; }
.prac-dialog .row { margin-top: 20px; }
.prac-timers { display: flex; flex-wrap: wrap; gap: 6px; }
.prac-timer { height: 42px; min-width: 64px; padding: 0 14px; border-radius: 21px; border: 1.5px solid #cfcac0; background: #fff; font: 700 16px var(--f-ui); }
.prac-timer.on { background: var(--graphite); color: #fff; border-color: var(--graphite); }
.prac-skip { font-size: 22px; gap: 10px; border-width: 2px; background: #fffcf5; }
.prac-skip.mobile { position: absolute; left: 8px; top: calc(52px + env(safe-area-inset-top)); z-index: 5; min-height: 40px; font-size: 14px; padding: 0 12px; }
.prac-btns { display: flex; gap: 16px; }
.prac-btns .btn { flex: 1; font-size: 26px; gap: 12px; border-width: 2px; }
.m-practice { width: 100%; font-size: 16px; }
.m-legal { display: flex; justify-content: center; gap: 16px; font: 500 14px var(--f-body); }
.m-legal a { color: var(--ink-2); }

.stage .support-plug { flex-wrap: nowrap; font-size: 15px; gap: 10px; white-space: nowrap; }
.stage .sp-btn { height: 36px; font-size: 16px; }
.fit-wrap { white-space: normal !important; overflow-wrap: anywhere; line-height: 1.02 !important; display: -webkit-box !important; -webkit-line-clamp: 2; -webkit-box-orient: vertical; text-align: center; }
