/* ===== webfont: Cabin, a variable sans (weight 400-700, width 75-100) */
@font-face {
  font-family: "Cabin";
  src: url("../data/ui/fonts/cabin.woff2") format("woff2-variations"),
    url("../data/ui/fonts/cabin.woff2") format("woff2");
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-style: normal;
  font-display: swap;
}

/* ===== typewriter faces: Courier Prime for text, Special Elite for names */
@font-face {
  font-family: "Courier Prime";
  src: url("../data/ui/fonts/courierprime-400i-latin-ext.woff2") format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Courier Prime";
  src: url("../data/ui/fonts/courierprime-400i-latin.woff2") format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Courier Prime";
  src: url("../data/ui/fonts/courierprime-400-latin-ext.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Courier Prime";
  src: url("../data/ui/fonts/courierprime-400-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Courier Prime";
  src: url("../data/ui/fonts/courierprime-700-latin-ext.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Courier Prime";
  src: url("../data/ui/fonts/courierprime-700-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Special Elite";
  src: url("../data/ui/fonts/specialelite-400-latin-ext.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Special Elite";
  src: url("../data/ui/fonts/specialelite-400-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ===== palette: manila, paper, and black, red and green inks */
:root {
  --manila: #c7aa6c;
  --manila-lo: #b4975b;
  --manila-edge: #7d6235;
  --sheet: #d9cba8;
  --sheet-lo: #cfc09c;

  --ink: #221e18;
  --ink-2: #4d4538;
  /* Ink for labels and unfilled blanks. */
  --ink-3: #7d725f;
  --ruled: #a48f66;
  --ribbon: #9b2a1f;
  /* Ink for bonuses. */
  --good: #2f6b2f;
  --text-dim: var(--ink-3);

  /* Typewriter key rim and cap. */
  --key-rim: #9a927f;
  --key-cap: radial-gradient(circle at 50% 32%, #4a4237, #17130f 68%);

  /* Key edge shadows at rest, hovered and pressed. */
  --key-edge: 0 0 0 1px #2f2a22, 0 3px 0 #2f2a22, inset 0 1px 0 rgba(255, 255, 255, .18);
  --key-edge-hover: 0 0 0 1px #2f2a22, 0 1px 0 #2f2a22, inset 0 1px 0 rgba(255, 255, 255, .18);
  --key-edge-down: 0 0 0 1px #2f2a22, inset 0 2px 4px rgba(0, 0, 0, .75);
  --key-hover-drop: 2px;
  --key-down-drop: 3px;
  --key-cap-down: radial-gradient(circle at 50% 70%, #2a241c, #100d0a 72%);
  --key-rim-down: #7d7667;
  --key-legend-down: #ab9f80;

  /* Ring round the selected province on the map. */
  --gold: #cea35e;

  /* Ground behind the map and the start-screen photograph. */
  --steel-deepest: #0c1015;

  /* Overhang of the start-screen photograph for parallax drift. */
  --parallax-slack: 40px;

  /* Time the loading-screen quote and prompt finish arriving. */
  --loading-settle: 1.45s;

  --shadow: 0 2px 10px rgba(0, 0, 0, .55);
  --bevel: inset 0 1px 0 rgba(255, 255, 255, .06), inset 0 -1px 0 rgba(0, 0, 0, .35);

  /* ----- typeface: Courier Prime for text, Special Elite for large names */
  --type: "Courier Prime", "Courier New", monospace;
  --stamp: "Special Elite", "Courier Prime", "Courier New", monospace;

  /* Cabin, used for the resource layer's lettering. */
  --ui: Cabin, "Segoe UI", sans-serif;
  --ui-narrow: var(--ui);

  /* Plain sans for map lettering and the debug menu. */
  --ui-plain: "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

/* ===== texture: per-box photographed grain overlay, sized in pixels */
:root {
  --texture-img: url('../data/ui/texture-tile.png');

  /* Drawn width of the texture tile; sets grain size. */
  --texture-size: 940px;
  /* Blend strength of the texture overlay. */
  --texture-strength: .5;
}

/* Texture overlay behind content, pinned to the host's top-left corner. */
#toolbar::before,
#tooltip::after,
#card::after,
#county-card::after,
#diplo::after,
#toolbar button::after,
.dialog-panel::after,
#start-enter::after,
#pause-resume::after,
.start-secondary::after,
.start-panel p::after,
.quote-paper::after,
#infra-list::after,
#clock-face::after,
.diplo-sheet::after,
.pause-body::after,
.folder-tab::after,
#hud-flag-strip::after,
#hud-values::after,
#hud-menu::after,
.hud-value::after,
#toolbar #modes::after,
.choose-major::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: var(--tex-span, 600px);
  height: var(--tex-span, 600px);
  transform: translate(-50%, -50%) rotate(var(--tex-turn, 0deg));
  background: var(--texture-img) var(--tex-at, 0 0) / var(--texture-size) auto repeat;
  mix-blend-mode: soft-light;
  opacity: var(--texture-strength);
  pointer-events: none;
  z-index: -1;
}

/* Hosts clip and isolate their overlay. */
#toolbar,
#tooltip,
#card,
#county-card,
#diplo,
#toolbar button,
.dialog-panel,
#start-enter,
#pause-resume,
.start-secondary,
.start-panel p,
.quote-paper,
#infra-list,
#clock-face,
.diplo-sheet,
.pause-body,
.folder-tab,
#hud-flag-strip,
#hud-values,
#hud-menu,
.hud-value,
#toolbar #modes,
.choose-major {
  isolation: isolate;
  overflow: hidden;
}

/* Overlay hosts positioned as its containing block. */
#toolbar,
#toolbar button,
.dialog-panel,
#start-enter,
#clock-face,
.diplo-sheet,
.pause-body,
#hud-flag-strip,
#hud-values,
#hud-menu,
.hud-value,
.choose-major {
  position: relative;
}

/* Boxes whose crop and turn are drawn at random. */
#hud-flag-strip,
#hud-values,
#hud-menu,
#toolbar #modes { --tex-span: 3000px; }

.hud-value,
.choose-major { --tex-span: 900px; }

/* Toolbar keys carry no grain. */
#toolbar button::after {
  opacity: 0;
}

/* --- per-box texture rotation and crop offset */
#toolbar {
  --tex-span: 8000px;
  --tex-turn: 7deg;
  --tex-at: -210px -40px;
}

#start-enter {
  --tex-span: 560px;
  --tex-turn: 204deg;
  --tex-at: -150px -120px;
}

.dialog-panel {
  --tex-span: 1600px;
  --tex-turn: 61deg;
  --tex-at: -420px -180px;
}

#tooltip {
  --tex-span: 760px;
  --tex-turn: 271deg;
  --tex-at: -320px -145px;
}

/* Texture crops for the map mode keys. */
#modes>button:nth-of-type(1) {
  --tex-span: 380px;
  --tex-turn: 27deg;
  --tex-at: -30px -190px;
}

#modes>button:nth-of-type(2) {
  --tex-span: 380px;
  --tex-turn: 143deg;
  --tex-at: -260px -70px;
}

#modes>button:nth-of-type(3) {
  --tex-span: 380px;
  --tex-turn: 236deg;
  --tex-at: -120px -330px;
}

#modes>button:nth-of-type(4) {
  --tex-span: 380px;
  --tex-turn: 311deg;
  --tex-at: -340px -20px;
}

#modes>button:nth-of-type(5) {
  --tex-span: 380px;
  --tex-turn: 198deg;
  --tex-at: -215px -285px;
}

#modes>button:nth-of-type(6) {
  --tex-span: 380px;
  --tex-turn: 76deg;
  --tex-at: -55px -365px;
}

#modes>button:nth-of-type(7) {
  --tex-span: 380px;
  --tex-turn: 59deg;
  --tex-at: -165px -235px;
}

#infra-list {
  --tex-span: 800px;
  --tex-turn: 187deg;
  --tex-at: -240px -110px;
}

#clock-face {
  --tex-span: 600px;
  --tex-turn: 118deg;
  --tex-at: -60px -300px;
}

/* Texture crops for the start-screen slips, note and quote card. */
.start-secondary {
  --tex-span: 520px;
}

.start-buttons .start-secondary:nth-child(2) {
  --tex-turn: 98deg;
  --tex-at: -95px -300px;
}

.start-buttons .start-secondary:nth-child(3) {
  --tex-turn: 12deg;
  --tex-at: -180px -85px;
}

.start-buttons .start-secondary:nth-child(4) {
  --tex-turn: 219deg;
  --tex-at: -355px -120px;
}

.start-buttons .start-secondary:nth-child(5) {
  --tex-turn: 143deg;
  --tex-at: -240px -210px;
}

.start-panel p {
  --tex-span: 1100px;
  --tex-turn: 167deg;
  --tex-at: -300px -160px;
}

.quote-paper {
  --tex-span: 1600px;
  --tex-turn: 63deg;
  --tex-at: -310px -210px;
}

/* Texture crops for the pause folder parts. */
.folder-tab {
  --tex-span: 400px;
  --tex-turn: 236deg;
  --tex-at: -120px -330px;
}

#pause .pause-board {
  --tex-span: 1400px;
  --tex-turn: 96deg;
  --tex-at: -270px -330px;
}

.pause-body {
  --tex-span: 1300px;
  --tex-turn: 304deg;
  --tex-at: -250px -35px;
}

#pause-resume {
  --tex-span: 820px;
  --tex-turn: 27deg;
  --tex-at: -30px -190px;
}

.pause-body .start-secondary:nth-of-type(2) {
  --tex-turn: 271deg;
  --tex-at: -320px -145px;
}

.pause-body .start-secondary:nth-of-type(3) {
  --tex-turn: 143deg;
  --tex-at: -340px -20px;
}

/* Texture crops for the layer menu rows. */
#infra-list button:nth-child(1) {
  --tex-span: 380px;
  --tex-turn: 12deg;
  --tex-at: -180px -85px;
}
#infra-list button:nth-child(2) {
  --tex-span: 380px;
  --tex-turn: 98deg;
  --tex-at: -95px -300px;
}
#infra-list button:nth-child(3) {
  --tex-span: 380px;
  --tex-turn: 167deg;
  --tex-at: -300px -160px;
}
#infra-list button:nth-child(4) {
  --tex-span: 380px;
  --tex-turn: 251deg;
  --tex-at: -40px -245px;
}
#infra-list button:nth-child(5) {
  --tex-span: 380px;
  --tex-turn: 304deg;
  --tex-at: -250px -35px;
}
#infra-list button:nth-child(6) {
  --tex-span: 380px;
  --tex-turn: 41deg;
  --tex-at: -140px -390px;
}
#infra-list button:nth-child(7) {
  --tex-span: 380px;
  --tex-turn: 219deg;
  --tex-at: -355px -120px;
}
#infra-list button:nth-child(8) {
  --tex-span: 380px;
  --tex-turn: 134deg;
  --tex-at: -70px -155px;
}
#infra-list button:nth-child(9) {
  --tex-span: 380px;
  --tex-turn: 281deg;
  --tex-at: -230px -340px;
}

