:root {
  --paper: #fbf8ef;
  --panel: #ffffff;
  --ink: #1b1c1d;
  --muted: #676b70;
  --line: #d9d2c3;
  --teal: #147c7c;
  --teal-dark: #0e5f60;
  --coral: #d95d4e;
  --gold: #b78919;
  --green: #28724f;
  --red: #b73333;
  --shadow: 0 14px 32px rgba(27, 28, 29, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(251, 248, 239, 0.96), rgba(246, 241, 229, 0.96)),
    repeating-linear-gradient(90deg, rgba(20, 124, 124, 0.05) 0 1px, transparent 1px 42px);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  width: min(1420px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0 18px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  background: var(--gold);
  color: var(--ink);
  font-weight: 900;
  font-size: 1.45rem;
  box-shadow: 5px 5px 0 var(--ink);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 2.15rem;
  line-height: 1;
}

.score-strip {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: right;
}

.score-strip strong {
  color: var(--ink);
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.side-panel,
.stage {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.side-panel {
  position: sticky;
  top: 16px;
  padding: 14px;
}

.theme-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 8;
  object-fit: cover;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(20, 124, 124, 0.22), rgba(217, 93, 78, 0.18)),
    var(--paper);
  margin-bottom: 14px;
}

.deck-nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.nav-button:hover,
.nav-button:focus-visible,
.nav-button.active {
  border-color: var(--ink);
  outline: none;
  box-shadow: 3px 3px 0 var(--ink);
}

.nav-title {
  font-weight: 800;
}

.nav-count {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.stage {
  min-height: 680px;
  padding: 24px;
}

body.royal-game-active {
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 8%, rgba(183, 137, 25, 0.26), transparent 28%),
    radial-gradient(circle at 86% 16%, rgba(20, 124, 124, 0.22), transparent 30%),
    linear-gradient(135deg, #160f0a 0%, #2a1a14 46%, #0b1618 100%);
}

body.royal-game-active .app-shell {
  width: 100%;
  height: 100vh;
  margin: 0;
  padding: 0;
}

body.royal-game-active .topbar,
body.royal-game-active .side-panel {
  display: none;
}

body.royal-game-active .layout {
  display: block;
  height: 100vh;
}

body.royal-game-active .stage {
  height: 100vh;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

.dashboard {
  display: grid;
  gap: 22px;
}

.hero-panel {
  min-height: 260px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 24px;
  align-items: end;
  padding: 26px;
  border: 2px solid var(--ink);
  background:
    linear-gradient(130deg, rgba(20, 124, 124, 0.16), transparent 42%),
    linear-gradient(315deg, rgba(217, 93, 78, 0.16), transparent 38%),
    var(--paper);
}

.hero-panel h2 {
  max-width: 720px;
  margin: 0 0 10px;
  font-size: 2.45rem;
  line-height: 1.03;
}

.hero-panel p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.5;
}

.hero-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  min-height: 84px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--ink);
  background: var(--panel);
}

.stat strong {
  font-size: 1.6rem;
}

.stat span {
  color: var(--muted);
  font-size: 0.84rem;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.deck-card {
  min-height: 190px;
  display: grid;
  align-content: space-between;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.deck-card h3 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.deck-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.primary-button,
.secondary-button,
.answer-button,
.tiny-button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 9px 14px;
}

.primary-button:hover,
.primary-button:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible,
.answer-button:hover,
.answer-button:focus-visible,
.tiny-button:hover,
.tiny-button:focus-visible {
  outline: none;
  box-shadow: 3px 3px 0 var(--gold);
}

.secondary-button {
  background: var(--panel);
  color: var(--ink);
}

.tiny-button {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 0.84rem;
}

.quiz-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.quiz-head h2 {
  margin: 0 0 6px;
  font-size: 1.8rem;
}

.quiz-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.progress-meter {
  width: min(280px, 100%);
  display: grid;
  gap: 8px;
  text-align: right;
}

.meter-track {
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--ink);
  background: var(--paper);
}

.meter-fill {
  width: 0;
  height: 100%;
  background: var(--teal);
  transition: width 180ms ease;
}

.question-card {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 2px solid var(--ink);
  background: var(--panel);
}

.question-card h3 {
  margin: 0;
  font-size: 1.65rem;
  line-height: 1.22;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.answer-button {
  min-height: 68px;
  padding: 12px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  line-height: 1.28;
}

.answer-button[disabled] {
  cursor: default;
  opacity: 0.9;
}

.answer-button.correct {
  border-color: var(--green);
  background: rgba(40, 114, 79, 0.12);
}

.answer-button.wrong {
  border-color: var(--red);
  background: rgba(183, 51, 51, 0.1);
}

.feedback {
  display: none;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.feedback.show {
  display: grid;
}

.feedback strong.correct-text {
  color: var(--green);
}

.feedback strong.wrong-text {
  color: var(--red);
}

.feedback p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.media-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #f7f1e6;
}

.waveform {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--ink);
  background: var(--panel);
}

.waveform span {
  width: 8px;
  height: 20px;
  background: var(--teal);
  animation: pulse 900ms ease-in-out infinite alternate;
}

.waveform span:nth-child(2n) {
  background: var(--coral);
  animation-delay: 120ms;
}

.waveform span:nth-child(3n) {
  background: var(--gold);
  animation-delay: 240ms;
}

@keyframes pulse {
  from { height: 18px; }
  to { height: 64px; }
}

@keyframes royalBoardGlow {
  from {
    transform: translate3d(-1.5%, -1%, 0) rotate(0deg);
    opacity: 0.72;
  }

  to {
    transform: translate3d(1.5%, 1%, 0) rotate(2deg);
    opacity: 1;
  }
}

@keyframes royalSlotPulse {
  0%, 100% {
    box-shadow:
      4px 4px 0 rgba(27, 28, 29, 0.14),
      0 0 0 rgba(183, 137, 25, 0);
  }

  50% {
    box-shadow:
      4px 4px 0 rgba(27, 28, 29, 0.14),
      0 0 0 7px rgba(183, 137, 25, 0.24);
  }
}

@keyframes royalViewportPulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(46, 32, 22, 0.72), 0 0 14px rgba(183, 137, 25, 0.32); }
  50% { box-shadow: 0 0 0 1px rgba(46, 32, 22, 0.72), 0 0 22px rgba(183, 137, 25, 0.62); }
}

