:root {
  color-scheme: light dark;

  /* Greys are tinted from gold (hue 43, sampled from gold leaf) so the page and the metal read as one material. */
  --ground: #e8e5df;
  --surface: #f6f4f0;
  --raised: #eae7e1;
  --line: #d6d1c7;
  --rule: #e2ded6;
  --control: #857e72;
  --text: #1e1a14;
  --muted: #5a5347;
  --focus: #946f0c;
  --wash: #efe7d3;
  --warn-bg: #f6ecd2;
  --warn-ink: #5e4100;
  --series-1: #946f0c;
  --series-2: #1b6ca8;
  --up: #1a6c43;
  --down: #b3261e;
  --skip: #6b6459;
  --empty-cell: #dcd8cf;
  --shadow: 0 6px 22px rgb(30 26 20 / 18%);

  /* The board keeps its colours in both themes, like the sign it is drawn from. */
  --lacquer: #5b0e18;
  --thread: #d6b066;
  --thread-sheen: #bf9648;
  --thread-bright: #fff3d6;
  --gold-soft: #eedfbc;
  --thread-rgb: 214 176 102;
  --on-thread: #3a0a10;
  --gold-line: rgb(var(--thread-rgb) / 24%);
  --gold-edge: rgb(var(--thread-rgb) / 70%);
  --board-up: #a9ecc3;
  --board-down: #ffc4b8;
  --photo-ink: #120c07;
  --photo-cream: #f5ecd8;
  --photo-cream-soft: #eee3cc;
  --idle: #8d8679;
  --paper: #faf4e6;
  --paper-ink: #1e1a14;
  --paper-muted: #5a5347;
  --paper-up: #1f7a4c;
  --paper-down: #b3261e;

  --font-display: "Noto Serif Display", "Noto Serif SC", Georgia, serif;
  --font-heading: "Noto Serif SC", "Songti SC", Georgia, serif;
  --font-body: "Noto Sans SC", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-figure: "Chivo Mono", ui-monospace, Consolas, monospace;

  --gap: 16px;
  --radius: 4px;
  --tab-bar: 60px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

/* Twice, because the reader can follow the system or choose dark outright. */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --ground: #14110d;
    --surface: #1d1914;
    --raised: #272219;
    --line: #342e25;
    --rule: #2a251d;
    --control: #7d7567;
    --text: #f1ede4;
    --muted: #b7afa1;
    --focus: #d6b066;
    --wash: #2c2518;
    --warn-bg: #3a2f13;
    --warn-ink: #f7dfa3;
    --series-1: #a67f12;
    --series-2: #2f86c4;
    --up: #4ac586;
    --down: #f4808a;
    --skip: #a59d90;
    --empty-cell: #2c271f;
    --shadow: 0 6px 22px rgb(0 0 0 / 60%);
  }
}

:root[data-mode="dark"] {
  --ground: #14110d;
  --surface: #1d1914;
  --raised: #272219;
  --line: #342e25;
  --rule: #2a251d;
  --control: #7d7567;
  --text: #f1ede4;
  --muted: #b7afa1;
  --focus: #d6b066;
  --wash: #2c2518;
  --warn-bg: #3a2f13;
  --warn-ink: #f7dfa3;
  --series-1: #a67f12;
  --series-2: #2f86c4;
  --up: #4ac586;
  --down: #f4808a;
  --skip: #a59d90;
  --empty-cell: #2c271f;
  --shadow: 0 6px 22px rgb(0 0 0 / 60%);
}

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

html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--control) transparent; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--text);
  caret-color: var(--series-1);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p, ol, ul, dl, dd, figure { margin: 0; padding: 0; }
ol, ul { list-style: none; }

/* Links are ink with a gold underline: blue belongs to the chart data. */
a { color: var(--text); text-decoration-color: var(--series-1); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }

::selection { background: var(--thread); color: var(--on-thread); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.board :focus-visible, .band :focus-visible { outline-color: var(--thread-bright); }

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

[hidden] { display: none !important; }

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

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--ground);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-right: auto;
  color: var(--text);
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.brand svg { flex: none; }

.tabs {
  position: fixed;
  inset: auto 0 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tabs a {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: var(--tab-bar);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s;
}

.tabs a[aria-current="page"] { color: var(--text); font-weight: 700; }

.tabs a[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset: 0 24% auto;
  height: 2px;
  background: var(--series-1);
}

.tabs a:active { background: var(--raised); }

.next-poll { display: none; font-size: 13px; color: var(--muted); white-space: nowrap; }

.lang select {
  appearance: none;
  min-height: 44px;
  max-width: 132px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--control);
  border-radius: var(--radius);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M0 0h10L5 6z' fill='%238d8679'/%3E%3C/svg%3E") right 10px center/9px no-repeat;
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s;
}

/* Page */

.page {
  flex: 1;
  width: 100%;
  max-width: 1272px;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}

.view { min-width: 0; }

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.view-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-width: 0; }

.view-head h1 { font-family: var(--font-heading); font-size: 24px; font-weight: 700; line-height: 1.25; }

.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }

.tag {
  display: inline-flex;
  flex: none;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 3px;
  background: var(--raised);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
}

.tag.is-ok { color: var(--up); }
.tag.is-bad { color: var(--down); }