#zoom-group button:nth-of-type(1) {
  --tex-span: 380px;
  --tex-turn: 84deg;
  --tex-at: -390px -240px;
}

#zoom-group button:nth-of-type(2) {
  --tex-span: 380px;
  --tex-turn: 168deg;
  --tex-at: -75px -410px;
}

#zoom-group button:nth-of-type(3) {
  --tex-span: 380px;
  --tex-turn: 253deg;
  --tex-at: -280px -160px;
}

body {
  margin: 0;
  background: var(--steel-deepest);
  color: var(--ink);
  font: calc(14px / var(--text-k, 1))/1.5 var(--type);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== drifting backdrop: artwork behind the loading and start screens */
#loading::before,
#start::before {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--parallax-slack));
  z-index: -1;
  pointer-events: none;
  background: url('../data/img/ui/start_menu_bg.jpg') center / cover no-repeat;
  transform: translate3d(var(--parallax-x, 0px), var(--parallax-y, 0px), 0);
}

/* Fixed scrim over the backdrop art. */
#loading::after,
#start::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

#start::after {
  background: linear-gradient(rgba(14, 10, 7, .62), rgba(14, 10, 7, .82));
}

/* Loading screen's darker scrim. */
#loading::after {
  background: linear-gradient(rgba(14, 10, 7, .76), rgba(14, 10, 7, .9));
}

/* Stops the backdrop drift under reduced motion. */
@media (prefers-reduced-motion: reduce) {

  #loading::before,
  #start::before {
    transform: none;
  }
}

/* ======================================================== start menu */
#start {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--steel-deepest);
  transition: opacity .45s ease;
}

/* Start menu states: pending hides at once, gone fades out. */
#start.pending {
  display: none;
}

#start.gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .45s ease, visibility 0s .45s;
}

/* Start menu panel. */
.start-panel {
  max-width: 720px;
  padding: 0 32px;
  text-align: center;
}

/* Game title in Special Elite. */
.start-panel h1 {
  position: relative;
  display: inline-block;
  margin: 0 0 34px;
  font: 400 calc(60px / var(--text-k, 1))/1.05 var(--stamp);
  letter-spacing: .02em;
  color: var(--sheet);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .6), 0 4px 22px rgba(0, 0, 0, .8);
}

/* Indev stamp at the title's bottom right, masked by the texture. */
.title-stamp {
  position: absolute;
  right: -47px;
  bottom: -1px;
  padding: 5px 7px 1px;
  border: 3px double #d0503c;
  border-radius: 7px;
  font: 400 calc(24px / var(--text-k, 1))/.8 var(--stamp);
  letter-spacing: .08em;
  text-transform: uppercase;
  text-shadow: none;
  color: #d0503c;
  rotate: -20deg;
  -webkit-mask: url("../data/ui/texture-tile.png") -110px -240px / 900px auto;
  mask: url("../data/ui/texture-tile.png") -110px -240px / 900px auto luminance;
}

/* Stacked start menu buttons. */
.start-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Primary button for Enter and Resume. */
#start-enter,
#pause-resume {
  position: relative;
  min-width: 260px;
  padding: 19px 54px 16px;
  background: var(--manila);
  color: var(--ink);
  border: 1px solid var(--manila-edge);
  border-radius: 0;
  font: 400 calc(24px / var(--text-k, 1))/1 var(--stamp);
  letter-spacing: .12em;
  text-indent: .12em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .6),
    inset 0 0 0 5px var(--manila), inset 0 0 0 8px var(--ribbon),
    inset 0 0 0 9px var(--manila), inset 0 0 0 10px var(--ribbon);
  transition: background .14s, transform .14s;
}

#start-enter:hover:not(:disabled),
#pause-resume:hover:not(:disabled) {
  background: #cfb378;
  transform: translateY(-1px);
}

#start-enter:disabled {
  opacity: .45;
  cursor: default;
}

/* No focus ring on the primary button. */
#start-enter:focus-visible,
#pause-resume:focus-visible {
  outline: none;
}

/* Secondary buttons as typed slips, slightly rotated. */
.start-secondary {
  position: relative;
  min-width: 210px;
  padding: 13px 22px 11px;
  background: var(--sheet);
  color: var(--ink);
  border: 0;
  border-radius: 0;
  font: 700 calc(14px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .08em;
  text-indent: .08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(0, 0, 0, .55);
  transition: transform .14s, box-shadow .14s;
}

.start-buttons .start-secondary:nth-child(2) { rotate: -.6deg; }
.start-buttons .start-secondary:nth-child(3) { rotate: .5deg; }
.start-buttons .start-secondary:nth-child(4) { rotate: -.3deg; }

.start-secondary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .6);
}

.start-secondary:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 3px;
}

/* Note card under the start menu. */
.start-panel p {
  position: relative;
  max-width: 470px;
  margin: 30px auto 0;
  padding: 12px 18px 13px;
  background: var(--sheet-lo);
  color: var(--ink);
  font: 400 calc(13.5px / var(--text-k, 1))/1.55 var(--type);
  text-align: left;
  rotate: -.8deg;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .55);
}

/* ===== loading screen: holds the window until the map is built */
#loading {
  position: fixed;
  inset: 0;
  z-index: 101;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--steel-deepest);
  transition: opacity .45s ease;
}

/* Fades out the loading screen. */
#loading.gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .45s ease, visibility 0s .45s;
}

/* Centres the quote card. */
.loading-panel {
  width: 100%;
  max-width: 780px;
  padding: 0 32px;
}

/* --- gauge: typed progress line at the foot of the window */
.loading-gauge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 13%;
  text-align: center;
  transition: opacity .5s ease;
}

#loading.ready .loading-gauge {
  opacity: 0;
  pointer-events: none;
}

.loading-bar {
  display: inline-block;
  font: 700 calc(15px / var(--text-k, 1))/1 var(--type);
  white-space: pre;
  color: var(--sheet);
  text-shadow: 0 1px 6px rgba(0, 0, 0, .9);
}

/* Unfilled part of the gauge, fainter. */
.loading-bar .todo {
  font-weight: 400;
  opacity: .5;
}

/* Load stage note under the gauge. */
#loading-note {
  margin: 10px 0 0;
  font: 400 calc(12.5px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .04em;
  color: var(--sheet);
  opacity: .82;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .9);
}

/* --- quote card: a torn scrap of typed paper */
#loading-quote {
  position: relative;
  max-width: 700px;
  margin: 0 auto;
  opacity: 0;
  transition: opacity calc(var(--loading-settle) - .35s) ease .35s;
}

#loading.ready #loading-quote {
  opacity: 1;
}

.quote-shadow {
  position: absolute;
  inset: 0;
  rotate: -1.4deg;
}

.quote-shadow.edge {
  clip-path: var(--deckle, none);
  background: rgba(0, 0, 0, .55);
  translate: 0 1px;
}

.quote-shadow.soft {
  background: rgba(0, 0, 0, .45);
  translate: 0 14px;
  filter: blur(12px);
}

/* Aged paper: darkened edges and foxing as gradients. */
.quote-paper {
  position: relative;
  rotate: -1.4deg;
  padding: 30px 40px 24px;
  text-align: left;
  clip-path: var(--deckle, none);
  background:
    radial-gradient(circle at 12% 78%, rgba(140, 98, 44, .16) 0 5px, transparent 9px),
    radial-gradient(circle at 87% 18%, rgba(140, 98, 44, .12) 0 3px, transparent 7px),
    radial-gradient(circle at 74% 84%, rgba(140, 98, 44, .1) 0 2px, transparent 5px),
    radial-gradient(ellipse at 50% 45%, transparent 62%, rgba(120, 86, 38, .15) 100%),
    var(--sheet);
}

#loading-quote blockquote {
  margin: 0;
  font: 400 calc(21px / var(--text-k, 1))/1.6 var(--type);
  color: var(--ink);
}

/* Per-character quote spans offset by whole pixels. */
#loading-quote blockquote .ch {
  position: relative;
}

#loading-quote figcaption {
  margin-top: 16px;
  text-align: right;
  font: 400 calc(18px / var(--text-k, 1))/1 var(--stamp);
  color: var(--ink-2);
}

/* Prompt anchored at the foot of the window. */
#loading-prompt {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 13%;
  margin: 0;
  font: 700 calc(14px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .1em;
  text-indent: .1em;
  text-transform: uppercase;
  text-align: center;
  color: var(--sheet);
  text-shadow: 0 1px 6px rgba(0, 0, 0, .9);
  opacity: 0;
  pointer-events: none;
  transition: opacity calc(var(--loading-settle) - .5s) ease .5s;
}

/* Prompt fades in, then blinks. */
#loading.ready #loading-prompt {
  opacity: 1;
  animation: loading-prompt 1.7s ease-in-out var(--loading-settle) infinite;
}

@keyframes loading-prompt {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: .38;
  }
}

@media (prefers-reduced-motion: reduce) {

  #loading.ready #loading-prompt {
    animation: none;
  }
}

/* ===== start dialogs: changelog and about box */
.start-dialog {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: rgba(10, 8, 6, .62);
  opacity: 0;
  visibility: hidden;
  transition: opacity .16s ease, visibility 0s .16s;
}

.start-dialog.open {
  opacity: 1;
  visibility: visible;
  transition: opacity .16s ease;
}

/* Dialog sheet: fixed head, scrolling body. */
.dialog-panel {
  display: flex;
  flex-direction: column;
  width: min(580px, 100%);
  max-height: min(100%, 460px);
  text-align: left;
  background: var(--sheet);
  color: var(--ink-2);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .6);
}

/* Dialog head ruled off with a red double line. */
.dialog-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 9px 16px;
  border-bottom: 3px double var(--ribbon);
}

.dialog-head h2 {
  margin: 0;
  font: 400 calc(20px / var(--text-k, 1))/1.1 var(--stamp);
  color: var(--ink);
}

