/* CUTLINE — carved stone, gilt trim and an overland map. */

:root {
  --stone-0: #17140f;
  --stone-1: #221d16;
  --stone-2: #2e2820;
  --stone-3: #3d352a;
  --stone-edge: #554835;
  --gold: #c8a24a;
  --gold-lit: #f0d68e;
  --gold-dim: #8a7444;
  --parchment: #efe4cb;
  --ink: #f0e8d6;
  --ink-dim: #b3a689;
  --ink-faint: #7d7259;
  --accent: #c0392b;
  --good: #4c9a4c;
  --radius: 6px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.65);
  --display:
    Georgia, "Palatino Linotype", "Book Antiqua", "Times New Roman", serif;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

/* Several elements below set `display`, which would otherwise beat the UA
   stylesheet's rule for the `hidden` attribute and leave them on screen. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background-color: #0c0b08;
  background-image:
    radial-gradient(
      ellipse at 50% -10%,
      rgba(90, 74, 44, 0.4) 0%,
      transparent 60%
    ),
    radial-gradient(
      ellipse at 10% 100%,
      rgba(60, 52, 34, 0.35) 0%,
      transparent 55%
    );
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button,
input {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------- carved chrome */

.panel,
.sidebar,
.result-card {
  background-color: var(--stone-1);
  background-image: linear-gradient(
    180deg,
    rgba(90, 76, 52, 0.34),
    rgba(20, 17, 12, 0.5)
  );
  border: 1px solid var(--stone-edge);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(214, 186, 130, 0.22),
    inset 0 0 0 1px rgba(0, 0, 0, 0.5),
    var(--shadow);
}

/* A gilt hairline just inside the stone edge. */
.panel::before,
.result-card::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(200, 162, 74, 0.28);
  border-radius: 3px;
  pointer-events: none;
}

.panel,
.result-card {
  position: relative;
  padding: 1.4rem;
}

button {
  cursor: pointer;
  font-family: var(--display);
  letter-spacing: 0.02em;
  border-radius: 4px;
  border: 1px solid var(--stone-edge);
  background-image: linear-gradient(180deg, #423829, #2a231a);
  color: var(--ink);
  padding: 0.55rem 1rem;
  box-shadow:
    inset 0 1px 0 rgba(220, 190, 130, 0.25),
    0 2px 5px rgba(0, 0, 0, 0.45);
  transition:
    filter 0.14s ease,
    transform 0.07s ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.25);
}

button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background-image: linear-gradient(180deg, #a8853a, #6d5526);
  border-color: var(--gold);
  color: #fff6e2;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

button.ghost {
  background-image: linear-gradient(
    180deg,
    rgba(80, 68, 48, 0.45),
    rgba(30, 26, 18, 0.5)
  );
}

input {
  font-family: var(--display);
  background: rgba(12, 10, 7, 0.7);
  border: 1px solid var(--stone-edge);
  border-radius: 4px;
  padding: 0.55rem 0.7rem;
  outline: none;
  width: 100%;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55);
}

input:focus {
  border-color: var(--gold-dim);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.55),
    0 0 0 2px rgba(200, 162, 74, 0.2);
}

.screen {
  display: none;
  height: 100dvh;
}

.screen.active {
  display: block;
}

/* --------------------------------------------------------------- lobby */

.home-wrap {
  position: relative;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Centring a flex column taller than the viewport clips its top out of the
     scroll range; `safe` keeps it scrollable when it no longer fits. */
  justify-content: safe center;
  gap: 1.4rem;
  padding: 2rem 1.25rem;
}

.brand {
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.2rem, 6.5vw, 3.6rem);
  letter-spacing: 0.3em;
  font-weight: 700;
  text-indent: 0.3em;
  color: var(--gold-lit);
  text-shadow:
    0 2px 0 #6b5528,
    0 4px 14px rgba(0, 0, 0, 0.8);
}

.brand h1 span {
  color: #e5d3a6;
}

.brand.small h1 {
  font-size: 1.5rem;
}

.tagline {
  margin: 0.6rem 0 0;
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-dim);
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(280px, 370px) minmax(300px, 470px);
  gap: 1.1rem;
  align-items: start;
}

.field {
  display: block;
  margin-bottom: 1rem;
}

.field > span {
  display: block;
  font-family: var(--display);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--gold-dim);
  margin-bottom: 0.4rem;
}

.palette {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.swatch-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.5);
  padding: 0;
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.4);
}