.tag-board { background: rgb(var(--thread-rgb) / 17%); color: var(--gold-soft); }

.panel {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel h2 {
  display: flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

.panel-note { margin-top: 10px; font-size: 13px; color: var(--muted); }

.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.panel-head a { font-size: 13.5px; }

.notice {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 14px;
}

/* The ⓘ button. The drawn mark is small; the tap area around it is not. */

.info {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.info::before {
  content: "i";
  display: grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font: 600 10px/1 Georgia, serif;
}

.info::after { content: ""; position: absolute; inset: -8px; }

.info[aria-expanded="true"] { color: var(--text); }

@media (hover: hover) {
  .info:hover { color: var(--text); }
  .lang select:hover { border-color: var(--control); }
}

.board .info { color: var(--gold-soft); }
.board .info[aria-expanded="true"] { color: var(--thread-bright); }

.popover {
  position: fixed;
  z-index: 30;
  width: min(320px, calc(100vw - 24px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.55;
}

/* The day's finding on solid dark, with the photograph beside it: no price ever sits on a photograph. */

.band {
  display: grid;
  margin-bottom: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--photo-ink);
  color: var(--photo-cream);
}

.band img { display: block; width: 100%; height: 26px; object-fit: cover; }

.band-text { padding: 8px 14px 10px; }

.band-finding { font-family: var(--font-heading); font-size: 16px; font-weight: 500; line-height: 1.35; }
.band-finding:empty { min-height: 22px; }
.band-note { font-size: 13px; color: var(--photo-cream-soft); }

/* Overview */

.overview { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }

.board {
  container-type: inline-size;
  min-width: 0;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--lacquer);
  color: var(--gold-soft);
}

.board-head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; }

.board h1 { font-family: var(--font-heading); font-size: 23px; font-weight: 700; line-height: 1.25; color: var(--thread); }

.market { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; font-size: 13.5px; }

.market-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--gold-soft); opacity: .6; }
.market[data-state="open"] .market-dot { background: var(--board-up); opacity: 1; }

.board-controls { display: flex; gap: 8px; width: 100%; margin-top: 6px; }

.board-select { position: relative; display: block; }
.board-flag { position: absolute; top: 50%; left: 10px; transform: translateY(-50%); pointer-events: none; }

.board-select select {
  appearance: none;
  height: 44px;
  padding: 0 28px 0 38px;
  border: 1px solid var(--gold-edge);
  border-radius: var(--radius);
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M0 0h10L5 6z' fill='%23eedfbc'/%3E%3C/svg%3E") right 10px center/9px no-repeat;
  color: var(--gold-soft);
  font-size: 15px;
  cursor: pointer;
  transition: background-color .15s, border-color .15s;
}

.board-select option { background: var(--surface); color: var(--text); }

.board-units {
  display: grid;
  flex: 1;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  border: 1px solid var(--gold-edge);
  border-radius: var(--radius);
  overflow: hidden;
}

.board-units button {
  appearance: none;
  min-width: 44px;
  height: 42px;
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: var(--gold-soft);
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}

.board-units button[aria-pressed="true"] { background: var(--thread); color: var(--on-thread); font-weight: 700; }
.board-units button:focus-visible { outline-offset: -4px; outline-color: currentColor; }

@media (hover: hover) {
  .board-units button:not([aria-pressed="true"]):hover { background: rgb(var(--thread-rgb) / 16%); }
  .board-select select:hover { background-color: rgb(var(--thread-rgb) / 12%); }
}

.price-row { padding: 4px 0 6px; }
.price-row + .price-row { border-top: 1px solid var(--gold-line); padding-top: 6px; }
.price-lead { margin-top: 6px; }

.price-row dt { font-family: var(--font-heading); font-size: 19px; font-weight: 500; line-height: 1.3; }

.board-change { display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px; font-family: var(--font-body); }
.board-change small { font-size: 13px; font-weight: 400; }

.board-price {
  --room: 96px;
  --scale: 1;
  --len: 6;
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--thread);
  font-family: var(--font-display);
  line-height: 1;
  white-space: nowrap;
}

.board-price small { flex: none; font-family: var(--font-body); font-size: 19px; font-weight: 400; color: var(--gold-soft); }

/* The figure takes the room left by the symbol and unit, however long the currency and unit make it. */
.board-price b {
  font-weight: 600;
  font-size: min(calc(104px * var(--scale)), calc((100cqw - var(--room)) / var(--len) * 1.86 * var(--scale)));
  letter-spacing: -.01em;
  font-variant-numeric: lining-nums tabular-nums;
}

.price-row:not(.price-lead) .board-price { --scale: .62; }

.delta {
  font-family: var(--font-figure);
  font-weight: 500;
  font-size: 15px;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--muted);
}

.delta[data-tone="up"] { color: var(--up); }
.delta[data-tone="down"] { color: var(--down); }
.delta:empty { display: none; }

.board .delta { font-size: 18px; color: var(--gold-soft); }
.board .delta[data-tone="up"] { color: var(--board-up); }
.board .delta[data-tone="down"] { color: var(--board-down); }

.is-new { animation: rise .32s var(--ease); }