/* Close keys, small and square. */
.dialog-close,
#card-close,
#county-close,
#diplo-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 4px;
  background: var(--key-cap);
  color: var(--sheet);
  border: 2px solid var(--key-rim);
  box-shadow: var(--key-edge);
  font: 700 calc(13px / var(--text-k, 1))/1 var(--type);
  cursor: pointer;
  transition: box-shadow .08s, transform .08s;
}

.dialog-close:hover,
#card-close:hover,
#county-close:hover,
#diplo-close:hover {
  transform: translateY(var(--key-hover-drop));
  box-shadow: var(--key-edge-hover);
}

.dialog-close:active,
#card-close:active,
#county-close:active,
#diplo-close:active {
  transform: translateY(var(--key-down-drop));
  background: var(--key-cap-down);
  border-color: var(--key-rim-down);
  color: var(--key-legend-down);
  box-shadow: var(--key-edge-down);
}

.dialog-close:focus-visible,
#card-close:focus-visible,
#county-close:focus-visible,
#diplo-close:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

.dialog-body {
  overflow-y: auto;
  padding: 16px 18px 18px;
}

/* Rules between changelog releases. */
.changelog-body section+section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--ruled);
}

.changelog-body h3 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 7px;
  font: 700 calc(13px / var(--text-k, 1))/1.3 var(--type);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink);
}

/* Release date in faded ink. */
.changelog-body h3 span {
  flex: none;
  font-size: calc(12px / var(--text-k, 1));
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-3);
}

.changelog-body ul {
  margin: 0;
  padding-left: 17px;
}

.changelog-body li,
.changelog-body p {
  margin: 0;
  font-size: calc(13px / var(--text-k, 1));
  line-height: 1.55;
  color: var(--ink-2);
}

.changelog-body li+li {
  margin-top: 4px;
}

.changelog-body li::marker {
  color: var(--ink-3);
}

/* --- about: narrower panel */
#about .dialog-panel {
  width: min(430px, 100%);
}

/* About seal, centred above its caption. */
.about-seal {
  display: block;
  width: 104px;
  height: auto;
  margin: 4px auto 14px;
  filter: drop-shadow(0 2px 4px rgba(60, 44, 18, .45));
}

.about-body {
  text-align: center;
}

.about-body p {
  margin: 0;
  font-size: calc(13px / var(--text-k, 1));
  line-height: 1.65;
  color: var(--ink-2);
}

/* Links, always underlined. */
.about-body a {
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--ribbon);
}

.about-body a:hover {
  color: var(--ribbon);
}

.about-body a:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

/* ===== pause menu: opened with Esc from the map */
#pause {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: rgba(14, 10, 7, .66);
  opacity: 0;
  visibility: hidden;
  transition: opacity .16s ease, visibility 0s .16s;
}

#pause.open {
  opacity: 1;
  visibility: visible;
  transition: opacity .16s ease;
}

/* Pause folder: tab, board and sheet. */
.pause-folder {
  width: min(440px, 100%);
}

/* Tab: the edge colour, with a manila face 1px inside it. */
.folder-tab {
  position: relative;
  display: inline-block;
  left: 18px;
  padding: 7px 23px 3px;
  background: var(--manila-edge);
  border: 0;
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 100%, 0 100%);
  font: 400 calc(16px / var(--text-k, 1))/1 var(--stamp);
  letter-spacing: .04em;
  color: var(--ink);
}

.folder-tab::before {
  content: "";
  position: absolute;
  inset: 1px 1px 0;
  z-index: -1;
  background: var(--manila);
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 100%, 0 100%);
}

#pause .pause-board {
  width: 100%;
  max-height: none;
  padding: 9px;
  background: var(--manila);
  border: 1px solid var(--manila-edge);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .7);
}

/* Pause buttons stretched to the sheet width. */
.pause-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 22px 26px 24px;
  background: var(--sheet);
}

.pause-body #pause-resume {
  min-width: 0;
}

/* Esc key hint on Resume. */
#pause-resume .key-hint {
  position: absolute;
  right: 18px;
  top: 50%;
  translate: 0 -50%;
  display: grid;
  place-items: center;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--key-cap);
  color: var(--sheet);
  border: 2px solid var(--key-rim);
  box-shadow: var(--key-edge);
  font: 700 calc(9px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .06em;
  text-indent: 0;
}

/* Slips inside the pause sheet lie square and flat. */
.pause-body .start-secondary {
  min-width: 0;
  rotate: 0deg;
  box-shadow: 0 0 0 1px var(--ruled), 0 2px 4px rgba(60, 44, 18, .3);
}

/* =============================================================== map */
#map-area {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Manila toolbar strip across the top. */
.wordmark {
  display: grid;
  line-height: 1;
  white-space: nowrap;
  font: 400 calc(18px / var(--text-k, 1))/1 var(--stamp);
  color: var(--ink);
}

.wordmark b {
  display: block;
  margin-top: 4px;
  font: italic 400 calc(11px / var(--text-k, 1))/1 var(--type);
  color: var(--ink-2);
}

.sep {
  width: 1px;
  height: 30px;
  background: var(--manila-edge);
  opacity: .6;
  flex: none;
}

/* --- map modes: a row of radio keys */
#modes {
  display: flex;
  align-items: center;
  gap: 6px;
}

#modes button {
  height: 26px;
  padding: 0 11px;
  border-radius: 13px;
  background: var(--key-cap);
  color: var(--sheet);
  border: 2px solid var(--key-rim);
  box-shadow: var(--key-edge);
  font: 700 calc(11px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: box-shadow .08s, transform .08s;
}

#modes button:hover {
  transform: translateY(var(--key-hover-drop));
  box-shadow: var(--key-edge-hover);
}

#modes button:active,
#modes button.active {
  transform: translateY(var(--key-down-drop));
  background: var(--key-cap-down);
  border-color: var(--key-rim-down);
  color: var(--key-legend-down);
  box-shadow: var(--key-edge-down);
}

#modes button:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

/* Disabled mode buttons when their data is missing. */
#modes button:disabled {
  opacity: .38;
  cursor: not-allowed;
}

/* Layer menu: caret and dropdown list. */
#infra-menu {
  display: inline-flex;
}

#infra-button i {
  font-style: normal;
  font-size: calc(9px / var(--text-k, 1));
  margin-left: 8px;
  opacity: .7;
  vertical-align: middle;
}

#infra-list {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px;
  background: var(--sheet);
  border: 1px solid var(--ruled);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .55);
  z-index: 40;
}

#infra-list[hidden] {
  display: none;
}

/* Layer list rows: borderless, left-aligned. */
#infra-list button {
  height: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
  transition: none;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
  border-radius: 0;
  font: 400 calc(12.5px / var(--text-k, 1))/1 var(--type);
  color: var(--ink-2);
  background: none;
  border: 0;
  text-align: left;
  padding: 7px 12px;
  cursor: pointer;
}

#infra-list button:hover {
  transform: none;
  box-shadow: none;
  color: var(--ink);
  background: rgba(164, 143, 102, .2);
}

#infra-list button:active,
#infra-list button.active {
  transform: none;
  background: none;
  box-shadow: none;
  border: 0;
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline 2px var(--ribbon);
  text-underline-offset: 4px;
}

/* --- keys: zoom and clock buttons as typewriter keys */
#zoom-group button,
#clock button {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  flex: none;
  border-radius: 50%;
  background: var(--key-cap);
  color: var(--sheet);
  border: 2px solid var(--key-rim);
  box-shadow: var(--key-edge);
  font: 700 calc(13px / var(--text-k, 1))/1 var(--type);
  cursor: pointer;
  transition: box-shadow .08s, transform .08s;
}

#zoom-group button:hover:not(:disabled),
#clock button:hover:not(:disabled) {
  transform: translateY(var(--key-hover-drop));
  box-shadow: var(--key-edge-hover);
}

#zoom-group button:active:not(:disabled),
#clock button:active:not(:disabled) {
  transform: translateY(var(--key-down-drop));
  background: var(--key-cap-down);
  border-color: var(--key-rim-down);
  color: var(--key-legend-down);
  box-shadow: var(--key-edge-down);
}

#zoom-group button:focus-visible,
#clock button:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

#zoom-group {
  display: flex;
  gap: 7px;
  align-items: center;
}

/* Fit as a long key. */
#zoom-group #zoom-fit {
  width: auto;
  border-radius: 13px;
  padding: 0 10px;
  font-size: calc(11px / var(--text-k, 1));
  letter-spacing: .06em;
  text-transform: uppercase;
}

#zoom-level {
  min-width: 44px;
  text-align: center;
  font: 700 calc(13px / var(--text-k, 1))/1 var(--type);
  color: var(--ink);
}

/* Inspector toggle as a quiet typed word. */
#toggle-panel {
  font: 400 calc(12px / var(--text-k, 1))/1 var(--type);
  color: var(--ink-3);
  background: none;
  border: 0;
  padding: 4px 2px;
  text-decoration: underline dotted 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}

#toggle-panel:hover,
#toggle-panel.active {
  color: var(--ink);
}

#toggle-panel:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

/* --- clock: slower, run state, date, faster, at the toolbar's right */
#clock {
  --go: #6fbf73;

  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 9px;
}

/* Date face reserved to the longest date, 26 characters. */
#clock-face {
  min-width: calc(26ch + 24px);
  padding: 6px 12px 5px;
  text-align: center;
  background: var(--sheet);
  border-top: 1px dashed var(--ruled);
  border-bottom: 1px dashed var(--ruled);
  box-shadow: 0 1px 2px rgba(60, 44, 18, .35);
  font: 700 calc(13px / var(--text-k, 1))/1 var(--type);
  color: var(--ink);
  white-space: nowrap;
}

/* Speed keys dimmed at the ends of the range. */
#clock button:disabled {
  opacity: .3;
  cursor: default;
}

/* Play and halt marks both present; one shown. */
#clock-play .play,
#clock-play .halt {
  display: block;
}

#clock.running .play,
#clock:not(.running) .halt {
  display: none;
}

/* Play triangle and halt bars drawn from borders. */
#clock-play .play {
  width: 0;
  height: 0;
  border-left: 8px solid var(--go);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  /* Optical centring of the triangle. */
  margin-left: 2px;
}

#clock-play .halt {
  width: 9px;
  height: 10px;
  border-left: 3px solid var(--go);
  border-right: 3px solid var(--go);
}

/* Running clock shown on the play key's rim. */
#clock.running #clock-play {
  border-color: var(--go);
}

/* ---------------------------------------------------------- canvas */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--steel-deepest);
}

