:root {
  --site-header-height: 4rem;
  --study-tabs-height: 0rem;
  --study-panel-gap: 1px;
  --study-control-bg: #181d24;
  --study-control-hover: #202731;
  --study-board-max: 34rem;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body.chess-study-page {
  min-width: 20rem;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(79, 157, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 157, 255, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--text-primary);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.panel-action,
.icon-button,
.fit-button,
.column-button,
.study-mobile-tab {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--study-control-bg);
  color: var(--text-secondary);
  cursor: pointer;
}

.panel-action {
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.45rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  white-space: nowrap;
}

.panel-action-primary {
  border-color: rgba(79, 157, 255, 0.38);
  color: var(--text-primary);
}

.panel-action-danger {
  color: var(--text-muted);
}

.panel-action:hover,
.panel-action:focus-visible,
.icon-button:hover:not(:disabled),
.icon-button:focus-visible,
.fit-button:hover,
.fit-button:focus-visible,
.column-button:hover,
.column-button:focus-visible {
  border-color: var(--accent-blue-dim);
  background: var(--study-control-hover);
  color: var(--text-primary);
}

.panel-action-danger:hover,
.panel-action-danger:focus-visible {
  border-color: #a95454;
  color: #f3a1a1;
}

.panel-action:focus-visible,
.icon-button:focus-visible,
.fit-button:focus-visible,
.column-button:focus-visible,
.study-mobile-tab:focus-visible,
.game-card:focus-visible,
.move-button:focus-visible,
.chesscom-import input:focus-visible,
.games-search input:focus-visible,
.page-control input:focus-visible,
.calibration input:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

.study-mobile-tabs {
  display: none;
}

.book-collapse-toggle {
  display: none;
}

.study-workspace {
  display: grid;
  grid-template-columns:
    minmax(14rem, 18rem)
    minmax(29rem, 1.05fr)
    minmax(25rem, 0.95fr);
  gap: var(--study-panel-gap);
  height: calc(100vh - var(--site-header-height) - var(--study-tabs-height));
  height: calc(100dvh - var(--site-header-height) - var(--study-tabs-height));
  overflow: hidden;
  background: var(--border);
}

.study-panel {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  background: rgba(11, 13, 16, 0.98);
}

.panel-drop-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: none;
  flex-direction: column;
  gap: var(--space-xs);
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  border: 2px dashed var(--accent-blue);
  background: rgba(11, 13, 16, 0.9);
  color: var(--text-primary);
  font-family: var(--font-mono);
  text-align: center;
}

.study-panel.is-dragging .panel-drop-overlay {
  display: flex;
}

.panel-drop-overlay > span {
  color: var(--accent-blue);
  font-size: 2rem;
}

.panel-drop-overlay p {
  max-width: 20rem;
  color: inherit;
  font-size: 0.8rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4rem;
  padding: var(--space-sm);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.panel-header > div:first-child {
  min-width: 0;
}

.panel-header-actions {
  display: flex;
  min-width: 0;
  gap: var(--space-2xs);
  align-items: center;
}

.panel-header h2 {
  margin: 0.15rem 0 0;
  overflow: hidden;
  font-size: 0.95rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-kicker {
  margin: 0;
  color: var(--accent-green);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
}

.panel-count {
  min-width: 2rem;
  padding: 0.22rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-align: center;
}

.panel-scroll {
  min-height: 0;
  flex: 1;
  overflow: auto;
  scrollbar-color: var(--border) transparent;
}

.panel-empty {
  display: grid;
  max-width: 25rem;
  min-height: 16rem;
  margin: auto;
  padding: var(--space-lg);
  place-content: center;
  text-align: center;
}

.panel-empty h3 {
  margin: var(--space-xs) 0;
  font-size: 1rem;
}

.panel-empty p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.55;
}

.compact-empty {
  min-height: 8rem;
}

.empty-symbol {
  color: var(--text-muted);
  font-size: 2rem;
}

.games-search {
  padding: var(--space-xs);
  border-bottom: 1px solid var(--border);
}

.chesscom-import {
  display: grid;
  gap: 0.35rem;
  padding: var(--space-xs);
  border-bottom: 1px solid var(--border);
  background: rgba(79, 157, 255, 0.035);
}

.chesscom-import > label {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.04em;
}

.chesscom-import-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2xs);
}

.chesscom-import input,
.games-search input {
  width: 100%;
  min-height: 2.35rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 0.78rem;
}

.chesscom-import input::placeholder,
.games-search input::placeholder {
  color: var(--text-muted);
}