@keyframes rise {
  from { opacity: .4; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* The woven band. touch-action keeps vertical scrolling with the page while a finger reads across. */

.woven-wrap { margin-top: 6px; }

.woven { position: relative; height: 72px; touch-action: pan-y; cursor: crosshair; }
.woven svg { display: block; }
.is-weaving .threads { animation: weave .8s var(--ease) both; }

@keyframes weave {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

.woven:focus-visible { outline-offset: 4px; }

.float-weave { fill: rgb(var(--thread-rgb) / 9%); }
.float-gold { fill: var(--thread); }
.float-sheen { fill: var(--thread-sheen); }
.float-active { fill: var(--thread-bright); }
.woven .crosshair { stroke: var(--thread-bright); stroke-opacity: .6; }

.board-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin-top: 6px; font-size: 13px; }
.spark-label { flex: 1 0 100%; order: 3; }
.board-time { margin-left: auto; white-space: nowrap; }

/* Spot and exchange rate as one ledger */

.rail { display: grid; gap: var(--gap); min-width: 0; align-content: start; }

.ledger { padding-block: 6px; }

.ledger-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; padding: 8px 0; }
.ledger-row + .ledger-row { border-top: 1px solid var(--rule); }

.ledger h2 { display: block; flex: 1 1 120px; font-family: var(--font-body); font-size: 13.5px; font-weight: 400; color: var(--muted); }
.ledger h2 .info { vertical-align: middle; margin-block: -6px; }

.ledger-figure { flex: none; margin-left: auto; text-align: right; }
.ledger-figure b { display: block; font-family: var(--font-figure); font-size: 25px; font-weight: 500; line-height: 1.2; }
.ledger-figure b small { font-size: 14px; font-weight: 400; color: var(--muted); }
.ledger-figure p { font-size: 12.5px; color: var(--muted); }
.ledger-figure p:empty { display: none; }
.ledger-figure .delta { font-size: 13.5px; }
.ledger-figure small { font-size: 12.5px; }

/* Calculator */

.calc-tabs { display: flex; align-items: center; gap: 18px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }

.calc-tabs button:not(.info) {
  appearance: none;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--muted);
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s;
}

.calc-tabs button[aria-pressed="true"] { border-bottom-color: var(--series-1); color: var(--text); }
.calc-tabs .info { margin-left: auto; }

.calc-fields { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.2fr) minmax(0, .8fr); gap: 8px; }

.field { display: grid; gap: 2px; min-width: 0; font-size: 12.5px; color: var(--muted); }

.field input, .field select {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 8px;
  border: 1px solid var(--control);
  border-radius: var(--radius);
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-figure);
  font-size: 16px; /* Below 16px, iPhones zoom the whole page when the control is tapped. */
  transition: border-color .15s;
}

.field select {
  appearance: none;
  padding-right: 22px;
  background: var(--ground) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M0 0h10L5 6z' fill='%238d8679'/%3E%3C/svg%3E") right 8px center/9px no-repeat;
  font-family: var(--font-body);
  font-size: 15px;
  cursor: pointer;
}

.calc-result:empty { display: none; }
.calc-result { margin-top: 10px; font-family: var(--font-figure); font-size: 28px; font-weight: 500; line-height: 1.4; overflow-wrap: anywhere; }
.calc-note { margin-top: 2px; font-size: 13px; color: var(--muted); }

/* Gold in every currency */

.rates { padding-inline: 0; padding-block: 12px 2px; }

.rates-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 0 16px 6px; }
.rates-head h2 { white-space: nowrap; }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--idle); }
.live[data-state="open"]::before { background: var(--up); }

.rates-time { font-size: 13px; color: var(--muted); }

.rates-search { flex: 1 0 100%; }

.rates-search input {
  width: 100%;
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--control);
  border-radius: var(--radius);
  background: var(--ground);
  font-size: 16px;
  transition: border-color .15s;
}

.rates-search input::placeholder { color: var(--muted); opacity: 1; }

.rates-more { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 0 16px 4px; font-size: 12.5px; color: var(--muted); }
.rates-more::after { content: ""; width: 6px; height: 6px; border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor; transform: rotate(45deg); }

/* position keeps screen-reader text inside the scroller, where it cannot widen the page. */
.table-scroll { position: relative; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }

/* Columns take their content width on a phone, so the next column is always cut through its figures. */
.rates-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }

.rates-table th, .rates-table td {
  height: 44px;
  padding: 0 10px;
  border-top: 1px solid var(--rule);
  background: var(--surface);
  text-align: left;
  font-weight: 400;
  white-space: nowrap;
  transition: background-color .12s;
}

.rates-table thead th { height: 30px; border: 0; font-size: 12.5px; color: var(--muted); }
.rates-table .num { text-align: right; }
.rates-table td.num { font-family: var(--font-figure); font-size: 14.5px; font-variant-numeric: tabular-nums; }

/* The first column stays put while the figures slide under it. */
.rates-table tr > :first-child { position: sticky; left: 0; z-index: 1; }

