/* The web client's look: one stylesheet for every screen the engine draws
   (Parun.Web.*). Mobile portrait first; wider screens put the prompt beside
   the table. Dark is html[data-theme="dark"], which index.html
   sets from the system's preference or the theme button's choice. */

:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --text: #1f1b16;
  --muted: #4d473e;
  --border: #d8d0c1;
  --accent: #2557a7;
  --accent-soft: rgb(37 87 167 / 0.12);
  --accent-text: #ffffff;
  --link: #1f4a8e;
  --danger: #a13024;
  --danger-text: #8a291f;
  --on-danger: #ffffff;
  --warn: #b45309;
  --warn-text: #8a3c06;
  --good: #1c5535;
  --good-text: #1c5535;
  --on-good: #ffffff;
  --border-strong: #8f897f;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 2px 8px rgb(0 0 0 / 0.06);
  --sheet-shadow: 0 -8px 32px rgb(0 0 0 / 0.18);

  --c-w: #9a8b4b;
  --c-w-bg: #fbf7e4;
  --c-u: #3d84c6;
  --c-u-bg: #e5eff9;
  --c-b: #4c4048;
  --c-b-bg: #e6e1e3;
  --c-r: #d0543a;
  --c-r-bg: #fae6e0;
  --c-g: #3c9a5a;
  --c-g-bg: #e3f2e6;
  --c-multi: #a78620;
  --c-multi-bg: #f7efd2;
  --c-none: #898989;
  --c-none-bg: #eeeeee;
  --c-land: #a0835e;
  --c-land-bg: #f1ebe1;

  --ms-w: #f8f2cc;
  --ms-w-text: #3b3410;
  --ms-u: #aed2ef;
  --ms-u-text: #0d2c48;
  --ms-b: #b09bc4;
  --ms-b-text: #1b1222;
  --ms-r: #f2a68f;
  --ms-r-text: #4a1205;
  --ms-g: #9fd2ac;
  --ms-g-text: #0e3519;
  --ms-c: #dde3e8;
  --ms-c-text: #26313a;
  --ms-generic: #d4cfc8;
  --ms-generic-text: #2b2722;
  --ms-rim: rgb(0 0 0 / 0.2);

  --radius: 10px;
  --card-w: 92px;
  --gap: 6px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15171c;
  --surface: #1e2128;
  --surface-2: #272b34;
  --text: #ece9e3;
  --muted: #b7b9be;
  --border: #353a45;
  --accent: #6aa3ff;
  --accent-soft: rgb(106 163 255 / 0.18);
  --accent-text: #0b1526;
  --link: #8cb8ff;
  --danger: #ff9c90;
  --danger-text: #ff9c90;
  --on-danger: #1a0a08;
  --warn: #f0a23b;
  --warn-text: #f5b75f;
  --good: #5fd08f;
  --good-text: #5fd08f;
  --on-good: #0b1f14;
  --border-strong: #686b74;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 2px 8px rgb(0 0 0 / 0.3);
  --sheet-shadow: 0 -8px 32px rgb(0 0 0 / 0.5);

  --c-w: #d8c56f;
  --c-w-bg: #2f2c1f;
  --c-u: #5aa0e0;
  --c-u-bg: #1b2a3a;
  --c-b: #a08fa0;
  --c-b-bg: #282229;
  --c-r: #e8735a;
  --c-r-bg: #3a221d;
  --c-g: #5cbf7a;
  --c-g-bg: #1b3022;
  --c-multi: #e0bd4a;
  --c-multi-bg: #332c18;
  --c-none: #8d939c;
  --c-none-bg: #2a2d33;
  --c-land: #b89a72;
  --c-land-bg: #2c2620;

  --ms-w: #efe6b4;
  --ms-u: #9cc8ee;
  --ms-b: #a690bb;
  --ms-r: #ee9c84;
  --ms-g: #93cba1;
  --ms-c: #c9d1d8;
  --ms-generic: #b9b4ad;
  --ms-rim: rgb(255 255 255 / 0.25);
}

@media (min-width: 700px) {
  :root {
    --card-w: 112px;
    --gap: 8px;
  }
}

@media (min-width: 1200px) {
  :root {
    --card-w: 124px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Buttons ---------- */

#app button:where(:not(.card, .stack-item, .scrim, .who, .slot, .deck, .log-card)),
.chrome button {
  appearance: none;
  min-height: 44px;
  padding: 0.55em 1em;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  transition:
    transform 0.08s ease,
    background-color 0.15s ease;
}

#app button:active {
  transform: scale(0.97);
}

#app button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-align: center;
}

/* A button that gives something up: ending the turn, conceding. */
#app button.danger,
.chrome button.danger {
  border-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  color: var(--warn-text);
  font-weight: 600;
}

#app button:disabled,
.chrome button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

#app button:focus-visible,
#app summary:focus-visible,
#app input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

input,
textarea {
  font: inherit;
  color: inherit;
  min-height: 44px;
  padding: 0.5em 0.8em;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  width: 100%;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
  background: var(--surface-2);
  padding: 0.6em;
  border-radius: var(--radius);
}

/* ---------- Symbols ---------- */

/* The symbols ({G}, {T}, {W/U}, [+1]) are Parun's own drawings: index.html
   holds each motif once, in the hidden sprite, and Parun.Web.Mana composes a
   symbol's circle from them, split for a hybrid. */