/* Vignette over the map, ignoring clicks. */
#canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, .38) 100%);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#map {
  position: absolute;
  inset: 0;
}

canvas.panning {
  cursor: grabbing;
}

/* Tooltip: typed paper slip beside the pointer. */
#tooltip {
  position: absolute;
  z-index: 30;
  pointer-events: none;
  background: var(--sheet);
  border: 1px solid var(--ruled);
  font: 400 calc(12.5px / var(--text-k, 1))/1.4 var(--type);
  padding: 0.5em 0.8em 0.55em;
  white-space: normal;
  max-width: 30em;
  color: var(--ink-2);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .5);
}

/* Tooltip's first line in bold black. */
#tooltip>:first-child {
  color: var(--ink);
  font-weight: 700;
}

#tooltip>.plain:first-child {
  color: var(--ink-2);
  font-weight: 400;
}

#tooltip b {
  color: var(--ink);
}

#tooltip .sub {
  color: var(--ink-2);
}

/* Map tooltip's local time with sun or moon icon. */
#tooltip .tip-time svg {
  width: .9em;
  height: .9em;
  margin-right: .3em;
  vertical-align: -.1em;
  fill: var(--ink-2);
}

/* Inline flag beside a country name. */
#tooltip .mini-flag-box,
#route-panel .mini-flag-box {
  position: relative;
  display: inline-block;
  margin-right: .3em;
  vertical-align: -.05em;
  border: 1px solid var(--ink-2);
  line-height: 0;
}

#tooltip .mini-flag,
#route-panel .mini-flag {
  display: block;
  height: .8em;
  width: auto;
  max-width: 1.8em;
}

/* Blank flag: country colour at flag shape. */
#tooltip .mini-flag-box.blank,
#route-panel .mini-flag-box.blank {
  width: 1.2em;
  height: .8em;
  background-color: var(--flag-colour, rgb(128, 128, 128));
}

/* Flag shading over the mini flag. */
#tooltip .mini-flag-box::after,
#route-panel .mini-flag-box::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../data/img/flags/overlay.png") no-repeat center / 100% 100%;
  pointer-events: none;
}

/* Leading figure in ideology rows. */
#tooltip .sub>b {
  color: var(--ink);
  font-weight: 700;
}

/* Names in a red sentence stay red. */
#tooltip .sub.down>b,
#tooltip .sub.down .named { color: inherit; }

/* ===== debug screen (dev only): plain text lines over the map */
#panel {
  position: fixed;
  top: 92px;
  right: 8px;
  z-index: 25;
  display: none;
  max-width: 400px;
  max-height: calc(100vh - 100px);
  font: calc(13px / var(--text-k, 1))/1.3 Consolas, "Courier New", monospace;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

#panel.open {
  display: flex;
  flex-direction: column;
}

#panel-scroll {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  scrollbar-width: none;
}

#panel-scroll::-webkit-scrollbar {
  display: none;
}

/* Each debug line on its own dark strip. */
#panel h1,
#panel h2,
#panel .row,
#panel .hint,
#panel .toggles button,
#panel li {
  display: block;
  width: fit-content;
  margin: 0 0 1px auto;
  padding: 0 3px;
  background: rgba(0, 0, 0, .45);
  font: inherit;
  color: inherit;
  text-align: right;
}

/* Debug section heading. */
#panel h1 {
  margin-top: 10px;
  color: #ffff55;
}

#panel h1:first-child {
  margin-top: 0;
}

#panel h2 {
  margin-top: 2px;
}

#perf,
#stats,
#sel-body,
#government,
#neighbours {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* Writes rows as "Label: value". */
#panel .row > span:first-child::after {
  content: ": ";
}

#panel .hint {
  color: #aaa;
}

#panel .warn {
  color: #ff5555;
}

/* Overlay switches. */
.toggles {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

#panel .toggles button {
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

#panel .toggles button::before {
  content: "[ ] ";
}

#panel .toggles button.active::before {
  content: "[x] ";
}

#panel .toggles button:hover,
#panel li:hover {
  background: rgba(0, 0, 0, .7);
}

#panel .toggles button:disabled {
  color: #777;
  cursor: not-allowed;
}

#panel ul {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0;
  padding: 0;
  list-style: none;
}

#panel li {
  cursor: pointer;
}

/* Hidden attribute always wins over author display rules. */
[hidden] {
  display: none !important;
}

.swatch {
  position: relative;
  display: inline-block;
  width: 9px;
  height: 9px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  border-radius: 1px;
  margin-right: 7px;
  vertical-align: baseline;
  border: 1px solid rgba(0, 0, 0, .55);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .07);
}

/* Flag shading on flag swatches. */
.swatch.flag::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: url("../data/img/flags/overlay.png") no-repeat center / 100% 100%;
  pointer-events: none;
}

/* Flag image filling the swatch, centre-cropped. */
.swatch.flag>img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* Country colour on blank flag swatches. */
.swatch.flag.blank {
  background-color: var(--flag-colour, rgb(128, 128, 128));
}

/* Narrow-window layout. */
@media (max-width: 900px) {

  .wordmark b {
    display: none;
  }

  #clock-face {
    min-width: 0;
    padding: 3px 6px;
    font-size: calc(11px / var(--text-k, 1));
  }
}

/* ===== province card: index card sliding up from the bottom left */
#card {
  --tex-span: 900px;
  --tex-turn: 149deg;
  --tex-at: -215px -75px;

  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 20;
  width: 312px;

  background: var(--sheet);
  box-shadow: 0 1px 0 var(--ruled), 0 10px 26px rgba(0, 0, 0, .55);

  font-size: calc(12.5px / var(--text-k, 1));
  color: var(--ink-2);

  visibility: hidden;
  transform: translateY(calc(100% + 16px));
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s .3s;
}

/* County card, sharing the province card's corner. */
#county-card {
  --tex-span: 900px;
  --tex-turn: 149deg;
  --tex-at: -215px -75px;

  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 20;
  width: 270px;
  padding-bottom: 6px;

  background: var(--sheet);
  box-shadow: 0 1px 0 var(--ruled), 0 10px 26px rgba(0, 0, 0, .55);

  font-size: calc(12.5px / var(--text-k, 1));
  color: var(--ink-2);

  visibility: hidden;
  transform: translateY(calc(100% + 16px));
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s .3s;
}

#county-card.open {
  visibility: visible;
  transform: none;
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s 0s;
}

#card.open {
  visibility: visible;
  transform: none;
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s 0s;
}

@media (prefers-reduced-motion: reduce) {

  #card,
  #card.open {
    transition: none;
  }
}

/* --- heading: name ruled off with a red double line */
.card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 10px 8px 13px;
  border-bottom: 3px double var(--ribbon);
}

/* Province name, mixed case, wrapping. */
.card-head h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
  padding-top: 1px;
  font: 400 calc(21px / var(--text-k, 1))/1.15 var(--stamp);
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* --- owner, with the polity's colour standing in for a flag */
.card-owner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px 8px;
  border-bottom: 1px solid var(--ruled);
}

.card-flag {
  position: relative;
  flex: none;
  display: inline-block;
  min-width: 36px;
  height: 24px;
  border: 1px solid var(--ink-2);
  background: var(--sheet-lo);
}

.card-flag img {
  display: block;
  height: 100%;
  width: auto;
}

/* Flag shading shared by the province and county cards. */
.card-flag::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../data/img/flags/overlay.png") no-repeat center / 100% 100%;
  pointer-events: none;
}

.card-owner b {
  display: block;
  font: 700 calc(14px / var(--text-k, 1))/1.2 var(--type);
  color: var(--ink);
}

.card-owner i {
  display: block;
  font-style: normal;
  font-size: calc(10px / var(--text-k, 1));
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* --- one-line facts: label, dotted leader, figure */
.card-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 13px;
}

.card-row::after {
  content: "";
  order: 1;
  flex: 1;
  min-width: 12px;
  border-bottom: 1.5px dotted var(--ink-3);
  transform: translateY(-3px);
}

.card-row span:first-child {
  color: var(--ink-2);
}

.card-row span:last-child {
  order: 2;
  color: var(--ink);
  font-weight: 700;
  text-align: right;
}

/* --- happiness and unrest meters, without hover feedback */
.card-meters {
  padding: 2px 0 4px;
}

.card-meter {
  display: grid;
  grid-template-columns: auto 2.6em 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 4px 13px;
}

.cm-label { color: var(--ink-2); }
.cm-value { color: var(--ink); font-weight: 700; text-align: right; }
.cm-note  { color: var(--ink-3); font-size: 11px; }

/* Meter bar: ink rule with hatched fill. */
.cm-bar {
  position: relative;
  height: 9px;
  border: 1px solid var(--ink-2);
  background: rgba(255, 248, 230, .07);
  overflow: hidden;
}

.cm-bar i {
  position: relative;
  display: block;
  height: 100%;
  width: 0;
  transition: width .18s ease, background-color .18s ease;
}

/* Hatching laid over the coloured fill. */
.cm-bar i::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, transparent 0 1.5px, var(--sheet) 1.5px 3.5px);
}

/* Red unrest step ticks. */
.cm-bar.unrest u {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: var(--ribbon);
}

/* Breakdown line: modifier label and figure on one line. */
#tooltip .cm-line { display: flex; justify-content: space-between; gap: 1.1em; white-space: nowrap; }
#tooltip .cm-line b { font-weight: 700; }
/* A long label wraps; its figure keeps the right edge. */
#tooltip .cm-line > :first-child { min-width: 0; white-space: normal; }
.flagged, #tooltip .cm-line .named { white-space: nowrap; }
#tooltip .cm-line > :last-child { flex: none; align-self: flex-end; }
/* Italic national spirits in breakdowns. */
#tooltip .cm-line i { font-style: italic; }

/* Green for helps, red for harms. */
#tooltip .up, .cm-note .up   { color: var(--good); }
#tooltip .down, .cm-note .down { color: var(--ribbon); }
#tooltip .none { color: var(--ink-3); font-style: italic; }

/* Bold names in tooltip lines. */
#tooltip .named, .cm-note .named, #route-panel .named { color: var(--ink); font-weight: 700; }

/* Tooltip rule drawn as typed hyphens. */
#tooltip hr, #route-panel-body hr {
  width: 0;
  min-width: 100%;
  height: 1em;
  margin: 0.3em 0;
  border: 0;
  overflow: hidden;
  color: var(--ink-3);
}

#tooltip hr::before, #route-panel-body hr::before {
  content: "--------------------------------------------------------------------------------";
  display: block;
  white-space: nowrap;
  line-height: 1;
}