/* On a phone the name sits under the place, so the sticky column stays narrow and the next figures show. */
.rate-pick {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 150px;
  min-height: 52px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.flag { display: block; flex: none; width: 20px; height: 15px; border-radius: 2px; box-shadow: 0 0 0 1px var(--line); object-fit: cover; }
.rate-words { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }

.rate-pick b { font-size: 14px; font-weight: 500; line-height: 1.3; white-space: nowrap; }
.rate-name { font-size: 12.5px; line-height: 1.3; color: var(--muted); white-space: nowrap; }
.rate-code { display: none; }

.rates-table tbody tr { cursor: pointer; }
.rates-table tr[aria-current="true"] > * { background: var(--wash); font-weight: 500; }
.rates-table tr[aria-current="true"] td.num { font-weight: 500; }

@media (hover: hover) {
  .rates-table tbody tr:not([aria-current="true"]):hover > * { background: var(--raised); }
  .field input:hover, .field select:hover, .rates-search input:hover { border-color: var(--muted); }
}

/* News on the overview */

.brief-list { margin-top: 2px; }
.brief-list li { border-top: 1px solid var(--rule); }
.brief-list li:first-child { border: 0; }
.brief-list a { display: block; padding: 7px 0; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.brief-list .news-title { font-size: 14.5px; }

/* Loading: the final layout with flat bars where figures will land, so nothing moves when the data arrives. */

.is-loading .band-finding::before,
.is-loading .board-price b,
.is-loading .ledger-figure b,
.bar {
  color: transparent;
  border-radius: 3px;
  background: currentColor;
  animation: settle 1.4s ease-in-out infinite alternate;
}

.bar { display: block; width: 100%; height: 14px; margin: 6px 0; background: var(--raised); }
.num .bar { width: 72%; margin-left: auto; }

.is-loading .board-price b { display: inline-block; min-width: 3em; background: rgb(var(--thread-rgb) / 16%); }
.is-loading .ledger-figure b { background: var(--raised); }
.is-loading .band-finding::before { content: ""; display: block; width: min(320px, 70%); height: 20px; background: rgb(245 236 216 / 18%); }

@keyframes settle {
  from { opacity: .55; }
  to { opacity: 1; }
}

/* Segmented control */

.segments {
  display: inline-flex;
  max-width: 100%;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--line);
}

.segments button {
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}

.segments button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 700; }

@media (hover: hover) {
  .segments button:not([aria-pressed="true"]):hover { color: var(--text); }
}

/* Chart */

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }

.line-key { display: inline-block; width: 16px; height: 2px; border-radius: 1px; flex: none; }

.chart {
  position: relative;
  min-height: 260px;
  transition: opacity .15s;
  touch-action: pan-y;
  cursor: crosshair;
}

.chart.is-loading { opacity: .5; }

.chart svg { display: block; width: 100%; }

.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-family: var(--font-figure); font-size: 12px; }
.chart .end-label { fill: var(--text); font-family: var(--font-figure); font-size: 12.5px; font-weight: 500; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

.tooltip {
  position: absolute;
  top: 8px;
  z-index: 2;
  pointer-events: none;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
}

.tooltip-time { color: var(--muted); }
.tooltip-row { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.tooltip-row b { color: var(--text); font-family: var(--font-figure); font-size: 14px; font-weight: 500; }
.tooltip-change { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.tooltip-change b { font-family: var(--font-figure); font-size: 13.5px; font-weight: 500; }
.tooltip-change[data-tone="up"] b { color: var(--up); }
.tooltip-change[data-tone="down"] b { color: var(--down); }

/* On the board the tooltip is a slip of paper, so it reads against the lacquer in both themes. */
.tooltip-woven { top: auto; bottom: 2px; padding: 3px 9px; border: 0; background: var(--paper); color: var(--paper-muted); }
.tooltip-woven .tooltip-time { color: var(--paper-muted); }
.tooltip-woven .tooltip-row b { color: var(--paper-ink); }
.tooltip-woven .tooltip-change { color: var(--paper-muted); }
.tooltip-woven .tooltip-change[data-tone="up"] b { color: var(--paper-up); }
.tooltip-woven .tooltip-change[data-tone="down"] b { color: var(--paper-down); }

.chart-table { margin-top: 8px; font-size: 14px; }
.chart-table summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; text-decoration: underline; text-decoration-color: var(--series-1); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }

.chart-table .table-scroll { max-height: 280px; overflow: auto; }

.chart-table table, .kijang-table { width: 100%; border-collapse: collapse; }

.chart-table th, .chart-table td {
  padding: 4px 8px 4px 0;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  font-family: var(--font-figure);
  font-size: 13.5px;
}

.chart-table th { font-family: var(--font-body); font-weight: 500; }
.chart-table th:first-child, .chart-table td:first-child { text-align: left; }
.chart-table thead th { position: sticky; top: 0; background: var(--ground); }

/* News */

.news-empty { position: relative; min-height: 160px; display: grid; place-items: center; border-radius: var(--radius); overflow: hidden; background: var(--photo-ink); color: var(--photo-cream); text-align: center; }
.news-empty img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.news-empty::after { content: ""; position: absolute; inset: 0; background: rgb(18 12 7 / 70%); }
.news-empty p { position: relative; z-index: 1; padding: 24px; font-family: var(--font-heading); font-size: 17px; }

.news-list { display: grid; grid-template-columns: minmax(0, 1fr); column-gap: 32px; }

.news-list li { min-width: 0; border-bottom: 1px solid var(--line); }

.news-list a {
  display: block;
  padding: 10px 0;
  color: var(--text);
  text-decoration: none;
  overflow-wrap: anywhere;
}

@media (hover: hover) {
  .news-list a:hover .news-title, .brief-list a:hover .news-title { text-decoration: underline; text-underline-offset: 3px; }
}

.news-title { display: block; font-size: 16px; line-height: 1.45; }
.news-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; margin-top: 2px; font-size: 13px; color: var(--muted); }
.news-lang { padding: 0 5px; border-radius: 3px; background: var(--raised); font-size: 12px; }

.more {
  appearance: none;
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  border: 1px solid var(--control);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 15px;
  cursor: pointer;
}

.empty { padding: 20px 14px; color: var(--muted); border: 0 !important; grid-column: 1 / -1; }

.link-button { padding: 0; border: 0; background: none; font-size: inherit; text-decoration: underline; text-decoration-color: var(--series-1); text-underline-offset: 3px; cursor: pointer; }

/* Kijang Emas */

.kijang-banner {
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: 112px;
  margin-bottom: var(--gap);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--photo-ink);
  color: var(--photo-cream);
}

