/* BDO Market: shared styles of the profit page and the market browser. The colors are the
   original dark theme; field borders and focus rings meet WCAG AA contrast (3:1 for controls). */
:root {
  color-scheme: dark;
  --bg: #0e1117;
  --card: #161b24;
  --card-2: #1c2230;
  --line: #262e3d;
  --field-border: #68748d;
  --text: #e6e9ef;
  --muted: #8892a6;
  --accent: #e3b55d;
  --accent-ink: #1b1408;
  --ok: #47c08a;
  --bad: #ef6b6b;
  --warn: #e8c547;
  --selected: #1f2735;
  --chart: #2fa596;
  --disabled-bg: #2a3140;
  --disabled-text: #8892a6;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --radius: 8px;
  --radius-lg: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 500px at 50% -200px, #1a2130, var(--bg));
  background-color: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: var(--space-4); top: -64px; z-index: 10; background: var(--accent); color: var(--accent-ink);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius); font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; }
.skip-link:focus { top: var(--space-2); }

/* Header and navigation */
.site-header { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; padding: var(--space-4);
  border-bottom: 1px solid var(--line); background: rgba(14, 17, 23, .6); backdrop-filter: blur(6px); }
.brand { font-size: 18px; font-weight: 600; margin: 0; }
.brand span { color: var(--accent); }
.site-nav { display: flex; gap: var(--space-1); }
.site-nav a { color: var(--muted); text-decoration: none; padding: var(--space-2) var(--space-3); border-radius: var(--radius); min-height: 44px;
  display: inline-flex; align-items: center; }
.site-nav a[aria-current="page"] { color: var(--text); background: var(--card-2); }
.live { margin-left: auto; color: var(--muted); display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.live.stale .dot { background: var(--warn); }
.live.down .dot { background: var(--bad); }

main { max-width: 1500px; margin: 0 auto; padding: var(--space-4); display: grid; gap: var(--space-6); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); min-width: 0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .25); }
h2 { font-size: 16px; margin: 0 0 var(--space-3); }
h3 { font-size: 14px; margin: 0 0 var(--space-2); }
p { margin: 0; }
.muted { color: var(--muted); }
.notice { border: 1px solid var(--line); border-left-width: 1px; background: var(--card-2); border-radius: var(--radius);
  padding: var(--space-2) var(--space-3); }
.notice.error { border-color: var(--bad); }
.notice.warn { border-color: var(--warn); }

/* Forms */
.controls { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-4); align-items: flex-end; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-1); }
.field > span, .field > label { color: var(--muted); font-size: 12px; }
.field .hint, .field .error-text { font-size: 12px; }
.field .error-text { color: var(--bad); }
input, select, button { font: inherit; }
select { max-width: 100%; }
.field { min-width: 0; }
input[type="text"], input[type="search"], input[type="password"], select {
  background: var(--card-2); color: var(--text); border: 1px solid var(--field-border); border-radius: var(--radius);
  padding: 8px 12px; min-height: 40px;
}
input[aria-invalid="true"] { border-color: var(--bad); }
/* A disabled field must look disabled, like a disabled button (e.g. the voice while reading aloud is off). */
input:disabled, select:disabled { background: var(--disabled-bg); color: var(--disabled-text); border-color: var(--line); cursor: not-allowed; }
/* The whole label is the hit area of its checkbox. */
.check { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; padding-right: var(--space-2); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
button, .button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--radius); padding: 8px 16px;
  font-weight: 600; cursor: pointer; min-height: 40px; text-decoration: none; display: inline-flex; align-items: center; gap: var(--space-2); }