@keyframes royalLockReveal {
  0% {
    transform: translateY(8px) scale(0.96);
    filter: brightness(0.92) saturate(0.95);
    box-shadow: 4px 4px 0 rgba(27, 28, 29, 0.14);
  }

  34% {
    transform: translateY(-8px) scale(1.045);
    filter: brightness(1.12) saturate(1.12);
    box-shadow:
      0 0 0 4px rgba(246, 207, 102, 0.42),
      0 0 34px rgba(246, 207, 102, 0.72),
      0 18px 30px rgba(27, 28, 29, 0.22);
  }

  100% {
    transform: translateY(0) scale(1);
    filter: brightness(1);
    box-shadow:
      4px 4px 0 rgba(27, 28, 29, 0.14),
      0 0 0 rgba(246, 207, 102, 0);
  }
}

@keyframes royalSealPop {
  0% {
    opacity: 0;
    transform: translate(18px, -18px) rotate(18deg) scale(0.32);
  }

  24% {
    opacity: 1;
    transform: translate(0, 0) rotate(-8deg) scale(1.08);
  }

  72% {
    opacity: 1;
    transform: translate(0, 0) rotate(-8deg) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-6px, 6px) rotate(-8deg) scale(0.9);
  }
}

@keyframes royalBoardSweep {
  0% {
    opacity: 0;
    transform: translateX(-58%) skewX(-14deg);
  }

  30% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateX(58%) skewX(-14deg);
  }
}

@keyframes royalEraSlide {
  0%,
  4% {
    opacity: 0;
    transform: scale(1.05);
  }

  9%,
  17% {
    opacity: 0.32;
    transform: scale(1);
  }

  23%,
  100% {
    opacity: 0;
    transform: scale(1.02);
  }
}

audio {
  width: 100%;
}

.spotify-frame {
  width: 100%;
  height: 152px;
  border: 0;
}

.spotify-credit {
  color: var(--muted);
  font-size: 0.86rem;
}

.spotify-credit a {
  color: var(--teal-dark);
  font-weight: 800;
}

.spotify-actions,
.auth-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.spotify-status {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.playlist-panel {
  display: grid;
  gap: 10px;
}

.music-save-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.music-quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  justify-content: space-between;
}

.music-quick-row .field {
  width: 150px;
}

.music-quick-row span,
.music-preset-card small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.music-examples {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.music-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.music-editor summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 900;
}

.music-editor[open] summary {
  margin-bottom: 12px;
}

.music-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.music-preset-card {
  min-height: 186px;
  display: grid;
  gap: 12px;
  align-content: space-between;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.music-preset-card:hover,
.music-preset-card:focus-within {
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--gold);
}

.music-preset-card strong,
.music-preset-card small {
  display: block;
}

.music-preset-card p {
  margin: 6px 0 8px;
  line-height: 1.4;
}

.music-preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.music-examples p {
  margin: 4px 0 0;
  color: var(--muted);
}

.example-cloud {
  max-height: 220px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  overflow: auto;
  padding-right: 4px;
}

.example-chip {
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
}

.example-chip:hover,
.example-chip:focus-visible {
  border-color: var(--ink);
  outline: none;
  box-shadow: 2px 2px 0 var(--gold);
}

.saved-playlist-list {
  display: grid;
  gap: 8px;
}

.saved-playlist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.saved-playlist-row strong,
.saved-playlist-row small {
  display: block;
}

.saved-playlist-row small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.saved-playlist-actions {
  display: flex;
  gap: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px auto;
  gap: 10px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.field input,
.field textarea,
.field select,
.slot select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
}

.field textarea {
  min-height: 118px;
  resize: vertical;
  line-height: 1.35;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.slot select:focus {
  border-color: var(--ink);
  outline: 2px solid rgba(183, 137, 25, 0.35);
}

.notice {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--gold);
  background: rgba(183, 137, 25, 0.11);
  color: var(--ink);
  line-height: 1.45;
}

.notice code {
  background: rgba(255, 255, 255, 0.72);
  padding: 2px 5px;
  border: 1px solid var(--line);
}

.royal-game-shell .notice {
  min-width: 0;
  min-height: 0;
  align-content: center;
  padding: 10px 12px;
  border-color: rgba(183, 137, 25, 0.72);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 247, 211, 0.94), rgba(232, 214, 167, 0.82));
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.18),
    inset 0 0 0 1px rgba(255, 255, 255, 0.36);
  font-size: 0.86rem;
}

.chart-toolbar {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 440px);
  gap: 14px;
  align-items: stretch;
  margin-bottom: 0;
}

.section-tabs {
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 5px;
}

.section-tab {
  min-height: 38px;
  flex: 0 0 auto;
  display: grid;
  gap: 2px;
  align-content: center;
  padding: 7px 11px;
  border: 1px solid rgba(255, 245, 216, 0.34);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(226, 211, 172, 0.92));
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.section-tab small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.section-tab.locked {
  opacity: 0.54;
  cursor: not-allowed;
}

.section-tab.active,
.section-tab:hover,
.section-tab:focus-visible {
  border-color: var(--ink);
  outline: none;
  box-shadow: 3px 3px 0 var(--gold);
}

.royal-game-shell {
  position: relative;
  isolation: isolate;
  min-height: 720px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  margin: -6px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(183, 137, 25, 0.55);
  border-radius: 8px;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 243, 194, 0.22), transparent 28%),
    radial-gradient(circle at 92% 24%, rgba(95, 28, 45, 0.2), transparent 30%),
    url("/assets/royal-board-bg.svg") center / cover no-repeat,
    linear-gradient(145deg, #2b1b14, #0c181a 58%, #120d0a);
  box-shadow:
    inset 0 0 0 2px rgba(255, 245, 216, 0.18),
    inset 0 0 120px rgba(0, 0, 0, 0.36),
    0 24px 70px rgba(0, 0, 0, 0.25);
}

body.royal-game-active .royal-game-shell {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  margin: 0;
  padding: 10px;
  border: 0;
  border-radius: 0;
}

.royal-game-shell::before {
  content: "";
  position: absolute;
  inset: -30%;
  z-index: -1;
  background:
    radial-gradient(circle at 20% 18%, rgba(183, 137, 25, 0.28), transparent 30%),
    radial-gradient(circle at 86% 28%, rgba(20, 124, 124, 0.24), transparent 31%),
    radial-gradient(circle at 50% 102%, rgba(82, 27, 45, 0.34), transparent 36%);
  animation: royalBoardGlow 16s ease-in-out infinite alternate;
}