.symbols {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.ms {
  display: inline-block;
  margin: 0 0.06em;
  vertical-align: -0.2em;
  line-height: 1;
}

.ms > svg {
  display: block;
  width: 1.15em;
  height: 1.15em;
  overflow: visible;
}

.ms text {
  fill: currentColor;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
}

/* A number or a variable is its text in a circle, widening for a long one. */
.ms.ms-generic {
  min-width: 1.44em;
  height: 1.44em;
  padding: 0 0.25em;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--ms-generic);
  color: var(--ms-generic-text);
  box-shadow: inset 0 0 0 1px var(--ms-rim);
  font-size: 0.8em;
  font-weight: 700;
  text-align: center;
  line-height: 1.44em;
  vertical-align: -0.25em;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.ms .rim { fill: none; stroke: var(--ms-rim); stroke-width: 1; }
.ms .bg-w { fill: var(--ms-w); }
.ms .bg-u { fill: var(--ms-u); }
.ms .bg-b { fill: var(--ms-b); }
.ms .bg-r { fill: var(--ms-r); }
.ms .bg-g { fill: var(--ms-g); }
.ms .bg-c { fill: var(--ms-c); }
.ms .bg-generic { fill: var(--ms-generic); }
.ms .fg-w { color: var(--ms-w-text); }
.ms .fg-u { color: var(--ms-u-text); }
.ms .fg-b { color: var(--ms-b-text); }
.ms .fg-r { color: var(--ms-r-text); }
.ms .fg-g { color: var(--ms-g-text); }
.ms .fg-c { color: var(--ms-c-text); }
.ms .fg-generic { color: var(--ms-generic-text); }

/* A loyalty cost: up for a gain, down for a loss, level for zero. */
.loyalty {
  display: inline-block;
  min-width: 2em;
  padding: 0.1em 0.35em;
  margin: 0 0.1em;
  background: var(--ms-generic);
  color: var(--ms-generic-text);
  font-weight: 700;
  font-size: 0.85em;
  text-align: center;
  line-height: 1.2;
  font-feature-settings: "tnum";
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
.loyalty.up {
  padding-top: 0.3em;
  clip-path: polygon(50% 0, 100% 0.3em, 100% 100%, 0 100%, 0 0.3em);
}
.loyalty.down {
  padding-bottom: 0.3em;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 0.3em), 50% 100%, 0 calc(100% - 0.3em));
}

.cost {
  white-space: nowrap;
}

/* ---------- Loading, messages ---------- */

.splash,
main.message {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8em;
  padding: 2em;
  text-align: center;
}

.splash h1 {
  font-size: 2.4rem;
  letter-spacing: -0.02em;
}

.splash .phase,
.matchup-line {
  color: var(--muted);
  font-size: 0.9rem;
}

.icon {
  width: 1em;
  height: 1em;
  flex: none;
}

/* A spinner (Parun.Web.Icon's loading, and the splash in index.html): an
   arc turning on a faint ring while something loads. */
.spinner {
  animation: spin 0.9s linear infinite;
}

.spinner .track,
.spinner .arc {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
}

.spinner .track {
  opacity: 0.2;
}

.spinner .arc {
  stroke-linecap: round;
}

.icon.spinner.small {
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.25em;
  margin-right: 0.45em;
  color: var(--accent);
}

.waiting {
  color: var(--muted);
  padding: 0.4em 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#insecure {
  margin: 0;
  padding: 0.6em 1em;
  background: color-mix(in srgb, var(--danger) 18%, var(--surface));
  border-bottom: 1px solid var(--danger);
  font-size: 0.85rem;
}

/* The engine is thinking: the page held still so a second tap cannot land. */
body.busy #app {
  pointer-events: none;
}

/* The page's settings gear turns while the engine works, once it takes a
   moment. */
body.busy #settings-button > svg {
  animation: spin 1.2s 0.15s linear infinite;
}

/* ---------- Home ---------- */

main.home {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.2em;
  padding: max(1em, env(safe-area-inset-top)) 1em calc(2em + env(safe-area-inset-bottom));
}

main.home .hero {
  flex-direction: column;
  align-items: center;
  text-align: center;
}

main.home .choices {
  display: flex;
  flex-direction: column;
  gap: 0.6em;
}

#app main.home .choices button {
  font-size: 1.1rem;
  padding: 0.9em 1.2em;
  text-align: center;
}

main.home .confirm {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
  text-align: center;
}

/* ---------- Lobby ---------- */

main.lobby {
  max-width: 980px;
  margin: 0 auto;
  padding: max(1em, env(safe-area-inset-top)) 1em calc(2em + env(safe-area-inset-bottom));
}

.lobby-top {
  display: flex;
  align-items: center;
  gap: 1em;
}

.lobby-top .hero {
  flex: 1;
}

#app button.home-button {
  flex: none;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4em 1em;
  padding: 0.6em 0 1em;
}

.logo {
  border-radius: 22%;
  flex: none;
}

.hero h1 {
  display: flex;
  align-items: center;
  gap: 0.35em;
  font-size: 2.2rem;
  letter-spacing: -0.03em;
}

.tagline {
  color: var(--muted);
  font-size: 0.9rem;
}

.matchup {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5em;
  align-items: stretch;
  padding: 0.75em;
  margin: 0 -0.25em 1em;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: calc(var(--radius) + 4px);
}

.matchup .start {
  grid-column: 1 / -1;
  font-size: 1.05rem;
}

.versus {
  align-self: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
}

/* One slot per bot, stacked, with the buttons seating or unseating one. */
.bots {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.bot-count {
  display: flex;
  gap: 0.5em;
}

.bot-count button {
  flex: 1;
  font-size: 0.85rem;
}

#app button.slot {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 0.15em;
  min-height: 64px;
  padding: 0.6em 0.8em;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}

#app button.slot.choosing {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.slot-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.slot-deck {
  font-weight: 600;
}

/* A bot's slot with the button switching it to a player invited from
   another browser, and an invited slot: its link, the box for the reply
   code, and whether the player is ready (Parun.Web.Lobby.inviteView). */
.seat {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
}

#app button.invite-slot,
#app button.bot-slot {
  font-size: 0.8rem;
  align-self: flex-start;
}

.invite {
  padding: 0.6em 0.8em;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.slot.invited {
  display: flex;
  flex-direction: column;
  gap: 0.15em;
}

.slot-ready {
  font-size: 0.8rem;
  color: var(--muted);
}

.invite input,
.join-status input {
  width: 100%;
  min-width: 0;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}

.invite-warning {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.matchup .start.is-ready {
  background: var(--accent-soft);
  color: inherit;
}

/* The screen a host's link opens (Parun.Web.Join). */
.join-status {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  margin-bottom: 1em;
}

.places {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35em;
}

.place {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  align-items: baseline;
}

/* A chosen deck's list: its curve in the summary, its cards on opening. */
.deck-preview {
  margin: -0.4em 0 1em;
  padding: 0.5em 0.75em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.deck-preview > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  cursor: pointer;
  font-size: 0.9rem;
}

.preview-title {
  font-weight: 600;
}

.curve {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 36px;
}

.curve .bar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  width: 14px;
  height: 100%;
}

.curve .fill {
  width: 100%;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
}

.curve .mv {
  font-size: 0.6rem;
  color: var(--muted);
  line-height: 1.1;
}

.deck-sections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6em 1.2em;
  padding-top: 0.6em;
}

