:root {
  color-scheme: dark;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  background: #0b0d0c;
  color: #e9ece8;
  --panel: #151816;
  --inset: #101310;
  --raised: #212622;
  --border: #303732;
  --muted: #aeb7af;
  --quiet: #949e95;
  --accent: #f2c230;
  --mono: 'Cascadia Mono', Consolas, monospace;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, select { font: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.shell { width: min(1080px, calc(100% - 48px)); margin-inline: auto; }
.topbar { border-bottom: 1px solid var(--border); background: var(--inset); }
.masthead { min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.identity { display: flex; align-items: center; gap: 16px; }
.wordmark { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 600; white-space: nowrap; }
.wordmark svg, .primary svg, .secondary svg, .empty-intro svg { width: 18px; height: 18px; flex: none; }
.wordmark svg { color: var(--accent); }
svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.game { padding-left: 16px; border-left: 1px solid var(--border); color: var(--quiet); font-size: 13px; }
.workspace { padding-top: 28px; }
.panel { min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.controls { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, .9fr); align-items: start; gap: 16px; margin-bottom: 12px; }
.capture-controls, .audio-controls { display: grid; gap: 8px; }
.capture-controls { align-self: center; }
h1, h2, h3 { font-weight: 600; }
h1 { margin: 0; font-size: clamp(25px, 3vw, 36px); line-height: 1.12; }
h2 { margin: 0; font-size: 22px; }
.file-controls { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
select { width: 100%; min-height: 40px; border: 1px solid var(--border); border-radius: 6px; background: var(--inset); color: inherit; padding: 8px; }
select:disabled { opacity: .65; }
.primary, .secondary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background-color 140ms var(--ease), border-color 140ms var(--ease); }
.primary { width: 100%; min-height: 44px; border-color: transparent; background: var(--accent); color: #191709; }
.primary:hover:not(:disabled) { background: #ffda60; }
.primary.active, .secondary { background: var(--inset); color: inherit; }
.primary.active { border-color: var(--border); }
.primary.active:hover:not(:disabled), .secondary:hover:not(:disabled) { background: var(--raised); }
.secondary[aria-pressed="true"] { border-color: #75622f; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
.hint, .notice, .overlay-notice { font-size: 13px; color: var(--muted); line-height: 1.5; }
.hint { margin: 0; }
.overlay-notice { margin-block: 0 8px; }
.fallback summary { width: fit-content; padding: 4px 0; color: var(--muted); font-size: 13px; cursor: pointer; }
.file-controls { margin-top: 12px; }
.text-button { background: transparent; border: 0; color: var(--muted); padding: 4px 0; cursor: pointer; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover:not(:disabled) { color: var(--accent); }
.receiver-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.receiver-header p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.state { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.state b { font-weight: 600; }
.state span { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.state[data-state="live"] { color: #a7d49d; }
.state[data-state="error"] { color: #ffbc99; }
.scan-flow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; list-style: none; margin: 0 0 12px; padding: 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--inset); }
.scan-flow li { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 8px; border: 1px solid transparent; border-radius: 4px; color: var(--quiet); font-size: 13px; }
.scan-flow li span { display: grid; place-items: center; min-width: 24px; min-height: 20px; border-radius: 3px; background: var(--raised); font: 11px var(--mono); }
.scan-flow [data-done] { color: var(--muted); }
.scan-flow [aria-current] { border-color: #5d4c23; background: #282318; color: #ffda70; }
.scan-flow [aria-current] span { background: var(--accent); color: #191709; }
.signal { padding: 12px; border: 1px solid var(--border); background: var(--inset); border-radius: 6px; }
.signal-label { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.signal-label span { font-family: var(--mono); }
.track { margin-top: 8px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
#meter { width: 100%; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform 120ms var(--ease); }
.notice { margin: 0 0 12px; }
.notice.error { color: #ffbc99; }
.board-panel { --board-line: #373d38; --unknown: #252a26; --no-red: #4c5138; --mixed: #613d34; --red: #743535; }
.board-header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.board-panel h2 { font-size: 18px; }
.board-header button { font-size: 12px; white-space: nowrap; }
.board-actions, .report-actions { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.board-report-frame { display: none; }
.board-message { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.4; }
#board-view {
  --board-width: calc(max(360px, 100dvh - 400px) * var(--columns) / var(--rows));
  display: grid;
  grid-template-columns: minmax(0, min(540px, var(--board-width))) minmax(0, 1fr);
  gap: 12px;
}
.board-legend { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 12px; }
.board-legend span::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 4px; border: 1px solid color-mix(in srgb, var(--tile) 45%, #979c97); border-radius: 2px; background: var(--tile); }
[data-kind="unknown"] { --tile: var(--unknown); }
[data-kind="no-red"] { --tile: var(--no-red); }
[data-kind="gold"] { --tile: #80632f; }
[data-kind="mixed"] { --tile: var(--mixed); }
[data-kind="red"] { --tile: var(--red); }
.merchant-grid {
  display: grid;
  grid-template: repeat(var(--rows), minmax(0, 1fr)) / repeat(var(--columns), minmax(0, 1fr));
  width: 100%;
  max-width: 540px;
  gap: 1px;
  aspect-ratio: var(--columns) / var(--rows);
  border: 1px solid var(--board-line);
  background-color: var(--inset);
  background-image: linear-gradient(to right, #252b26 1px, transparent 1px),
    linear-gradient(to bottom, #252b26 1px, transparent 1px);
  background-size: calc((100% + 1px) / var(--columns)) calc((100% + 1px) / var(--rows));
}
.cargo-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  min-height: 0;
  padding: 3px;
  border: 1px solid color-mix(in srgb, var(--tile) 70%, #96938a);
  border-radius: 2px;
  background: var(--tile);
  color: #fff;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
.cargo-slot { min-width: 0; min-height: 0; container-type: inline-size; }
.cargo-slot[data-hovered] { position: relative; z-index: 1; outline: 2px solid var(--accent); outline-offset: -1px; }
button.cargo-tile { cursor: pointer; }
button.cargo-tile[aria-pressed="true"] { border-color: #e3b7a8; }
button.cargo-tile:focus-visible { outline-offset: -3px; }
.cargo-tile .item-icon { flex: 0 1 48px; max-height: 52px; height: 100%; min-width: 0; }
.cargo-tile .item-icon:only-child { flex-basis: 80px; max-height: 72px; }
.cargo-more { position: absolute; right: 2px; bottom: 2px; padding: 0 2px; border-radius: 2px; background: var(--inset); font: 11px var(--mono); }
.cargo-tile.has-estimate { padding-bottom: 19px; }
.cargo-tile.has-estimate .cargo-more { inset: 2px 2px auto auto; }
.cargo-estimate {
  position: absolute;
  inset: auto 1px 1px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  gap: 0 3px;
  padding: 1px 2px;
  border-radius: 2px;
  background: #151816;
  color: #f6e3e3;
  font: 10px/1.15 var(--mono);
}
.cargo-estimate span { white-space: nowrap; }
@container (max-width: 55px) {
  .cargo-estimate .cargo-minimum { display: none; }
  .cargo-tile.has-estimate { padding-bottom: 13px; }
}
@container (max-width: 34px) {
  .cargo-estimate { font-size: 8px; gap: 0; padding-inline: 0; }
}
.board-detail { align-self: start; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--inset); }
.board-detail strong { font-size: 13px; font-weight: 600; }
.board-estimate { display: grid; gap: 2px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.board-estimate p { margin: 0; }
.board-estimate .board-chance { color: #f6b3ad; font-weight: 600; }
.board-detail-close { display: none; }
.board-detail ul { display: flex; flex-wrap: wrap; list-style: none; gap: 4px; margin: 8px 0 0; padding: 0; }
.board-detail li { width: 44px; height: 44px; padding: 4px; border: 1px solid var(--board-line); border-radius: 4px; background: var(--raised); }
.board-detail li[data-rarity="6"] { border-color: #be7474; background: var(--mixed); }
.board-detail li[data-rarity="5"] { border-color: #92733d; }
.board-detail .item-icon { height: 100%; }
.result { border: 1px solid var(--border); border-radius: 8px; background: var(--inset); }
.empty { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); align-items: center; gap: 24px; padding: 24px; }
.empty-intro { display: grid; justify-items: start; gap: 12px; }
.empty-intro svg { box-sizing: content-box; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--accent); }
.empty-intro strong, .overlay-placeholder strong { font-size: 16px; font-weight: 600; }
.empty-intro p, .overlay-placeholder p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.grid-guide {
  display: grid;
  grid-template: repeat(4, minmax(0, 1fr)) / repeat(9, minmax(0, 1fr));
  max-width: 540px;
  aspect-ratio: 9 / 4;
  border: 1px solid var(--border);
  background-image: linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: calc(100% / 9) 25%;
}
.grid-guide span { margin: 1px; border: 1px solid #4c554d; border-radius: 2px; background: #242a25; }
.grid-guide span:nth-child(1) { grid-area: 1 / 2 / span 2 / span 3; }
.grid-guide span:nth-child(2) { grid-area: 2 / 6 / span 1 / span 2; }
.grid-guide span:nth-child(3) { grid-area: 3 / 4 / span 2 / span 2; }
.overlay-placeholder { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 6px; background: var(--inset); }
.overlay-placeholder:not([hidden]) + .result { margin-top: 12px; }
.raid-selection, .raid-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  text-align: left;
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--inset);
  cursor: pointer;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.raid-selection:hover:not(:disabled), .raid-card:hover, .raid-card[aria-pressed="true"] { border-color: var(--accent); }
.raid-selection { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 84px; padding: 10px 12px; }
.raid-selection svg { width: 18px; height: 18px; flex: none; color: var(--accent); }
.raid-copy { display: grid; gap: 3px; }
.raid-copy > span, .raid-copy small { color: var(--muted); font-size: 12px; }
.raid-copy strong { font-size: 17px; font-weight: 600; line-height: 1.2; }
.raid-selection[data-map] .raid-copy > span, .raid-selection[data-map] .raid-copy small { color: #dce0dc; }
.raid-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 48%; z-index: -2; }
[data-map="Distorted Valley"] .raid-art { filter: sepia(.3) hue-rotate(230deg); }
.raid-selection[data-map]::before, .raid-card::before { position: absolute; inset: 0; z-index: -1; content: ''; background: linear-gradient(90deg, #101310f5 0%, #1013109e 49%, #1013102e 100%); }
.raid-selection[data-mode]:not([data-mode=""]) small::before, .mode-options .raid-card span::before {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--mode-color, #b7a7db);
  content: '';
}
[data-mode="Normal"] { --mode-color: #a5cf96; }
[data-mode="Lockdown"] { --mode-color: #f2c230; }
[data-mode="Forbidden"] { --mode-color: #f77e70; }
[data-mode$="Infection"] { --mode-color: #83d4c2; }
[data-mode="DeepAnomaly"] { --mode-color: #df96d6; }
.raid-dialog {
  position: fixed;
  width: min(708px, calc(100% - 24px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid #454f46;
  border-radius: 10px;
  background: var(--panel);
  color: inherit;
  box-shadow: 0 20px 64px #000a;
}
.raid-dialog[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.raid-dialog::backdrop { background: #050706c9; }
.raid-dialog-head { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--border); }
.raid-dialog-head h2:focus { outline: none; }
.raid-step { margin: 0 0 4px; color: var(--muted); font-size: 12px; }
.icon-button { display: grid; flex: none; width: 36px; height: 36px; padding: 0; place-items: center; border: 1px solid var(--border); border-radius: 6px; background: var(--inset); color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--raised); color: #fff; }
.icon-button svg { width: 16px; height: 16px; }
#raid-close { margin-left: auto; }
.raid-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: max-content; gap: 8px; padding: 12px 16px; overflow: auto; scrollbar-color: #454f46 var(--panel); }
.raid-card { display: flex; align-items: end; min-height: 76px; aspect-ratio: 3.5 / 1; padding: 12px; font-size: 16px; font-weight: 600; }
.raid-card::before { background: linear-gradient(0deg, #080a09f5, #080a0924 75%); }
.raid-card:focus-visible { outline-offset: -3px; }
.raid-card[aria-pressed="true"] span { color: #ffdc6e; }
.mode-options { grid-template-columns: 1fr; }
.mode-options .raid-card { aspect-ratio: auto; align-items: center; }
.mode-options .raid-card::before { background: linear-gradient(90deg, #101310f7, #101310b3 52%, #10131030); }
.raid-dialog-foot { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--inset); }
.raid-dialog-foot button { width: 100%; }
.overlay-window {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100dvh;
  padding: 8px;
  overflow: hidden;
}
.mini-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 4px 4px 0; }
.mini-header strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.25; }
.mini-raid { margin: 2px 0 0; color: var(--muted); font-size: 11px; line-height: 1.35; }
.mini-state { gap: 4px; font-size: 11px; }
.overlay-window .scan-flow { flex: none; margin: 0; }
.overlay-window .scan-flow li { min-height: 36px; gap: 2px; padding: 2px; }
.overlay-window .scan-flow li span { min-width: 20px; min-height: 15px; font-size: 10px; }
.overlay-window .board-panel { display: grid; flex: 1; min-height: 0; grid-template-rows: auto auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); gap: 4px; }
.overlay-window .board-header { grid-area: 1 / 1; justify-content: flex-end; margin: 0; }
.overlay-window .board-header h2 { display: none; }
.overlay-window .board-report-frame { display: inline-block; }
.overlay-window .board-header button { font-size: 11px; }
.overlay-window .board-message { grid-area: 2 / 1; margin: 0; padding: 4px; font-size: 12px; }
.overlay-window #board-view { position: relative; display: grid; grid-column: 1 / -1; min-height: 0; grid-template: auto minmax(0, 1fr) / minmax(0, 1fr); gap: 6px; }
.overlay-window .board-legend { justify-content: center; gap: 2px 8px; margin: 0; padding: 4px 0; border-block: 1px solid var(--border); font-size: 10px; }
.overlay-window .board-legend span::before { width: 7px; height: 7px; }
.overlay-window .board-grid-area { display: grid; place-items: start center; min-height: 0; overflow: auto; scrollbar-width: thin; container-type: size; }
.overlay-window .merchant-grid { width: min(100cqw, max(100px, calc(100cqh * var(--columns) / var(--rows)))); max-width: none; }
.overlay-window .board-detail { position: absolute; inset: auto 0 0; z-index: 2; padding: 6px 8px; background: var(--panel); box-shadow: 0 -4px 16px #0009; }
.overlay-window .board-detail-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.overlay-window .board-estimate { gap: 1px; margin-top: 2px; font-size: 11px; }
.overlay-window .board-detail-close { display: grid; width: 24px; height: 24px; place-items: center; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: var(--inset); color: inherit; font-size: 17px; line-height: 1; cursor: pointer; }
.overlay-window .board-detail ul { flex-wrap: nowrap; margin-top: 4px; overflow-x: auto; }
.overlay-window .board-detail li { flex: 0 0 32px; height: 32px; }
.group + .group { border-top: 1px solid var(--border); }
.group-title { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 13px 15px; }
.group-title strong { color: var(--accent); }
.group-title span { color: var(--muted); font-size: 13px; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; list-style: none; padding: 0 15px 15px; margin: 0; }
.items li {
  --rarity: #9faeac;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  aspect-ratio: 1;
  min-width: 0;
  padding: 6px;
  border: 1px solid color-mix(in srgb, var(--rarity) 55%, var(--border));
  border-radius: 5px;
  background: color-mix(in srgb, var(--rarity) 11%, #101618);
}
.items li[data-rarity="3"] { --rarity: #83abd8; }
.items li[data-rarity="4"] { --rarity: #bc9de5; }
.items li[data-rarity="5"] { --rarity: #e7c573; }
.items li[data-rarity="6"] { --rarity: #f27b73; }
.item-icon { display: block; min-height: 0; }
.item-icon img { display: block; width: 100%; height: 100%; object-fit: contain; }
.item-icon:empty {
  background: center / 30px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239faeac' stroke-width='1.5'%3E%3Cpath d='M12 3 21 8v8l-9 5-9-5V8l9-5ZM3 8l9 5 9-5m-9 5v8'/%3E%3C/svg%3E");
}
.items .size { justify-self: end; color: var(--muted); font: 11px var(--mono); }
.no-items { color: var(--muted); font-size: 13px; padding: 0 15px 13px; margin: 0; }
footer { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; padding: 16px 0 24px; color: var(--quiet); font-size: 12px; }
footer a { color: inherit; text-underline-offset: 3px; }

@media (max-width: 1100px) {
  #board-view { grid-template-columns: minmax(0, min(65%, var(--board-width))) minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .workspace { padding-top: 20px; }
  .controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
  .audio-controls { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; align-items: start; }
  .fallback summary { padding-block: 12px; }
  .file-controls { margin-top: 0; }
  .empty { padding: 16px; gap: 16px; }
  #board-view { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .game { display: none; }
  .scan-flow li { flex-direction: column; justify-content: center; gap: 4px; padding: 4px; font-size: 11px; }
  .raid-options { grid-template-columns: 1fr; }
  .raid-card { aspect-ratio: 4 / 1; }
  .empty { grid-template-columns: 1fr; }
  .empty-intro { display: flex; align-items: start; }
}
@media (max-width: 430px) {
  .shell { width: calc(100% - 24px); }
  .panel { padding: 12px; }
  .receiver-header { margin-bottom: 16px; }
  .receiver-header p { font-size: 13px; }
  .hint { font-size: 12px; }
  .overlay-placeholder { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  #meter, .primary, .secondary, .raid-card, .raid-selection { transition: none; }
}