.swatch-btn[aria-pressed="true"] {
  border-color: var(--gold-lit);
  box-shadow: 0 0 0 2px rgba(200, 162, 74, 0.35);
}

.swatch-btn:disabled {
  opacity: 0.25;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 1.2rem;
}

.or {
  text-align: center;
  color: var(--ink-faint);
  font-family: var(--display);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}

#input-code {
  text-transform: uppercase;
  letter-spacing: 0.4em;
  text-align: center;
  color: var(--gold-lit);
}

/* A checkbox and its sentence, used for founding publicly and for the host's
   listing switch in the lobby. */
.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink-dim);
  font-size: 0.84rem;
  cursor: pointer;
  user-select: none;
}

.check-row input {
  width: auto;
  margin: 0;
  accent-color: var(--gold);
  flex: none;
}

/* ------------------------------------------------------------ open realms */

.realms {
  margin-top: 1.4rem;
  border-top: 1px solid var(--stone-3);
  padding-top: 0.9rem;
}

.realms-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem;
}

.realms-head .label {
  font-family: var(--display);
  color: var(--gold);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

.link-btn {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  width: auto;
  color: var(--ink-faint);
  font-family: var(--display);
  font-size: 0.78rem;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--gold);
}

.realm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  /* Long lists scroll rather than pushing the rules panel off the page. */
  max-height: 13rem;
  overflow-y: auto;
}

.realm-list:empty {
  display: none;
}

.realm-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.55rem;
  border-radius: 3px;
  background: rgba(10, 8, 5, 0.4);
  border: 1px solid var(--stone-3);
}

.realm-who {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1;
}

.realm-host {
  font-family: var(--display);
  color: var(--parchment);
  /* A stranger's name, so it is given a lane rather than the whole row. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.realm-seats {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
}

.realm-join {
  width: auto;
  flex: none;
  padding: 0.3rem 0.9rem;
  font-size: 0.8rem;
}

.rules-panel h2,
.lobby-panel h2 {
  margin: 0 0 0.9rem;
  font-family: var(--display);
  font-size: 0.95rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid rgba(200, 162, 74, 0.25);
  padding-bottom: 0.5rem;
}

.rules {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--ink-dim);
  line-height: 1.55;
  font-size: 0.9rem;
}

.rules li + li {
  margin-top: 0.55rem;
}

.rules strong {
  color: var(--parchment);
}

.error {
  margin: 0.85rem 0 0;
  color: #ff9d9d;
  font-size: 0.88rem;
}

/* --------------------------------------------------- the gesture diagram */

.gesture {
  margin: 0 0 1rem;
  display: flex;
  gap: 0.9rem;
  align-items: center;
  background: rgba(10, 8, 5, 0.45);
  border: 1px solid rgba(200, 162, 74, 0.22);
  border-radius: 4px;
  padding: 0.8rem;
}

.gesture svg {
  flex: none;
  width: 132px;
  height: 92px;
}

.gesture.big svg {
  width: 190px;
  height: 132px;
}

.gesture.big p {
  font-size: 0.95rem;
}

.gesture p {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.5;
  color: var(--ink-dim);
}

.gesture b {
  color: var(--parchment);
}

/* ---------------------------------------------------------- room lobby */

.lobby-panel {
  width: min(580px, 92vw);
}

.code-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.label {
  font-family: var(--display);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--gold-dim);
}

.room-code {
  font-family: var(--display);
  font-size: 2.3rem;
  letter-spacing: 0.3em;
  font-weight: 700;
  line-height: 1.15;
  color: var(--gold-lit);
  text-shadow: 0 2px 0 #6b5528;
}

.hint {
  color: var(--ink-faint);
  font-size: 0.84rem;
  margin: 0.5rem 0 0;
}

.seat-list {
  list-style: none;
  margin: 1.2rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.seat {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: rgba(10, 8, 5, 0.45);
  border: 1px solid var(--stone-3);
  border-left: 3px solid var(--stone-edge);
  border-radius: 3px;
  padding: 0.55rem 0.75rem;
  font-family: var(--display);
}

.swatch {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.5);
}

.swatch.neutral {
  background: #8d846f;
}

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

.tag {
  font-family: var(--font);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  border: 1px solid var(--stone-3);
  border-radius: 2px;
  padding: 0.12rem 0.4rem;
}

.tag.you {
  color: var(--gold-lit);
  border-color: var(--gold-dim);
}