button.secondary, .button.secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--field-border); }
button.link { background: none; border: 0; padding: 0 var(--space-1); min-height: 24px; color: var(--accent); font-weight: 400; text-decoration: underline; }
button:disabled { background: var(--disabled-bg); color: var(--disabled-text); cursor: default; }
@media (hover: hover) and (pointer: fine) {
  button:hover:not(:disabled), .button:hover { filter: brightness(1.08); }
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
caption { text-align: left; color: var(--muted); padding-bottom: var(--space-2); }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 600; vertical-align: bottom; }
th:has(button.sort) { padding: 0 8px; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th button.sort { background: none; color: inherit; border: 0; padding: 8px 0; min-height: 40px; width: 100%; font: inherit; font-weight: 600;
  cursor: pointer; display: flex; gap: 4px; align-items: center; }
th.num button.sort { justify-content: flex-end; }
th[aria-sort] button.sort { color: var(--accent); }
tbody tr.selected { background: var(--selected); }
tbody tr.selected .row-button { font-weight: 600; }
.row-button { background: none; border: 0; color: var(--text); padding: 4px 0; min-height: 40px; font-weight: 400; text-align: left;
  display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; white-space: normal; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.badge { display: inline-block; font-size: 11px; border: 1px solid var(--field-border); border-radius: 999px; padding: 0 8px; color: var(--text);
  margin-left: var(--space-1); white-space: nowrap; }
.badge.warn { border-color: var(--warn); }

/* Item icons and grade colors (game colors, always next to the name) */
.icon { width: 32px; height: 32px; border-radius: 4px; border: 1px solid var(--line); background: #0b0e13; flex: none; }
.icon.big { width: 56px; height: 56px; border-radius: 6px; }
.icon.small { width: 24px; height: 24px; border-radius: 3px; }
.grade-0 { color: #e6e6e6; } .grade-1 { color: #8fd16a; } .grade-2 { color: #5aa7e6; }
.grade-3 { color: #e8c547; } .grade-4 { color: #f08a3c; } .grade-5 { color: #e05d5d; }

/* Key figures */
.figures { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; }
.figures div { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-2) var(--space-3); min-width: 120px; }
.figures dt { color: var(--muted); font-size: 12px; }
.figures dd { margin: 0; font-size: 16px; font-weight: 600; }
.figures dd .small { font-size: 12px; font-weight: 400; }

/* Charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--space-3); }
.chart { margin: 0; background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3); min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); margin-bottom: var(--space-2); }
.chart-head h3 { margin: 0; }
.chart-body { position: relative; }
.chart svg { display: block; touch-action: none; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--chart); opacity: .1; }
.chart .dot { fill: var(--chart); stroke: var(--card-2); stroke-width: 2; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart .tooltip { position: absolute; transform: translate(-50%, -100%); background: #0b0e13; border: 1px solid var(--field-border);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; pointer-events: none; display: none; text-align: center; }
.chart .tooltip.on { display: grid; }
.chart .tooltip b { font-variant-numeric: tabular-nums; }
.chart summary { cursor: pointer; color: var(--muted); font-size: 12px; line-height: 44px; }
.chart details { margin-top: 0; }
.chart details table { margin-top: var(--space-2); }

/* Touch screens: every control at least 44 px tall */
@media (pointer: coarse) {
  button, .button, input[type="text"], input[type="search"], input[type="password"], select, .row-button, .site-nav a, .check, button.link, summary { min-height: 44px; }
}
@media (max-width: 700px) {
  .site-header { padding: var(--space-4); }
  /* Wide tables marked .stack become one labelled card per row */
  table.stack, .stack tbody, .stack tr, .stack td, .stack thead th { display: block; }
  .stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stack tr { border-bottom: 1px solid var(--line); padding: var(--space-2) 0; }
  .stack td, .stack td.num { border: 0; padding: var(--space-1) 0; text-align: left; white-space: normal; }
  .stack td[data-label] { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: var(--space-3); align-items: center; }
  .stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; }
  .stack td[data-label]:empty { display: none; }
  .live { margin-left: 0; width: 100%; }
}

/* Profit page */
.page-title { font-size: 18px; margin: 0 0 var(--space-3); }
.settings .settings-notes { margin-top: var(--space-3); display: grid; gap: var(--space-1); }
.results-head { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-6); align-items: flex-end; justify-content: space-between;
  margin-bottom: var(--space-3); }
.results-head h2 { margin: 0; }
#list-state:empty { display: none; }
#list-state { margin-bottom: var(--space-3); }
#list-note:empty { display: none; }
#list-note { margin-top: var(--space-3); }
.plan-head { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: flex-start; justify-content: space-between; }
.plan-name { display: flex; gap: var(--space-3); align-items: center; }
.plan-name h2 { margin: 0 0 var(--space-1); font-size: 18px; }
.plan-name .meta { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; color: var(--muted); }
.plan-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: flex-end; min-width: 0; max-width: 100%; }
.plan-head > * { min-width: 0; }
.plan-head .figures, #plan > .figures { margin-top: var(--space-4); }
.steps { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); margin-top: var(--space-4); }
.step-title { display: flex; align-items: center; gap: var(--space-2); font-size: 14px; margin: 0 0 var(--space-2); }
.step-title .number { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 600; }
.material { display: flex; gap: var(--space-2); align-items: center; }
.price-input { width: 110px; }
td details summary { cursor: pointer; color: var(--accent); }
td details ul { margin: var(--space-1) 0 0; padding-left: 18px; white-space: normal; }
/* NPC vendors: a summary in the cell; open, a scrolling box in the cell (an overlay would be clipped by the
   table's scroll box), so a long list never stretches the row past the box height. */