.deck-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.2em;
}

.deck-line {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  font-size: 0.88rem;
  padding: 0.05em 0;
}

.deck-line .copies {
  min-width: 1.4em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.deck-line .deck-card {
  flex: 1;
}

.deck-tools {
  display: flex;
  gap: 0.5em;
  margin-bottom: 0.6em;
}

.deck-tools .random,
.deck-tools .open-import {
  flex: none;
}

/* A saved deck's list with the ways to copy it out and delete it. */
.saved-tools {
  display: flex;
  gap: 0.5em;
  margin: -0.4em 0 1em;
}

/* The panel a deck list is pasted into, and a saved deck's list to copy. */
.import,
.export {
  display: grid;
  gap: 0.4em;
  margin: 0 0 1em;
  padding: 0.75em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.import h2,
.export h2 {
  margin: 0;
  font-size: 1rem;
}

.import textarea,
.export textarea {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  resize: vertical;
}

.import .problems {
  margin: 0;
  padding-left: 1.2em;
  color: var(--danger-text);
}

.import-tools {
  display: flex;
  gap: 0.5em;
}

.deck-tools input {
  flex: 1;
  width: auto;
  min-width: 0;
}

.choosing-for {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 0.6em;
}

.sets {
  display: grid;
  gap: 1em;
}

.set h2 {
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.4em;
}

.deck-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.4em;
}

#app button.deck {
  appearance: none;
  min-height: 44px;
  padding: 0.5em 0.75em;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

#app button.deck {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4em;
}

.pips {
  flex: none;
  font-size: 0.9rem;
}

.deck-format {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

#app button.deck.picked {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.empty {
  color: var(--muted);
  font-style: italic;
  padding: 0.5em 0;
}

/* ---------- The game screen ---------- */

body:has(main.game) {
  overflow: hidden;
}

main.game {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "bar"
    "play"
    "hand"
    "side";
}

/* Sticky, though nothing scrolls it: iOS 26 blurs the top of a Home Screen
   app unless a fixed or sticky full-width box with a solid background and no
   backdrop filter spans the edge (WebKit's
   LocalFrameView::fixedContainerEdges), and then tints the status bar with
   that colour instead. */
.turn-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  grid-area: bar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em;
  padding: calc(0.4em + env(safe-area-inset-top)) 0.75em 0.4em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.turn-bar.yours {
  box-shadow: inset 0 -3px 0 var(--accent);
}

.turn-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The phases and the auto-pass level, one strip: the phases its segments,
   the current one lit. */
.strip {
  display: flex;
  align-items: stretch;
  flex: none;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.phases {
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
}

.phases li {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  color: var(--muted);
  transition: background-color 0.25s, color 0.25s;
}

.phases li:first-child {
  border-radius: 7px 0 0 7px;
}

.phases li + li {
  border-left: 1px solid var(--border);
}

.phases li .icon {
  width: 16px;
  height: 16px;
}

/* The second main phase's card, marked so the two read apart. */
.phases li.second::after {
  content: "2";
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.55rem;
  font-weight: 800;
}

.phases li.past {
  opacity: 0.45;
}

.phases li.now {
  background: var(--accent);
  color: var(--accent-text);
}

/* An extra phase or step (CR 500.8, 500.9): the lit phase ringed, and a chip
   beside the turn (Parun.Web.Board's turnBar). */
.phases li.now.extra {
  box-shadow: inset 0 0 0 2px var(--accent-text);
}

.turn-label .extra {
  margin-left: 0.4em;
  padding: 0.05em 0.5em;
  border-radius: 999px;
  border: 1px solid var(--accent);
  font-size: 0.85em;
  font-weight: 700;
}

/* The auto-pass level, the strip's last segment, a menu (Parun.Web.Question's
   autoPass). */
.auto-pass {
  position: relative;
  display: flex;
  border-left: 1px solid var(--border);
}

.auto-pass > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  padding: 0 0.55em;
  border-radius: 0 7px 7px 0;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--muted);
}

.auto-pass > summary::-webkit-details-marker {
  display: none;
}

.auto-pass > summary::after {
  content: "\25BE";
}

.auto-pass[open] > summary {
  background: var(--surface);
  color: var(--text);
}

/* The seat's designations: the monarch, the initiative, the Ring, speed. */
.count.monarch,
.count.initiative {
  background: color-mix(in srgb, var(--c-multi) 32%, var(--surface-2));
  font-weight: 600;
}

.count.monarch .k,
.count.initiative .k {
  color: var(--text);
}

.count.ring,
.count.speed,
.count.blessing,
.count.dungeons,
.count.player-counter,
.count.commander-damage {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface-2));
}

/* A subgame (CR 730), on the turn bar. */
.subgame {
  flex: none;
  padding: 0.1em 0.6em;
  border-radius: 999px;
  background: var(--danger);
  color: var(--on-danger);
  font-weight: 700;
  font-size: 0.85em;
}

/* Day or night (CR 732), beside the turn. */
.daytime {
  margin-left: 0.5em;
  padding: 0.05em 0.5em;
  border-radius: 999px;
  font-size: 0.85em;
  font-weight: 600;
}

.daytime.day {
  background: color-mix(in srgb, var(--c-w) 30%, var(--surface));
}

.daytime.night {
  background: color-mix(in srgb, var(--c-b) 45%, var(--surface));
}

.k {
  color: var(--muted);
}

.auto-pass > .segmented {
  position: absolute;
  z-index: 55;
  top: calc(100% + 0.4em);
  right: 0;
  flex-direction: column;
  flex-wrap: nowrap;
  min-width: 10em;
  background: var(--surface);
  box-shadow: var(--sheet-shadow);
}

#app .auto-pass > .segmented button {
  border-right: 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

#app .auto-pass > .segmented button:last-child {
  border-bottom: 0;
}

#app .turn-bar .settings-button {
  flex: none;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.turn-bar .settings-button > svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 420px) {
  .phases li:not(.now) {
    width: 12px;
  }
  .phases li:not(.now) > *,
  .phases li:not(.now)::after {
    display: none;
  }
}