.kijang-banner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.kijang-banner::after { content: ""; position: absolute; inset: 0; background: rgb(18 12 7 / 68%); }

.kijang-banner-text { position: relative; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 14px 16px; }
.kijang-banner h1 { font-family: var(--font-heading); font-size: 24px; font-weight: 700; line-height: 1.25; }
.kijang-banner .tag { background: rgb(245 236 216 / 16%); color: var(--photo-cream); }
.kijang-banner .info { color: var(--photo-cream); }

.kijang-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
.kijang-side { display: grid; gap: var(--gap); min-width: 0; align-content: start; }

.kijang-chart-panel { display: flex; flex-direction: column; }
.kijang-chart-panel h2 { margin-bottom: 6px; }
.kijang-chart-panel .chart { flex: 1; }

.ladder { display: flex; flex-direction: column; }
.ladder .panel-note { padding-top: 10px; }

.ladder-track { position: relative; height: 44px; margin: 14px 8px 4px; }

.ladder-rail { position: absolute; top: 20px; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--raised); }
.ladder-span { position: absolute; top: 20px; height: 4px; background: var(--series-2); }

.ladder-mark { position: absolute; top: 12px; width: 4px; height: 20px; margin-left: -2px; border-radius: 2px; background: var(--series-2); }
.ladder-mark[data-kind="theory"] { top: 6px; width: 6px; height: 32px; margin-left: -3px; background: var(--series-1); }

.ladder-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

.ladder-legend li { min-width: 0; }
.ladder-legend li:nth-child(2) { text-align: center; }
.ladder-legend li:last-child { text-align: right; }

.ladder-name { display: block; font-size: 13px; line-height: 1.3; color: var(--muted); }

.ladder-value {
  display: block;
  font-family: var(--font-figure);
  font-weight: 500;
  font-size: clamp(16px, 4.6vw, 21px);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.ladder-diff { display: block; font-family: var(--font-figure); font-size: 13px; color: var(--text); }

.kijang-table th, .kijang-table td { padding: 10px 0 10px 12px; border-bottom: 1px solid var(--rule); text-align: right; vertical-align: top; }
.kijang-table tr > :first-child { padding-left: 0; text-align: left; }
.kijang-table tbody tr:last-child > * { border-bottom: 0; }
.kijang-table thead th { font-size: 13px; font-weight: 400; color: var(--muted); }
.kijang-table tbody th { font-weight: 500; font-size: 15px; }

.kijang-price { display: block; font-family: var(--font-figure); font-weight: 500; font-size: 18px; line-height: 1.3; white-space: nowrap; }
.kijang-diff { display: block; font-size: 13px; color: var(--muted); }

/* System status */

.status-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
.status-side { display: grid; gap: var(--gap); min-width: 0; }

.sources li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 0 8px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.sources li:last-child { border-bottom: 0; padding-bottom: 0; }
.sources li.empty { display: block; padding-inline: 0; }

.source-icon { width: 20px; height: 20px; margin-top: 2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.source-icon[data-status="ok"] { color: var(--up); }
.source-icon[data-status="skipped"] { color: var(--skip); }
.source-icon[data-status="failed"] { color: var(--down); }

.source-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 10px; }
.source-name { font-weight: 500; }
.source-state { font-size: 14px; font-weight: 500; }
.source-state[data-status="ok"] { color: var(--up); }
.source-state[data-status="skipped"] { color: var(--skip); }
.source-state[data-status="failed"] { color: var(--down); }

.source-reason { font-size: 14px; }
.source-detail, .source-last { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.quota-figure { margin-top: 6px; font-family: var(--font-figure); font-weight: 500; font-size: 24px; line-height: 1.3; }

.quota-bar { position: relative; height: 8px; margin: 8px 0 6px; border-radius: 4px; background: var(--raised); }
.quota-used { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--series-1); }
.quota-cap { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); }