#tooltip .cm-line.sub b, #tooltip .cm-line.sub span { color: var(--ink-3); }

/* --- built things, two to a row, each with a leader */
.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
  padding: 6px 13px;
  border-top: 1px solid var(--ruled);
  border-bottom: 1px solid var(--ruled);
}

.card-cell {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
}

.card-cell::after {
  content: "";
  order: 1;
  flex: 1;
  min-width: 4px;
  border-bottom: 1.5px dotted var(--ink-3);
  transform: translateY(-3px);
}

/* Grid labels never break. */
.card-cell span {
  color: var(--ink-2);
  font-size: calc(12px / var(--text-k, 1));
  white-space: nowrap;
}

/* Faded cells for types the ground forbids. */
.card-cell.none span,
.card-cell.none b { opacity: .45; }

.card-cell b {
  order: 2;
  font-weight: 700;
  color: var(--ink);
}

/* --- building slots: one strip shared by both factory types */
.card-slots {
  padding: 9px 13px 12px;
}

/* Slot strip heading. */
.card-slot-head {
  margin-bottom: 7px;
  color: var(--ink-2);
  font-size: calc(12.5px / var(--text-k, 1));
}

.card-slot-head span {
  color: var(--ink);
  font-weight: 700;
}

.card-slot-boxes {
  display: flex;
  gap: 5px;
}

/* Over ten sockets: a wrapping ten-column grid. */
.card-slot-boxes.wrapped {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  row-gap: 5px;
}

/* Open socket ruled in dashes. */
.card-slot {
  flex: 1;
  height: 24px;
  border: 1.5px dashed var(--ink-3);
  background: rgba(255, 248, 230, .07);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Fixed-width tile for the socket art. */
.card-slot i {
  width: 18px;
  height: 18px;
  background-repeat: no-repeat;
}

/* Locked socket, faded. */
.card-slot.locked {
  border-color: var(--ruled);
  opacity: .55;
}

.card-slot.locked i {
  background-image: url("../data/icons/locked.png");
  background-size: 13px 13px;
  background-position: center;
}

/* Factory sprite on civilian and military sockets. */
.card-slot.civ i,
.card-slot.mil i {
  background-image: url("../data/icons/factories.png");
  background-size: 36px 18px;
}

.card-slot.civ {
  border-style: solid;
  border-color: #3d4f66;
}

.card-slot.civ i {
  background-position: 0 0;
}

.card-slot.mil {
  border-style: solid;
  border-color: #6b5340;
}

.card-slot.mil i {
  background-position: -18px 0;
}

.card-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  color: var(--ink-2);
  font-size: calc(12px / var(--text-k, 1));
}

.card-legend span {
  display: inline-flex;
  align-items: center;
}

.card-legend b {
  margin-left: 5px;
  color: var(--ink);
}

/* Legend key showing the factory sprite. */
.card-legend .key {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 5px;
  background: url("../data/icons/factories.png") 0 0 / 32px 16px no-repeat;
}

.card-legend .key.mil {
  background-position: -16px 0;
}

/* --- diplomacy panel: a folder along the left edge */
#diplo {
  --tex-span: 4400px;
  --tex-turn: 21deg;
  --tex-at: -330px -140px;

  position: absolute;
  left: 12px;
  top: 122px;
  bottom: 12px;
  z-index: 21;
  width: 480px;
  display: flex;
  flex-direction: column;
  padding: 8px;

  background: var(--manila);
  border: 1px solid var(--manila-edge);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .6);

  font-size: calc(12.5px / var(--text-k, 1));
  color: var(--ink-2);

  visibility: hidden;
  transform: translateX(calc(-100% - 24px));
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s .3s;
}

#diplo.open {
  visibility: visible;
  transform: none;
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s 0s;
}

@media (prefers-reduced-motion: reduce) {
  #diplo,
  .diplo-folder-tab { transition: none; }
}

/* Diplomacy folder tab, sliding with the folder. */
.diplo-folder-tab {
  --tex-span: 400px;
  --tex-turn: 311deg;
  --tex-at: -200px -60px;

  position: absolute;
  left: 30px;
  top: 101px;
  z-index: 21;
  visibility: hidden;
  transform: translateX(calc(-100% - 60px));
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s .3s;
}

#diplo.open + .diplo-folder-tab {
  visibility: visible;
  transform: none;
  transition: transform .3s cubic-bezier(.22, .61, .36, 1), visibility 0s 0s;
}

/* Typed sheet in the folder, laid out as a column. */
.diplo-sheet {
  --tex-span: 4000px;
  --tex-turn: 76deg;
  --tex-at: -55px -365px;

  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  box-shadow: 0 1px 3px rgba(60, 44, 18, .45);
}

/* --- blanks: unfilled fields typed faint in a dashed box */
.diplo-sheet .blank,
.diplo-focus,
.diplo-spirits .none,
.diplo-box > .diplo-row.none {
  display: grid;
  place-items: center;
  text-align: center;
  border: 1.5px dashed var(--ruled);
  background: rgba(255, 248, 230, .07);
  color: var(--ink-3);
  font-style: italic;
}

/* Identity band: flag, titles, two figures. */
.diplo-ident {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 13px 10px;
  min-height: 48px;
}

/* Panel flag, slightly rotated, with a shading overlay. */
.diplo-flag {
  position: relative;
  display: inline-block;
  flex: none;
  max-width: 160px;
}

.diplo-ident .diplo-flag {
  rotate: -1.2deg;
  margin-top: 3px;
}

.diplo-flag img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 48px;
  filter: drop-shadow(0 0 .6px rgba(34, 30, 24, .9));
}

.diplo-ident .diplo-flag img {
  filter: drop-shadow(0 0 .6px rgba(34, 30, 24, .9)) drop-shadow(0 2px 2px rgba(60, 44, 18, .35));
}

/* Flag shading masked to the flag's outline. */
.diplo-flag::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../data/img/flags/overlay.png") no-repeat center / 100% 100%;
  -webkit-mask: var(--flag-mask, linear-gradient(transparent, transparent)) center / 100% 100% no-repeat;
  mask: var(--flag-mask, linear-gradient(transparent, transparent)) center / 100% 100% no-repeat;
  pointer-events: none;
}

/* Paper clip over the flag's top edge. */
.paperclip {
  position: absolute;
  z-index: 2;
  left: 5px;
  top: -8px;
  width: 13px;
  height: 34px;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(.5px 1px .5px rgba(0, 0, 0, .3));
}

.paperclip path {
  fill: none;
  stroke: rgba(128, 124, 116, .9);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.diplo-titles {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 3px;
  justify-items: start;
}

.diplo-titles b {
  font: 700 calc(15px / var(--text-k, 1))/1.25 var(--type);
  color: var(--ink);
}

.diplo-titles i {
  font-style: normal;
  font-size: calc(13px / var(--text-k, 1));
  line-height: 1.3;
  color: var(--ink-2);
}

/* Blank chip inside the titles line. */
.diplo-titles .blank {
  display: inline-block;
  padding: 0 7px;
  font-size: calc(11.5px / var(--text-k, 1));
  line-height: 18px;
  font-style: italic;
}

/* Two flags and what each thinks of the other. */
.diplo-pair {
  position: relative;
  flex: none;
  width: 88px;
  height: 64px;
}

.diplo-pair[hidden] { display: none; }

.diplo-pair .pair-flag {
  position: absolute;
  margin: 0;
  translate: -50% -50%;
}

.diplo-pair .pair-flag img {
  max-width: 34px;
  max-height: 22px;
}

.pair-us { left: 17px; top: 22px; }
.pair-them { left: 71px; top: 42px; }

.pair-arrows {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}

.pair-arrows path {
  fill: none;
  stroke: var(--good);
  stroke-width: 2;
}

/* Wide unseen stroke that takes the hover. */
.pair-arrows path.hit {
  stroke: transparent;
  stroke-width: 12;
  pointer-events: stroke;
}

.diplo-pair b {
  position: absolute;
  font: 700 calc(12px / var(--text-k, 1))/1 var(--type);
  color: var(--ink);
}

.diplo-pair b.up { color: var(--good); }
.diplo-pair b.down { color: var(--ribbon); }
.pair-ours { right: 0; top: 0; }
.pair-theirs { left: 0; bottom: 0; }

.diplo-meters {
  flex: none;
  display: grid;
  gap: 5px;
  text-align: right;
}

.diplo-meters span {
  display: grid;
}

.diplo-meters u {
  text-decoration: none;
  font-size: calc(10px / var(--text-k, 1));
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.diplo-meters b {
  font: 700 calc(17px / var(--text-k, 1))/1.1 var(--type);
  color: var(--ink);
}

/* Leader row with party and focus. */
.diplo-portrait-row {
  display: flex;
  gap: 12px;
  padding: 2px 13px 12px;
  border-bottom: 1px solid var(--ruled);
}

/* Leader photo in photo corners. */
.diplo-photo {
  position: relative;
  flex: none;
  align-self: flex-start;
  height: 120px;
  aspect-ratio: 312 / 420;
  border: 1px solid var(--ink-2);
  background: #cfc4a6;
}

.diplo-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: sepia(.35) contrast(1.05);
}

.diplo-photo::after {
  content: "";
  position: absolute;
  inset: -1px;
  pointer-events: none;
  background:
    linear-gradient(135deg, var(--ink) 0 8px, transparent 8px) top left / 16px 16px no-repeat,
    linear-gradient(225deg, var(--ink) 0 8px, transparent 8px) top right / 16px 16px no-repeat,
    linear-gradient(45deg, var(--ink) 0 8px, transparent 8px) bottom left / 16px 16px no-repeat,
    linear-gradient(315deg, var(--ink) 0 8px, transparent 8px) bottom right / 16px 16px no-repeat;
}

/* Party lines above, focus below, beside the portrait. */
.diplo-stack {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.diplo-party {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
}

.diplo-party b {
  font: 700 calc(14.5px / var(--text-k, 1))/1.25 var(--type);
  color: var(--ink);
}

.diplo-party i {
  font-style: normal;
  font-size: calc(13.5px / var(--text-k, 1));
  line-height: 1.3;
  color: var(--ink-2);
}

.diplo-party .blank {
  min-height: 22px;
  padding: 1px 6px;
  font-size: calc(12px / var(--text-k, 1));
  font-weight: 400;
}

.diplo-focus {
  flex: 1 1 auto;
  min-height: 34px;
  padding: 6px 8px;
  font-size: calc(13px / var(--text-k, 1));
}

/* Spirit cells, wrapping, with placeholder art. */
.diplo-spirits {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 9px 13px 10px;
  border-bottom: 1px solid var(--ruled);
  min-height: 66px;
}

.diplo-spirits .diplo-tile {
  width: 46px;
  height: 46px;
}

.diplo-spirits .none {
  width: 100%;
  height: 46px;
  font-size: calc(13px / var(--text-k, 1));
}

/* Folder tabs on the sheet. */
.diplo-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 13px 0;
  border-bottom: 1px solid var(--ink-2);
}

.diplo-tabs button {
  flex: 1 1 0;
  margin-bottom: -1px;
  padding: 8px 0 7px;
  background: rgba(180, 151, 91, .35);
  border: 1px solid var(--ruled);
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  color: var(--ink-3);
  font: 700 calc(12.5px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .03em;
  text-transform: uppercase;
  cursor: pointer;
}

.diplo-tabs button.on {
  padding-bottom: 8px;
  background: var(--sheet);
  border-color: var(--ink-2);
  color: var(--ink);
}

.diplo-tabs button:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

/* Panes that fill the rest of the panel and scroll. */
/* The tab body takes what the head leaves, whichever tab is open. */
.diplo-body { flex: 1 1 0; min-height: 0; }

.diplo-pane {
  display: flex;
  gap: 10px;
  height: 100%;
  padding: 12px 13px 14px;
  box-sizing: border-box;
}

.diplo-pane[hidden] { display: none; }



.diplo-box {
  flex: 1 1 0;
  min-width: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--ruled);
  background: rgba(255, 248, 230, .07);
  padding: 9px 10px 10px;
}

.diplo-box h3 {
  margin: 4px 0 0;
  font: 700 calc(10px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.diplo-box h3:first-child { margin-top: 0; }

/* Diplomacy row: label, dotted leader, figure. */
.diplo-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  font-size: calc(12px / var(--text-k, 1));
}

.diplo-row:not(.none)::after {
  content: "";
  order: 1;
  flex: 1;
  min-width: 8px;
  align-self: baseline;
  border-bottom: 1.5px dotted var(--ink-3);
  transform: translateY(-3px);
}

/* Labels wrap instead of truncating. */
.diplo-row .lab { flex: 0 1 auto; min-width: 0; }

/* No leader on relation rows. */
#diplo-relations .diplo-row::after { display: none; }

/* --- relation rows: flags fanned like a hand of cards */
#diplo-relations .deck-row {
  flex-wrap: nowrap;
  align-items: center;
}

/* Relation kind icon. */
#diplo-relations .deck-row .kind {
  flex: none;
  width: 16px;
  height: 16px;
  background: url("../data/icons/placeholder.png") center / contain no-repeat;
  cursor: default;
}