.lobby-actions {
  display: flex;
  gap: 0.7rem;
}

.lobby-actions button {
  flex: 1;
}

/* ---------------------------------------------------------------- game */

.game-layout {
  height: 100dvh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr) 286px;
  gap: 0.6rem;
  padding: 0.6rem;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 0;
  padding: 0.8rem;
  overflow: hidden;
}

.round-badge {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--display);
  font-size: 0.85rem;
  color: var(--gold);
  border-bottom: 1px solid rgba(200, 162, 74, 0.2);
  padding-bottom: 0.45rem;
}

.muted {
  color: var(--ink-faint);
  font-size: 0.78rem;
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-y: auto;
}

/* Each ruler gets a banner strip in their colour. */
.score {
  border: 1px solid var(--stone-3);
  border-left: 4px solid currentColor;
  border-radius: 3px;
  padding: 0.45rem 0.55rem;
  background: rgba(10, 8, 5, 0.5);
  transition:
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.score.active {
  background: rgba(200, 162, 74, 0.1);
  box-shadow: 0 0 0 1px rgba(200, 162, 74, 0.45);
}

.score.dead {
  opacity: 0.35;
  filter: grayscale(0.7);
}

.score-top {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--display);
  font-size: 0.88rem;
}

.score-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.mono {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--gold);
}

.bar {
  position: relative;
  height: 6px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.55);
  margin-top: 0.4rem;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.7);
}

/*
 * Where conquest sits. It moves with the size of the table, so it has to be
 * drawn rather than remembered — and a bar with no finish line on it gives no
 * sense of how close anyone is to ending the match.
 */
.bar::after {
  content: "";
  position: absolute;
  top: -1px;
  bottom: -1px;
  left: calc(var(--goal, 60) * 1%);
  width: 2px;
  margin-left: -1px;
  background: var(--gold-lit);
  opacity: 0.75;
}

.bar > i {
  display: block;
  height: 100%;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.35);
}

.score-sub {
  display: flex;
  justify-content: space-between;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--ink-faint);
}

/*
 * An exile holds nothing but is still playing, so the row has to read as
 * neither alive-and-well nor out — a warning, with a countdown under it.
 */
.score.exiled .score-sub {
  color: #d99a4e;
}

.score.exiled .bar {
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(217, 154, 78, 0.5);
}

.score.exiled .score-name {
  font-style: italic;
  color: var(--ink-dim);
}

.neutral-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--ink-dim);
  padding-top: 0.5rem;
  border-top: 1px solid var(--stone-3);
}

.arena-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.7),
    inset 0 0 0 2px rgba(200, 162, 74, 0.18);
}

#arena {
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.turn-banner {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(
    180deg,
    rgba(48, 40, 28, 0.95),
    rgba(20, 17, 11, 0.95)
  );
  border: 1px solid var(--gold-dim);
  border-radius: 3px;
  padding: 0.4rem 1.1rem;
  font-family: var(--display);
  font-size: 0.88rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  max-width: 94%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-banner.flash {
  animation: flash 0.5s ease;
}

@keyframes flash {
  0%,
  100% {
    border-color: var(--gold-dim);
  }
  35% {
    border-color: #ff8a8a;
    background: linear-gradient(
      180deg,
      rgba(120, 40, 40, 0.95),
      rgba(50, 18, 18, 0.95)
    );
  }
}

.toast {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(16, 13, 9, 0.94);
  border: 1px solid var(--gold-dim);
  border-radius: 3px;
  padding: 0.45rem 0.9rem;
  font-family: var(--display);
  font-size: 0.86rem;
  pointer-events: none;
  animation: rise 0.25s ease;
  max-width: 90%;
  text-align: center;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* -------------------------------------------------------------- ladder */

.ladder-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--display);
  color: var(--gold);
  border-bottom: 1px solid rgba(200, 162, 74, 0.2);
  padding-bottom: 0.4rem;
}

.ladder {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
}

.rung {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.28rem 0.45rem;
  border-radius: 2px;
  border: 1px solid transparent;
  background: rgba(10, 8, 5, 0.4);
  box-shadow: none;
  font-family: var(--display);
  font-size: 0.82rem;
  text-align: left;
}

/*
 * How full this strike's price is. A locked rung is not simply "off" — it is a
 * thing being saved towards, and the bar is the saving made visible.
 */