.royal-game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.44), transparent 13%, transparent 87%, rgba(0, 0, 0, 0.44)),
    linear-gradient(180deg, rgba(0, 0, 0, 0.32), transparent 16%, transparent 84%, rgba(0, 0, 0, 0.38));
}

.royal-game-shell > * {
  min-width: 0;
}

.royal-menu-shell {
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  gap: 18px;
  overflow: auto;
  color: #fff8df;
}

body.royal-game-active .royal-menu-shell {
  overflow: auto;
}

.royal-title-screen {
  min-height: 720px;
  display: grid;
  grid-template-rows: 1fr;
  align-content: stretch;
  place-items: center;
  padding: 28px;
}

body.royal-game-active .royal-title-screen {
  min-height: 100vh;
}

.royal-title-exit {
  position: absolute;
  left: 24px;
  top: 24px;
  z-index: 4;
}

.royal-era-slideshow {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.royal-era-slideshow::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 48%, transparent 0 28%, rgba(15, 12, 9, 0.36) 68%),
    linear-gradient(90deg, rgba(15, 12, 9, 0.42), transparent 24%, transparent 76%, rgba(15, 12, 9, 0.42));
}

.royal-era-slide {
  position: absolute;
  inset: -8%;
  display: grid;
  place-items: center;
  margin: 0;
  opacity: 0;
  animation: royalEraSlide calc(var(--slide-count) * 4s) infinite;
  animation-delay: calc(var(--slide-index) * 4s);
}

.royal-era-slide img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
  filter: blur(3px) saturate(0.88) contrast(1.05);
}

.royal-era-slide figcaption {
  position: absolute;
  left: 28px;
  bottom: 28px;
  max-width: 360px;
  color: rgba(255, 248, 223, 0.54);
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.royal-menu-modal {
  width: min(520px, calc(100vw - 48px));
  position: relative;
  z-index: 2;
  max-height: min(760px, calc(100vh - 72px));
  display: grid;
  gap: 18px;
  padding: 26px;
  overflow: auto;
  border: 2px solid rgba(255, 245, 216, 0.52);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.34), transparent 31%),
    linear-gradient(180deg, rgba(255, 250, 232, 0.98), rgba(224, 204, 150, 0.96));
  color: var(--ink);
  text-align: center;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.46),
    inset 0 0 0 2px rgba(255, 255, 255, 0.46);
}

.royal-menu-modal h2 {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 4.6rem);
  line-height: 0.95;
}

.royal-menu-modal h3 {
  margin: 0;
}

.royal-title-modal .eyebrow,
.royal-dynasty-modal .eyebrow,
.royal-pause-modal .eyebrow {
  margin-bottom: -8px;
}

.royal-main-actions {
  display: grid;
  gap: 10px;
  width: min(320px, 100%);
  justify-self: center;
}

.royal-main-actions .primary-button,
.royal-main-actions .secondary-button {
  min-height: 48px;
  font-size: 1rem;
}

.royal-load-panel {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid rgba(46, 32, 22, 0.2);
  text-align: left;
}

.royal-title-modal .royal-save-list,
.royal-pause-modal .royal-save-list {
  max-height: 250px;
}

.royal-dynasty-modal {
  width: min(1060px, calc(100vw - 48px));
  text-align: left;
}

.royal-dynasty-modal > .eyebrow,
.royal-dynasty-modal > h2 {
  text-align: center;
}

.royal-pause-modal {
  width: min(760px, calc(100vw - 48px));
}

.royal-menu-top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 245, 216, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.92), rgba(223, 205, 154, 0.86));
  color: var(--ink);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.24),
    inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.royal-menu-top h2,
.royal-menu-panel h3,
.royal-dynasty-card h3 {
  margin: 0;
}

.royal-menu-top h2 {
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1;
}

.royal-menu-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(270px, 420px) minmax(0, 1fr);
  gap: 16px;
}

.royal-menu-panel,
.royal-dynasty-card,
.royal-save-card {
  border: 1px solid rgba(255, 245, 216, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.96), rgba(224, 204, 150, 0.93));
  color: var(--ink);
  box-shadow:
    0 16px 38px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.48);
}

.royal-menu-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
  overflow: hidden;
}

.royal-command-panel {
  align-self: start;
}

.royal-command-panel h3 {
  font-size: 1.5rem;
  line-height: 1.08;
}

.royal-command-list {
  display: grid;
  gap: 10px;
}

.royal-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.royal-save-list {
  min-height: 0;
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 3px;
}

.royal-save-card {
  display: grid;
  gap: 9px;
  padding: 12px;
}

.royal-save-card.active {
  border-color: var(--gold);
  box-shadow:
    0 16px 38px rgba(0, 0, 0, 0.3),
    inset 0 0 0 2px rgba(183, 137, 25, 0.36);
}

.royal-save-card strong,
.royal-save-card span,
.royal-save-card small {
  display: block;
}

.royal-save-card span,
.royal-save-card small,
.royal-dynasty-card p,
.royal-dynasty-card small,
.royal-settings-panel span {
  color: var(--muted);
}

.royal-save-card small,
.royal-dynasty-card small {
  font-weight: 800;
  line-height: 1.3;
}

.royal-save-meter {
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(46, 32, 22, 0.24);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.72);
}

.royal-save-meter i {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.royal-save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.royal-empty-saves {
  padding: 16px;
  border: 1px dashed rgba(46, 32, 22, 0.36);
  background: rgba(255, 253, 248, 0.58);
  color: var(--muted);
  font-weight: 850;
  line-height: 1.35;
}

.royal-dynasty-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-content: start;
}

.royal-dynasty-card {
  min-height: 142px;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr) 190px;
  align-items: stretch;
  gap: 16px;
  padding: 12px;
}

.royal-dynasty-card h3 {
  margin-top: 8px;
  font-size: 1.1rem;
  line-height: 1.12;
}

.royal-dynasty-card p {
  margin: 8px 0;
  font-size: 0.88rem;
  line-height: 1.4;
}

.royal-dynasty-copy {
  min-width: 0;
  display: grid;
  align-content: center;
}

.royal-dynasty-image {
  min-height: 118px;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid rgba(46, 32, 22, 0.36);
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 255, 255, 0.32), transparent 32%),
    linear-gradient(145deg, #d9c17b, #6f5420);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.24);
}

.royal-dynasty-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
}