.play-area {
  grid-area: play;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.table {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  padding: 0.5em;
  min-height: 100%;
}

.seat {
  border-radius: calc(var(--radius) + 2px);
  padding: 0.5em;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border: 2px solid transparent;
}

.seat.opponent {
  flex: none;
}

.seat.you {
  margin-top: auto;
}

/* The other seats, in turn order from yours: side by side where they fit,
   each battlefield capped so yours stays on screen. */
.opponents {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: 0.5em;
  align-items: start;
}

.opponents.several .seat .battlefield {
  max-height: 28vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.opponents.several .seat .seat-head {
  position: static;
}

.seat.active {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.seat-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4em 0.75em;
}

/* Each seat's totals stay in view while the table scrolls under them. */
.seat .seat-head {
  position: sticky;
  z-index: 3;
  padding: 0.3em 0.2em;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius);
}

.seat.opponent .seat-head {
  top: 0;
  margin-bottom: 0.4em;
}

.seat.you .seat-head {
  bottom: 0;
  margin-top: 0.4em;
}

.who {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-weight: 600;
}

#app button.who {
  appearance: none;
  padding: 0.25em 0.5em;
  border: 2px dashed var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  cursor: pointer;
}

#app button.who.chosen {
  border-style: solid;
  background: var(--accent);
  color: var(--accent-text);
}

.life {
  display: inline-flex;
}

.life .value {
  display: inline-block;
  min-width: 2.2em;
  padding: 0.1em 0.5em;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  animation: pop 0.45s ease-out;
}

@keyframes pop {
  0% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em;
  font-size: 0.8rem;
}

.count {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}

.count.turn {
  background: color-mix(in srgb, var(--accent) 35%, var(--surface-2));
}

.count.priority {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.count.turn .k,
.count.priority .k {
  color: inherit;
}

.count.poison {
  background: color-mix(in srgb, var(--good) 30%, var(--surface-2));
}

.k {
  color: var(--muted);
  font-size: 0.85em;
}

/* A zone's icon in place of its name. */
.k.zone {
  display: inline-flex;
}

.k.zone .icon {
  width: 15px;
  height: 15px;
}

details.pile {
  position: relative;
}

details.pile > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  gap: 0.35em;
  align-items: center;
}

details.pile > summary::-webkit-details-marker {
  display: none;
}

details.pile[open] {
  flex-basis: 100%;
  border-radius: var(--radius);
}

.pile-cards,
.seen {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  padding: 0.4em 0 0.2em;
}

.seen {
  flex-basis: 100%;
  align-items: center;
}

.pool {
  display: flex;
  align-items: center;
  gap: 0.2em;
  font-size: 0.95rem;
}

.battlefield {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  min-height: 0;
  /* Room for a tapped tile's turned corners. */
  padding-block: 6px;
}

.group {
  display: flex;
  flex-direction: column;
}

/* Phased out (CR 702.26b) and the command zone (CR 408): rows apart from
   the permanents, each labelled. */
.row.phased,
.row.command {
  position: relative;
  align-items: center;
  margin-top: 0.5rem;
  padding: 0.7rem 6px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.row-label {
  position: absolute;
  top: -0.6em;
  left: 8px;
  padding: 0 0.35em;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.row.phased .card {
  opacity: 0.55;
  filter: grayscale(0.6);
}

.group {
  position: relative;
}

.many {
  position: absolute;
  z-index: 2;
  top: -9px;
  right: -9px;
  min-width: 22px;
  height: 20px;
  padding: 0 0.4em;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  pointer-events: none;
}

/* Permanents sharing a tile show as a pile: card edges behind the first. */
#app .group:has(> .many) > .card:first-child:not(.playable, .attacking) {
  box-shadow:
    3px 3px 0 -1px var(--surface-2),
    3px 3px 0 0 var(--border-strong),
    6px 6px 0 -1px var(--surface-2),
    6px 6px 0 0 var(--border);
}

/* An attachment tucks under the permanent it is attached to, its name
   showing below it as a tab. */
.group > .card:first-child {
  z-index: 1;
}

#app .group > .card + .card {
  min-height: 0;
  margin-top: -8px;
  padding-top: 12px;
  border-top-width: 1px;
  border-left: 4px solid var(--c);
  border-radius: 0 0 8px 8px;
  box-shadow: none;
}

.group > .card + .card .type,
.group > .card + .card .foot:empty {
  display: none;
}

.stack {
  padding: 0.5em;
  border-radius: calc(var(--radius) + 2px);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  animation: enter 0.2s ease-out;
}

.zone-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35em;
}

.hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.stack-items {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

#app button.stack-item {
  appearance: none;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1em 0.6em;
  align-items: baseline;
  padding: 0.5em 0.7em;
  text-align: left;
  border: 1px solid var(--border);
  border-left: 5px solid var(--c);
  border-radius: var(--radius);
  background: var(--cbg);
  cursor: pointer;
  box-shadow: var(--shadow);
  animation: enter 0.25s ease-out;
}