.rung::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: calc(var(--fill, 0) * 100%);
  background: var(--gold-dim);
  opacity: 0;
  transition:
    width 420ms cubic-bezier(0.2, 0.8, 0.3, 1),
    opacity 200ms ease;
}

.rung:disabled::before {
  opacity: 0.55;
}

/* A strike that reaches where nothing cheaper can, called out in the detail. */
.stance-detail .ability {
  color: var(--gold-lit);
  font-style: italic;
}

/* The one being saved for right now gets the brighter bar and a faint glow. */
.rung.saving-for:disabled {
  opacity: 0.62;
  background: rgba(200, 162, 74, 0.06);
}

.rung.saving-for::before {
  opacity: 1;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-lit));
  box-shadow: 0 0 5px rgba(240, 214, 142, 0.55);
}

.rung:disabled {
  opacity: 0.28;
}

.rung.selected {
  border-color: var(--gold);
  background: rgba(200, 162, 74, 0.16);
  color: var(--gold-lit);
}

.rung.current::after {
  content: "★";
  font-size: 0.62rem;
  color: var(--good);
}

.rung .icon {
  width: 2.1rem;
  flex: none;
  text-align: center;
  font-family: var(--display);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--gold-dim);
}

.rung.selected .icon {
  color: var(--gold-lit);
}

.rung .rung-name {
  flex: 1;
}

/*
 * A signature strike is good for one throw a campaign. Marked with a gilt edge
 * rather than a word: the name column is tight enough that a four-letter badge
 * wrapped "Champion's Gambit" onto two lines. The text stays for screen
 * readers, and the detail panel says it in full.
 */
.rung .sig {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--gold-lit), var(--gold-dim));
  font-size: 0;
  color: transparent;
}

/* Already thrown: not a thing to save for any more, so it reads as struck out. */
.rung.gone {
  opacity: 0.16;
}

.rung.gone .rung-name,
.rung.gone .cost {
  text-decoration: line-through;
}

.rung .cap {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
}

/* Resolve price, right-aligned so the column reads as a price list. */
.rung .cost {
  font-family: var(--mono);
  font-size: 0.72rem;
  min-width: 2.1rem;
  text-align: right;
  color: var(--gold);
}

.rung:disabled .cost {
  color: #b06a6a;
}

.rung.current::after {
  content: "";
}

/* The Resolve purse, shown above the strike list. */
.resolve-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--display);
  font-size: 0.84rem;
  color: var(--gold-lit);
  background: rgba(10, 8, 5, 0.5);
  border: 1px solid rgba(200, 162, 74, 0.3);
  border-radius: 3px;
  padding: 0.35rem 0.55rem;
}

.resolve-bar .pips {
  flex: 1;
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.resolve-bar i {
  width: 7px;
  height: 12px;
  border-radius: 1px;
  background: linear-gradient(180deg, #f0d68e, #8a7444);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.4);
  transition: background 220ms ease;
}

.resolve-bar i.empty {
  background: rgba(255, 255, 255, 0.09);
  box-shadow: none;
}

/*
 * What the selected strike is about to cost. Banked but already claimed, so it
 * reads as spoken-for rather than as money you still have.
 */
.resolve-bar i.spend {
  background: repeating-linear-gradient(
    -45deg,
    rgba(240, 214, 142, 0.85) 0 2px,
    rgba(120, 92, 40, 0.7) 2px 4px
  );
  box-shadow: inset 0 0 0 1px rgba(240, 214, 142, 0.55);
}

/* Income landing: the pips that just arrived flare, staggered left to right. */
.resolve-bar i.fresh {
  animation: pip-land 620ms ease-out backwards;
}

@keyframes pip-land {
  0% {
    transform: scaleY(0.2);
    background: #fff6d8;
    box-shadow: 0 0 8px rgba(255, 240, 200, 0.9);
  }
  60% {
    transform: scaleY(1.15);
    box-shadow: 0 0 6px rgba(255, 235, 180, 0.6);
  }
  100% {
    transform: scaleY(1);
  }
}

/*
 * Starts over the unfilled end of the pip row — dead space, and right where
 * the new pips just landed — then rises clear of the bar as it fades.
 */
.resolve-gain {
  position: absolute;
  right: 0.5rem;
  top: 0.2rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--good);
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.resolve-gain.rise {
  animation: gain-rise 1100ms ease-out forwards;
}

@keyframes gain-rise {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }
  18% {
    opacity: 1;
    transform: translateY(-6px);
  }
  100% {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/*
 * What the purse is filling towards. Naming the next strike and its distance
 * is the difference between "I have 4" and "two more turns and I can take a
 * province" — the second is the decision the game is actually asking about.
 */
.resolve-next {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.1rem 0.4rem;
  font-family: var(--display);
  font-size: 0.7rem;
  color: var(--ink-dim);
  padding: 0 0.1rem;
  min-height: 1.9em;
}

.resolve-next .next-label b {
  color: var(--gold);
}

.resolve-next .next-eta {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--gold-lit);
  white-space: nowrap;
}

.resolve-next .next-track {
  grid-column: 1 / -1;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.resolve-next .next-track i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-lit));
  transition: width 420ms cubic-bezier(0.2, 0.8, 0.3, 1);
}