.royal-dynasty-image img[hidden],
.royal-dynasty-image .royal-image-fallback[hidden],
.royal-image-fallback[hidden] {
  display: none !important;
}

.royal-dynasty-image img.arms-image {
  width: 78%;
  height: 78%;
  margin: auto;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 10px 12px rgba(27, 28, 29, 0.26));
}

.royal-dynasty-placeholder {
  width: 76%;
  height: 76%;
  border-radius: 7px;
  border: 1px dashed rgba(46, 32, 22, 0.44);
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.66), rgba(103, 107, 112, 0.18)),
    rgba(255, 253, 248, 0.4);
}

.royal-dynasty-image span {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 5px 7px;
  border: 1px solid rgba(255, 245, 216, 0.3);
  border-radius: 5px;
  background: rgba(27, 28, 29, 0.68);
  color: #fff8df;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.12;
  text-align: center;
  text-transform: uppercase;
}

.royal-dynasty-card > .primary-button {
  align-self: center;
  min-height: 52px;
}

.royal-settings-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(46, 32, 22, 0.22);
  background: rgba(255, 253, 248, 0.58);
}

.royal-settings-panel strong,
.royal-settings-panel span {
  display: block;
}

.royal-play-status {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(128px, 180px);
  gap: 10px;
  align-items: stretch;
}

.royal-stage-status {
  display: grid;
  place-content: center;
  padding: 9px 12px;
  border: 1px solid rgba(255, 245, 216, 0.24);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.92), rgba(223, 205, 154, 0.86));
  color: var(--ink);
  text-align: center;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.18),
    inset 0 0 0 1px rgba(255, 255, 255, 0.36);
}

.royal-stage-status strong,
.royal-stage-status span {
  display: block;
}

.royal-stage-status span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.royal-top-hud {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(170px, 260px);
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid rgba(255, 245, 216, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.92), rgba(223, 205, 154, 0.86)),
    rgba(255, 253, 248, 0.88);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.24),
    inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.royal-title-block {
  min-width: 0;
}

.royal-title-block h2 {
  margin: 0 0 3px;
  font-size: 1.3rem;
  line-height: 1;
}

.royal-title-block p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.25;
}

.royal-exit-button {
  min-width: 46px;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 2px solid #24180f;
  border-radius: 8px;
  background:
    linear-gradient(145deg, #e2b64b, #b78919 62%, #705018);
  color: #21170f;
  font-size: 1.08rem;
  font-weight: 950;
  box-shadow: 0 5px 0 rgba(36, 24, 15, 0.35);
}

.royal-menu-button {
  width: auto;
  padding: 0 12px;
  font-size: 0.84rem;
  text-transform: uppercase;
}

.royal-exit-button:hover,
.royal-exit-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  box-shadow:
    0 7px 0 rgba(36, 24, 15, 0.3),
    0 0 0 3px rgba(255, 245, 216, 0.36);
}

.royal-builder {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.royal-card-hand {
  min-width: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  padding: 12px;
  border: 2px solid #2e2016;
  border-radius: 8px;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 255, 255, 0.36), transparent 28%),
    linear-gradient(180deg, rgba(255, 250, 232, 0.98), rgba(222, 196, 122, 0.96)),
    rgba(255, 253, 248, 0.94);
  box-shadow:
    0 15px 34px rgba(0, 0, 0, 0.32),
    inset 0 0 0 2px rgba(255, 255, 255, 0.55);
  overflow: hidden;
}

.royal-card-hand-head {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid rgba(82, 27, 45, 0.22);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.56);
}

.royal-card-hand-head strong {
  font-size: 1rem;
  line-height: 1.05;
}

.royal-card-hand-head span,
.royal-card small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.royal-card-list {
  min-width: 0;
  grid-column: 2;
  grid-row: 1 / span 2;
  display: flex;
  align-items: start;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px 4px 9px;
  scroll-snap-type: x proximity;
}

.royal-card-shell {
  width: 158px;
  flex: 0 0 158px;
  display: grid;
  gap: 6px;
  scroll-snap-align: start;
}

.royal-hand-meter {
  min-height: 30px;
  display: grid;
  place-items: center;
  padding: 6px 8px;
  border: 1px solid rgba(20, 124, 124, 0.28);
  border-radius: 5px;
  background: rgba(20, 124, 124, 0.1);
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
}

.royal-card {
  width: 100%;
  min-height: 190px;
  flex: none;
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 9px;
  border: 2px solid #2e2016;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.8), transparent 38%),
    linear-gradient(135deg, #fdf7e5, #e7d097 58%, #b78919);
  color: var(--ink);
  text-align: center;
  box-shadow:
    0 8px 0 rgba(46, 32, 22, 0.16),
    0 14px 24px rgba(27, 28, 29, 0.16),
    inset 0 0 0 2px rgba(255, 255, 255, 0.42);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.royal-card::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(82, 27, 45, 0.28);
  border-radius: 5px;
  pointer-events: none;
}

.royal-card::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 5px;
  background: linear-gradient(115deg, transparent 18%, rgba(255, 255, 255, 0.36) 44%, transparent 62%);
  opacity: 0;
  transform: translateX(-42%);
  transition: opacity 160ms ease, transform 220ms ease;
  pointer-events: none;
}

.royal-card:hover,
.royal-card:focus-visible,
.royal-card.active {
  border-color: #7b2d34;
  outline: none;
  transform: translateY(-6px);
  box-shadow:
    0 12px 0 rgba(46, 32, 22, 0.13),
    0 20px 34px rgba(27, 28, 29, 0.22),
    0 0 0 3px rgba(183, 137, 25, 0.28),
    inset 0 0 0 2px rgba(255, 255, 255, 0.52);
}

.royal-card:hover::after,
.royal-card:focus-visible::after,
.royal-card.active::after {
  opacity: 1;
  transform: translateX(42%);
}

.royal-card.dragging {
  opacity: 0.45;
}

.royal-card strong,
.royal-card small {
  display: block;
  line-height: 1.2;
}

.royal-card strong {
  margin-bottom: 4px;
  font-size: 0.92rem;
}

.royal-card-copy {
  min-height: 44px;
  display: grid;
  align-content: center;
  padding: 5px 6px;
  border-radius: 5px;
  background: rgba(255, 253, 248, 0.66);
}

.royal-card-details,
.slot-detail-list {
  display: grid;
  gap: 5px;
}

.royal-detail-select {
  display: grid;
  gap: 2px;
}