details.vendors summary { display: grid; gap: 2px; list-style: none; line-height: 1.3; padding: var(--space-1) 0; }
details.vendors summary::-webkit-details-marker { display: none; }
details.vendors summary b::after { content: " ▾"; font-weight: 400; }
details.vendors[open] summary b::after { content: " ▴"; }
.vendor-panel { width: min(360px, 100%); min-width: 260px; max-height: 260px; overflow-y: auto; margin-top: var(--space-1);
  background: var(--card); border: 1px solid var(--field-border); border-radius: var(--radius); padding: var(--space-2) var(--space-3);
  white-space: normal; }
.vendor-filter { width: 100%; margin-bottom: var(--space-2); }
/* An open vendor list makes its row tall: keep that row's other cells at the top, next to the material. */
tr:has(details.vendors[open]) > td { vertical-align: top; }
.vendor-town { padding: var(--space-1) 0; border-bottom: 1px solid var(--line); }
.vendor-town:last-child { border-bottom: 0; }
.vendor-town h4 { margin: 0 0 2px; font-size: 12px; color: var(--muted); font-weight: 600; }
.vendor-town ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px var(--space-3); }
.vendor-town a { color: var(--text); }
.vendor-town a:hover { color: var(--accent); }
@media (max-width: 700px) { .vendor-panel { width: auto; min-width: 0; } }
.sell-lines { display: grid; gap: var(--space-1); }
.sell-lines .big { font-size: 16px; }
.sell-price { margin-top: var(--space-3); }
.plan-charts { margin-top: var(--space-6); }
.icon.missing { visibility: hidden; }
.manual-note { margin-top: var(--space-3); }

/* Market browser */
.browser-panes { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: var(--space-3); align-items: start; }
.browser-panes #detail { position: sticky; top: var(--space-4); }
#detail > h3 { margin-top: var(--space-4); }
#detail .figures { margin: var(--space-3) 0 var(--space-2); }
#items-state:empty, #items-note:empty { display: none; }
@media (max-width: 900px) {
  .browser-panes { grid-template-columns: minmax(0, 1fr); }
  .browser-panes #detail { position: static; }
}

/* Watchlist alerts, in every page: cards in the bottom right corner, newest last */
.small { font-size: 12px; }
.alert-stack { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 20; display: grid; gap: var(--space-2);
  width: min(360px, calc(100vw - 2 * var(--space-4))); }
.alert-card { display: flex; gap: var(--space-3); align-items: center; background: var(--card-2); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3); box-shadow: 0 8px 24px rgba(0, 0, 0, .45); }
.alert-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.alert-title { font-weight: 600; overflow-wrap: anywhere; }
button.icon-button { min-width: 40px; min-height: 40px; padding: 0; justify-content: center; background: none; border: 0; color: var(--muted);
  font-size: 20px; line-height: 1; }

/* Watchlist page */
.watchlist-panes { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--space-3); align-items: start; }
.watchlist-side { display: grid; gap: var(--space-3); }
.section-head { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); align-items: baseline; justify-content: space-between; }
.section-head .page-title { margin-bottom: var(--space-2); }
.search-form { margin-top: var(--space-3); }
.search-form .field { max-width: 360px; }
.search-results { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: var(--space-1); }
.search-results:empty { display: none; }
#watched .table-wrap { margin-top: var(--space-3); }
#watch-note:empty, #list-state:empty { display: none; }
.options { display: grid; gap: var(--space-3); }
.options .field { max-width: 320px; }
.options input[type="file"] { min-height: 40px; color: var(--muted); }
#watch-body button.link { min-height: 40px; }
@media (pointer: coarse) {
  #watch-body button.link, .options input[type="file"] { min-height: 44px; }
}
.option-group { border: 0; margin: 0; padding: 0; display: grid; }
.option-group legend { color: var(--muted); font-size: 12px; padding: 0; margin-bottom: var(--space-1); }
.option-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
#sound-hint { margin-top: var(--space-2); }
.recent-alerts { margin: 0; padding-left: var(--space-4); display: grid; gap: var(--space-1); }
.recent-alerts:empty { display: none; }
@media (max-width: 900px) {
  .watchlist-panes { grid-template-columns: minmax(0, 1fr); }
}
@media (hover: hover) and (pointer: fine) {
  button.icon-button:hover { color: var(--text); }
  .row-button:hover { text-decoration: underline; }
}