.resolve-next .ready {
  color: var(--good);
}

/* Motion is decoration here; the pip states carry the meaning without it. */
@media (prefers-reduced-motion: reduce) {
  .resolve-bar i.fresh,
  .resolve-gain.rise {
    animation: none;
  }
  .rung::before,
  .resolve-next .next-track i {
    transition: none;
  }
}

/* ---------------------------------------------------------------- works */

/* Two tiles side by side under a heading that has to be told to take the whole
   width, or "Works 0/2 standing" is dragged in alongside the buttons. */
.works {
  display: flex;
  flex-flow: row wrap;
  gap: 3px;
}

.works-head {
  flex: 0 0 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--display);
  color: var(--gold);
  border-bottom: 1px solid rgba(200, 162, 74, 0.2);
  padding-bottom: 0.3rem;
  margin-bottom: 0.15rem;
}

.work-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  border: 1px solid transparent;
  background: rgba(10, 8, 5, 0.4);
  box-shadow: none;
  font-family: var(--display);
  min-height: 44px;
}

/* Dimmed rather than hidden — a tile you cannot afford is still worth wanting,
   and the panel below says what is in the way. Kept hoverable on purpose (see
   the note in refreshWorks), so it is `aria-disabled`, not `disabled`. */
.work-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: default;
}

.work-btn[aria-disabled="true"] .work-cost {
  color: #b06a6a;
}

/* Armed: the next click on the map is what completes the action. */
.work-btn.armed {
  border-color: var(--gold);
  background: rgba(200, 162, 74, 0.16);
  box-shadow: 0 0 6px rgba(200, 162, 74, 0.25);
}

.work-btn .work-icon {
  display: block;
  flex: none;
}

.work-btn .work-cost {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--gold);
}

/* The ladder's costs sit in a column under a Resolve heading; these float next
   to a picture, so they carry the mark. */
.work-btn .work-cost::after {
  content: " ◈";
  font-size: 0.72em;
  opacity: 0.8;
}

.work-btn.armed .work-cost {
  color: var(--gold-lit);
}

.stance-detail {
  font-size: 0.8rem;
  color: var(--ink-dim);
  line-height: 1.45;
  min-height: 5.4em;
  border-top: 1px solid var(--stone-3);
  padding-top: 0.5rem;
  font-family: var(--display);
}

.stance-detail b {
  color: var(--parchment);
}

.stance-detail .blurb {
  display: block;
  font-style: italic;
  margin: 0.15rem 0 0.3rem;
  color: var(--ink-faint);
}

.stance-detail .stat {
  display: block;
  font-size: 0.76rem;
}

/* The one reason an action is out of reach, said once, in the same muted red
   the ladder already uses for a strike you cannot pay for. */
.stance-detail .stat.locked:not(:empty) {
  color: #b06a6a;
}

.stance-detail .stat.locked.nudge {
  animation: nudge 0.28s ease-out;
}

@keyframes nudge {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .stance-detail .stat.locked.nudge {
    animation: none;
  }
}

.turn-actions {
  display: flex;
  gap: 0.4rem;
}

.turn-actions button {
  flex: 1;
  padding: 0.4rem;
  font-size: 0.82rem;
}

.feed-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  gap: 0.45rem;
  border-top: 1px solid var(--stone-3);
  padding-top: 0.5rem;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--ink-dim);
  line-height: 1.4;
}

.feed li {
  border-left: 2px solid var(--stone-3);
  padding-left: 0.45rem;
}

.feed li.chat {
  border-left-color: currentColor;
}

.feed .who {
  font-weight: 700;
  font-family: var(--display);
}

.chat-row {
  display: flex;
  gap: 0.35rem;
}