.chesscom-import input:disabled,
.chesscom-import button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.game-list {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--border);
}

.game-card {
  display: grid;
  width: 100%;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-xs);
  padding: var(--space-sm);
  border: 0;
  background: var(--bg);
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.game-card:hover {
  background: var(--bg-elevated);
}

.game-card[aria-current="true"] {
  background: linear-gradient(90deg, rgba(79, 157, 255, 0.14), var(--bg-elevated));
  box-shadow: inset 3px 0 0 var(--accent-blue);
}

.game-number {
  padding-top: 0.05rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.66rem;
}

.game-card-main {
  min-width: 0;
}

.game-card-title {
  display: block;
  overflow: hidden;
  font-size: 0.79rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-card-meta {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.game-card-result {
  color: var(--accent-green);
}

.board-panel {
  overflow: hidden;
}

.board-content {
  container: board-content / inline-size;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  padding: var(--space-sm);
  scrollbar-color: var(--border) transparent;
}

.analysis-workbench {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-columns:
    minmax(22rem, min(42rem, calc(100dvh - 12rem)))
    minmax(18rem, 1fr);
  gap: var(--space-sm);
  align-items: start;
  margin: 0 auto;
}

.board-column {
  display: flex;
  width: 100%;
  min-width: 0;
  flex-direction: column;
}

.board-column .player-strip-black { order: 1; }
.board-column .board-shell { order: 2; }
.board-column .player-strip-white { order: 3; }
.board-column .board-edit-hint { order: 4; }
.board-column.is-black-orientation .player-strip-white { order: 1; }
.board-column.is-black-orientation .player-strip-black { order: 3; }

.player-strip {
  display: flex;
  min-height: 2.35rem;
  gap: 0.5rem;
  align-items: center;
  padding: 0.35rem 0.2rem;
  color: var(--text-primary);
  font-size: 0.78rem;
}

.player-strip strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-avatar {
  display: grid;
  width: 1.75rem;
  height: 1.75rem;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-elevated-2);
  font-size: 1.05rem;
  place-items: center;
}

.player-rating {
  margin-left: auto;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
}

.player-clock {
  min-width: 4.7rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--study-control-bg);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.player-strip-white .player-clock {
  border-color: rgba(235, 236, 208, 0.34);
  background: #ebecd0;
  color: #262522;
}

.white-piece {
  color: #f2f2ee;
}

.black-piece {
  color: #7f8995;
}

.game-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--border);
}

.game-facts div {
  min-width: 0;
  padding: 0.55rem 0.65rem;
  background: var(--bg-elevated);
}

.game-facts dt {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.55rem;
  text-transform: uppercase;
}

.game-facts dd {
  margin: 0.08rem 0 0;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 0.66rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-shell {
  display: grid;
  grid-template-columns: 1.7rem minmax(0, 1fr);
  gap: var(--space-2xs);
  align-items: stretch;
}

.advantage-meter {
  position: relative;
  min-height: 12rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #151719;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

.advantage-white-fill {
  position: absolute;
  inset: 0;
  background: #ecebe4;
  transform: scaleY(var(--white-share, 0.5));
  transform-origin: center bottom;
  transition: transform 220ms var(--ease-out);
}

.advantage-meter.is-black-orientation .advantage-white-fill {
  transform-origin: center top;
}

.advantage-score {
  position: absolute;
  z-index: 1;
  bottom: 0.28rem;
  left: 50%;
  color: #151719;
  font-family: var(--font-mono);
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  transform: translateX(-50%);
}

.advantage-meter.is-black-leading .advantage-score {
  top: 0.28rem;
  bottom: auto;
  color: #f5f5f2;
}

.advantage-meter.is-black-orientation .advantage-score {
  top: 0.28rem;
  bottom: auto;
  color: #151719;
}

.advantage-meter.is-black-orientation.is-black-leading .advantage-score {
  top: auto;
  bottom: 0.28rem;
  color: #f5f5f2;
}

.board-stage {
  position: relative;
  width: 100%;
  margin: 0;
  border: 1px solid var(--border);
  background: #ebecd0;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.24);
}

.board-move-quality {
  position: absolute;
  z-index: 5;
  top: calc(var(--quality-rank) * 12.5% + 0.18rem);
  left: calc((var(--quality-file) + 1) * 12.5% - 1.55rem);
  display: grid;
  width: 1.35rem;
  height: 1.35rem;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 800;
  line-height: 1;
  place-items: center;
  pointer-events: none;
}

.board-move-quality[hidden] {
  display: none;
}

#chessboard {
  width: 100%;
}

#chessboard .cm-chessboard.default .board .square.white {
  fill: #ebecd0;
}