.royal-detail-select span {
  color: var(--teal-dark);
  font-size: 0.62rem;
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.royal-detail-select select {
  width: 100%;
  min-height: 27px;
  padding: 4px 7px;
  border: 1px solid rgba(46, 32, 22, 0.28);
  border-radius: 5px;
  background: rgba(255, 253, 248, 0.9);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
}

.royal-detail-select select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(183, 137, 25, 0.22);
}

.slot-detail-list {
  max-height: 142px;
  overflow: auto;
  padding-right: 2px;
}

.royal-card-empty {
  flex: 1;
  min-width: 260px;
  padding: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
  line-height: 1.35;
}

.card-portrait {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid #2e2016;
  border-radius: 6px;
  background: #f5efe3;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.42);
}

.card-portrait img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
}

.family-tree {
  min-width: 0;
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 0%, rgba(183, 137, 25, 0.18), transparent 42%),
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(238, 224, 185, 0.94)),
    #f6ecd2;
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.32),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5),
    inset 0 0 54px rgba(83, 32, 44, 0.14);
  cursor: grab;
  scrollbar-width: none;
  touch-action: none;
}

.family-tree::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.family-tree.is-panning {
  cursor: grabbing;
}

.royal-board-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
}

.royal-board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 24;
  pointer-events: none;
  background:
    linear-gradient(105deg, transparent 28%, rgba(255, 245, 190, 0.46) 46%, rgba(255, 255, 255, 0.34) 50%, transparent 66%);
  opacity: 0;
}

.royal-game-shell.lock-celebrating .royal-board-wrap::after {
  animation: royalBoardSweep 1050ms ease-out;
}

.royal-board-space {
  min-width: 100%;
  position: relative;
  min-height: 100%;
}

.royal-board-content {
  width: max-content;
  min-width: 100%;
  display: grid;
  gap: 10px;
  justify-items: stretch;
  padding: 20px;
  transform-origin: 0 0;
  will-change: transform;
}

.royal-board-controls {
  position: absolute;
  left: 18px;
  top: 18px;
  z-index: 22;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px;
  border: 1px solid rgba(36, 24, 15, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.96), rgba(221, 202, 150, 0.94));
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.24),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.royal-board-controls button,
.royal-board-controls output {
  min-width: 40px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(46, 32, 22, 0.72);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.88);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 950;
}

.royal-board-controls button:hover,
.royal-board-controls button:focus-visible {
  outline: none;
  background: #fff5ce;
  box-shadow: 0 0 0 3px rgba(183, 137, 25, 0.28);
}

.royal-minimap {
  width: 218px;
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 22;
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid rgba(36, 24, 15, 0.76);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.96), rgba(224, 204, 150, 0.93));
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.46);
}

.royal-minimap strong {
  color: #422819;
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.royal-minimap-map {
  height: 132px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(46, 32, 22, 0.68);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(247, 238, 210, 0.94), rgba(213, 191, 135, 0.9)),
    repeating-linear-gradient(0deg, rgba(46, 32, 22, 0.06) 0 1px, transparent 1px 12px);
  cursor: crosshair;
}

.royal-minimap-node {
  position: absolute;
  min-width: 2px;
  min-height: 2px;
  border: 1px solid rgba(46, 32, 22, 0.34);
  background: rgba(20, 124, 124, 0.55);
}

.royal-minimap-node.collateral {
  background: rgba(101, 80, 141, 0.62);
}

.royal-minimap-node.support {
  background: rgba(138, 106, 46, 0.58);
}

.royal-minimap-viewport {
  position: absolute;
  border: 2px solid #fff8df;
  border-radius: 4px;
  background: rgba(20, 124, 124, 0.16);
  box-shadow:
    0 0 0 1px rgba(46, 32, 22, 0.72),
    0 0 18px rgba(183, 137, 25, 0.5);
  animation: royalViewportPulse 1800ms ease-in-out infinite;
  pointer-events: none;
}

.royal-start-assist {
  width: min(440px, calc(100% - 36px));
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 26;
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 2px solid #2e2016;
  border-radius: 8px;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.44), transparent 32%),
    linear-gradient(180deg, rgba(255, 250, 232, 0.98), rgba(221, 199, 137, 0.97));
  box-shadow:
    0 20px 44px rgba(0, 0, 0, 0.38),
    inset 0 0 0 2px rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
}

.royal-start-assist h3,
.royal-start-assist p {
  margin: 0;
}

.royal-start-assist h3 {
  font-size: 1.2rem;
  line-height: 1.1;
}

.royal-start-assist p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.35;
}

.royal-start-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.royal-start-actions .primary-button {
  grid-column: 1 / -1;
}

.tree-house-label {
  width: 190px;
  margin: 0 auto 14px;
  text-align: center;
  color: var(--ink);
}

.tree-house-label span {
  display: block;
  color: var(--teal-dark);
  font-size: 0.86rem;
  font-weight: 900;
}

.tree-house-label strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
  line-height: 1.1;
}

.tree-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.tree-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  width: 30px;
  height: 0;
  border-top: 3px solid #476f72;
}