.chat-row input {
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
}

.chat-row button {
  padding: 0.35rem 0.6rem;
  font-size: 0.76rem;
}

/* -------------------------------------------------------------- result */

.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 5, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.result-card {
  width: min(450px, 92vw);
  text-align: center;
}

.result-card h2 {
  margin: 0 0 1rem;
  font-family: var(--display);
  font-size: 1.45rem;
  color: var(--gold-lit);
  text-shadow: 0 2px 0 #6b5528;
}

.result-list {
  list-style: none;
  margin: 0 0 1.2rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
}

.result-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.65rem;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
  border-left: 3px solid var(--stone-edge);
  font-family: var(--display);
  font-size: 0.88rem;
}

.result-list .rank {
  font-family: var(--mono);
  color: var(--gold-dim);
  width: 1.4rem;
}

.connection {
  position: fixed;
  bottom: 0.7rem;
  left: 0.7rem;
  background: rgba(150, 40, 40, 0.94);
  border: 1px solid #d88;
  color: #fff;
  padding: 0.4rem 0.75rem;
  border-radius: 3px;
  font-size: 0.8rem;
  z-index: 30;
}

/* ---------------------------------------------------------- help sheet */

.help-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 0.95rem;
  z-index: 5;
}

/* The language picker: present but never the loudest thing on the screen. */
.lang-select {
  font-family: var(--display);
  font-size: 0.75rem;
  color: var(--ink-dim);
  background: rgba(10, 8, 5, 0.5);
  border: 1px solid var(--stone-edge);
  border-radius: 3px;
  padding: 0.2rem 0.35rem;
  cursor: pointer;
}

/*
 * Pinned to the screen, not to the title block: `.brand` shrinks to fit its
 * text, so anchoring here to its top-right put the picker on top of the "E".
 */
.corner-lang {
  position: absolute;
  top: 0.9rem;
  right: 1.1rem;
  z-index: 4;
}

.map-lang {
  position: absolute;
  top: 0.6rem;
  right: 4.6rem;
  z-index: 5;
}

.sound-btn {
  right: 2.6rem;
  font-size: 0.8rem;
  line-height: 1;
}

.sound-btn[aria-pressed="false"] {
  opacity: 0.5;
}

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 5, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  padding: 1rem;
}

.help-card {
  width: min(560px, 94vw);
  max-height: 90dvh;
  overflow-y: auto;
}

.help-card h2 {
  margin: 0 0 0.9rem;
  font-family: var(--display);
  color: var(--gold);
  font-size: 1rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.help-card ol {
  margin: 0 0 1rem;
  padding-left: 1.15rem;
  color: var(--ink-dim);
  line-height: 1.55;
  font-size: 0.9rem;
}

.help-card li + li {
  margin-top: 0.5rem;
}

.help-card strong {
  color: var(--parchment);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) and (orientation: landscape) {
  .home-grid {
    grid-template-columns: minmax(280px, 470px);
  }
}

/*
 * A phone on its side: plenty of width, almost no height. The columns stay,
 * narrowed, and the rails scroll inside themselves — which is what makes the
 * works reachable rather than clipped off the bottom.
 */
@media (max-height: 520px) and (orientation: landscape) {
  .game-layout {
    grid-template-columns: 150px minmax(0, 1fr) 210px;
    gap: 0.4rem;
    padding: 0.4rem;
  }

  .sidebar {
    overflow-y: auto;
    padding: 0.5rem;
  }

  /* Chat is the one thing worth its height here. The detail panel stays: with
     the tiles reduced to pictures it is the only place the game explains
     itself, and a landscape player needs that as much as anyone. */
  .feed-wrap {
    display: none;
  }

  /* `flex: none` is load-bearing: the rail overflows here and a shrinkable
     item is squeezed to its padding, which is how the panel ended up nine
     pixels tall. It keeps its content and the rail scrolls instead. */
  .stance-detail {
    flex: none;
    min-height: 0;
    font-size: 0.74rem;
    line-height: 1.35;
  }

  /*
   * Touch targets, not mouse ones. The ladder keeps its upright desktop form
   * here, and its rungs come out at 27px — fine for a cursor, too small for a
   * thumb on the very device this layout exists for.
   */
  .rung,
  .work-btn,
  .realm-join,
  #btn-pass {
    min-height: 38px;
  }

  /*
   * The banner and the language/sound/help controls both want the top of the
   * map. Centred, the banner ran underneath them. It is pinned left with room
   * reserved on the right instead — the bottom is not free, the toast lives
   * there.
   */
  .turn-banner {
    left: 0.5rem;
    transform: none;
    max-width: calc(100% - 11rem);
    white-space: normal;
    font-size: 0.72rem;
    padding: 0.25rem 0.6rem;
  }
}