.stack-item .who {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.stack-item .name {
  font-weight: 600;
}

.stack-item .detail {
  grid-column: 2;
  font-size: 0.82rem;
  color: var(--muted);
}

.hand {
  grid-area: hand;
  padding: 0.3em 0.5em 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.hand .zone-title {
  margin-bottom: 0;
}

.hand-cards {
  scrollbar-width: thin;
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  padding: 0.3em 0.1em 0.5em;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.hand-cards > .card {
  flex: none;
  scroll-snap-align: start;
}

/* ---------- Card tiles ---------- */

.card,
.sheet {
  --c: var(--c-none);
  --cbg: var(--c-none-bg);
}

.c-w { --c: var(--c-w); --cbg: var(--c-w-bg); }
.c-u { --c: var(--c-u); --cbg: var(--c-u-bg); }
.c-b { --c: var(--c-b); --cbg: var(--c-b-bg); }
.c-r { --c: var(--c-r); --cbg: var(--c-r-bg); }
.c-g { --c: var(--c-g); --cbg: var(--c-g-bg); }
.c-multi { --c: var(--c-multi); --cbg: var(--c-multi-bg); }
.c-land { --c: var(--c-land); --cbg: var(--c-land-bg); }
.c-none { --c: var(--c-none); --cbg: var(--c-none-bg); }

#app button.card {
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.15em;
  width: var(--card-w);
  min-height: calc(var(--card-w) * 0.72);
  padding: 0.35em 0.45em 0.3em;
  border: 1px solid color-mix(in srgb, var(--c) 55%, var(--border));
  border-top: 4px solid var(--c);
  border-radius: 8px;
  background: var(--cbg);
  color: var(--text);
  text-align: left;
  font-size: 0.74rem;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition:
    transform 0.2s ease,
    opacity 0.2s ease,
    box-shadow 0.15s ease;
  animation: enter 0.25s ease-out;
}

/* Entrances move but never fade, so a page whose animations are held (a
   background tab) still shows everything. */
@keyframes enter {
  from { transform: translateY(6px) scale(0.96); }
}

/* The cost wraps under a name too long to share its line, rather than the
   name breaking mid-word. */
.card .top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0 0.2em;
}

.card .name {
  font-weight: 650;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex: 1 1 auto;
  /* Its longest word, so the cost wraps rather than the word breaking. */
  min-width: min(min-content, 100%);
  overflow-wrap: break-word;
}

.card .cost {
  flex: none;
  font-size: 0.92em;
}

.card .type {
  color: var(--muted);
  font-size: 0.9em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card .foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 0.2em;
}

.pt {
  margin-left: auto;
  padding: 0.05em 0.4em;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 800;
  font-size: 0.95em;
  font-variant-numeric: tabular-nums;
}

.pt.loyalty {
  border-radius: 6px 6px 50% 50%;
}

.badge {
  padding: 0.05em 0.35em;
  border-radius: 999px;
  font-size: 0.85em;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
}

.badge.damage {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-danger);
}

/* What a permanent is doing now, spelled out rather than only coloured. */
.badge.state {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-size: 0.72em;
}

.badge.target {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

#app button.card.targeted {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.seat-head.targeted .who {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 999px;
}

.badge.attack {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-danger);
}

.badge.block {
  background: var(--good);
  border-color: var(--good);
  color: var(--on-good);
}

.badge.marked {
  background: color-mix(in srgb, var(--c-multi) 28%, var(--surface));
  border-color: var(--c-multi);
  color: var(--text);
}

.badge.sick {
  background: var(--surface-2);
  color: var(--text);
}

.card .keywords {
  color: var(--text);
  font-style: italic;
}

.pt.up {
  color: var(--good-text);
  border-color: var(--good-text);
}

.pt.down {
  color: var(--danger-text);
  border-color: var(--danger-text);
}

.pt.mixed {
  border-style: dashed;
  border-color: var(--text);
}


#app button.card.c-land {
  min-height: calc(var(--card-w) * 0.5);
}

#app button.card.tapped {
  /* Tapped: turned and greyed, its text kept at full contrast. */
  transform: rotate(7deg) translateY(2px);
  background: repeating-linear-gradient(135deg, var(--cbg), var(--cbg) 6px, var(--surface-2) 6px, var(--surface-2) 7px);
  border-top-color: var(--border-strong);
}

/* The tap symbol ({T}, index.html's ms-tap), at the right edge. */
#app button.card.tapped::after {
  content: "";
  position: absolute;
  right: 5px;
  top: calc(50% - 8px);
  width: 16px;
  height: 16px;
  background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9.6 24.4A9.5 9.5 0 1 1 25.2 18' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round'/%3E%3Cpath d='M21 15.6L25.3 21.6L29 15.2Z' stroke='black' stroke-width='1' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9.6 24.4A9.5 9.5 0 1 1 25.2 18' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round'/%3E%3Cpath d='M21 15.6L25.3 21.6L29 15.2Z' stroke='black' stroke-width='1' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

#app button.card.back {
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, var(--surface) 6px, var(--surface) 12px);
  border-top-color: var(--border);
  justify-content: center;
  align-items: center;
  color: var(--muted);
}

#app button.card.playable {
  box-shadow:
    0 0 0 2px var(--accent),
    0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
}

#app button.card.choosable,
#app button.stack-item.choosable {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

#app button.card.chosen,
#app button.stack-item.chosen {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  transform: translateY(-4px);
}

#app button.card.chosen::before {
  content: "\2713";
  position: absolute;
  top: -9px;
  right: -9px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app button.card.focused {
  outline: 3px solid var(--good);
  outline-offset: 2px;
  transform: translateY(-4px);
}

#app button.card.attacking {
  box-shadow:
    0 0 0 2px var(--danger),
    0 0 12px color-mix(in srgb, var(--danger) 40%, transparent);
}

#app button.card.blocking {
  outline: 3px solid var(--good);
  outline-offset: 2px;
}

/* ---------- The side panel: prompt and log ---------- */

.side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  max-height: 40dvh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--sheet-shadow);
  padding-bottom: env(safe-area-inset-bottom);
}

.prompt {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  padding: 0.7em 0.75em;
  overflow-y: auto;
  min-height: 0;
}

.prompt h2 {
  font-size: 0.98rem;
  font-weight: 600;
}

.prompt > button,
.prompt .actions > button,
.prompt .passes > button {
  width: 100%;
}

.actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.4em;
}

.passes {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.4em;
}

.passes > :only-child {
  grid-column: 1 / -1;
}

.news {
  margin: 0;
  padding: 0.45em 0.7em 0.45em 1.6em;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.1em;
}

.news .more {
  list-style: none;
  margin-left: -0.9em;
  color: var(--muted);
  font-size: 0.9em;
}

.amount-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.3em 0.6em;
}

.amount-label {
  font-size: 0.9rem;
}

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#app .segmented button {
  min-width: 40px;
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#app .segmented button:last-child {
  border-right: 0;
}

#app .segmented button.on {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.subhead {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 0.3em;
}

/* CR 724: a choice the seat makes for a player it controls. */
.controlling {
  margin: 0;
  padding: 0.45em 0.7em;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--c-b) 30%, var(--surface));
  font-weight: 600;
  font-size: 0.9rem;
}

.nudge {
  margin: 0;
  padding: 0.4em 0.7em;
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-soft);
  font-size: 0.88rem;
}

/* The source "Pay automatically" taps next. */
#app button.card.auto-next {
  outline: 3px solid var(--good);
  outline-offset: 2px;
}