.legend-line.relationship-parent { border-color: #27777a; }
.legend-line.relationship-marriage { border-color: #b78919; border-top-width: 5px; border-top-style: double; }
.legend-line.relationship-sibling { border-color: #65508d; border-top-style: dashed; }
.legend-line.relationship-collateral { border-color: #245f9f; border-top-style: dashed; }
.legend-line.relationship-illegitimate { border-color: #b46d12; border-top-style: dotted; }
.legend-line.relationship-legitimised { border-color: #b46d12; border-top-style: dotted; box-shadow: inset 10px 0 0 #d6a928; }
.legend-line.relationship-disputed { border-color: #9a9da3; border-top-style: dotted; }

.tree-canvas {
  min-width: 760px;
  position: relative;
  padding: 8px 10px 14px;
}

.tree-layout-board {
  position: relative;
  z-index: 1;
  min-height: 540px;
  isolation: isolate;
}

.tree-link-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
}

.tree-link {
  fill: none;
  stroke: #27777a;
  stroke-width: 2.75px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tree-link-dot {
  fill: #476f72;
  stroke: none;
}

.tree-link-parent,
.tree-link-direct {
  stroke: #27777a;
}

.tree-link-parent.tree-link-dot,
.tree-link-direct.tree-link-dot {
  fill: #27777a;
}

.tree-link-marriage {
  stroke: #b78919;
  stroke-width: 5px;
}

.tree-link-marriage.tree-link-dot {
  fill: #b78919;
}

.tree-link-sibling,
.tree-link-collateral {
  stroke: #65508d;
  stroke-dasharray: 7 7;
}

.tree-link-sibling.tree-link-dot,
.tree-link-collateral.tree-link-dot {
  fill: #65508d;
}

.tree-link-collateral {
  stroke: #245f9f;
  stroke-dasharray: 12 7;
}

.tree-link-collateral.tree-link-dot {
  fill: #245f9f;
}

.tree-link-illegitimate,
.tree-link-legitimised,
.tree-link-support {
  stroke: #b46d12;
  stroke-dasharray: 2 7;
}

.tree-link-illegitimate.tree-link-dot,
.tree-link-legitimised.tree-link-dot,
.tree-link-support.tree-link-dot {
  fill: #b46d12;
}

.tree-link-legitimised {
  stroke-width: 3.4px;
  filter: drop-shadow(0 0 2px rgba(214, 169, 40, 0.7));
}

.tree-link-disputed {
  stroke: #9a9da3;
  stroke-dasharray: 1 8;
  opacity: 0.82;
}

.tree-link-disputed.tree-link-dot {
  fill: #9a9da3;
}

.tree-link-partner {
  stroke-width: 3.25px;
}

.tree-link-label {
  pointer-events: auto;
  transition: opacity 160ms ease;
}

.tree-link-label rect {
  fill: rgba(255, 253, 248, 0.95);
  stroke: rgba(46, 32, 22, 0.34);
  stroke-width: 1;
}

.tree-link-label text {
  fill: #2e2016;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.line-labels-hidden .tree-link-label {
  opacity: 0;
}

.tree-chart {
  position: relative;
  z-index: 1;
  min-width: calc(var(--tree-max-columns) * 240px);
  display: grid;
  justify-items: center;
  gap: 36px;
}

.tree-generation {
  width: 100%;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--tree-columns), minmax(190px, 230px));
  justify-content: center;
  justify-items: center;
  gap: 28px;
}

.tree-row-label {
  position: absolute;
  top: -20px;
  left: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.tree-generation-label {
  position: absolute;
  left: 0;
  z-index: 4;
  width: 136px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: rgba(251, 248, 239, 0.94);
  color: var(--teal-dark);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.18;
  text-transform: uppercase;
}

.tree-generation-rule {
  position: absolute;
  left: 150px;
  right: 0;
  z-index: 2;
  border-top: 1px solid rgba(103, 107, 112, 0.18);
}

.tree-generation-band {
  position: absolute;
  left: 150px;
  right: 0;
  z-index: 0;
  background: rgba(251, 248, 239, 0.58);
  border-top: 1px solid rgba(217, 210, 195, 0.58);
  border-bottom: 1px solid rgba(217, 210, 195, 0.58);
}

.branch-generation {
  margin-top: 0;
}

.slot {
  min-height: 236px;
  display: grid;
  gap: 9px;
  align-content: start;
  padding: 10px;
  border: 1px solid #1b1c1d;
  background: #ffffff;
}

.tree-node {
  width: 100%;
  position: relative;
  box-shadow: 4px 4px 0 rgba(27, 28, 29, 0.14);
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.tree-node-positioned {
  position: absolute;
  z-index: 3;
  overflow: hidden;
}

.tree-node:not(.correct) {
  cursor: pointer;
}

.tree-node.drop-target {
  outline: 3px solid rgba(183, 137, 25, 0.65);
  outline-offset: 4px;
  background: #fff9e8;
  animation: royalSlotPulse 900ms ease-in-out infinite;
}

.tree-node.placed {
  border-color: var(--gold);
  background: rgba(183, 137, 25, 0.08);
}

.tree-node.newly-locked {
  z-index: 6;
  border-color: #b78919;
  animation: royalLockReveal 1450ms cubic-bezier(0.18, 0.88, 0.22, 1);
}

.tree-node.newly-locked::after {
  content: "";
  width: 54px;
  height: 54px;
  position: absolute;
  right: -13px;
  top: -16px;
  z-index: 7;
  border: 3px double rgba(46, 32, 22, 0.86);
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.65) 0 16%, transparent 17%),
    radial-gradient(circle at 50% 50%, #f6cf66 0 46%, #b78919 47% 70%, #6f5420 71%);
  box-shadow:
    0 9px 18px rgba(46, 32, 22, 0.28),
    inset 0 0 0 3px rgba(255, 255, 255, 0.32);
  animation: royalSealPop 1450ms ease-out both;
}

.tree-node.line-collateral {
  border-color: #65508d;
}

.tree-node.line-support {
  border-style: dashed;
  border-color: #8a6a2e;
}

.tree-connector {
  width: min(72%, 640px);
  height: 58px;
  position: relative;
  display: grid;
  place-items: center;
}

.tree-connector::before {
  content: "";
  width: 4px;
  height: 100%;
  display: block;
  background: #d01919;
}

.tree-connector.branch-connector::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  height: 4px;
  background: #d01919;
}

.tree-connector span {
  content: "";
  position: absolute;
  left: calc(50% + 14px);
  top: 50%;
  width: 150px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: left;
  transform: translateY(-50%);
}

.monarch-card-top {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.monarch-portrait {
  width: 64px;
  aspect-ratio: 1;
  overflow: hidden;
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid #1b1c1d;
  background:
    linear-gradient(135deg, rgba(183, 137, 25, 0.18), rgba(20, 124, 124, 0.12)),
    #f5efe3;
  color: var(--ink);
  font-weight: 900;
  font-size: 1.1rem;
}

.portrait-missing {
  background:
    linear-gradient(135deg, rgba(103, 107, 112, 0.12), rgba(20, 124, 124, 0.08)),
    #f8f5ee;
}

.portrait-arms {
  background:
    radial-gradient(circle at 50% 26%, rgba(255, 255, 255, 0.82), transparent 34%),
    linear-gradient(145deg, #f7eed2, #d8bf72 62%, #7a5720);
}

.royal-image-fallback {
  width: 100%;
  height: 100%;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.royal-image-fallback > i {
  width: 34%;
  aspect-ratio: 1;
  position: relative;
  display: block;
  border: 2px solid rgba(46, 32, 22, 0.36);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.56);
}

.royal-image-fallback > i::after {
  content: "";
  width: 165%;
  height: 82%;
  position: absolute;
  left: 50%;
  top: 112%;
  transform: translateX(-50%);
  border: 2px solid rgba(46, 32, 22, 0.32);
  border-radius: 999px 999px 0 0;
  background: rgba(255, 253, 248, 0.42);
}

.portrait-real .portrait-fallback,
.portrait-arms .portrait-fallback {
  background:
    linear-gradient(135deg, rgba(103, 107, 112, 0.12), rgba(20, 124, 124, 0.08)),
    #f8f5ee;
}

.portrait-fallback[hidden] {
  display: none !important;
}

.gender-badge {
  width: 24px;
  height: 24px;
  position: absolute;
  right: 5px;
  bottom: 5px;
  display: grid;
  place-items: center;
  border: 1px solid #2e2016;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.92);
  color: #2e2016;
  font-size: 0.88rem;
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 3px 8px rgba(27, 28, 29, 0.22);
}

.card-portrait .gender-badge {
  width: 30px;
  height: 30px;
  right: 7px;
  bottom: 7px;
  font-size: 1.06rem;
}

.gender-badge.gender-female::before {
  content: "\2640";
}

.gender-badge.gender-male::before {
  content: "\2642";
}

.gender-badge.gender-unknown::before {
  content: "\25C6";
  font-size: 0.68rem;
}

.monarch-portrait-empty {
  background:
    linear-gradient(135deg, rgba(103, 107, 112, 0.08), rgba(20, 124, 124, 0.06)),
    #f8f5ee;
}

.monarch-portrait-empty span {
  width: 34px;
  height: 34px;
  border: 1px dashed rgba(103, 107, 112, 0.54);
  background: rgba(255, 255, 255, 0.45);
}

.monarch-portrait img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
}

.monarch-portrait img.arms-image {
  width: 88%;
  height: 88%;
  margin: auto;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 5px 5px rgba(27, 28, 29, 0.24));
}

.card-portrait img.arms-image {
  width: 90%;
  height: 90%;
}

.portrait-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.slot.correct {
  border-color: var(--green);
  background: rgba(40, 114, 79, 0.09);
}

.slot.wrong {
  border-color: var(--red);
  background: rgba(183, 51, 51, 0.08);
}

.slot-kicker {
  color: var(--teal-dark);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.line-badge {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 5px;
  border: 1px solid var(--line);
  background: rgba(20, 124, 124, 0.08);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.slot p {
  margin: 0;
  color: var(--muted);
  line-height: 1.38;
  font-size: 0.82rem;
}

.slot-hidden {
  color: rgba(103, 107, 112, 0.72);
  font-style: italic;
}

.slot strong {
  display: block;
  line-height: 1.25;
}

.slot-clear-button {
  justify-self: start;
  align-self: end;
  margin-top: 2px;
  background: var(--panel);
  color: var(--ink);
}

.royal-game-bottom-hud {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 330px);
  gap: 10px;
  align-items: stretch;
}

.chart-actions {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 0;
  align-items: center;
  padding: 12px;
  border: 2px solid #2e2016;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.97), rgba(227, 209, 160, 0.94));
  box-shadow:
    0 15px 34px rgba(0, 0, 0, 0.28),
    inset 0 0 0 2px rgba(255, 255, 255, 0.46);
}

.chart-batch-status {
  min-height: 42px;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-weight: 850;
  line-height: 1.35;
}

.royal-check-panel {
  grid-template-columns: 1fr;
  align-content: stretch;
}

.royal-check-panel .primary-button {
  min-height: 58px;
  font-size: 1.04rem;
}

.complete-panel {
  display: grid;
  gap: 16px;
  padding: 26px;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.complete-panel h2 {
  margin: 0;
  font-size: 2rem;
}

.complete-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.country-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.country-visual {
  min-height: 430px;
  display: grid;
  place-items: center;
  padding: 16px;
  border: 2px solid var(--ink);
  background:
    linear-gradient(180deg, rgba(20, 124, 124, 0.08), rgba(183, 137, 25, 0.08)),
    var(--paper);
}

.map-shell {
  width: 100%;
  max-width: 900px;
  position: relative;
}

.map-controls {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: flex;
  gap: 6px;
}

.map-controls .tiny-button {
  min-width: 36px;
  background: var(--panel);
  color: var(--ink);
}

.world-map {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.world-map.dragging {
  cursor: grabbing;
}

.world-map path {
  fill: #d8d1c2;
  stroke: #ffffff;
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
}

.world-map path.target {
  fill: var(--coral);
  stroke: var(--ink);
  stroke-width: 1.4;
}

.flag-display {
  width: min(520px, 100%);
  display: grid;
  gap: 14px;
  justify-items: center;
}

.flag-display img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border: 1px solid var(--ink);
  background: #fff;
  box-shadow: 6px 6px 0 var(--ink);
}

.flag-fallback {
  width: min(520px, 100%);
  min-height: 220px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.anthem-display {
  width: min(620px, 100%);
  display: grid;
  gap: 12px;
}

.country-panel {
  display: grid;
  gap: 12px;
}

.country-search {
  position: sticky;
  top: 12px;
  z-index: 2;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.country-search input,
.country-search select {
  min-height: 42px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
}

.country-give-up {
  width: 100%;
  justify-content: center;
}

.choice-list {
  max-height: 470px;
  display: grid;
  gap: 6px;
  overflow: auto;
  padding-right: 4px;
}

.country-group {
  display: grid;
  gap: 6px;
  padding-bottom: 8px;
}

.country-group > strong {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--teal-dark);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.country-option {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.country-option:hover,
.country-option:focus-visible {
  border-color: var(--ink);
  outline: none;
  box-shadow: 2px 2px 0 var(--gold);
}

.country-option small {
  color: var(--muted);
  white-space: nowrap;
}

.country-option[disabled],
.country-give-up[disabled] {
  cursor: default;
  opacity: 0.55;
}

.country-feedback {
  display: grid;
  gap: 8px;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.country-feedback strong.ok {
  color: var(--green);
}

.country-feedback strong.no {
  color: var(--red);
}

.loading {
  display: grid;
  gap: 16px;
  place-items: center;
  min-height: 420px;
  text-align: center;
}

.loader-bars {
  display: flex;
  gap: 7px;
  height: 68px;
  align-items: end;
}

.loader-bars span {
  width: 12px;
  min-height: 16px;
  background: var(--teal);
  animation: pulse 700ms ease-in-out infinite alternate;
}

.loader-bars span:nth-child(2) {
  background: var(--coral);
  animation-delay: 90ms;
}

.loader-bars span:nth-child(3) {
  background: var(--gold);
  animation-delay: 180ms;
}

.loader-bars span:nth-child(4) {
  background: var(--green);
  animation-delay: 270ms;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }

  .theme-image {
    display: none;
  }

  .deck-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-panel {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .music-save-row,
  .saved-playlist-row {
    grid-template-columns: 1fr;
  }

  .saved-playlist-actions {
    justify-content: flex-start;
  }

  .country-layout {
    grid-template-columns: 1fr;
  }

  .country-search {
    position: static;
  }

  .royal-menu-layout {
    grid-template-columns: 1fr;
  }

  .royal-top-hud {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .royal-top-hud .progress-meter {
    grid-column: 1 / -1;
  }

  .chart-toolbar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .royal-builder {
    grid-template-columns: 1fr;
  }

  .royal-game-bottom-hud {
    grid-template-columns: 1fr;
  }

  .royal-card-hand {
    grid-template-columns: 118px minmax(0, 1fr);
    max-height: none;
  }

  .royal-card-list {
    display: flex;
    grid-column: 2;
    grid-row: 1 / span 2;
    grid-template-columns: none;
  }

  .chart-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  body.royal-game-active {
    height: auto;
    min-height: 100vh;
    overflow: auto;
    overflow-x: hidden;
  }

  body.royal-game-active .app-shell,
  body.royal-game-active .layout {
    height: auto;
    min-height: 100vh;
  }

  body.royal-game-active .stage {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    overflow-x: hidden;
  }

  body.royal-game-active .royal-game-shell {
    width: 100%;
    max-width: 100vw;
    height: auto;
    overflow: visible;
    overflow-x: hidden;
    padding: 6px;
  }

  .royal-game-shell {
    margin: -8px;
    padding: 10px;
    gap: 7px;
    min-height: auto;
    grid-template-rows: auto auto 390px auto;
  }

  .royal-menu-shell {
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    min-height: 100vh;
  }

  .royal-menu-top {
    padding: 7px;
  }

  .royal-menu-top h2 {
    font-size: 1.25rem;
  }

  .royal-dynasty-grid {
    grid-template-columns: 1fr;
  }

  .royal-dynasty-card {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .royal-dynasty-image {
    min-height: 150px;
  }

  .royal-menu-panel {
    padding: 12px;
  }

  .royal-top-hud {
    grid-template-columns: auto minmax(0, 1fr);
    padding: 7px;
  }

  .royal-title-block h2 {
    font-size: 1rem;
  }

  .royal-title-block p:last-child {
    display: none;
  }

  .royal-exit-button {
    min-width: 38px;
    width: 38px;
    height: 38px;
  }

  .royal-menu-button {
    width: auto;
    padding: 0 9px;
    font-size: 0.74rem;
  }

  .section-tab {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 0.78rem;
  }

  .royal-game-shell .notice {
    padding: 8px 10px;
    font-size: 0.78rem;
  }

  .royal-play-status {
    grid-template-columns: 1fr;
  }

  .royal-stage-status {
    display: none;
  }

  .family-tree {
    height: 390px;
    min-height: 390px;
    padding: 0;
  }

  .royal-board-content {
    padding: 14px;
  }

  .royal-board-controls {
    left: 10px;
    top: 10px;
  }

  .royal-board-controls button,
  .royal-board-controls output {
    min-width: 34px;
    height: 32px;
    font-size: 0.76rem;
  }

  .royal-minimap {
    width: 150px;
    right: 10px;
    top: 10px;
    padding: 7px;
  }

  .royal-minimap-map {
    height: 92px;
  }

  .tree-canvas {
    min-width: 720px;
    padding: 4px 10px 10px;
  }

  .tree-chart {
    min-width: calc(var(--tree-max-columns) * 190px);
    gap: 30px;
  }

  .tree-generation {
    width: 100%;
    grid-template-columns: repeat(var(--tree-columns), minmax(160px, 190px));
    gap: 18px;
  }

  .tree-node {
    width: 100%;
    min-height: 0;
  }

  .tree-node-positioned {
    width: 198px;
  }

  .tree-connector {
    width: min(80%, 520px);
    height: 48px;
  }

  .tree-connector span {
    left: calc(50% + 12px);
    top: 50%;
    width: 130px;
    text-align: left;
    transform: translateY(-50%);
  }

  .monarch-card-top {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .monarch-portrait {
    width: 52px;
  }

  .royal-card-hand {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
    min-height: 270px;
    overflow: visible;
  }

  .royal-card-shell {
    width: 118px;
    flex-basis: 118px;
  }

  .royal-card-list {
    display: flex;
    grid-column: 1;
    grid-row: auto;
    grid-template-columns: none;
    min-height: 218px;
    overflow-x: auto;
    overflow-y: visible;
  }

  .royal-card {
    width: 118px;
    min-height: 172px;
    flex-basis: 118px;
    gap: 6px;
    padding: 6px;
  }

  .royal-card strong {
    font-size: 0.78rem;
  }

  .royal-card small {
    font-size: 0.66rem;
  }

  .royal-card-copy {
    min-height: 46px;
    padding: 4px;
  }

  .card-portrait .gender-badge {
    width: 24px;
    height: 24px;
    font-size: 0.88rem;
  }

  .chart-actions {
    padding: 8px;
  }

  .royal-check-panel .primary-button {
    min-height: 46px;
  }

  .royal-start-assist {
    top: 54%;
    padding: 12px;
  }

  .royal-start-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .royal-game-shell::before,
  .royal-game-shell.lock-celebrating .royal-board-wrap::after,
  .royal-era-slide,
  .royal-minimap-viewport,
  .tree-node.newly-locked,
  .tree-node.newly-locked::after,
  .tree-node.drop-target,
  .loader-bars span,
  .waveform span {
    animation: none;
  }

  .royal-card,
  .royal-card::after,
  .royal-exit-button {
    transition: none;
  }

  .royal-era-slide:first-child {
    opacity: 0.28;
    transform: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 1420px);
    padding-top: 10px;
  }

  .topbar,
  .quiz-head {
    display: grid;
  }

  .score-strip,
  .progress-meter {
    text-align: left;
  }

  .stage {
    min-height: 560px;
    padding: 14px;
  }

  .deck-nav,
  .deck-grid,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .hero-panel {
    min-height: 0;
    padding: 18px;
  }

  .hero-panel h2 {
    font-size: 1.75rem;
  }

  .question-card {
    padding: 16px;
  }
}