@media (max-width: 1080px) {
  .game-layout {
    grid-template-columns: 196px minmax(0, 1fr) 234px;
  }
}

/*
 * The stacked layout is for *narrow* screens, not merely small ones. Gated on
 * width alone it also caught a phone held sideways — 844 wide and 342 tall —
 * where stacking a map and three panels vertically has no chance. Landscape
 * keeps the columns and gets its own rule below.
 */
@media (max-width: 900px) and (orientation: portrait) {
  .home-grid {
    grid-template-columns: minmax(280px, 470px);
  }

  /*
   * A phone cannot hold three columns, and the previous attempt did not admit
   * it: the rails were capped at 32dvh and clipped with `overflow: hidden`, so
   * on a 390x664 screen the works panel, both work buttons and the pass button
   * sat below the fold with no way to reach them — you could not choose a tool
   * at all. The page scrolls instead. The canvas keeps `touch-action: none`, so
   * dragging a border still aims rather than scrolling the page away.
   */
  body {
    overflow: auto;
  }

  .game-layout {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    overflow: visible;
  }

  .sidebar {
    max-height: none;
    overflow: visible;
  }

  /*
   * Actions directly under the map, scores below them. On your turn the thing
   * you need is the ladder, not the standings — putting the scoreboard second
   * pushed every control below the fold and made acting a scroll away.
   */
  .arena-wrap {
    order: 0;
    min-height: 44dvh;
  }

  /*
   * The map is square, so on a portrait phone its *width* sets its height and
   * a min-height does nothing — it was 371px tall on a 390px screen and pushed
   * the works below the fold. Capping the height letterboxes it instead; the
   * renderer already scales to the smaller axis, so the realm stays a circle.
   */
  #arena {
    max-height: 42dvh;
  }

  /*
   * The banner shares the top of the map with the language, sound and help
   * controls, and on a phone there is not room for both — it was running
   * underneath them, half unreadable. It sits along the bottom of the map
   * instead, where nothing competes with it, and wraps rather than clipping.
   */
  .turn-banner {
    top: auto;
    bottom: 0.5rem;
    max-width: calc(100% - 1.2rem);
    white-space: normal;
    text-align: center;
    font-size: 0.8rem;
    padding: 0.35rem 0.7rem;
  }

  .sidebar.right {
    order: 1;
  }

  .sidebar.left {
    order: 2;
  }

  .feed-wrap {
    display: none;
  }

  /*
   * The ladder turns on its side and scrolls. `flex: none` is load-bearing:
   * as a shrinkable item in a column it collapsed to four pixels, leaving the
   * rungs spilling out of their own container and under the detail panel,
   * where a tap landed on the wrong element.
   */
  .ladder {
    flex: none;
    flex-direction: row;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 0.3rem;
    scrollbar-width: thin;
  }

  .rung {
    flex: 0 0 auto;
    width: auto;
    /* A comfortable thumb target rather than a mouse one. */
    min-height: 44px;
    padding: 0.3rem 0.55rem;
  }

  .rung .rung-name,
  .rung .cap {
    display: none;
  }

  .stance-detail {
    min-height: 0;
    font-size: 0.74rem;
    line-height: 1.35;
    padding-top: 0.35rem;
  }

  /* The blurb is flavour; on a phone the ability and the price are the point. */
  .stance-detail .blurb {
    display: none;
  }

  .resolve-next {
    min-height: 0;
  }

  /* The tiles already sit in a row; here they get thumb spacing and the
     heading gives up its rule to save a few pixels of height. */
  .works {
    gap: 0.4rem;
  }

  .works-head {
    margin-bottom: 0;
    font-size: 0.66rem;
    padding-bottom: 0.15rem;
    border-bottom: none;
  }

  #btn-pass {
    min-height: 44px;
    width: 100%;
  }

  /* The one control on the front page a stranger has to hit to get into a
     game; at its desktop size it comes out at 27px. */
  .realm-join {
    min-height: 44px;
    padding: 0.3rem 1.1rem;
  }

  .gesture {
    flex-direction: column;
    text-align: center;
  }
}