#diplo-relations .deck {
  flex: 1 1 auto;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-width: 0;
  padding: 5px 0 1px;
}

#diplo-relations .card {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  margin-right: 2px;
  cursor: default;
  transition: transform .1s;
}

/* Flags keep their size in squeezed slots. */
#diplo-relations .card .diplo-flag {
  max-width: none;
  vertical-align: middle;
}

#diplo-relations .card .diplo-flag img {
  height: 18px;
  width: auto;
  max-width: none;
  max-height: none;
}

#diplo-relations .card:last-child {
  flex-shrink: 0;
  margin-right: 0;
}

/* Card shadow to the left in the fan. */
#diplo-relations .card .diplo-flag img {
  filter: drop-shadow(0 0 .6px rgba(34, 30, 24, .9)) drop-shadow(-1.5px 0 1.5px rgba(60, 44, 18, .45));
}

/* Hovered card lifts to the top. */
#diplo-relations .card:hover {
  z-index: 1;
  transform: translateY(-4px);
}
.diplo-row .val { order: 2; flex: none; color: var(--ink); font-weight: 700; }

/* Small flags in relation rows. */
.diplo-flag.small { max-width: 46px; }
.diplo-flag.small img { max-height: 18px; }

/* Blank row filling an empty box. */
.diplo-box > .diplo-row.none {
  flex: none;
  min-height: 30px;
  padding: 4px 8px;
  font-size: calc(12.5px / var(--text-k, 1));
}


.diplo-row i.ico {
  flex: none;
  width: 16px;
  height: 16px;
  background-size: cover;
  background-image: url("../data/icons/placeholder.png");
}

/* Factory icons: civilian cell, then military. */
.diplo-row i.ico.civ {
  background-image: url("../data/icons/factories.png");
  background-size: 200% 100%;
  background-position: 0 0;
}

.diplo-row i.ico.mil {
  background-image: url("../data/icons/factories.png");
  background-size: 200% 100%;
  background-position: 100% 0;
}

.diplo-row i.ico.dock { background-image: url("../data/icons/Dockyard.png"); }

/* Laws as a grid of icons. */
.diplo-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  padding: 2px 0 4px;
}

/* Law tiles: bare art, no hover feedback. */
.diplo-tile {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  background: url("../data/img/national_spirits/placeholder.png") no-repeat center / contain;
}

/* Empty minister slot with placeholder photo. */
.diplo-tile.empty {
  position: relative;
  width: 34px;
  height: 46px;
  border: 1px solid var(--ink-2);
  background: #cfc4a6 url("../data/img/portraits/placeholder.png") center / cover no-repeat;
  filter: sepia(.35) contrast(1.05);
}

.diplo-tile.empty::after {
  content: "";
  position: absolute;
  inset: -1px;
  background:
    linear-gradient(135deg, var(--ink) 0 4px, transparent 4px) top left / 8px 8px no-repeat,
    linear-gradient(225deg, var(--ink) 0 4px, transparent 4px) top right / 8px 8px no-repeat,
    linear-gradient(45deg, var(--ink) 0 4px, transparent 4px) bottom left / 8px 8px no-repeat,
    linear-gradient(315deg, var(--ink) 0 4px, transparent 4px) bottom right / 8px 8px no-repeat;
}

.diplo-row i.ico.law { background-image: url("../data/img/national_spirits/placeholder.png"); }

/* --- action rows: keys typed as ledger lines */
#diplo-actions .act-slot { flex: none; }

#diplo-actions .act {
  align-items: flex-end;
  width: 100%;
  margin: 0;
  padding: 3px 4px;
  border: 0;
  border-radius: 2px;
  background: none;
  color: var(--ink-2);
  font: 400 calc(12px / var(--text-k, 1))/1.25 var(--type);
  text-align: left;
  cursor: pointer;
}

/* Leader on the last line of the label. */
#diplo-actions .act::after { align-self: flex-end; transform: translateY(-0.3em); }

#diplo-actions .act:hover {
  background: rgba(180, 151, 91, .25);
  color: var(--ink);
}

#diplo-actions .act:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 1px;
}

/* Shut actions in faded ink; the slot carries their tooltip. */
#diplo-actions .act:disabled {
  color: var(--ink-3);
  cursor: default;
  pointer-events: none;
}

#diplo-actions .act:disabled .val { color: var(--ink-3); font-weight: 400; }

/* Development aid picker under its row. */
.diplo-aid {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  padding: 1px 4px 5px 14px;
}

.diplo-aid select {
  flex: 1 1 0;
  height: 22px;
  min-width: 0;
  padding: 2px 3px;
  background: rgba(255, 248, 230, .35);
  border: 1px solid var(--ruled);
  border-radius: 2px;
  color: var(--ink);
  font: 400 calc(11.5px / var(--text-k, 1))/1.2 var(--type);
}

/* Province across the row; project and the key beneath. */
.diplo-aid select[data-pick="province"] { flex-basis: 100%; }

.diplo-aid .aid-build {
  flex: none;
  height: 22px;
  padding: 4px 8px 3px;
  background: rgba(180, 151, 91, .35);
  border: 1px solid var(--ink-2);
  border-radius: 2px;
  color: var(--ink);
  font: 700 calc(10px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}

.diplo-aid .aid-build:hover { background: rgba(180, 151, 91, .55); }

.diplo-aid select:focus-visible,
.diplo-aid .aid-build:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 1px;
}

/* Note for an action not in the game yet. */
#wip-note {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 40;
  width: auto;
  max-width: calc(100% - 24px);
  transform: translate(-50%, -50%);
  border-top: 3px double var(--ribbon);
  cursor: default;
}

#wip-note[hidden] { display: none; }

#wip-note .dialog-body {
  padding: 13px 20px 12px;
  font: 400 calc(14px / var(--text-k, 1))/1.3 var(--stamp);
  color: var(--ink);
  white-space: nowrap;
}

/* One cell of the resource icon sheet, placed by --col and --row. */
.res {
  --res-px: 14px;
  display: inline-block;
  width: var(--res-px);
  height: var(--res-px);
  margin-right: .15em;
  vertical-align: -2px;
  background-image: url("../data/icons/resources.png");
  background-size: calc(var(--cols) * var(--res-px)) auto;
  background-position: calc(var(--col) * var(--res-px) * -1) calc(var(--row) * var(--res-px) * -1);
}

/* Consumer goods icon, its own file. */
.res.goods {
  background-image: url("../data/icons/consumer_goods.png");
  background-size: 100% 100%;
  background-position: 0 0;
}

/* ===== trade route panel: a dialog sheet over the map, dragged by its head */
#route-panel {
  position: absolute;
  top: 92px;
  right: 12px;
  z-index: 22;
  width: min(440px, calc(100% - 24px));
  max-height: min(560px, calc(100% - 104px));
  box-shadow: 0 10px 26px rgba(0, 0, 0, .55);
}

#route-panel-head {
  cursor: grab;
  user-select: none;
  touch-action: none;
}

#route-panel-head.grabbed {
  cursor: grabbing;
}

#route-panel-body {
  font: 400 calc(12.5px / var(--text-k, 1))/1.4 var(--type);
}

/* Section heads: label left, unit right. */
#route-panel-body h3 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 6px;
  font: 700 calc(12px / var(--text-k, 1))/1.3 var(--type);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink);
}

#route-panel-body h3 span {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-3);
}

#route-panel-body hr {
  margin: 8px 0;
}

/* One trade a row: good, amount, ends; the ends wrap under on a narrow sheet. */
.route-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.route-rows li {
  display: grid;
  grid-template-columns: 10.5em 3.5em 1fr;
  align-items: baseline;
  gap: 2px 10px;
  padding: 3px 0;
}

.route-rows b {
  color: var(--ink);
  text-align: right;
}