#chessboard .cm-chessboard.default .board .square.black {
  fill: #779556;
}

#chessboard .cm-chessboard-accessibility.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.board-edit-hint {
  width: 100%;
  margin: 0.2rem auto 0;
  color: var(--text-muted);
  font-size: 0.68rem;
  line-height: 1.45;
  text-align: center;
}

.move-controls {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, 2.35rem) minmax(4.5rem, 1fr) repeat(2, 2.35rem);
  gap: var(--space-2xs);
  align-items: center;
  padding: var(--space-xs);
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.icon-button {
  display: inline-grid;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 1rem;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.36;
}

.move-status {
  margin: 0;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-align: center;
}

.engine-section {
  display: flex;
  width: 100%;
  min-width: 0;
  flex-direction: column;
  margin: 0;
  padding: var(--space-sm);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.analysis-sidebar {
  display: grid;
  height: 100%;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto auto minmax(9rem, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
}

.engine-header,
.engine-evaluation,
.engine-line {
  display: flex;
  align-items: center;
}

.engine-header {
  flex-direction: row;
  gap: var(--space-xs);
  align-items: center;
  justify-content: space-between;
}

.engine-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.engine-status,
.engine-attribution,
.engine-empty {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.engine-depth-label {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.engine-depth-label select {
  min-height: 2.25rem;
  padding: 0.35rem 1.45rem 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--study-control-bg);
  color: var(--text-secondary);
}

.engine-result {
  min-height: 0;
  margin-top: var(--space-xs);
  padding-top: var(--space-xs);
  border-top: 1px solid var(--border);
}

.engine-evaluation {
  gap: var(--space-xs);
  margin-bottom: var(--space-xs);
}

.engine-evaluation output {
  min-width: 4rem;
  color: var(--accent-green);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
}

.engine-evaluation span {
  color: var(--text-muted);
  font-size: 0.63rem;
}

.engine-lines {
  display: grid;
  gap: 0.38rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.engine-line {
  min-width: 0;
  gap: var(--space-xs);
  align-items: flex-start;
  padding: 0.42rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--study-control-bg);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.67rem;
  line-height: 1.45;
}

.engine-line-score {
  min-width: 3.2rem;
  padding: 0.15rem 0.22rem;
  border-radius: 2px;
  background: #ecebe4;
  color: #151719;
  font-weight: 600;
  text-align: center;
}

.engine-line-pv {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  white-space: normal;
}

.engine-attribution {
  margin-top: auto;
  padding-top: var(--space-xs);
  text-align: right;
}

.notation-section {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

.notation-section h3 {
  margin: 0;
  padding: 0.65rem var(--space-sm);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
}

.notation {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 0;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.8;
}

.notation > .move-button {
  margin: 0.45rem var(--space-sm);
}

.move-sequence {
  display: grid;
}

.move-row {
  display: grid;
  min-height: 2.15rem;
  grid-template-columns: 2.5rem repeat(2, minmax(0, 1fr));
  align-items: stretch;
  background: var(--bg);
}

.move-row:nth-child(even) {
  background: var(--bg-elevated);
}

.move-cell {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: 0.15rem;
  align-items: center;
  padding: 0.25rem 0.4rem;
}

.move-cell + .move-cell {
  border-left: 1px solid rgba(255, 255, 255, 0.035);
}

.move-button {
  display: inline-flex;
  min-width: 0;
  gap: 0.15rem;
  align-items: center;
  margin: 0;
  padding: 0.22rem 0.36rem;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.move-quality {
  display: inline-grid;
  min-width: 1.05rem;
  height: 1.05rem;
  margin-left: 0.2rem;
  padding: 0 0.18rem;
  border-radius: 50%;
  color: #fff;
  font-size: 0.56rem;
  font-weight: 800;
  line-height: 1;
  place-items: center;
  vertical-align: 0.08rem;
}

.quality-brilliant { background: #20bfa9; }
.quality-great { background: #4c92c3; }
.quality-best { background: #73a942; }
.quality-excellent { background: #7896b5; }
.quality-good { background: #7d8b94; }
.quality-inaccuracy { background: #e49a3a; }
.quality-mistake { background: #e26d45; }
.quality-missed-win { background: #df5353; }
.quality-blunder { background: #d83b3b; }

.move-button:hover {
  border-color: var(--border);
  background: var(--bg-elevated-2);
}

.move-button.is-active {
  border-color: var(--accent-blue-dim);
  background: rgba(79, 157, 255, 0.18);
  color: #fff;
}

.move-number {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  background: rgba(255, 255, 255, 0.025);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
}

.move-nag {
  color: var(--accent-green);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.move-comment {
  display: inline;
  color: #bdc7d1;
  font-style: italic;
}

.move-variation {
  display: block;
  width: 100%;
  margin: 0.45rem 0 0.45rem 0.65rem;
  padding-left: 0.65rem;
  border-left: 1px solid var(--accent-blue-dim);
  color: var(--text-muted);
}

.move-variation .move-number {
  display: inline;
  margin-right: 0.2rem;
  background: transparent;
}

.book-file-name {
  max-width: 55%;
  margin: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-content {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.book-controls {
  display: flex;
  gap: var(--space-2xs);
  align-items: center;
  flex-wrap: wrap;
  padding: var(--space-xs);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.page-control {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
}

.page-control input {
  width: 4rem;
  height: 2.35rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  text-align: center;
}

.column-toggle,
.zoom-controls {
  display: flex;
  gap: 1px;
}

.column-button,
.fit-button {
  min-height: 2.35rem;
  padding: 0.35rem 0.58rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
}

.column-button.is-active {
  border-color: var(--accent-blue-dim);
  background: rgba(79, 157, 255, 0.16);
  color: var(--accent-blue);
}

.calibration {
  position: relative;
  margin-left: auto;
}

.calibration summary {
  min-height: 2.35rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--study-control-bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  list-style-position: inside;
}

.calibration-fields {
  position: absolute;
  z-index: 5;
  top: calc(100% + var(--space-2xs));
  right: 0;
  display: grid;
  width: min(22rem, 80vw);
  gap: var(--space-sm);
  padding: var(--space-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated-2);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.calibration-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2xs);
  color: var(--text-secondary);
  font-size: 0.7rem;
}

.calibration-field output {
  color: var(--accent-green);
  font-family: var(--font-mono);
}

.calibration-field input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent-blue);
}

.book-position {
  margin: 0;
  padding: 0.5rem var(--space-sm);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-align: center;
}

.ocr-status {
  margin: 0;
  padding: 0.42rem var(--space-sm);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  text-align: center;
}

.ocr-status:empty {
  display: none;
}

.ocr-status.is-ready {
  color: var(--accent-green);
}

.ocr-status.is-error {
  color: #f2b2b2;
}

.pdf-viewport {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: var(--space-sm);
  background:
    linear-gradient(45deg, #171b21 25%, transparent 25%),
    linear-gradient(-45deg, #171b21 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #171b21 75%),
    linear-gradient(-45deg, transparent 75%, #171b21 75%),
    #12151a;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  text-align: center;
}

.pdf-page-stage {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.4);
}

#pdf-canvas {
  display: block;
  max-width: none;
  background: #fff;
}

.pdf-diagram-layer {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}

.pdf-diagram-target {
  position: absolute;
  display: grid;
  padding: 0;
  border: 2px solid var(--accent-blue);
  border-radius: 2px;
  background: rgba(79, 157, 255, 0.08);
  color: var(--text-primary);
  cursor: pointer;
  opacity: 0.82;
  pointer-events: auto;
  place-items: start end;
  transition:
    opacity var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-out);
}

.pdf-diagram-target::after {
  min-width: 1.35rem;
  padding: 0.16rem 0.28rem;
  border-radius: 0 0 0 var(--radius-sm);
  background: var(--accent-blue);
  color: var(--bg);
  content: attr(data-diagram-number);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}

.pdf-diagram-target:hover,
.pdf-diagram-target:focus-visible {
  opacity: 1;
  transform: scale(1.015);
}

.pdf-diagram-target.is-analyzing {
  border-color: #e5b567;
  background: rgba(229, 181, 103, 0.14);
}

.pdf-diagram-target.is-analyzing::after {
  background: #e5b567;
}

.pdf-diagram-target.is-matched,
.pdf-diagram-target.is-created {
  border-color: var(--accent-green);
  background: rgba(95, 216, 143, 0.12);
}

.pdf-diagram-target.is-matched::after,
.pdf-diagram-target.is-created::after {
  background: var(--accent-green);
}

.pdf-diagram-target.is-ambiguous,
.pdf-diagram-target.is-failed {
  border-color: #e5b567;
}

.ocr-dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: min(42rem, calc(100dvh - 2rem));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
}

.ocr-dialog::backdrop {
  background: rgba(4, 6, 8, 0.78);
  backdrop-filter: blur(4px);
}

.ocr-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm);
  border-bottom: 1px solid var(--border);
}

.ocr-dialog-header h2 {
  margin-top: 0.2rem;
  font-size: 0.95rem;
}

.ocr-dialog-intro {
  padding: var(--space-sm);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.ocr-candidate-list {
  display: grid;
  gap: 1px;
  background: var(--border);
}

.ocr-candidate-button {
  display: grid;
  gap: 0.3rem;
  width: 100%;
  padding: var(--space-sm);
  border: 0;
  background: var(--bg);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}

.ocr-candidate-button:hover,
.ocr-candidate-button:focus-visible {
  background: var(--bg-elevated-2);
}

.ocr-candidate-title {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 650;
}

.ocr-candidate-meta {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.pdf-loading {
  position: sticky;
  z-index: 3;
  top: var(--space-sm);
  width: fit-content;
  margin: 0 auto var(--space-sm);
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(11, 13, 16, 0.9);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.66rem;
}

.study-status {
  position: fixed;
  z-index: 20;
  right: var(--space-sm);
  bottom: var(--space-sm);
  max-width: min(28rem, calc(100vw - 2rem));
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(18, 21, 26, 0.96);
  color: var(--text-secondary);
  font-size: 0.72rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.5rem);
  transition:
    opacity var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-out);
}

.study-status.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.study-status.is-error {
  border-color: #a95454;
  color: #f2b2b2;
}

@media (max-width: 78rem) {
  .study-workspace {
    grid-template-columns: minmax(13rem, 16rem) minmax(24rem, 1fr) minmax(23rem, 1fr);
  }
}

@media (min-width: 61.0625rem) {
  .book-collapse-toggle {
    display: inline-grid;
  }

  .study-workspace.is-book-collapsed {
    grid-template-columns: minmax(13rem, 18rem) minmax(24rem, 1fr) 3.5rem;
  }

  .book-panel.is-collapsed .book-panel-header {
    justify-content: center;
    padding-inline: var(--space-2xs);
  }

  .book-panel.is-collapsed .book-panel-header > div:first-child,
  .book-panel.is-collapsed .panel-header-actions > :not(.book-collapse-toggle),
  .book-panel.is-collapsed .book-empty,
  .book-panel.is-collapsed .book-content,
  .book-panel.is-collapsed .panel-drop-overlay {
    display: none !important;
  }

  .book-panel.is-collapsed .panel-header-actions {
    justify-content: center;
  }
}

@container board-content (max-width: 43rem) {
  .analysis-workbench {
    height: 100%;
    grid-template-columns: minmax(0, 1fr);
    overflow: auto;
    padding-bottom: var(--space-sm);
  }

  .board-column {
    width: min(100%, 38rem);
    margin-inline: auto;
  }

  .analysis-sidebar {
    min-height: 38rem;
  }

  .engine-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

@media (max-width: 61rem) {
  :root {
    --study-tabs-height: 3.2rem;
  }

  .study-mobile-tabs {
    display: grid;
    height: var(--study-tabs-height);
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    padding: var(--space-2xs);
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
  }

  .study-mobile-tab {
    font-family: var(--font-mono);
    font-size: 0.7rem;
  }

  .study-mobile-tab.is-active {
    border-color: var(--accent-blue-dim);
    background: rgba(79, 157, 255, 0.15);
    color: var(--accent-blue);
  }

  .study-workspace {
    display: block;
  }

  .study-panel {
    display: none;
    height: 100%;
  }

  .study-panel.is-mobile-active {
    display: flex;
  }

  .board-column {
    width: min(100%, 42rem);
  }
}

@media (max-width: 44rem) {
  .panel-action {
    min-height: 2.25rem;
    padding-inline: 0.55rem;
    font-size: 0.65rem;
  }

  .panel-action-danger {
    padding-inline: 0.55rem;
    font-size: 0.65rem;
  }

  .book-panel-header .book-file-name {
    display: none;
  }

  .game-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-facts dd {
    max-width: 100%;
  }

  .engine-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .engine-depth-label > span {
    position: absolute;
    overflow: hidden;
    width: 1px;
    height: 1px;
    clip: rect(0, 0, 0, 0);
  }

  .book-controls {
    align-items: stretch;
  }

  .column-toggle {
    order: 4;
    width: 100%;
  }

  .column-button {
    flex: 1;
  }

  .zoom-controls {
    order: 5;
  }

  .calibration {
    order: 6;
  }
}

@media (prefers-reduced-motion: reduce) {
  .study-status,
  .pdf-diagram-target,
  .advantage-white-fill {
    transition: none;
  }
}