#app button.card.auto-next::before {
  content: "Auto";
  position: absolute;
  top: -10px;
  right: -6px;
  padding: 0 0.4em;
  border-radius: 999px;
  background: var(--good);
  color: var(--on-good);
  font-size: 0.7rem;
  font-weight: 800;
}

.problem {
  padding: 0.5em 0.7em;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 15%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent);
  font-size: 0.9rem;
}

/* The log, a flyout from the turn label (Parun.Web.Board's turnBar). */
details.log {
  flex: 1 1 auto;
  min-width: 0;
}

details.log > summary {
  display: inline-block;
  max-width: 100%;
  vertical-align: middle;
  cursor: pointer;
  list-style: none;
  border-radius: 6px;
  padding: 0.15em 0.4em;
  margin-left: -0.4em;
}

details.log > summary::-webkit-details-marker {
  display: none;
}

details.log > summary::after {
  content: " \25BE";
  color: var(--muted);
}

details.log > summary:hover,
details.log[open] > summary {
  background: var(--surface-2);
}

.log-panel {
  position: absolute;
  z-index: 55;
  top: calc(100% + 4px);
  left: 0.5em;
  width: min(440px, calc(100vw - 1em));
  max-height: min(60dvh, 520px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--sheet-shadow);
  font-size: 0.88rem;
  white-space: normal;
}

.log-list {
  margin: 0;
  padding: 0.4em 0.75em 0.6em 2em;
  color: var(--muted);
}

.log-list li {
  padding: 0.12em 0;
}

/* A card named in the log, which opens its sheet. */
#app button.log-card {
  appearance: none;
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  font: inherit;
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  cursor: pointer;
}

.log-list li.turn,
.game-log li.turn,
.news li.turn {
  list-style: none;
  margin: 0.5em 0 0.15em -1.2em;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.log-list li.minor,
.game-log li.minor,
.news li.minor {
  font-style: italic;
}

.log-list li.fresh {
  color: var(--text);
  font-weight: 500;
}

.log-list li.fresh::marker {
  color: var(--accent);
}

@media (min-width: 900px) {
  main.game {
    grid-template-columns: minmax(0, 1fr) clamp(300px, 30vw, 400px);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "bar bar"
      "play side"
      "hand side";
  }

  .side {
    max-height: none;
    min-height: 0;
    border-top: 0;
    border-left: 1px solid var(--border);
    box-shadow: none;
  }

  .prompt {
    flex: 1;
  }

  .table {
    padding: 0.75em 1em;
    gap: 0.75em;
  }
}

/* ---------- The card sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#app button.scrim {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgb(0 0 0 / 0.42);
  cursor: default;
  animation: fade 0.18s ease-out;
}

@keyframes fade {
  from { background: transparent; }
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 86dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6em;
  padding: 1.1em 1.1em calc(1em + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  border-top: 6px solid var(--c);
  box-shadow: var(--sheet-shadow);
  animation: rise 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

/* A preview: the sheet beside the table, not over it, and not in the way. */
.sheet-backdrop.peek {
  pointer-events: none;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 4.5em 1em;
}

.sheet-backdrop.peek .sheet {
  max-width: 340px;
  border-radius: 18px;
  animation: fade-in 0.12s ease-out;
}

@keyframes fade-in {
  from { transform: translateY(4px); }
}

@keyframes rise {
  from { transform: translateY(40%); }
}

@media (min-width: 700px) {
  .sheet-backdrop {
    align-items: center;
  }

  .sheet {
    border-radius: 18px;
    border-top-width: 8px;
  }
}

.sheet header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6em;
}

.sheet h2 {
  font-size: 1.3rem;
}

.sheet header .cost {
  font-size: 1.15rem;
}

.type-line {
  color: var(--muted);
  font-size: 0.9rem;
  padding-bottom: 0.4em;
  border-bottom: 1px solid var(--border);
}

.oracle {
  display: flex;
  flex-direction: column;
  gap: 0.45em;
  padding: 0.7em 0.8em;
  border-radius: var(--radius);
  background: var(--cbg);
  line-height: 1.45;
}

.status {
  font-size: 0.88rem;
  color: var(--muted);
}

.stats-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.3em;
  font-size: 1rem;
}

.sheet-actions {
  display: grid;
  gap: 0.4em;
}

#app .sheet button.close {
  text-align: center;
}

/* ---------- Hand-off and ending ---------- */

main.handoff {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1em;
  font-size: 1.2rem;
}

main.ending {
  max-width: 720px;
  margin: 0 auto;
  padding: max(1.5em, env(safe-area-inset-top)) 1em calc(2em + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 1em;
}

.verdict {
  padding: 1.4em 1.2em;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.4em;
}

.verdict.won {
  background: color-mix(in srgb, var(--good) 18%, var(--surface));
}

.verdict.lost {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
}

.verdict h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.verdict p {
  color: var(--muted);
}

.ending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  justify-content: center;
}