/* One thread per run, in the same language as the woven band. */
.runs { display: grid; grid-template-columns: repeat(48, minmax(0, 1fr)); gap: 2px; margin-top: 10px; }
.run { height: 44px; background: var(--empty-cell); }
.run[data-state="ok"] { background: var(--up); }
/* A failed run is also shorter, so the row does not rely on colour alone. */
.run[data-state="failed"] { align-self: end; height: 60%; background: var(--down); }

/* Login */

.gate { display: grid; place-items: center; min-height: 60vh; }
.gate-form { display: grid; gap: 12px; width: min(400px, 100%); padding: 22px; }
.gate-form h1 { font-family: var(--font-heading); font-size: 24px; font-weight: 700; line-height: 1.25; }
.gate-form .panel-note { margin-top: 0; }
.gate-form .field input { font-family: var(--font-body); }

.is-locked .view,
.is-locked .asset-bar,
.is-locked .ticker,
.is-locked .tabs,
.is-locked .next-poll,
.is-locked .top-link,
.is-locked .notice { display: none !important; }

.form-error { font-size: 13.5px; color: var(--down); }
.form-error:empty { display: none; }

.primary, .secondary, .danger {
  appearance: none;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, border-color .15s;
}

.primary { border: 1px solid var(--lacquer); background: var(--lacquer); color: var(--thread); }
.secondary { border: 1px solid var(--control); background: var(--surface); color: var(--text); }
.danger { margin-right: auto; border: 1px solid var(--down); background: transparent; color: var(--down); }
.primary:disabled, .secondary:disabled { opacity: .55; cursor: not-allowed; }

.view-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Choosing an asset */

.asset-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.asset-chip {
  appearance: none;
  flex: none;
  min-width: 44px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}

/* A little space between the three kinds, so the row reads as groups without any labels. */
.asset-chip[data-group="base"]:first-of-type,
.asset-chip[data-asset="HG"],
.asset-chip[data-asset="BTC"] { margin-left: 10px; }

.asset-chip[aria-pressed="true"] { border-color: var(--lacquer); background: var(--lacquer); color: var(--thread); font-weight: 700; }

/* The price strip */

.ticker { display: flex; align-items: center; border-bottom: 1px solid var(--line); background: var(--surface); }

.ticker-view { flex: 1; min-width: 0; overflow: hidden; }

.ticker-track { display: flex; width: max-content; animation: ticker-run var(--ticker-seconds, 60s) linear infinite; }

@keyframes ticker-run {
  to { transform: translateX(-50%); }
}

.ticker:hover .ticker-track,
.ticker:focus-within .ticker-track,
.ticker.is-paused .ticker-track { animation-play-state: paused; }

.ticker-set { display: flex; }

.ticker-item {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--rule);
  background: none;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.ticker-item b { font-weight: 700; }
.ticker-price { font-family: var(--font-figure); }
.ticker-change { font-family: var(--font-figure); font-size: 12.5px; color: var(--muted); }
.ticker-change[data-tone="up"] { color: var(--up); }
.ticker-change[data-tone="down"] { color: var(--down); }

.ticker-pause {
  position: relative;
  flex: none;
  width: 44px;
  height: 36px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}

.ticker-pause::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 18px;
  width: 8px;
  height: 12px;
  border-inline: 3px solid var(--muted);
}

.ticker-pause[aria-pressed="true"]::before {
  width: 0;
  height: 0;
  border-block: 6px solid transparent;
  border-inline: 10px solid var(--muted);
  border-right: 0;
}

/* The band without a photograph */

.band.no-photo { grid-template-columns: minmax(0, 1fr); }

/* News tools */

.news-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: 8px; margin-bottom: 8px; }
.news-search { grid-column: 1 / -1; }

.news-search input {
  width: 100%;
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--control);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px;
}

.news-search input::placeholder { color: var(--muted); opacity: 1; }
.news-tools .field:last-of-type { grid-column: 1 / -1; }
.news-count { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.news-count:empty { display: none; }

mark { border-radius: 2px; background: var(--wash); color: inherit; box-shadow: inset 0 -2px 0 var(--series-1); }

/* Kijang history */

.kijang-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: 8px; margin-bottom: 10px; }
.kijang-ranges, .kijang-units { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kijang-ranges button, .kijang-units button { padding: 0 4px; font-size: 14px; }
.field select:disabled { opacity: .55; cursor: not-allowed; }

.kijang-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; margin-top: 10px; }
.kijang-stats dt { font-size: 12.5px; color: var(--muted); }
.kijang-stats dd { font-family: var(--font-figure); font-size: 15px; font-weight: 500; }
.kijang-stats dd[data-tone="up"] { color: var(--up); }
.kijang-stats dd[data-tone="down"] { color: var(--down); }

/* Long ranges wrap on a phone rather than run off the page. */
.chart-ranges { flex-wrap: wrap; }
.chart-ranges button { flex: 1 0 22%; padding: 0 8px; }

/* AI note */

.ai { grid-column: 1 / -1; }
.ai-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--series-1); }
.ai-result { max-width: 75ch; margin-top: 10px; font-size: 15.5px; line-height: 1.7; }
.ai-result:empty { display: none; }

/* Holdings */