/* An item name that copies itself (copy.js) */
.copy-name { background: none; border: 0; padding: 0; min-height: 0; color: inherit; font: inherit; font-weight: inherit; cursor: copy;
  text-align: left; border-bottom: 1px dashed var(--field-border); border-radius: 0; display: inline; }
.copy-name:hover { color: var(--accent); filter: none; }
.copy-toast { position: fixed; left: 50%; bottom: var(--space-4); transform: translateX(-50%); z-index: 50; background: var(--accent);
  color: var(--accent-ink); font-weight: 600; padding: var(--space-2) var(--space-4); border-radius: var(--radius); opacity: 0;
  transition: opacity .2s; pointer-events: none; }
.copy-toast.on { opacity: 1; }
/* Where in the game a recipe is crafted */
.how-to { color: var(--text); }
.block { display: block; }

/* ---------- Theme: inspired by Black Desert's own interface ----------
   Gold for the interface (buttons, titles, ornaments), teal for data (charts), grade colors for
   items as in the game. Titles in Cinzel, text in Inter; both fall back to system fonts offline. */
:root {
  --gold-1: #f3d48a;
  --gold-2: #e3b55d;
  --gold-3: #a8782f;
  --glow: rgba(227, 181, 93, .18);
  --surface-1: #1b2131;
  --surface-2: #141923;
  --edge: #2c3548;
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-title: "Cinzel", Georgia, "Times New Roman", serif;
}
body {
  font-family: var(--font-ui);
  background:
    radial-gradient(900px 420px at 50% -160px, rgba(227, 181, 93, .10), transparent 70%),
    radial-gradient(1100px 600px at 100% 0, rgba(47, 165, 150, .05), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .012) 0 2px, transparent 2px 14px),
    var(--bg);
  background-attachment: fixed;
}

/* Header: a dark band with a gold line under it */
.site-header { background: linear-gradient(180deg, rgba(9, 11, 16, .96), rgba(14, 17, 23, .88)); border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, transparent, var(--gold-3) 20%, var(--gold-2) 50%, var(--gold-3) 80%, transparent) 1; }
.brand { font-family: var(--font-title); font-size: 20px; letter-spacing: .06em; }
.brand::before { content: "\25C6"; color: var(--gold-2); font-size: 12px; margin-right: 8px; vertical-align: 3px; }
.site-nav a { transition: color .12s, background .12s; }
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--gold-1); background: linear-gradient(180deg, rgba(227, 181, 93, .16), rgba(227, 181, 93, .03));
  box-shadow: inset 0 -2px 0 var(--gold-2); }

/* Cards: a gradient surface, a gold glint on the top edge, small gold corners */
.card { position: relative; background: linear-gradient(180deg, var(--surface-1), var(--surface-2)); border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 rgba(243, 212, 138, .12), 0 12px 32px rgba(0, 0, 0, .35); }
.card::before, .card::after { content: ""; position: absolute; width: 14px; height: 14px; border: 1px solid var(--gold-3); opacity: .65; pointer-events: none; }
.card::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; border-top-left-radius: 4px; }
.card::after { bottom: 6px; right: 6px; border-left: 0; border-top: 0; border-bottom-right-radius: 4px; }