.ending-actions a,
.replay a.branch {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.55em 1.1em;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.ending-actions a.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

main.ending h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.summary {
  padding: 0.8em;
  border-radius: var(--radius);
  background: var(--surface);
}

.life-chart {
  width: 100%;
  height: auto;
  max-height: 200px;
  overflow: visible;
}

.life-chart .zero {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.life-line {
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.life-line {
  stroke: var(--line);
}

.life-line.you {
  stroke-width: 4;
}

/* Each seat's colour in the chart and its key (Parun.Web.Ending). */
.seat-0 { --line: #2f6fd6; }
.seat-1 { --line: #d4492f; }
.seat-2 { --line: #2e9a55; }
.seat-3 { --line: #8a4fc9; }
.seat-4 { --line: #c98a12; }
.seat-5 { --line: #1d9aa6; }

.chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

.stats {
  margin: 0.5em 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

/* Each seat's line in the chart, drawn as its key. */
.stats li::before {
  content: "";
  display: inline-block;
  width: 1.6em;
  margin-right: 0.5em;
  vertical-align: middle;
  border-top: 3px solid var(--line);
}

/* A win's confetti, bursting once (none for reduced motion). */
.confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 80;
}

.confetti span {
  position: absolute;
  top: 55%;
  left: 50%;
  width: var(--size);
  height: var(--size);
  margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  --bx: calc(cos(var(--angle)) * var(--reach));
  --by: calc(sin(var(--angle)) * var(--reach));
  animation: burst var(--fall) var(--delay) linear both;
}

/* Each piece sways and tumbles as it falls, at its own pace. */
.confetti svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.25));
  animation: flutter var(--flutter) var(--delay) ease-in-out 8 alternate both;
}

.confetti .fg-w { color: var(--c-w); }
.confetti .fg-u { color: var(--c-u); }
.confetti .fg-b { color: var(--c-b); }
.confetti .fg-r { color: var(--c-r); }
.confetti .fg-g { color: var(--c-g); }

/* Out fast to where the piece was thrown, then down under gravity. */
@keyframes burst {
  0% {
    transform: scale(0.3);
    animation-timing-function: cubic-bezier(0.1, 0.8, 0.3, 1);
  }
  20% {
    transform: translate(var(--bx), var(--by)) rotate(calc(var(--spin) / 4));
    animation-timing-function: cubic-bezier(0.45, 0, 0.9, 0.6);
  }
  100% {
    transform: translate(calc(var(--bx) + var(--drift)), calc(var(--by) + 110vh)) rotate(var(--spin));
  }
}

@keyframes flutter {
  from { transform: translateX(calc(-1 * var(--sway))) rotateX(0deg) rotateY(0deg); }
  to { transform: translateX(var(--sway)) rotateX(160deg) rotateY(40deg); }
}

:root[data-motion="reduced"] .confetti {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .confetti {
    display: none;
  }
}

.game-log {
  margin: 0;
  padding: 0.8em 0.8em 0.8em 2.2em;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.88rem;
  max-height: 60dvh;
  overflow-y: auto;
}

.game-log li {
  padding: 0.1em 0;
}

/* ---------- Keyboard shortcuts (page.js) ---------- */

/* A button's key, as a keycap after its label, while Alt is held (page.js)
   where there is a keyboard to press it with. */
@media (hover: hover) and (pointer: fine) {
  :root.show-keys .prompt button[aria-keyshortcuts]::after,
  :root.show-keys .sheet-actions button[aria-keyshortcuts]::after {
    content: attr(aria-keyshortcuts);
    float: right;
    margin-left: 0.6em;
    padding: 0 0.4em;
    min-width: 1.4em;
    border: 1px solid currentColor;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 500;
    line-height: 1.6;
    text-align: center;
    opacity: 0.75;
  }

  :root.show-keys .prompt button[aria-keyshortcuts="Enter"]::after,
  :root.show-keys .sheet-actions button[aria-keyshortcuts="Enter"]::after {
    content: "\21B5";
  }
}

@media not ((hover: hover) and (pointer: fine)) {
  .keys-only {
    display: none;
  }
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.35em;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface-2);
  font: inherit;
  font-size: 0.85em;
  line-height: 1.5;
  text-align: center;
}

#keys {
  max-width: min(32em, calc(100vw - 2em));
  padding: 1em 1.2em;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--sheet-shadow);
}

#keys::backdrop {
  background: rgb(0 0 0 / 0.35);
}

#keys h2 {
  font-size: 1.05rem;
  margin-bottom: 0.6em;
}

#keys dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45em 1em;
  margin: 0 0 0.8em;
  font-size: 0.9rem;
}

#keys dt {
  white-space: nowrap;
}

#keys dd {
  margin: 0;
}

#keys p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.8em;
}

#keys button {
  appearance: none;
  min-height: 44px;
  padding: 0.55em 1em;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

#keys button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Chrome outside the engine's view ---------- */

.chrome {
  position: fixed;
  z-index: 60;
  right: max(0.5em, env(safe-area-inset-right));
  bottom: max(0.5em, env(safe-area-inset-bottom));
  display: flex;
  gap: 0.4em;
}

/* The game's turn bar carries its own (page.js opens the menu beneath it). */
body:has(main.game) #settings-button {
  display: none;
}

#settings-button {
  width: 36px;
  min-height: 36px !important;
  height: 36px;
  padding: 0 !important;
  border-radius: 50% !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#settings-button > svg {
  width: 24px;
  height: 24px;
}

#settings {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.4em);
  width: min(360px, calc(100vw - 1em));
  padding: 0.6em 0.8em;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--sheet-shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  font-size: 0.9rem;
}

#settings .about {
  margin: 0.2em 0 0;
  padding-top: 0.5em;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

#settings .legal {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
}

#settings a {
  color: var(--link);
}

#settings[hidden],
#settings .concede[hidden],
#concede-why[hidden] {
  display: none;
}

/* The game's actions in the menu: leaving first, conceding last. */
#settings .leave {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2em 0.8em;
  padding-bottom: 0.5em;
  border-bottom: 1px solid var(--border);
}

#settings .leave[hidden],
#settings .concede[hidden] {
  display: none;
}

#settings .leave p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85em;
}

#settings .concede {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2em 0.8em;
  padding-top: 0.5em;
  border-top: 1px solid var(--border);
}

#concede-why {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Each setting a segmented control: its choices side by side, the chosen
   one lit; the radio buttons stay, unseen, for the keyboard. */
#settings fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
}

#settings legend {
  width: 100%;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35em;
}

#settings label {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 0.7em;
  border: 1px solid var(--border);
  margin-left: -1px;
  background: var(--surface-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}

#settings legend + label {
  margin-left: 0;
  border-radius: 999px 0 0 999px;
}

#settings label:last-child {
  border-radius: 0 999px 999px 0;
}

#settings label:has(input:checked) {
  position: relative;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 650;
}

#settings label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  z-index: 1;
}

#settings input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

:root[data-density="compact"] {
  --card-w: 76px;
  font-size: 14px;
}

:root[data-density="large"] {
  --card-w: 112px;
}

@media (min-width: 700px) {
  :root[data-density="compact"] {
    --card-w: 92px;
  }

  :root[data-density="large"] {
    --card-w: 140px;
  }
}

:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after {
  animation-duration: 0.001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001s !important;
}


/* A life total's change, floating up from it (page.js). */
.float-delta {
  position: fixed;
  z-index: 90;
  transform: translate(-50%, 0);
  padding: 0.1em 0.5em;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.1rem;
  pointer-events: none;
  animation: float-up 1.3s ease-out forwards;
}