.route-stops li {
  grid-template-columns: 1fr 3.5em;
}

.route-none {
  margin: 0;
  color: var(--ink-3);
}

@media (max-width: 480px) {
  .route-rows li {
    grid-template-columns: 1fr 3.5em;
  }

  .route-rows li .route-ends {
    grid-column: 1 / -1;
    padding-left: 1em;
  }

  .route-stops li .route-ends {
    grid-column: auto;
    padding-left: 0;
  }
}

/* Controls list: key and action in two columns. */
.controls-body dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 5px 18px;
  margin: 0;
}

.controls-body dt,
.controls-body dd {
  margin: 0;
  font-size: calc(13px / var(--text-k, 1));
  line-height: 1.55;
}

.controls-body dt {
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.controls-body dd {
  color: var(--ink-2);
}

/* Controls dialog, fixed above the pause menu. */
#controls {
  position: fixed;
  z-index: 110;
}

/* --- the scrollbar: a punched telegraph tape with a typewriter key */
.tape-scroller { scrollbar-width: none; }

.tape-room { border-right: 14px solid transparent; }

.tape-track {
  position: absolute;
  z-index: 3;
  width: 13px;
  border-left: 1px solid var(--ruled);
  background-color: #eee3c5;
  background-size: 13px 1400px;
  background-repeat: repeat-y;
  touch-action: none;
}

.tape-key {
  position: absolute;
  left: -1px;
  right: -1px;
  border: 2px solid var(--key-rim);
  border-radius: 7px;
  background: linear-gradient(to right, #17130f, #4a4237 42%, #17130f);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .55);
  cursor: grab;
  touch-action: none;
}

.tape-key:hover {
  border-color: #b5ad98;
  background: linear-gradient(to right, #221c16, #5c5244 42%, #221c16);
}

.tape-key.held {
  border-color: var(--key-rim-down);
  background: linear-gradient(to right, #100d0a, #2a241c 50%, #100d0a);
  cursor: grabbing;
}

/* --- country selection: a manila folder over the map */
#choose {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 25;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
}

#choose.open { display: flex; }

#choose [hidden] { display: none !important; }

#choose-folder {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: min(1100px, 100%);
  max-height: calc((100vh - 72px) / var(--ui-scale, 1));
  pointer-events: auto;
}

#choose-box,
.choose-paper {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

#choose-box::after,
.choose-paper::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: var(--tex-span, 600px);
  height: var(--tex-span, 600px);
  transform: translate(-50%, -50%) rotate(var(--tex-turn, 0deg));
  background: var(--texture-img) var(--tex-at, 0 0) / var(--texture-size) auto repeat;
  mix-blend-mode: soft-light;
  opacity: var(--texture-strength);
  pointer-events: none;
  z-index: -1;
}

#choose-box {
  --tex-span: 4400px;
  --tex-turn: 118deg;
  --tex-at: -260px -90px;

  display: flex;
  flex-direction: column;
  gap: 9px;
  width: 100%;
  min-height: 0;
  padding: 10px;
  background: var(--manila);
  border: 1px solid var(--manila-edge);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .6);
}

#choose-majors {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
}

/* A personnel slip: photograph, flag and name. */
.choose-major {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px 6px;
  min-width: 0;
  padding: 5px 4px;
  appearance: none;
  background: var(--sheet);
  border: 0;
  outline: 2px solid transparent;
  outline-offset: -2px;
  box-shadow: 0 1px 3px rgba(60, 44, 18, .45);
  cursor: pointer;
  transition: transform .1s ease-out, box-shadow .1s ease-out;
}

.choose-major:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 7px rgba(60, 44, 18, .5);
}

.choose-major.on { outline-color: var(--ribbon); }

.choose-major .diplo-photo { height: 74px; }

.choose-tile-side { display: contents; }

.choose-major .diplo-flag img {
  max-width: 40px;
  max-height: 28px;
}

.choose-tile-name {
  flex: 0 0 100%;
  max-width: 100%;
  color: var(--ink);
  font: 700 calc(11px / var(--text-k, 1))/1.15 var(--type);
  text-align: center;
  overflow-wrap: anywhere;
}

#choose-minors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.choose-minor {
  padding: 0;
  appearance: none;
  background: none;
  border: 0;
  outline: 2px solid transparent;
  outline-offset: 1px;
  cursor: pointer;
  transition: transform .1s ease-out;
}

.choose-minor:hover { transform: translateY(-2px); }

.choose-minor.on { outline-color: var(--ribbon); }

.choose-minor { line-height: 0; }

.choose-minor .diplo-flag img {
  max-width: 48px;
  max-height: 24px;
}

#choose-panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1fr);
  gap: 9px;
  height: clamp(190px, 28vh, 270px);
  min-height: 0;
}

.choose-paper {
  --tex-span: 2400px;
  --tex-turn: 76deg;
  --tex-at: -55px -365px;

  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 8px 12px 10px;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(60, 44, 18, .45);
}

.choose-paper:nth-child(2) { --tex-turn: 203deg; --tex-at: -310px -120px; }

.choose-paper:nth-child(3) { --tex-turn: 311deg; --tex-at: -150px -240px; }

#choose-panes h3,
#choose-rule-sheets h3 {
  flex: none;
  margin: 0 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--ruled);
  font: 400 calc(15px / var(--text-k, 1))/1.2 var(--stamp);
  text-align: center;
}

.choose-info-wrap {
  position: relative;
  display: flex;
  flex: 1;
  gap: 10px;
  min-height: 0;
}

#choose-info { flex: 1; min-width: 0; overflow-y: auto; }

.choose-info-wrap .diplo-photo { height: 96px; margin-top: 4px; }

.choose-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
  border-bottom: 1px dotted var(--ruled);
  font: 400 calc(12px / var(--text-k, 1))/1.25 var(--type);
}

.choose-row u { flex: none; color: var(--ink-3); text-decoration: none; }

.choose-row b { font-weight: 700; text-align: right; }

#choose-brief {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow-y: auto;
  font: 400 calc(12.5px / var(--text-k, 1))/1.4 var(--type);
}

#choose-middle { align-items: center; gap: 7px; }

#choose-middle h3 { align-self: stretch; margin-bottom: 0; }

#choose-flag-box { flex: none; }

#choose-spirits {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 5px;
  min-height: 0;
}

#choose-actions { flex: none; display: flex; gap: 10px; }

/* The two folder tabs: the one not shown in faded type. */
#choose-tabs { display: flex; align-items: flex-end; gap: 4px; }
/* The open tab over the box's top edge. */
#choose-tabs .folder-tab {
  z-index: 2;
  margin-bottom: -2px;
  padding-bottom: 5px;
  appearance: none;
  cursor: pointer;
}
/* The tab not shown: behind the box's top edge, in faded type. */
#choose-tabs .folder-tab:not(.on) {
  z-index: 0;
  margin-bottom: -1px;
  padding-bottom: 4px;
  color: var(--ink-3);
}
#choose-tabs .folder-tab:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: -2px;
}

/* Game rules: a sheet per rule, Back and Play under them. */
#choose-rules {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
}
#choose-rule-sheets {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 9px;
  min-height: 0;
}

.rule-sheet:nth-child(4) { --tex-turn: 142deg; --tex-at: -420px -60px; }
.rule-sheet.shown-ledger { grid-row: 1 / -1; }

#choose-rules button[data-rule] {
  appearance: none;
  background: none;
}
#choose-rules [data-rule] { cursor: pointer; }
.rule-level,
.rule-notch { border: 0; }
#choose-rules [data-rule]:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

/* Red rubber stamp, masked by the paper texture. */
.rule-level.on span,
.rule-stamp.on {
  border: 3px double var(--ribbon);
  border-radius: 6px;
  color: var(--ribbon);
  -webkit-mask: url("../data/ui/texture-tile.png") -110px -240px / 900px auto;
  mask: url("../data/ui/texture-tile.png") -110px -240px / 900px auto luminance;
}

/* Ledger: every level against its effects. */
table.rule-ledger {
  flex: 1;
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font: 400 calc(12.5px / var(--text-k, 1))/1.25 var(--type);
}
table.rule-ledger th:first-child { width: 28%; }
table.rule-ledger thead th {
  height: 56px;
  padding: 0 2px 8px;
  vertical-align: bottom;
}
.rule-level {
  width: 100%;
  padding: 0;
  color: var(--ink-3);
  font: 400 calc(11.5px / var(--text-k, 1))/1.15 var(--stamp);
}
.rule-level:hover { color: var(--ink); }
/* Level name, in a blank stamp border. */
.rule-level span {
  display: inline-block;
  padding: 4px 4px 2px;
  border: 3px double transparent;
  border-radius: 6px;
}
.rule-level.on span { rotate: -8deg; }
table.rule-ledger tbody th,
table.rule-ledger tbody td {
  padding: 6px 3px;
  border-bottom: 1px dotted var(--ruled);
}
table.rule-ledger tbody th {
  color: var(--ink-3);
  font-weight: 400;
  text-align: left;
}
table.rule-ledger td {
  color: var(--ink-3);
  text-align: center;
}
table.rule-ledger td.up { color: var(--good); font-weight: 700; }
table.rule-ledger td.down { color: var(--ribbon); font-weight: 700; }
table.rule-ledger .on { background: rgba(155, 42, 31, .08); }

/* Stamps: the chosen one inked, the rest faint. */
.rule-stamps {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.rule-stamp {
  padding: 7px 12px 4px;
  border: 3px double var(--ink-3);
  border-radius: 6px;
  color: var(--ink-3);
  font: 400 calc(16px / var(--text-k, 1))/1 var(--stamp);
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: .4;
  rotate: 3deg;
  transition: opacity .1s ease-out;
}
.rule-stamp:nth-child(2) { rotate: -4deg; }
.rule-stamp:hover { opacity: .7; }
.rule-stamp.on { opacity: 1; }

/* Dial: notches on a track, the key-cap knob on the chosen one. */
.rule-dial {
  display: grid;
  cursor: grab;
  touch-action: none;
  user-select: none;
  flex: 1;
  grid-template-columns: repeat(var(--notches, 5), minmax(0, 1fr));
  align-items: center;
}
.rule-notch {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 0;
}
.rule-notch::before {
  content: "";
  position: absolute;
  top: 9px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--ruled);
}
.rule-notch:first-child::before { left: 50%; }
.rule-notch:last-child::before { right: 50%; }
.rule-notch i {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: 1px;
  height: 10px;
  margin: 4px 0;
  background: var(--ruled);
}
.rule-notch.on i {
  width: 18px;
  height: 18px;
  margin: 0;
  background: var(--key-cap);
  border: 2px solid var(--key-rim);
  border-radius: 50%;
  box-shadow: var(--key-edge);
}
.rule-notch span {
  color: var(--ink-3);
  font: 400 calc(11.5px / var(--text-k, 1))/1.15 var(--type);
  text-align: center;
}
.rule-notch:hover span { color: var(--ink); }
.rule-notch.on span { color: var(--ink); font-weight: 700; }
/* Back and Play where the country tab's middle pane holds them. */
#choose-rules-foot {
  display: flex;
  flex: none;
  justify-content: center;
  padding-bottom: 10px;
}