/* Titles in gold */
.page-title, .ornate, .card h2:not(#plan-title):not(#detail-title), .how-sell h2 {
  font-family: var(--font-title); letter-spacing: .03em; font-weight: 700;
  background: linear-gradient(180deg, var(--gold-1), var(--gold-2) 60%, var(--gold-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.page-title { font-size: 22px; }
#plan-title, #detail-title { font-family: var(--font-title); letter-spacing: .02em; font-size: 20px; }

/* The main button in gold */
button:not([class]), .button:not(.secondary) { background: linear-gradient(180deg, var(--gold-1), var(--gold-2) 55%, var(--gold-3));
  border: 1px solid #8a6326; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 3px 12px rgba(227, 181, 93, .22); text-shadow: 0 1px 0 rgba(255, 255, 255, .25); }
button.secondary, .button.secondary { background: linear-gradient(180deg, #232b3c, #1b2230); border-color: #3a4558; }

/* Item icons framed in their grade color, as in the game */
.icon.frame-0 { border-color: #7d8594; }
.icon.frame-1 { border-color: #5f9a3e; box-shadow: 0 0 8px rgba(143, 209, 106, .22); }
.icon.frame-2 { border-color: #3d7bb0; box-shadow: 0 0 8px rgba(90, 167, 230, .25); }
.icon.frame-3 { border-color: #c9a227; box-shadow: 0 0 9px rgba(232, 197, 71, .28); }
.icon.frame-4 { border-color: #d06a26; box-shadow: 0 0 10px rgba(240, 138, 60, .3); }
.icon.frame-5 { border-color: #c44545; box-shadow: 0 0 10px rgba(224, 93, 93, .3); }

/* Tables: a soft hover, the selected row marked in gold */
tbody tr { transition: background .1s; }
tbody tr:hover > td { background: rgba(227, 181, 93, .035); }
tr.selected > td { background: rgba(227, 181, 93, .07); }
tr.selected > td:first-child { box-shadow: inset 3px 0 var(--gold-2); }
th { text-transform: uppercase; letter-spacing: .05em; font-size: 11px; }

/* Figures: tiles with a small uppercase label and a large value */
.figures div { background: linear-gradient(180deg, #212a3c, #1a2131); border-color: #2f3a51; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04); }
.figures dt { text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; }
.figures dd { font-size: 19px; font-variant-numeric: tabular-nums; }
.figures dd.pos { text-shadow: 0 0 14px rgba(71, 192, 138, .35); }

/* Step numbers as gold diamonds */
.step-title { font-family: var(--font-title); font-size: 15px; letter-spacing: .03em; }
.step-title .number { border-radius: 0; width: 26px; height: 26px; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  background: linear-gradient(180deg, var(--gold-1), var(--gold-3)); font-family: var(--font-ui); }

/* Best right now: the top three products as large cards */
.top-picks { display: grid; gap: var(--space-3); }
.top-picks h2 { margin: 0; font-size: 17px; }
.top-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--space-3); }
.top-card { position: relative; display: grid; gap: var(--space-2); text-align: left; padding: var(--space-4); min-height: 0;
  background: linear-gradient(160deg, #20283a, #151a24 70%); border: 1px solid var(--edge); border-radius: var(--radius-lg);
  color: var(--text); font-weight: 400; overflow: hidden; box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  transition: transform .12s, border-color .12s, box-shadow .12s; }
.top-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--grade-edge, var(--gold-2)); }
.top-card:hover { transform: translateY(-2px); border-color: var(--gold-3); box-shadow: 0 12px 30px rgba(0, 0, 0, .4), 0 0 0 1px rgba(227, 181, 93, .15); filter: none; }
.top-card[aria-pressed="true"] { border-color: var(--gold-2); box-shadow: 0 0 0 1px var(--gold-2), 0 0 26px var(--glow); }
.grade-edge-0 { --grade-edge: #9aa3b2; } .grade-edge-1 { --grade-edge: #8fd16a; } .grade-edge-2 { --grade-edge: #5aa7e6; }
.grade-edge-3 { --grade-edge: #e8c547; } .grade-edge-4 { --grade-edge: #f08a3c; } .grade-edge-5 { --grade-edge: #e05d5d; }
.top-rank { position: absolute; top: 8px; right: 14px; font-family: var(--font-title); font-size: 34px; font-weight: 700; color: rgba(227, 181, 93, .16); }
.top-head { display: flex; gap: var(--space-3); align-items: center; padding-right: 32px; }
.top-name { font-weight: 600; font-size: 15px; line-height: 1.3; }
.top-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: 0 0 18px rgba(71, 192, 138, .3); }
.top-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 11.5px; padding: 2px 9px; border-radius: 999px; background: rgba(255, 255, 255, .04); border: 1px solid #2f3a51; color: var(--muted); }

/* The sell page's steps for the game */
.how-sell { margin-top: var(--space-4); padding: var(--space-3) var(--space-4); border: 1px dashed #3a4558; border-radius: var(--radius); background: rgba(227, 181, 93, .03); }
.how-sell h2 { font-size: 15px; margin: 0 0 var(--space-2); }
.how-sell ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; color: var(--muted); }
.how-sell b { color: var(--text); }

@media (prefers-reduced-motion: reduce) { .top-card, tbody tr { transition: none; } .top-card:hover { transform: none; } }

/* ---------- Accounts: sign-in pages, the user menu, the admin page ---------- */
.auth-page { min-height: 100vh; display: grid; align-content: center; justify-items: center; gap: var(--space-4);
  padding: var(--space-6) var(--space-4); }
.auth-brand { font-size: 24px; margin: 0; }
.auth-card { width: 100%; max-width: 400px; display: grid; gap: var(--space-4); }
.auth-card .page-title { margin: 0; }
.auth-card form { display: grid; gap: var(--space-4); }
.auth-card form > button[type="submit"] { justify-content: center; }
.auth-card p { margin: 0; }
.auth-links { font-size: 14px; }
.auth-links a { color: var(--accent); }
.field .hint { margin: 0; }
.field .error-text { margin: 0; }
.notice[data-form-alert] { margin: 0; }
/* A password field with its Show/Hide button on one line */
.password-field { display: flex; gap: var(--space-2); }
.password-field input { flex: 1; min-width: 0; }
.password-field .reveal { flex: none; min-width: 64px; justify-content: center; }
/* The submit button while a request runs: a spinner before the label, which stays */
button.busy::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor;
  border-right-color: transparent; flex: none; }
@media (prefers-reduced-motion: no-preference) {
  button.busy::before { animation: spin .8s linear infinite; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* The signed-in user's menu at the right end of the header. The header's backdrop filter makes it a
   stacking context: it needs its own level, or the page below covers the open menu. */
.site-header { position: relative; z-index: 30; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 40px; padding: var(--space-2) var(--space-3); border: 1px solid var(--field-border); border-radius: var(--radius); }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::after { content: "\25BE"; color: var(--muted); }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + var(--space-1)); z-index: 20; min-width: 180px; display: grid;
  background: var(--card); border: 1px solid var(--edge, var(--line)); border-radius: var(--radius); padding: var(--space-2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45); }
.user-menu-panel a, .user-menu-panel button.link { min-height: 40px; display: flex; align-items: center; padding: 0 var(--space-2);
  color: var(--text); text-decoration: none; font-weight: 500; }
.site-nav .count { display: inline-flex; min-width: 20px; height: 20px; padding: 0 6px; margin-left: var(--space-1); border-radius: 999px;
  align-items: center; justify-content: center; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }

/* Account and admin pages */
main.narrow { max-width: 560px; }
main.narrow form { display: grid; gap: var(--space-4); max-width: 400px; }
.section-title { font-size: 16px; margin: var(--space-2) 0 0; }
.admin-sections { display: grid; gap: var(--space-4); }
.admin-sections .section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.admin-sections h2 { margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }

/* Dialogs: invite links, generated passwords, confirmations */
dialog { background: var(--card); color: var(--text); border: 1px solid var(--edge, var(--line)); border-radius: var(--radius-lg);
  padding: var(--space-6); width: min(480px, calc(100vw - 2 * var(--space-4))); box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
dialog::backdrop { background: rgba(5, 7, 10, .7); }
dialog form { display: grid; gap: var(--space-4); }
dialog h2 { margin: 0; font-size: 18px; }
dialog p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; }
.secret-field { display: flex; gap: var(--space-2); }
.secret-field .secret { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
@media (max-width: 480px) {
  .secret-field { flex-wrap: wrap; }
  .secret-field .secret { flex-basis: 100%; }
  .dialog-actions button { flex: 1; justify-content: center; }
}
/* A user row's rarely needed actions */
.row-menu { position: relative; }
.row-menu summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: var(--space-1); min-height: 40px;
  padding: 0 var(--space-3); border: 1px solid var(--field-border); border-radius: var(--radius); }
.row-menu summary::-webkit-details-marker { display: none; }
.row-menu summary::after { content: "\25BE"; color: var(--muted); }
.row-menu-panel { position: absolute; left: 0; top: calc(100% + var(--space-1)); z-index: 5; display: grid; min-width: 180px;
  background: var(--card); border: 1px solid var(--edge, var(--line)); border-radius: var(--radius); padding: var(--space-2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45); }
.row-menu-panel button.link { min-height: 40px; justify-content: flex-start; color: var(--text); text-decoration: none; font-weight: 500; }
@media (pointer: coarse) { .row-menu summary { min-height: 44px; } }