.float-delta.gain {
  background: var(--good);
  color: var(--on-good);
}

.float-delta.loss {
  background: var(--danger);
  color: var(--on-danger);
}

@keyframes float-up {
  0% { transform: translate(-50%, 0) scale(0.8); }
  15% { transform: translate(-50%, -12px) scale(1.15); }
  100% { transform: translate(-50%, -48px) scale(1); opacity: 0; }
}

.badge.damage,
.badge.state {
  animation: pop 0.4s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}

/* ---------- Scenario replay (Parun.Web.Replay) ---------- */

/* The replay's controls keep their height while a long form scrolls. */
.replay .prompt > * {
  flex-shrink: 0;
}

/* The steps in a row, the scrubber the whole width beneath them. */
.replay .scrubber {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4em;
}

.replay .scrubber button {
  flex: 1;
}

.replay .scrubber input[type="range"] {
  order: 1;
  flex-basis: 100%;
  min-width: 0;
}

.replay-description,
.replay .position {
  color: var(--muted);
  font-size: 0.85rem;
}

.replay pre.entry {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.8rem;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 0.4em 0.55em;
}

main.scenarios {
  justify-content: flex-start;
  align-items: stretch;
  max-width: 980px;
  margin: 0 auto;
  text-align: left;
}

.scenario-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.scenario-list a {
  color: var(--link);
}

/* Playing on from a position (Parun.Browser.Replay.branch). */
.replay a.branch {
  justify-content: center;
}

main.scenarios h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* ---------- Deck builder ---------- */

main.builder {
  max-width: 1200px;
  margin: 0 auto;
  padding: max(1em, env(safe-area-inset-top)) 1em calc(2em + env(safe-area-inset-bottom));
}

.builder-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5em;
  margin-bottom: 1em;
}

.builder-top .builder-name {
  flex: 1;
  min-width: 10em;
  width: auto;
}

.builder-top .saved {
  color: var(--good-text);
  font-size: 0.85rem;
}

.builder-top .problems,
.builder-deck .problems {
  flex-basis: 100%;
  margin: 0;
  padding-left: 1.2em;
  color: var(--danger-text);
  font-size: 0.88rem;
}

/* Cards and deck side by side where there is room, stacked otherwise. */
.builder-body {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1.2em;
  align-items: start;
}

@media (max-width: 760px) {
  .builder-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

.builder-search,
.builder-deck {
  display: grid;
  gap: 0.6em;
}

.builder-deck {
  position: sticky;
  top: 0.5em;
  padding: 0.75em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.builder-deck h2 {
  margin: 0;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.filters,
.basics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35em;
}

#app .filters button.toggle {
  padding: 0.25em 0.6em;
  font-size: 0.82rem;
}

#app .filters button.toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

#app .basics button.basic {
  padding: 0.25em 0.6em;
  font-size: 0.82rem;
}

#app .basics button.basic::before {
  content: "+ ";
}

.shown-count {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

.results {
  display: grid;
}

.result {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.3em 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.result {
  min-height: 2.6em;
}

.result .type-line {
  flex: 1;
  padding-bottom: 0;
  border-bottom: none;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result .copies {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}

#app button.card-name {
  min-height: 0;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#app button.card-name:hover {
  text-decoration: underline;
}

.builder-deck .deck-line {
  align-items: center;
}

.builder-deck .deck-line .card-name {
  flex: 1;
}

.builder-deck .deck-line.flagged {
  color: var(--danger-text);
}

.builder-deck .deck-line.flagged .copies {
  color: var(--danger-text);
  font-weight: 600;
}

#app button.add,
#app button.remove {
  flex: none;
  width: 1.9em;
  height: 1.9em;
  min-height: 0;
  padding: 0;
  line-height: 1;
  text-align: center;
}

#app button.add::before {
  content: "+";
}

#app button.remove::before {
  content: "\2212";
}

.card-reading,
.leave {
  position: fixed;
  left: 50%;
  bottom: 1em;
  transform: translateX(-50%);
  width: min(32em, calc(100% - 2em));
  display: grid;
  gap: 0.4em;
  padding: 1em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--sheet-shadow);
  z-index: 10;
}

.card-reading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.card-reading .type-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.card-reading .rules {
  margin: 0;
}

.leave {
  grid-template-columns: 1fr auto auto;
  align-items: center;
}

.leave p {
  margin: 0;
}

/* A saved deck the check found breaking its format, and why Start refused it. */
.not-legal {
  margin-left: 0.4em;
  padding: 0 0.4em;
  border-radius: 999px;
  background: var(--danger);
  color: var(--on-danger);
  font-size: 0.7rem;
  font-weight: 600;
}

.refusal {
  margin: -0.4em 0 1em;
  padding-left: 1.2em;
  color: var(--danger-text);
  font-size: 0.88rem;
}

/* The sections of an opened list the builder keeps but does not edit. */
.builder-deck .kept {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* A card pool pasted in, and how many of a pooled card remain. */
.paste-pool {
  position: fixed;
  left: 50%;
  top: 2em;
  transform: translateX(-50%);
  width: min(36em, calc(100% - 2em));
  display: grid;
  gap: 0.5em;
  padding: 1em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--sheet-shadow);
  z-index: 11;
}

.paste-pool h2,
.paste-pool p {
  margin: 0;
}

.paste-pool textarea {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  resize: vertical;
}

.result .left {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

#app button.add:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Which zone the search adds to, a card's deckbuilding choice, and notes. */
.targets,
.choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35em;
}

.choice {
  flex-basis: 100%;
  padding-left: 1.9em;
}

.choice-prompt {
  color: var(--muted);
  font-size: 0.8rem;
}

#app .targets button.toggle,
#app .choice button.toggle {
  min-height: 0;
  padding: 0.2em 0.55em;
  font-size: 0.82rem;
}

#app .targets button.toggle.on,
#app .choice button.toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.builder-deck .deck-line {
  flex-wrap: wrap;
}

.notices {
  margin: 0;
  padding-left: 1.2em;
  color: var(--warn-text);
  font-size: 0.85rem;
}

.deck-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
}

.card-reading .face-name {
  margin: 0.3em 0 0;
  font-size: 0.9rem;
}