.holdings-summary { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
.holdings-summary:empty { display: none; }

.holding-figure { padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.holding-figure span:first-child { display: block; font-size: 13px; color: var(--muted); }
.holding-figure b { display: block; font-family: var(--font-figure); font-size: 24px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }

/* The total is the one figure that matters here, so it takes the board's colours. */
.holding-figure:nth-child(2) { border-color: var(--lacquer); background: var(--lacquer); color: var(--thread); }
.holding-figure:nth-child(2) span:first-child { color: var(--gold-soft); }

.holdings-empty { display: grid; justify-items: start; gap: 10px; }

.holdings-table-panel { padding: 0; }
.holdings-table { width: 100%; min-width: 760px; border-collapse: separate; border-spacing: 0; }
.holdings-table th, .holdings-table td { padding: 8px 12px; border-top: 1px solid var(--rule); background: var(--surface); text-align: left; font-weight: 400; vertical-align: top; white-space: nowrap; }
.holdings-table thead th { border: 0; font-size: 12.5px; color: var(--muted); }
.holdings-table .num { text-align: right; font-family: var(--font-figure); font-size: 14.5px; }
.holdings-table thead .num { font-family: var(--font-body); font-size: 12.5px; }
.holdings-table tr > :first-child { position: sticky; left: 0; z-index: 1; }
.holdings-table tbody th b { display: block; font-weight: 500; }
.holdings-table td .delta { display: block; font-size: 13px; }

.cell-note { display: block; font-size: 12.5px; color: var(--muted); }

.holdings-share { margin-top: var(--gap); }
.share-list { display: grid; gap: 6px; margin-top: 8px; }
.share-list li { display: grid; grid-template-columns: 72px minmax(0, 1fr) 56px; align-items: center; gap: 8px; font-size: 14px; }
.share-list li { position: relative; }
.share-bar { display: block; height: 8px; border-radius: 1px; background: var(--series-1); }
.share-pct { font-family: var(--font-figure); font-size: 13.5px; text-align: right; }

/* Forms */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.field-wide { grid-column: 1 / -1; }
.field input[type="date"] { font-family: var(--font-body); font-size: 15px; }
.field input[type="text"]:not([inputmode]), .field input[type="password"], .field input[type="email"] { font-family: var(--font-body); }

.stack { display: grid; gap: 10px; margin-top: 10px; }

.dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop { background: rgb(0 0 0 / 55%); }
.dialog h2 { font-family: var(--font-heading); font-size: 19px; font-weight: 700; }
.dialog .form-error { margin-top: 10px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Alerts */

.alerts-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
.alert-form .primary { margin-top: 10px; }
.alert-form .form-error { margin-top: 6px; }

.alert-list { margin-top: 6px; }
.alert-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.alert-row:last-child { border-bottom: 0; }
.alert-row b { font-weight: 500; }
.alert-row[data-state="fired"] b { color: var(--muted); }
.alert-actions { display: flex; gap: 14px; font-size: 14px; }
.alert-actions button { min-height: 44px; }

.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 4px; padding: 0 5px; border-radius: 9px; background: var(--down); color: var(--surface); font-size: 12px; font-weight: 700; }

/* Settings */

.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
.settings-appearance .segments { margin-top: 6px; }

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 6px; }

.theme-card {
  appearance: none;
  display: grid;
  justify-items: start;
  gap: 2px;
  min-height: 84px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ground);
  text-align: left;
  cursor: pointer;
  transition: border-color .15s;
}

.theme-card b { font-size: 14px; font-weight: 500; }
.theme-card[aria-pressed="true"] { border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); }

.swatches { display: flex; gap: 4px; margin-bottom: 4px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); }

.account-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 8px; overflow-wrap: anywhere; }
.account-line b { font-weight: 500; }
.account-logout { min-height: 44px; margin-top: 8px; }

.member-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 16px; padding: 8px 0; border-bottom: 1px solid var(--rule); overflow-wrap: anywhere; }
.member-row:last-child { border-bottom: 0; }
.member-row b { display: block; font-weight: 500; }
.field input[readonly] { font-family: var(--font-figure); font-size: 13px; }

/* Admin-only parts stay out of the page entirely for everyone else. */
body:not(.is-admin) [data-admin] { display: none !important; }

.more-list { display: grid; gap: 8px; }
.more-list a { display: flex; align-items: center; min-height: 52px; padding: 0 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-decoration: none; }

.tabs a.tab-extra { display: none; }
.top-link { display: none; font-size: 14px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.top-link[aria-current="page"] { color: var(--text); font-weight: 500; }

/* The desktop widget: a small window of its own, sharing the page's colours. */

.widget { min-height: 100dvh; background: var(--lacquer); color: var(--gold-soft); }
.widget-main { display: flex; flex-direction: column; min-height: 100dvh; padding: 14px; }
.widget-lead { display: grid; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--gold-line); color: inherit; text-decoration: none; }
.widget-name { font-size: 14px; }
.widget-price { color: var(--thread); font-family: var(--font-display); font-size: clamp(26px, 11vw, 44px); font-weight: 600; line-height: 1.1; overflow-wrap: anywhere; }
.widget .delta { color: var(--gold-soft); font-size: 14px; }
.widget .delta[data-tone="up"] { color: var(--board-up); }
.widget .delta[data-tone="down"] { color: var(--board-down); }
.widget-list { flex: 1; margin-top: 4px; }
.widget-list li { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: baseline; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--gold-line); font-size: 13.5px; }
.widget-value { font-family: var(--font-figure); overflow-wrap: anywhere; }
.widget-foot { margin-top: 8px; font-size: 12.5px; }