/* The same round-capped keys as the toolbar. */
.choose-key {
  min-width: 96px;
  padding: 6px 16px 7px;
  appearance: none;
  background: var(--key-cap);
  border: 2px solid var(--key-rim);
  border-radius: 999px;
  box-shadow: var(--key-edge);
  color: var(--sheet);
  font: 400 calc(13px / var(--text-k, 1))/1 var(--stamp);
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}

.choose-key:hover {
  box-shadow: var(--key-edge-hover);
  transform: translateY(var(--key-hover-drop));
}

.choose-key:active {
  background: var(--key-cap-down);
  border-color: var(--key-rim-down);
  box-shadow: var(--key-edge-down);
  color: var(--key-legend-down);
  transform: translateY(var(--key-down-drop));
}

.choose-major:focus-visible,
.choose-minor:focus-visible,
.choose-key:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

body.choosing #card,
body.choosing #county-card { display: none; }

/* --- the gauge alone over the map, after Play */
#loading.brief,
#loading.brief.gone {
  background: rgba(12, 16, 21, .62);
  transition: none;
}

#loading.brief::before,
#loading.brief::after,
#loading.brief #loading-quote,
#loading.brief #loading-prompt { display: none; }

#loading.brief .loading-gauge {
  opacity: 1;
  transition: none;
}

/* --- the interface scales with the screen */
:root { --ui-scale: 1; --ui-text-k: 1; }

#hud,
#toolbar,
#card,
#county-card,
#diplo,
#route-panel,
#wip-note,
#choose-folder,
#tooltip,
.diplo-folder-tab,
.start-panel,
.start-dialog .dialog-panel,
.loading-panel,
.loading-gauge,
#loading-prompt,
.pause-folder {
  --text-k: var(--ui-text-k);
  zoom: var(--ui-scale);
}

#hud,
#toolbar,
#choose-folder { font-size: calc(14px / var(--text-k)); }

/* --- the typewriter bar */
.platen {
  position: relative;
  z-index: 3;
  height: 13px;
  border-radius: 7px;
  background: linear-gradient(180deg, #55554f, #1a1a18 45%, #000);
  box-shadow: 0 2px 3px rgba(0, 0, 0, .7);
}

.platen::before,
.platen::after {
  content: "";
  position: absolute;
  top: -3px;
  width: 12px;
  height: 19px;
  border-radius: 3px;
  background: repeating-linear-gradient(90deg, #2b2b28 0 2px, #77776f 2px 3px);
}

.platen::before { left: -8px; }
.platen::after { right: -8px; }

#hud {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  align-items: flex-start;
  pointer-events: none;
}

body.playing #hud { display: flex; }

/* The flag on its upright roller, flush with the screen's left. */
#hud-flag-mount {
  flex: none;
  display: flex;
  align-items: center;
  height: 84px;
  margin-right: 11px;
  pointer-events: auto;
}

.hoist {
  position: relative;
  z-index: 2;
  flex: none;
  align-self: stretch;
  width: 11px;
  background: repeating-linear-gradient(0deg, transparent 0 7px, rgba(0, 0, 0, .28) 7px 8px),
    linear-gradient(90deg, #17171a, #5d5d5a 30%, #2a2a29 55%, #050505);
  filter: drop-shadow(2px 1px 2px rgba(0, 0, 0, .6));
}

.hoist::before,
.hoist::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .55), transparent 35%, rgba(0, 0, 0, .55)),
    repeating-linear-gradient(90deg, #2b2b28 0 1.5px, #8c8c84 1.5px 3px);
}

.hoist::before { top: 0; border-radius: 0 0 2px 2px; box-shadow: 0 1px 0 #b8b4a8, 0 2px 0 #4a4842; }
.hoist::after { bottom: 0; border-radius: 2px 2px 0 0; box-shadow: 0 -1px 0 #b8b4a8, 0 -2px 0 #4a4842; }

#hud-flag-box {
  max-width: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .6));
}

#hud-flag-box img { max-width: none; max-height: none; filter: none; }

#hud-flag-box::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, .5), transparent 9px);
  -webkit-mask: var(--flag-mask, linear-gradient(transparent, transparent)) center / 100% 100% no-repeat;
  mask: var(--flag-mask, linear-gradient(transparent, transparent)) center / 100% 100% no-repeat;
  pointer-events: none;
}

#hud-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .55));
  pointer-events: auto;
}

/* The values are the sheet coming out of the roller. */
#hud-values {
  --tex-span: 3000px;

  position: relative;
  isolation: isolate;
  overflow: hidden;
  z-index: 2;
  display: flex;
  gap: 11px;
  padding: 7px 18px 8px 14px;
  background: var(--sheet);
  color: var(--ink);
  clip-path: polygon(0 0, 100% 0, calc(100% - 4px) 18%, 100% 38%, calc(100% - 5px) 60%, calc(100% - 1px) 80%, calc(100% - 5px) 100%, 0 100%);
}

.hud-value {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  overflow: visible;
  font: 700 calc(15px / var(--text-k, 1))/1 var(--type);
  white-space: nowrap;
}

.hud-value::after { display: none; }
.hud-value img { width: 17px; height: 17px; }

#hud-stack .platen { margin-top: -4px; }

/* The menu keys hang from the roller on levers, with no backing. */
#hud-menu {
  display: flex;
  gap: 8px;
  padding: 11px 0 0 9px;
}

.hud-key {
  position: relative;
  box-sizing: border-box;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  appearance: none;
  border-radius: 50%;
  background: var(--key-cap);
  color: var(--sheet);
  border: 2px solid var(--key-rim);
  box-shadow: var(--key-edge);
  cursor: pointer;
  transition: box-shadow .08s, transform .08s;
}

.hud-key img { width: 18px; height: 18px; }
.hud-key:hover { transform: translateY(var(--key-hover-drop)); box-shadow: var(--key-edge-hover); }

.hud-key:active {
  transform: translateY(var(--key-down-drop));
  background: var(--key-cap-down);
  border-color: var(--key-rim-down);
  box-shadow: var(--key-edge-down);
}

.hud-key:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

.lever {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 2.5px;
  height: 15px;
  margin-left: -1px;
  background: linear-gradient(90deg, #5c5a52, #d2cfc4, #55534c);
  transform: rotate(var(--tilt, 0deg));
  transform-origin: bottom;
}

/* The clock on its torn slip, and Layers on a rod under its roller. */
#toolbar {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 5;
  isolation: isolate;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  color: var(--ink);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .55));
}

#toolbar::before { display: none; }

#clock-paper {
  --tex-span: 3000px;

  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  right: 0;
  height: 42px;
  isolation: isolate;
  overflow: hidden;
  background: var(--sheet);
  clip-path: polygon(0 0, 100% 0, 100% 92%, 90% 100%, 80% 91%, 70% 98%, 60% 92%, 50% 100%, 40% 91%, 30% 97%, 20% 90%, 10% 98%, 5% 92%, 2% 64%, 6% 42%, 1% 20%);
}

#clock-paper::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  width: var(--tex-span);
  height: var(--tex-span);
  transform: translate(-50%, -50%) rotate(var(--tex-turn, 0deg));
  background: var(--texture-img) var(--tex-at, 0 0) / var(--texture-size) auto repeat;
  mix-blend-mode: soft-light;
  opacity: var(--texture-strength);
  pointer-events: none;
}

#toolbar #clock {
  height: 38px;
  margin: 0;
  padding: 0 12px 0 24px;
}

#clock-face {
  min-width: 0;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  font: 700 calc(15px / var(--text-k, 1))/1 var(--type);
}

#clock-face::after { display: none; }

#toolbar > .platen {
  position: absolute;
  top: 36px;
  left: 4px;
  right: 4px;
}

#layer-rod {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 138px;
  margin: 14px 12px 0 0;
}

#layer-rod::before {
  content: "";
  position: absolute;
  top: -11px;
  bottom: 8px;
  left: 50%;
  width: 3px;
  margin-left: -1px;
  background: linear-gradient(90deg, #5c5a52, #d2cfc4, #55534c);
}

#layers-button {
  position: relative;
  box-sizing: border-box;
  height: 26px;
  padding: 0 11px;
  border-radius: 13px;
  background: var(--key-cap);
  color: var(--sheet);
  border: 2px solid var(--key-rim);
  box-shadow: var(--key-edge);
  font: 700 calc(11px / var(--text-k, 1))/1 var(--type);
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: box-shadow .08s, transform .08s;
}

#layers-button:hover { transform: translateY(var(--key-hover-drop)); box-shadow: var(--key-edge-hover); }

#layers-button:active,
#layers-button.active {
  transform: translateY(var(--key-down-drop));
  background: var(--key-cap-down);
  border-color: var(--key-rim-down);
  color: var(--key-legend-down);
  box-shadow: var(--key-edge-down);
}

#layers-button:focus-visible {
  outline: 2px solid var(--ribbon);
  outline-offset: 2px;
}

#toolbar #modes {
  position: relative;
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  width: 100%;
  margin-top: 7px;
  overflow: visible;
  background: none;
  border: 0;
  box-shadow: none;
}

#toolbar #modes.open { display: flex; }
#toolbar #modes::after { display: none; }
#toolbar #modes button { width: 100%; }

#toolbar #infra-menu,
#toolbar #infra-button {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

#hud-menu { overflow: visible; isolation: auto; }
#hud-menu::after { display: none; }

body.choosing #toolbar { display: none; }

/* The infrastructure list opens beside its key. */
#toolbar #infra-menu { position: relative; }

#toolbar #infra-list {
  position: absolute;
  top: 0;
  right: calc(100% + 8px);
  width: max-content;
}

#toolbar #infra-list button { width: 100%; }

/* One modifier under its group on a breakdown. */
.cm-line.cm-part > span:first-child { padding-left: 1em; }

.hud-value b { font-weight: inherit; }
