:root {
  color-scheme: dark;
  font-family: 'Instrument Sans', system-ui, sans-serif;
  color: #f5eee8;
  background: #181619;
  --muted: #b9abb4;
  --panel: #231f24;
  --border: #3b343c;
  --accent: #ffac8e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .38; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }

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

.site-header { border-bottom: 1px solid var(--border); }
.header-inner, .workspace { width: min(100% - 64px, 1000px); margin: 0 auto; }
.header-inner { min-height: 67px; display: flex; align-items: center; gap: 17px; }
.brand { color: inherit; text-decoration: none; font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; gap: 9px; flex: none; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 6px); gap: 2px; }
.brand-mark i { height: 6px; background: var(--accent); border-radius: 1.5px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { opacity: .38; }
.visualization-nav { position: relative; display: flex; flex-shrink: 0; align-self: stretch; gap: 4px; padding-left: 17px; min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.visualization-nav::-webkit-scrollbar { display: none; }
.visualization-nav::before { content: ''; position: absolute; left: 0; top: 50%; width: 1px; height: 20px; transform: translateY(-50%); background: var(--border); }
.visualization-nav button { position: relative; padding: 0 16px; border: 0; background: transparent; color: var(--muted); font-size: .87rem; font-weight: 600; white-space: nowrap; }
.visualization-nav button[aria-pressed="true"] { color: #ffd0be; }
.visualization-nav button[aria-pressed="true"]::after { content: ''; position: absolute; bottom: 0; left: 16px; right: 16px; height: 2px; background: var(--accent); }
.visualization-nav button:hover { color: #ffdfd0; }
.nav-label-short, .nav-icon { display: none; }
.nav-icon { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-icon .nav-icon-soft { opacity: .45; }

.workspace { padding: 36px 0 56px; }
.intro { margin-bottom: 29px; }
h1 { font: 400 clamp(3.1rem, 6.5vw, 5.35rem)/.93 'Instrument Serif', Georgia, serif; letter-spacing: -.035em; }
.header-game { position: relative; display: flex; align-items: center; min-width: 260px; max-width: 320px; flex: 1 1 320px; margin: 8px 0 8px auto; border: 1px solid var(--border); border-radius: 8px; background: #211d25; }
.game-switcher { flex: 1; min-width: 0; }
.game-switcher > summary { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 6px 10px; cursor: pointer; list-style: none; }
.game-switcher > summary::-webkit-details-marker { display: none; }
.current-game-players, .game-option-players { display: grid; gap: 3px; min-width: 0; flex: 1; }
.current-player { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: .74rem; line-height: 1.3; }
.current-player::before { content: ''; flex: none; width: 7px; height: 7px; border-radius: 50%; background: #151319; border: 1px solid #c9bcc880; }
.current-player[data-color="w"]::before { background: #f8ebd7; border-color: #f8ebd7; }
.current-player > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-game-status { flex: none; color: var(--muted); font-size: .62rem; white-space: nowrap; }
.current-game-status[data-live="true"] { color: var(--accent); }
.current-game-status[data-live="true"]::before { content: ''; display: inline-block; width: 4px; height: 4px; margin-right: 5px; border-radius: 50%; background: currentColor; }
.game-switcher-chevron { flex: none; width: 13px; height: 13px; color: var(--muted); }
.game-switcher[open] .game-switcher-chevron { transform: rotate(180deg); }
.game-new { display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0; border: 0; border-left: 1px solid var(--border); background: transparent; color: var(--muted); }
.game-new svg { width: 15px; height: 15px; }
.game-new:hover { color: var(--accent); }
.game-popover { position: absolute; top: calc(100% + 10px); right: 0; z-index: 20; width: 360px; max-width: calc(100vw - 32px); max-height: min(70vh, 520px); overflow-y: auto; padding: 14px; border: 1px solid #514555; border-radius: 10px; background: #211d25; box-shadow: 0 16px 45px #0008; }
.game-context { color: #e0d4dd; font-size: .72rem; line-height: 1.5; margin-bottom: 14px; overflow-wrap: anywhere; }
.game-menu-label { color: var(--muted); font-size: .63rem; letter-spacing: .06em; margin-bottom: 7px; }
.game-options { display: grid; gap: 3px; }
.game-option { display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); text-align: left; }
.game-option:hover { color: #eee2ea; background: #ffffff06; }
.game-option[aria-pressed="true"] { color: #f5eee8; border-color: #89708150; background: #ffbd9708; }
.game-option-check { width: 14px; font-size: .8rem; color: var(--accent); text-align: center; }
.game-menu-new { width: 100%; margin-top: 10px; padding: 10px 6px 2px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--accent); text-align: left; font-size: .75rem; }
.game-menu-new > span { font-size: 1rem; margin-right: 5px; }
.game-new-panel { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.game-form { display: flex; align-items: center; gap: 5px; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.game-form input { min-width: 0; width: 100%; background: transparent; color: inherit; border: 0; border-radius: 5px; padding: 7px 8px; font-size: .78rem; }
.game-form input::placeholder { color: var(--muted); }
.load-game { flex: none; background: var(--accent); color: #291912; border: 0; border-radius: 5px; padding: 8px 10px; font-weight: 700; font-size: .75rem; }
.load-game span { margin-left: 4px; }
.load-game:hover:not(:disabled) { background: #ffbea7; }
#game-error { margin-top: 8px; font-size: .75rem; line-height: 1.5; color: var(--accent); overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .header-inner { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 17px; padding-top: 8px; }
  .visualization-nav { min-height: 44px; }
  .visualization-nav button { flex: none; }
  .header-game { grid-column: 1 / -1; width: 100%; min-width: 0; max-width: none; margin: 6px 0 12px; }
}

.game-layout { display: grid; grid-template-columns: minmax(0, 575px) minmax(278px, 1fr); gap: 24px; align-items: start; }

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  border-radius: 9px;
  overflow: hidden;
  container-type: inline-size;
  background: #cbbdaf;
}
.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  isolation: isolate;
  background: #cbbdaf;
  color: #665350;
}
.square.dark { background: #877481; color: #fff0e6; }
.square.spot-heat::before, .square.piece-heat::before { content: ''; position: absolute; inset: 0; z-index: -1; }
.square.spot-heat::before { background: rgb(var(--heat-color) / .78); }
.square.piece-heat::before {
  background: radial-gradient(ellipse 58% 57% at 50% 55%, rgb(var(--heat-color) / .28) 21%, rgb(var(--heat-color) / .12) 52%, transparent 91%);
}
.rank, .file { position: absolute; font-size: clamp(.58rem, 2.15cqw, .72rem); font-weight: 700; line-height: 1; }
.rank { top: 4px; left: 4px; }
.file { bottom: 4px; right: 4px; }
.square.spot-heat :is(.rank, .file) { color: #291820; }
.piece {
  position: absolute;
  inset: 0;
  display: block;
  pointer-events: none;
  user-select: none;
}
.piece svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 .25cqw .35cqw #32252a45);
}
.piece-heat .piece.white svg [fill="#fff"],
.piece-heat .piece:not(.white) svg [fill="#000"] {
  fill: rgb(var(--heat-color));
}
.piece-heat .piece:not(.white) svg { fill: rgb(var(--heat-color)); }
.piece-heat .piece svg {
  --piece-outline: #241e25;
  filter:
    drop-shadow(0 0 .1cqw var(--piece-outline))
    drop-shadow(0 0 .75cqw rgb(var(--heat-color) / .5))
    drop-shadow(0 0 1.5cqw rgb(var(--heat-color) / .2));
}
.piece-heat .piece.white svg { --piece-outline: #fff7e8; }
.piece-heat .piece svg [stroke]:not([stroke="none"]) {
  stroke: var(--piece-outline);
}
.piece-heat .piece svg [stroke="#000"] {
  stroke-width: 2;
}
.piece-heat .piece.white svg [fill="#000"],
.piece-heat .piece:not(.white) svg [fill="#fff"],
.piece-heat .piece svg [fill="#ececec"] {
  fill: var(--piece-outline);
}
.piece-heat .piece[data-kind="bQ"] svg circle {
  fill: rgb(var(--heat-color));
  stroke: var(--piece-outline);
  stroke-width: 2;
}
.heat-count {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 1.3em;
  padding: 2px 3px;
  border-radius: 4px;
  background: #2d2227;
  color: #fff1e9;
  font-size: clamp(.57rem, 2.1cqw, .72rem);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.replay { padding: 13px 0 0; }
.replay-caption { display: flex; justify-content: space-between; gap: 12px; font-size: .85rem; }
.replay-caption label { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.replay-caption > span { flex: none; align-self: center; white-space: nowrap; }
.move-number-badge { display: inline-flex; align-items: baseline; gap: 5px; padding: 3px 6px; border: 1px solid #ffffff20; border-radius: 5px; background: #ffffff04; color: #f1e6ef; font: 500 .78rem/1.3 'Instrument Sans', system-ui, sans-serif; white-space: nowrap; font-variant-numeric: tabular-nums; }
.move-number-badge small { color: var(--muted); font-size: .6rem; font-weight: 400; }
.move-number-badge strong { font-weight: 600; }
.move-side-badge { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.move-side-badge::before { content: ''; width: 9px; height: 9px; border: 1px solid #c9bcc880; border-radius: 50%; background: #121116; flex: none; }
.move-side-badge[data-color="w"]::before { background: #f8ebd7; border-color: #f8ebd7; }
.replay-caption .move-notation { font-weight: 600; }
#time-selected-move { display: flex; align-items: center; gap: 10px; }
.replay-caption > span { color: var(--muted); font-variant-numeric: tabular-nums; }
.replay input[type="range"] { display: block; width: 100%; margin: 8px 0 10px; accent-color: var(--accent); }
.replay-actions { display: flex; justify-content: center; gap: 6px; }
.replay-actions button { width: 42px; height: 34px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel); color: inherit; font-size: 1.12rem; }
.replay-actions button:hover:not(:disabled) { border-color: var(--muted); }
.replay-actions .play { background: var(--accent); color: #291912; border-color: transparent; font-size: .75rem; }

.analysis-panel { padding: 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.analysis-panel h2 { font-size: 1.19rem; font-weight: 600; }
.mode-toggle { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; margin-top: 13px; padding: 4px; background: #171518; border: 1px solid var(--border); border-radius: 8px; }
.mode-toggle button { border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-weight: 600; font-size: .83rem; padding: 8px 4px; }
.mode-toggle button[aria-pressed="true"] { background: #493038; color: #ffd0be; }
.mode-toggle button:hover { color: #ffdfd0; }
.view-settings { margin: 10px 0 0; padding: 0; border: 0; min-width: 0; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; color: var(--muted); font-size: .84rem; cursor: pointer; }
.setting-switch { appearance: none; position: relative; flex: none; width: 34px; height: 20px; margin: 0; border: 1px solid #625361; border-radius: 999px; background: #413a42; cursor: pointer; }
.setting-switch::before { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #f5eee8; }
.setting-switch:checked { border-color: var(--accent); background: var(--accent); }
.setting-switch:checked::before { transform: translateX(14px); background: #291912; }
#mode-description { margin: 13px 0 14px; color: var(--muted); font-size: .87rem; line-height: 1.5; min-height: 2.65em; }
.legend-ramp { height: 7px; border-radius: 10px; }
.legend-labels { display: flex; justify-content: space-between; margin-top: 5px; color: var(--muted); font-size: .76rem; font-variant-numeric: tabular-nums; }
.analysis-panel h3 { margin: 20px 0 6px; font-size: .82rem; font-weight: 600; }
.ranking { list-style: none; padding: 0; margin: 0; }
.ranking-row { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 43px; border-top: 1px solid var(--border); font-size: .84rem; }
.ranking-key { display: grid; place-items: center; height: 27px; border-radius: 5px; background: #362a32; color: #ffbeaa; font-size: .76rem; font-weight: 700; }
.ranking-count { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }
.ranking-detail { display: block; color: var(--muted); font-size: .74rem; margin-top: 1px; }
#ranking-empty { color: var(--muted); font-size: .84rem; padding: 9px 0 3px; }
.captured-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.captured-group { min-width: 0; }
.captured-group h4 { margin: 0 0 7px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.captured-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; container-type: inline-size; }
.captured-piece {
  position: relative;
  isolation: isolate;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 5px;
  background: #877481;
}
.captured-piece .heat-count { top: 2px; right: 2px; padding: 2px; font-size: .69rem; }
.captured-empty { color: var(--muted); font-size: .78rem; }

.time-panel { --prep: #8dc8f6; --deep: #f2b765; --pressure: #f4779b; --white-time: #89c9f5; --black-time: #b49bea; padding: 26px; border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(135deg, #25212a, #211d23 70%); min-width: 0; }
.time-display-settings { display: flex; justify-content: flex-end; }
.time-display-settings .setting-row { gap: 14px; }
.time-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.time-chip { display: inline-flex; align-items: center; gap: 6px; font-size: .73rem; padding: 5px 8px; border: 1px solid #4c414d; border-radius: 5px; color: var(--muted); white-space: nowrap; }
.time-chip::before { content: ''; width: 6px; height: 6px; border-radius: 2px; background: currentColor; }
.time-chip.normal { color: #b7aeb7; background: #b7aeb709; }
.time-chip.prep { color: var(--prep); border-color: #3c5369; background: #8dc8f609; }
.time-chip.deep { color: var(--deep); border-color: #6b5339; background: #f2b76509; }
.time-chip.pressure { color: var(--pressure); border-color: #6f3f54; background: #f4779b09; }
.time-coverage { color: var(--muted); font-size: .78rem; margin-top: 12px; line-height: 1.5; }
.time-side { display: flex; align-items: center; gap: 12px; font-size: .78rem; margin-left: 46px; }
.time-side span { font-weight: 700; }
.time-side strong { color: var(--muted); font-weight: 400; overflow-wrap: anywhere; }
.white-side { color: #c8dcec; margin-top: 25px; }
.black-side { color: #b7a2cf; margin-top: 8px; }
.time-axis-title { font-size: .7rem; color: var(--muted); margin: 10px 0 17px; }
.time-chart { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 6px; }
.time-y-axis { position: relative; height: 340px; color: var(--muted); font-size: .68rem; font-variant-numeric: tabular-nums; }
.time-y-axis span { position: absolute; right: 0; transform: translateY(-50%); white-space: nowrap; }
.time-chart-scroll { overflow-x: auto; padding-top: 1px; scrollbar-width: thin; scrollbar-color: #66505f #211d23; }
.time-columns { display: grid; grid-template-columns: repeat(var(--move-columns), minmax(18px, 1fr)); min-width: calc(var(--move-columns) * 18px); background: repeating-linear-gradient(to bottom, #72657730 0 1px, transparent 1px calc(340px / 8)); }
.time-column { display: grid; grid-template-rows: 170px 170px 23px; min-width: 0; }
.time-bar-slot { position: relative; display: flex; justify-content: center; border: 0; border-radius: 0; padding: 0 3px; background: transparent; min-width: 0; color: inherit; }
.white-time { align-items: end; border-bottom: 1px solid #bda5b2; --bar-color: #b7aeb7; }
.black-time { align-items: start; --bar-color: #8e858f; }
.time-bar-slot[data-marker="prep"] { --bar-color: var(--prep); }
.time-bar-slot[data-marker="deep"] { --bar-color: var(--deep); }
.time-bar-slot[data-marker="pressure"] { --bar-color: var(--pressure); }
.time-panel[data-insights="false"] .white-time, .white-time[data-live] { --bar-color: var(--white-time); }
.time-panel[data-insights="false"] .black-time, .black-time[data-live] { --bar-color: var(--black-time); }
.time-panel[data-insights="false"] .white-side { color: var(--white-time); }
.time-panel[data-insights="false"] .black-side { color: var(--black-time); }
.time-bar-slot[data-live] .time-bar { border: 1px dashed var(--bar-color); background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--bar-color) 70%, #322438) 0 3px, color-mix(in srgb, var(--bar-color) 40%, #322438) 3px 6px); box-shadow: 0 0 12px color-mix(in srgb, var(--bar-color) 22%, transparent); transition: height .2s linear; }
.time-bar { display: block; width: 100%; max-width: 23px; background: linear-gradient(to top, color-mix(in srgb, var(--bar-color) 65%, #33273a), var(--bar-color)); border-radius: 3px 3px 0 0; box-shadow: 0 0 9px color-mix(in srgb, var(--bar-color) 10%, transparent); }
.black-time .time-bar { border-radius: 0 0 3px 3px; background: linear-gradient(to bottom, color-mix(in srgb, var(--bar-color) 65%, #33273a), var(--bar-color)); }
.time-bar-slot:hover, .time-bar-slot[aria-pressed="true"] { background: #ffffff09; }
.time-bar-slot[aria-pressed="true"] .time-bar { outline: 1px solid #fff2e9; outline-offset: 2px; }
.time-bar-slot:focus-visible { z-index: 1; outline-offset: -2px; }
.missing-time { background: transparent !important; border-top: 1px dashed #89788b; border-radius: 0; box-shadow: none; }
.time-x-tick { background: #211d23; color: var(--muted); font-size: .68rem; text-align: center; padding-top: 7px; font-variant-numeric: tabular-nums; }
.time-x-title { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 13px; }
.time-scroll-hint { text-align: right; color: var(--muted); font-size: .72rem; margin-top: 8px; }
.time-selection { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; margin-top: 22px; padding: 18px; background: #18161c; border: 1px solid var(--border); border-radius: 8px; }
#time-selected-player { color: var(--muted); font-size: .77rem; }
#time-selected-move { font: 400 2rem/1.2 'Instrument Serif', Georgia, serif; margin-top: 5px; }
.time-selection dl { display: flex; gap: 26px; margin: 0; align-items: center; }
.time-selection dt { color: var(--muted); font-size: .73rem; }
.time-selection dd { margin: 4px 0 0; font-size: 1.12rem; font-variant-numeric: tabular-nums; }
.time-selection-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.time-selection-actions button { border: 1px solid #5b4d69; border-radius: 5px; background: #302638; color: #eadcf6; padding: 9px 10px; font-size: .74rem; }
.time-selected-markers { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.time-selected-markers:empty { display: none; }
#time-selected-note { grid-column: 1 / -1; color: var(--muted); font-size: .78rem; }
#time-selected-context { grid-column: 1 / -1; color: var(--muted); font-size: .76rem; line-height: 1.55; }
.time-methods { border-top: 1px solid var(--border); margin-top: 22px; padding-top: 16px; color: var(--muted); font-size: .8rem; line-height: 1.6; }
.time-methods summary { color: #dbceda; cursor: pointer; width: fit-content; }
.time-methods p, .time-methods ul { margin-top: 12px; }
.time-methods ul { padding-left: 19px; }
.time-methods li + li { margin-top: 8px; }
.time-methods strong { color: #e9dce7; font-weight: 500; }
.time-empty { padding: 50px 16px; text-align: center; }
.time-empty > span { font-size: 3rem; color: var(--prep); display: block; margin-bottom: 10px; }
.time-empty h3 { font-size: 1.1rem; }
.time-empty p { max-width: 420px; margin: 10px auto 0; font-size: .85rem; line-height: 1.6; color: var(--muted); }

@media (max-width: 720px) {
  .header-inner, .workspace { width: calc(100% - 44px); }
  /* Phones: the views move to a fixed bottom tab bar, within thumb reach, and the header keeps only the logo and game. */
  .header-inner { grid-template-columns: minmax(0, 1fr); padding-top: 12px; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); --consent-offset: 64px; }
  .visualization-nav { position: fixed; z-index: 30; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); overflow: visible; border-top: 1px solid var(--border); background: rgb(24 22 25 / .88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
  .visualization-nav::before { display: none; }
  .visualization-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 52px; padding: 4px 2px; font-size: .68rem; font-weight: 600; letter-spacing: .01em; -webkit-tap-highlight-color: transparent; }
  .visualization-nav .nav-icon { display: block; width: 44px; height: 28px; padding: 4px 12px; border-radius: 14px; transition: background-color .2s ease, color .2s ease; }
  .visualization-nav button[aria-pressed="true"] .nav-icon { background: rgb(255 172 142 / .16); }
  .visualization-nav button[aria-pressed="true"]::after { display: none; }
  .visualization-nav button:active .nav-icon { background: rgb(255 255 255 / .08); }
  .header-game { margin-top: 12px; }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .time-panel { padding: 20px 16px; }
}
@media (max-width: 720px) {
  .nav-label-full { display: none; }
  .nav-label-short { display: inline; }
}
@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .visualization-nav .nav-icon { transition: none; }
}
@media (max-width: 400px) {
  .header-inner, .workspace { width: calc(100% - 28px); }
  .header-inner { min-height: 54px; column-gap: 10px; }
  .workspace { padding-top: 25px; }
  h1 { font-size: 3rem; }
  .heat-count { top: 2px; right: 2px; padding-inline: 2px; }
  .rank, .file { inset-inline: 2px auto; }
  .file { inset-inline: auto 2px; }
  .time-selection { grid-template-columns: minmax(0, 1fr); padding: 14px; }
  .time-selection dl { gap: 24px; }
  .time-legend { gap: 6px; }
}
@media (pointer: coarse) {
  .setting-row { min-height: 44px; }
  .replay-actions button { min-width: 44px; min-height: 44px; }
  .mode-toggle button { min-height: 44px; }
  .time-columns { grid-template-columns: repeat(var(--move-columns), minmax(44px, 1fr)); min-width: calc(var(--move-columns) * 44px); }
}

.candidate-panel { padding: 26px; border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(135deg, #25212a, #211d23 70%); }
.candidate-settings { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px; }
.candidate-settings select { background: #18161c; border: 1px solid #5a4a59; border-radius: 6px; color: #eee2ea; font: inherit; padding: 8px; }
.candidate-view-menu { position: relative; margin-left: auto; }
.candidate-view-menu > summary { display: flex; align-items: center; gap: 8px; min-width: 156px; padding: 8px 10px; border: 1px solid #66546a; border-radius: 6px; color: #e7dce7; font-size: .78rem; cursor: pointer; list-style: none; background: #19161c; }
.candidate-view-menu > summary::-webkit-details-marker { display: none; }
.candidate-view-menu > summary > svg { width: 15px; height: 15px; color: var(--muted); }
.candidate-view-menu > summary::after { content: ''; width: 5px; height: 5px; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; transform: rotate(45deg); margin: -3px 2px 0 3px; }
.candidate-view-menu[open] > summary { border-color: var(--accent); }
.candidate-view-menu[open] > summary::after { transform: rotate(225deg); margin-top: 3px; }
.candidate-view-label { color: #f3c5b2; font-size: .7rem; padding-left: 8px; border-left: 1px solid #59465b; }
.candidate-view-popover { position: absolute; z-index: 20; right: 0; top: calc(100% + 8px); width: 280px; max-width: calc(100vw - 48px); padding: 14px; border: 1px solid #6b586e; border-radius: 9px; background: #211d25; box-shadow: 0 16px 45px #0008; }
.candidate-view-presets { border: 0; margin: 0; padding: 0; min-width: 0; }
.candidate-view-presets legend { color: var(--muted); font-size: .72rem; margin-bottom: 10px; }
.candidate-view-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.candidate-view-option { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: start; border: 1px solid #514555; border-radius: 6px; padding: 9px; color: #c1b3c4; font-size: .75rem; cursor: pointer; }
.candidate-view-option > input { grid-column: 2; grid-row: 1; width: 13px; height: 13px; margin: 0; accent-color: var(--accent); }
.candidate-view-option > svg { grid-column: 1; grid-row: 1; width: 35px; height: 31px; opacity: .75; }
.candidate-view-option > span { grid-column: 1 / -1; }
.candidate-view-option:has(input:checked) { color: #ffdfcf; border-color: #d49b80; background: #ffbd9710; }
.candidate-view-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.candidate-view-options-extra { margin-top: 14px; padding-top: 9px; border-top: 1px solid var(--border); }
.candidate-view-options-extra .setting-row { font-size: .75rem; }
.candidate-view-options-extra .setting-row:has(input:disabled) { opacity: .5; cursor: default; }
.candidate-analysis-setting { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; color: var(--muted); font-size: .72rem; }
.candidate-analysis-setting select { min-width: 0; max-width: 150px; padding: 6px; }
.candidate-limit { border: 1px solid #5a4a59; border-radius: 5px; color: #e9c5b8; padding: 6px 8px; font-size: .75rem; white-space: nowrap; }
.candidate-error { color: var(--accent); font-size: .85rem; margin-top: 12px; line-height: 1.5; }
.candidate-retry { background: #493038; color: #ffd0be; border: 1px solid #79534e; border-radius: 6px; padding: 8px 12px; margin-top: 8px; }
.candidate-replay { margin-top: 22px; padding-block: 13px; border-block: 1px solid var(--border); }
#candidate-position-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.candidate-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 15px; margin: 20px 0 26px; color: var(--muted); font-size: .75rem; }
.candidate-legend span { display: inline-flex; gap: 6px; align-items: center; }
.candidate-legend i { display: block; width: 7px; height: 7px; border-radius: 2px; }
.candidate-legend .good { background: #45be84; }
.candidate-legend .equal { background: #9ca2a8; }
.candidate-legend .bad { background: #de555b; }
.candidate-played-key { margin-left: auto; color: #f9e3cf; }
.candidate-layout { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); max-width: 600px; margin-inline: auto; gap: 18px; align-items: center; }
.candidate-panel[data-view="bars"] .candidate-layout { grid-template-columns: minmax(0, 1fr); max-width: 220px; }
.candidate-panel[data-view="bars"] .candidate-played, .candidate-panel[data-view="bars"] .replay-caption .move-notation { display: none; }
.candidate-panel[data-view="bars"] .candidate-slot:disabled { opacity: 1; cursor: default; }
.candidate-panel[data-view="bars"] .candidate-slot:hover { background: transparent; }
.candidate-bars { min-width: 0; width: 100%; max-width: 220px; margin-inline: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 10px; }
.candidate-player { --side-ring: #8396b5b0; --side-halo: #95afd123; --side-text: #d0def1; min-width: 0; padding: 12px 8px; border: 1px solid #ffffff1c; border-radius: 9px; background: #080b134a; }
.candidate-player[data-color="w"] { --side-ring: #fff2dccc; --side-halo: #fff1cf2b; --side-text: #fff0d9; background: linear-gradient(160deg, #fff2dc12, #fff2dc06); border-color: #fff2dc29; }
.candidate-player[data-current="true"] { border-color: var(--side-ring); box-shadow: 0 0 15px var(--side-halo); }
.candidate-player-heading { display: flex; flex-direction: column-reverse; align-items: center; justify-content: center; gap: 7px; height: 45px; }
.candidate-player-heading h3 { font-size: .78rem; line-height: 1.4; font-weight: 600; min-width: 0; }
.candidate-player-heading h3::before { content: ''; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; background: #121116; border: 1px solid #c9bcc880; }
.candidate-player[data-color="w"] h3::before { background: #f8ebd7; border-color: #f8ebd7; }
.candidate-phase { color: var(--muted); border: 1px solid #ffffff24; border-radius: 4px; padding: 2px 5px; font-size: .6rem; line-height: 1.2; flex: none; }
.candidate-player[data-current="true"] .candidate-phase { color: var(--side-text); border-color: var(--side-ring); background: #080b1340; }
.candidate-player[data-current="true"] .candidate-phase::before { content: ''; display: inline-block; width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; background: #131923; border: 1px solid var(--side-ring); box-shadow: 0 0 5px var(--side-halo); }
.candidate-player[data-color="w"][data-current="true"] .candidate-phase::before { background: #fff2dc; }
.candidate-caption { margin-top: 7px; height: 26px; font-size: .7rem; line-height: 26px; color: var(--muted); text-align: center; }
.candidate-caption .move-number-badge { font-size: .85rem; padding: 3px 6px; }
.candidate-strip { position: relative; height: 342px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 7px; }
.candidate-edge { color: var(--muted); font-size: .59rem; line-height: 12px; text-align: center; }
.candidate-ramp { display: flex; flex-direction: column; flex: none; width: 48px; height: 260px; border-radius: 7px; background: #9ca2a8; position: relative; box-shadow: 0 4px 14px #0003; }
.candidate-bars:not([data-active="none"]) .candidate-player[data-current="false"] .candidate-ramp { width: 36px; height: 220px; }
.candidate-player[data-current="true"] .candidate-ramp { width: 62px; height: 300px; box-shadow: 0 0 0 3px #080b13, 0 0 0 4px var(--side-ring), 0 0 18px var(--side-halo); }
.candidate-player[data-color="w"][data-current="true"] .candidate-ramp { box-shadow: 0 0 0 2px var(--side-ring), 0 0 22px var(--side-halo); }
.candidate-slot { flex: 1; min-height: 0; width: 100%; background: transparent; border: 0; padding: 0; position: relative; color: #fff3e4; cursor: crosshair; }
.candidate-slot:first-child { border-radius: 8px 8px 0 0; }
.candidate-slot:last-child { border-radius: 0 0 8px 8px; }
.candidate-slot:only-child { border-radius: 8px; }
.candidate-slot:hover { background: #ffffff18; }
.candidate-slot.played { z-index: 1; background: #fff7e614; box-shadow: inset 0 0 0 2px #fff3e4, 0 0 15px #ffe3af50; border-radius: 4px; }
.candidate-slot.played::before { content: '◆'; position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%); font-size: .6rem; color: #fff3e4; text-shadow: 0 0 9px #ffe5ba70; }
.candidate-slot:focus-visible { z-index: 2; outline-offset: 2px; }
.candidate-skeleton { overflow: hidden; isolation: isolate; pointer-events: none; }
.candidate-bar-skeleton { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 2px; padding: 3px; border-radius: inherit; }
.candidate-skeleton-row { flex: 1; min-height: 0; border-radius: 2px; background: linear-gradient(90deg, #65596f, #796f82); }
.candidate-count-skeleton { display: block; position: relative; width: 78px; height: 22px; border: 1px solid #73637e50; border-radius: 5px; background: #594d63; }
.candidate-skeleton::after { content: ''; position: absolute; inset: -100% 0; background: linear-gradient(180deg, transparent 35%, #f4eafb28 50%, transparent 65%); transform: translateY(-65%); animation: candidate-skeleton-sweep 1.6s ease-in-out .15s infinite; }
.candidate-player[data-color="b"] .candidate-skeleton::after { animation-delay: .3s; }
@keyframes candidate-skeleton-sweep { from { transform: translateY(-65%); } to { transform: translateY(65%); } }
@media (prefers-reduced-motion: reduce) { .candidate-skeleton::after { animation: none; opacity: 0; } }
.candidate-tooltip { position: fixed; z-index: 5; width: max-content; max-width: min(240px, calc(100vw - 24px)); background: #17141a; border: 1px solid #706075; border-radius: 5px; padding: 7px 9px; color: #fff0e6; box-shadow: 0 6px 20px #0005; font-size: .72rem; line-height: 1.4; pointer-events: none; }
.candidate-meta { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; min-height: 28px; color: var(--muted); font-size: .65rem; line-height: 1.4; font-variant-numeric: tabular-nums; text-align: center; }
.candidate-move-count { display: inline-flex; align-items: baseline; gap: 2px; padding: 4px 6px; border: 1px solid #ffffff1c; border-radius: 5px; background: #080b1328; white-space: nowrap; }
.candidate-move-count strong { color: #eee4ee; font-weight: 600; }
.candidate-move-count small { font-size: .56rem; margin-left: 3px; }
.candidate-played { margin-top: 8px; min-height: 27px; font-size: .66rem; line-height: 1.5; color: #f1d7c0; text-align: center; }
.candidate-played-choice, .candidate-outside { width: 100%; background: #fff0d707; border: 1px solid #ffffff26; border-radius: 5px; color: #f1d7c0; padding: 5px 3px; font-size: .66rem; line-height: 1.3; }
.candidate-outside small { display: block; margin-top: 3px; color: var(--muted); font-size: .56rem; }
.candidate-preview { min-width: 0; }
.candidate-panel[data-view="board"] .candidate-preview { display: block; width: 100%; max-width: 320px; margin-inline: auto; }
.candidate-preview.board-hidden { display: block; }
.candidate-preview.board-hidden .candidate-detail { margin-top: 0; }
.candidate-preview-label { font-size: .75rem; color: var(--muted); margin-bottom: 10px; }
.candidate-board-wrap { position: relative; aspect-ratio: 1; border-radius: 7px; overflow: hidden; }
.candidate-board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); aspect-ratio: 1; container-type: inline-size; }
.candidate-square { --square-bg: #cbbdaf; background: var(--square-bg); position: relative; }
.candidate-square.dark { --square-bg: #877481; }
.candidate-coordinate { position: absolute; left: 2px; bottom: 2px; color: #2b242c; font-size: .56rem; font-weight: 600; z-index: 1; }
.candidate-board .piece[data-kind="bQ"] circle { fill: var(--square-bg); stroke: #151319; stroke-width: 1.8; }
.candidate-arrow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; filter: drop-shadow(0 1px 2px #2c182a80); }
.candidate-detail { margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 7px; background: #18161c; }
#candidate-detail-side { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: .73rem; color: var(--muted); }
.candidate-detail-primary { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 5px; }
#candidate-detail-move { font: 400 2.1rem/1.2 'Instrument Serif', Georgia, serif; }
#candidate-detail-score { font-size: 1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
#candidate-detail-rank { color: var(--muted); font-size: .65rem; line-height: 1.5; margin-top: 5px; }
#candidate-detail-line { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
#candidate-detail-line:empty { display: none; }
.candidate-line-move { border: 1px solid #ffffff1b; border-radius: 4px; padding: 4px 6px; color: #dfd4df; font-size: .69rem; line-height: 1.1; background: #ffffff04; }
.candidate-line-move + .candidate-line-move::before { content: '›'; color: #978a98; margin-right: 5px; }
.candidate-methods { margin-top: 24px; padding-top: 15px; border-top: 1px solid var(--border); color: var(--muted); font-size: .79rem; line-height: 1.6; }
.candidate-methods summary { color: #d9cbd8; cursor: pointer; width: fit-content; }
.candidate-methods p { margin-top: 10px; }
.candidate-methods a { color: #e7b5a1; }
@media (max-width: 600px) {
  .candidate-layout { grid-template-columns: minmax(0, 1fr); }
  .candidate-preview { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); align-items: start; gap: 12px; }
  .candidate-preview-label { grid-column: 1 / -1; margin-bottom: 0; }
  .candidate-detail { margin-top: 0; }
}
@media (max-width: 480px) {
  .candidate-panel { padding: 18px 14px; }
  .candidate-preview { grid-template-columns: minmax(0, 1fr); }
  .candidate-board-wrap { width: min(100%, 280px); margin-inline: auto; }
  .candidate-bars { gap: 10px; }
  .candidate-player { padding: 12px 8px; }
  .candidate-settings { gap: 10px; }
  .candidate-played-key { margin-left: 0; }
}
@media (pointer: coarse) {
  .candidate-played-choice, .candidate-outside, .candidate-retry { min-height: 44px; }
}

.flow-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.flow-progress { margin-right: auto; min-width: 120px; color: var(--muted); font-size: .72rem; }
.flow-progress progress { display: block; width: 120px; height: 3px; margin-top: 7px; border: 0; accent-color: var(--accent); border-radius: 3px; overflow: hidden; }
.flow-progress progress::-webkit-progress-bar { background: #554650; }
.flow-progress progress::-webkit-progress-value { background: var(--accent); }
.flow-action { padding: 8px 10px; border: 1px solid #66546a; border-radius: 6px; color: #e7dce7; font-size: .73rem; background: #19161c; }
.flow-view-menu { margin-left: auto; }
.flow-view-menu > summary { min-width: 100px; }
.flow-view-menu select { padding: 6px; background: #18161c; border: 1px solid #5a4a59; border-radius: 6px; color: #eee2ea; font: inherit; }
.flow-legend { margin-bottom: 18px; }
.flow-legend svg { width: 32px; height: 12px; }
.flow-chart-scroll { overflow-x: auto; padding-bottom: 10px; scrollbar-color: #756170 #211d25; scrollbar-width: thin; }
.flow-plane { --flow-columns: 1; width: 100%; min-width: calc(var(--flow-columns) * 24px + 48px); }
.flow-side { --flow-plot-height: 200px; --flow-ink: #1c2431; --flow-rim: #8396b5b0; --flow-halo: #95afd123; --flow-bg: #211e27; padding-top: 10px; background: linear-gradient(90deg, #080b131a, transparent); }
.flow-side[data-outside="true"] { --flow-plot-height: 234px; }
.flow-side:not([data-outside="true"]) .flow-y-labels span:last-child { display: none; }
.flow-side[data-color="w"] { --flow-ink: #fff0d9; --flow-rim: #fff2dccc; --flow-halo: #fff1cf2b; --flow-bg: #29232a; background: linear-gradient(90deg, #fff2dc05, transparent); }
.flow-side + .flow-side { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 16px; }
.flow-side-name { display: flex; align-items: center; gap: 12px; width: fit-content; max-width: 100%; position: sticky; left: 0; padding: 0 0 10px 48px; font-size: .8rem; font-weight: 600; }
.flow-player-name { font-size: .7rem; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-plot-row { display: grid; grid-template-columns: 48px minmax(0, 1fr); }
.flow-y-labels { height: var(--flow-plot-height); position: sticky; left: 0; z-index: 3; background: var(--flow-bg); font-size: .55rem; color: var(--muted); }
.flow-y-labels span { position: absolute; left: 0; }
.flow-y-labels span:first-child { top: 0; }
.flow-y-labels span:nth-child(2) { top: 183px; }
.flow-y-labels span:last-child { top: 215px; }
.flow-plot { height: var(--flow-plot-height); position: relative; border-radius: 5px; }
.flow-side[data-outside="true"] .flow-plot { background: linear-gradient(180deg, transparent 200px, #11101850 200px); }
.flow-surface { position: absolute; inset: 0 0 auto; width: 100%; height: 200px; border-radius: 5px; pointer-events: none; }
.flow-columns { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(var(--flow-columns), minmax(0, 1fr)); height: var(--flow-plot-height); }
.flow-column { display: block; height: var(--flow-plot-height); width: 100%; border: 0; padding: 0; position: relative; background: transparent; color: inherit; }
.flow-column-ramp { display: block; position: absolute; top: 0; left: 0; right: 0; height: 200px; overflow: hidden; background: repeating-linear-gradient(180deg, #514658 0 9px, #463c4d 9px 10px); }
.flow-column[data-phase="loading"][data-loading="true"] .flow-column-ramp::after { content: ''; position: absolute; inset: -100% 0; background: linear-gradient(180deg, transparent 35%, #f4eafb28 50%, transparent 65%); animation: candidate-skeleton-sweep 1.6s ease-in-out infinite; }
.flow-column[data-phase="error"] .flow-column-ramp { background: repeating-linear-gradient(135deg, #51363b 0 5px, #3c2c33 5px 10px); }
.flow-column .flow-column-ramp[data-analysed="true"] { background: transparent; }
.flow-column[data-current="true"]::before { content: ''; position: absolute; left: 50%; bottom: 10px; width: 5px; height: 5px; transform: translateX(-50%); border-radius: 50%; background: var(--accent); }
.flow-column.selected::after { content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: linear-gradient(90deg, transparent, #ffffff0c, transparent); }
.flow-column:hover::after { content: ''; position: absolute; inset: 0; z-index: 2; background: #ffffff0a; pointer-events: none; }
.flow-column:focus-visible { z-index: 4; outline-offset: 0; }
.flow-column-gap { background: #11101825; }
.flow-line { position: absolute; z-index: 2; inset: 0; width: 100%; height: var(--flow-plot-height); pointer-events: none; overflow: visible; }
.flow-line :is(path, circle) { vector-effect: non-scaling-stroke; }
.flow-path-halo { fill: none; stroke: var(--flow-rim); stroke-width: 3.5px; stroke-linecap: round; filter: blur(.3px); opacity: .65; }
.flow-side[data-color="w"] .flow-path-halo { stroke: #15131b66; filter: blur(.8px); }
.flow-path { fill: none; stroke: var(--flow-ink); stroke-width: 1.65px; stroke-linecap: round; stroke-linejoin: round; }
.flow-point { fill: var(--flow-ink); stroke: var(--flow-rim); stroke-width: .8px; opacity: .9; }
.flow-point.highlighted { opacity: 1; stroke-width: 1px; }
.flow-point.outside { fill: var(--flow-bg); stroke: var(--flow-rim); }
.flow-point-halo { fill: var(--flow-halo); stroke: var(--flow-rim); stroke-width: .75px; }
.flow-x-axis { display: grid; grid-template-columns: repeat(var(--flow-columns), minmax(0, 1fr)); margin-left: 48px; padding-top: 8px; font-size: .62rem; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.flow-axis-caption { text-align: center; margin-top: 8px; font-size: .65rem; color: var(--muted); }
.flow-detail { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 20px; align-items: center; padding: 16px; margin-top: 20px; border: 1px solid var(--border); border-radius: 8px; background: #18161c; }
#flow-detail-side { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .73rem; }
#flow-detail-move { font: 400 2rem/1.2 'Instrument Serif', Georgia, serif; margin-top: 6px; }
.flow-detail-evaluation { display: flex; flex-direction: column; gap: 6px; text-align: right; font-variant-numeric: tabular-nums; }
.flow-detail-evaluation strong { font-size: 1.15rem; }
#flow-detail-rank, #flow-detail-context { color: var(--muted); font-size: .68rem; }
#flow-detail-context { line-height: 1.5; }
.flow-empty { margin-top: 25px; color: var(--muted); font-size: .85rem; }
@media (max-width: 600px) {
  .flow-panel { padding: 20px 16px; }
  .flow-toolbar { gap: 8px; }
  .flow-progress { min-width: 95px; font-size: .65rem; }
  .flow-progress progress { width: 90px; }
  .flow-view-menu > summary { min-width: 80px; }
  .flow-action { font-size: .65rem; padding: 8px; }
  .flow-detail { padding: 12px; gap: 12px; }
}
@media (prefers-reduced-motion: reduce) { .flow-column-ramp::after { animation: none !important; opacity: 0; } }