/* Footer */

.footer {
  width: 100%;
  max-width: 1272px;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(var(--tab-bar) + 16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}

/* The narrowest phones: four 44px unit buttons no longer fit beside the currency menu. */

@media (max-width: 359px) {
  .board-controls { flex-wrap: wrap; }
  .board-select, .board-select select { width: 100%; }
  .calc-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .calc-fields .field:first-child { grid-column: 1 / -1; }
}

/* Tablet and wider: the tabs move up into the top bar. */

@media (min-width: 720px) {
  .topbar { min-height: 60px; gap: 28px; padding-inline: max(16px, calc((100vw - 1240px) / 2)); }

  .brand { margin-right: 0; }

  .tabs {
    position: static;
    display: flex;
    flex: 1;
    gap: 24px;
    padding: 0;
    background: none;
    border: 0;
  }

  .tabs a { min-height: 60px; font-size: 15px; }
  .tabs a[aria-current="page"] { font-weight: 500; }
  .tabs a[aria-current="page"]::before { inset: auto 0 12px; }
  .tabs a:active { background: none; }

  .lang select { min-height: 36px; }

  .page { padding-top: 16px; }
  .footer { padding-bottom: 16px; }

  .band { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); min-height: 64px; margin-bottom: var(--gap); }
  .band img { order: 2; height: 100%; min-height: 0; }
  .band-text { align-self: center; padding: 8px 22px; }
  .band-finding { font-size: 20px; }

  .board { padding: 18px 24px 14px; }
  .board h1 { font-size: 26px; }
  .board-controls { width: auto; margin: 0 0 0 auto; }
  .board-select select { height: 40px; font-size: 14px; }
  .board-units { flex: none; }
  .board-units button { width: 52px; height: 38px; font-size: 14px; }

  .price-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
  .board-price { --room: 300px; }
  .board-price small { font-size: 20px; }

  .woven { height: 88px; }
  .spark-label { flex: 1 1 auto; order: 0; }

  .rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ledger { display: grid; align-content: space-evenly; }

  .rates-search { flex: 0 1 240px; margin-left: auto; }
  .rates-search input { height: 36px; font-size: 14px; }
  .rates-table { width: 100%; min-width: 620px; }
  .rates-table th, .rates-table td { height: 41px; padding: 0 14px; }
  .rate-pick { width: 100%; min-height: 40px; }
  .rate-words { flex-direction: row; align-items: center; gap: 6px; }
  .rate-pick b { font-size: inherit; }
  .rate-code { display: inline; }
  .rates-table th:first-child { padding-left: 18px; }
  .rates-table tr > :last-child { padding-right: 18px; }

  .chart, .chart-empty { min-height: 320px; }

  .tabs a.tab-extra { display: grid; grid-auto-flow: column; }
  .tabs a.tab-more { display: none; }
  .tabs { gap: 18px; }
  .top-link { display: block; }
  .news-tools { grid-template-columns: minmax(0, 1fr) 150px 200px 130px; }
  .news-search { grid-column: auto; }
  .news-tools .field:last-of-type { grid-column: auto; }
  .kijang-ranges, .kijang-units { display: inline-flex; grid-column: auto; }
  .kijang-controls { display: flex; flex-wrap: wrap; align-items: flex-end; }
  .kijang-controls .field { width: 116px; }
  .kijang-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .holdings-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-appearance { grid-column: 1 / -1; }
  .chart-ranges { flex-wrap: nowrap; }
  .chart-ranges button { flex: 1 1 auto; }
}

/* Room for the next price poll only once every tab already fits. */

@media (min-width: 1160px) {
  .next-poll { display: block; }
}

/* The asymmetric grid: board and rates take two thirds, and the right third is the working column. */

@media (min-width: 1000px) {
  .overview { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: stretch; }
  .rail { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .ledger, .calc { min-width: 0; }
  .brief-news { padding-block: 12px; }

  .news-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .alerts-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); align-items: start; }
  .kijang-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

  /* Sources become a table across the page, with allowance and recent runs side by side under it. */
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-sources { grid-column: 1 / -1; }
  .status-side { display: contents; }
  .sources li { grid-template-columns: 24px 150px 72px minmax(0, 1fr) auto; align-items: baseline; gap: 0 12px; padding: 12px 0; }
  .source-body, .source-head { display: contents; }
  .source-icon { align-self: center; margin-top: 0; }
  .source-detail { grid-column: 4 / -1; }
  .source-last { grid-column: 5; grid-row: 1; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }

  /* The strip stops moving and scrolls by hand, and the copy that only exists for the loop goes. */
  .ticker-view { overflow-x: auto; }
  .ticker-set[aria-hidden="true"] { display: none; }
  .ticker-pause { display: none; }
}

@media (forced-colors: active) {
  .chart .series { stroke: CanvasText; }
  .line-key { background: CanvasText !important; }
  .float-gold, .float-sheen, .float-active { fill: CanvasText; }
  .bar { outline: 1px solid CanvasText; }
  .run { outline: 1px solid CanvasText; }
}
