:root {
    --cv-bg: #0b1114;
    --cv-bg-soft: rgba(16, 24, 28, 0.78);
    --cv-panel: rgba(255, 247, 231, 0.08);
    --cv-panel-strong: rgba(255, 247, 231, 0.12);
    --cv-border: rgba(255, 247, 231, 0.14);
    --cv-line: rgba(255, 247, 231, 0.28);
    --cv-text: #f5efe4;
    --cv-muted: #c7bca6;
    --cv-accent: #f0c36a;
    --cv-accent-strong: #e68a2e;
    --cv-success: #6bcf93;
    --cv-white-card: linear-gradient(145deg, #121b21, #18252d);
    --cv-black-card: linear-gradient(145deg, #f6e7c6, #f0dcc2);
    --cv-radius: 24px;
    --cv-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

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

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
    color: var(--cv-text);
    background:
        radial-gradient(circle at top left, rgba(240, 195, 106, 0.18), transparent 28%),
        radial-gradient(circle at 88% 10%, rgba(107, 207, 147, 0.15), transparent 24%),
        linear-gradient(180deg, #11181c 0%, #090d10 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 0.88), transparent 95%);
}

code {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.95em;
}

.cv-page {
    padding: 32px 18px 48px;
}

.cv-shell {
    width: min(1480px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 18px;
}

.cv-hero,
.cv-panel {
    position: relative;
    overflow: hidden;
    border-radius: var(--cv-radius);
    border: 1px solid var(--cv-border);
    background: var(--cv-bg-soft);
    backdrop-filter: blur(20px);
    box-shadow: var(--cv-shadow);
}

.cv-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    padding: 20px 30px;
}

.cv-hero-main {
    position: relative;
    z-index: 1;
    width: 100%;
    min-width: 0;
}

.cv-editor-workspace {
    display: grid;
    grid-template-columns: minmax(340px, 460px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.cv-main-board {
    position: sticky;
    top: 12px;
    z-index: 40;
    width: 100%;
    padding: 12px;
    border: 1px solid var(--cv-border);
    border-radius: 20px;
    background: rgba(9, 14, 17, 0.96);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
    backdrop-filter: blur(18px);
}

.cv-main-board-head {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
}

.cv-main-board-head strong {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 5px;
    min-width: 0;
    font: 700 0.78rem/1.45 "IBM Plex Mono", monospace;
}

.cv-board-navigation {
    display: flex;
    flex: 0 0 auto;
    gap: 2px;
}

.cv-board-navigation button {
    display: inline-grid;
    place-items: center;
    min-width: 25px;
    height: 24px;
    padding: 0 4px;
    border: 1px solid rgba(240, 195, 106, 0.34);
    border-radius: 7px;
    color: var(--cv-text);
    background: rgba(240, 195, 106, 0.1);
    font: 700 0.68rem/1 "IBM Plex Mono", monospace;
    cursor: pointer;
}

.cv-board-navigation button:hover:not(:disabled),
.cv-board-navigation button:focus-visible {
    border-color: rgba(240, 195, 106, 0.72);
    background: rgba(240, 195, 106, 0.22);
    outline: none;
}

.cv-board-navigation button:disabled {
    opacity: 0.32;
    cursor: default;
}

.cv-board-history-move {
    padding: 1px 3px;
    border: 0;
    border-radius: 5px;
    color: inherit;
    background: transparent;
    font: inherit;
    cursor: pointer;
}

.cv-board-history-move:hover,
.cv-board-history-move:focus-visible {
    color: var(--cv-accent);
    background: rgba(240, 195, 106, 0.12);
    outline: none;
}

.cv-board-history-move.is-current {
    color: #171006;
    background: var(--cv-accent);
    box-shadow: 0 0 0 1px rgba(255, 236, 173, 0.55);
}

.cv-main-board-canvas {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 12px;
}

.cv-main-board-canvas .cm-chessboard {
    width: 100%;
    height: 100%;
}

.cm-chessboard-draggable-piece {
    z-index: 100;
}

.cv-main-board-canvas .marker-last-move {
    fill: #ffe06a;
    opacity: 0.58;
}

.cv-main-board-canvas [class*="arrow-next-move-"] .arrow-head {
    fill: #188a3b;
}

.cv-main-board-canvas [class*="arrow-next-move-"] .arrow-line {
    stroke: #188a3b;
    stroke-linecap: round;
}

.cv-main-board-canvas .arrow-next-move-1 { opacity: 0.9; }
.cv-main-board-canvas .arrow-next-move-2 { opacity: 0.82; }
.cv-main-board-canvas .arrow-next-move-3 { opacity: 0.74; }
.cv-main-board-canvas .arrow-next-move-4 { opacity: 0.66; }
.cv-main-board-canvas .arrow-next-move-5 { opacity: 0.58; }
.cv-main-board-canvas .arrow-next-move-6 { opacity: 0.5; }
.cv-main-board-canvas .arrow-next-move-7 { opacity: 0.42; }
.cv-main-board-canvas .arrow-next-move-8 { opacity: 0.34; }
.cv-main-board-canvas .arrow-next-move-9 { opacity: 0.26; }
.cv-main-board-canvas .arrow-next-move-10 { opacity: 0.18; }

.cv-main-board-canvas [class*="arrow-stockfish-"] .arrow-line {
    stroke-linecap: round;
}

.cv-main-board-canvas .arrow-stockfish-1 .arrow-head {
    fill: #003088;
}

.cv-main-board-canvas .arrow-stockfish-1 .arrow-line {
    stroke: #003088;
    opacity: 0.72;
}

.cv-main-board-canvas .arrow-stockfish-2 .arrow-head {
    fill: #1456a0;
}

.cv-main-board-canvas .arrow-stockfish-2 .arrow-line {
    stroke: #1456a0;
    opacity: 0.67;
}

.cv-main-board-canvas .arrow-stockfish-3 .arrow-head {
    fill: #2b78b9;
}

.cv-main-board-canvas .arrow-stockfish-3 .arrow-line {
    stroke: #2b78b9;
    opacity: 0.62;
}

.cv-main-board-canvas .arrow-stockfish-4 .arrow-head {
    fill: #519bcf;
}

.cv-main-board-canvas .arrow-stockfish-4 .arrow-line {
    stroke: #519bcf;
    opacity: 0.57;
}

.cv-main-board-canvas .arrow-stockfish-5 .arrow-head {
    fill: #81bce0;
}

.cv-main-board-canvas .arrow-stockfish-5 .arrow-line {
    stroke: #81bce0;
    opacity: 0.52;
}

.cv-engine-panel {
    margin-top: 10px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 11px;
    color: #d3d3d3;
    background: #262522;
    font-family: "IBM Plex Mono", monospace;
}

.cv-next-unanswered {
    width: 100%;
    margin-top: 10px;
}

.cv-engine-toolbar {
    min-height: 48px;
    display: grid;
    grid-template-columns: 38px 54px minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    padding: 5px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: #33322f;
}

.cv-engine-toggle {
    width: 34px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    color: rgba(255, 255, 255, 0.72);
    background: #55534e;
    cursor: pointer;
}

.cv-engine-toggle span:first-child {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    margin: 2px;
    border-radius: 50%;
    background: #77746e;
    transform: translateX(0);
    transition: background 140ms ease, transform 140ms ease;
}

.cv-engine-toggle.is-enabled span:first-child {
    color: #fff;
    background: #639b24;
    transform: translateX(10px);
}

.cv-engine-toggle:focus-visible {
    outline: 2px solid var(--cv-accent);
    outline-offset: 2px;
}

.cv-engine-score {
    color: #f1f1f1;
    font-size: 1.05rem;
    text-align: center;
}

.cv-engine-identity {
    min-width: 0;
    line-height: 1.15;
}

.cv-engine-identity > span,
.cv-engine-identity small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cv-engine-identity > span {
    color: #b9b9b9;
    font-size: 0.7rem;
}

.cv-engine-identity em {
    margin-left: 4px;
    color: #91b64a;
    font-style: normal;
}

.cv-engine-identity small {
    margin-top: 3px;
    color: #8e8d89;
    font-size: 0.63rem;
}

.cv-engine-next-moves {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #d1d0cc;
    font-size: 0.68rem;
    cursor: pointer;
    white-space: nowrap;
}

.cv-engine-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 3px 9px;
}

.cv-engine-next-moves input {
    accent-color: #80a93e;
}

.cv-engine-lines {
    max-height: 144px;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    list-style: none;
}

.cv-engine-lines li {
    min-height: 28px;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-top: 1px solid rgba(255, 255, 255, 0.075);
    font-size: 0.69rem;
    line-height: 1.35;
}

.cv-engine-lines.has-percent li:not(.is-placeholder) {
    grid-template-columns: 58px 42px minmax(0, 1fr);
}

.cv-engine-lines li:first-child {
    border-top: 0;
}

.cv-engine-lines .is-placeholder {
    display: block;
    min-height: 32px;
    color: #8e8d89;
    text-align: center;
}

.cv-engine-line-score {
    color: #eee;
    font-weight: 700;
}

.cv-engine-line-percent {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    color: #9dcc5a;
    background: transparent;
    font: inherit;
    font-weight: 700;
    text-align: left;
    white-space: nowrap;
    cursor: help;
}

.cv-engine-line-percent.is-missing {
    color: #8e8d89;
}

.cv-engine-line-percent-bar {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    height: 16px;
    overflow: hidden;
    border-radius: 7px;
}

.cv-engine-line-percent-segment {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    height: 16px;
    overflow: hidden;
    font-size: 0.6rem;
    font-weight: 600;
    line-height: 16px;
    white-space: nowrap;
}

.cv-engine-line-percent-segment.is-victory {
    color: #222;
    background: #ccc;
}

.cv-engine-line-percent-segment.is-draw {
    color: #ddd;
    background: #666;
}

.cv-engine-line-percent-segment.is-defeat {
    color: #ddd;
    background: #333;
}

.cv-engine-line-percent-tooltip {
    position: absolute;
    top: 50%;
    left: calc(100% + 7px);
    z-index: 30;
    display: none;
    align-items: center;
    gap: 7px;
    width: min(340px, calc(100vw - 125px));
    padding: 3px;
    border: 1px solid rgba(157, 204, 90, 0.5);
    border-radius: 7px;
    color: #f3f3f1;
    background: rgba(12, 14, 11, 0.97);
    box-shadow: 0 7px 18px rgba(0, 0, 0, 0.42);
    pointer-events: none;
    transform: translateY(-50%);
}

.cv-engine-line-percent:hover .cv-engine-line-percent-tooltip,
.cv-engine-line-percent:focus-visible .cv-engine-line-percent-tooltip {
    display: flex;
}

.cv-engine-line-percent-games {
    flex: 0 0 auto;
    color: #d7d6d2;
    font-size: 0.61rem;
    font-weight: 600;
    white-space: nowrap;
}

.cv-engine-line-percent:focus-visible {
    outline: 1px solid #9dcc5a;
    outline-offset: 2px;
}

.cv-engine-line-pv {
    overflow: hidden;
    color: #cecdca;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cv-account {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    align-self: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--cv-border);
    border-radius: 16px;
    background: rgba(255, 247, 231, 0.05);
}

.cv-account-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--cv-success);
    box-shadow: 0 0 0 4px rgba(107, 207, 147, 0.14);
}

.cv-account span,
.cv-account strong {
    display: block;
}

.cv-account span {
    color: var(--cv-muted);
    font-size: 0.72rem;
}

.cv-account strong {
    font: 600 0.9rem/1.35 "IBM Plex Mono", monospace;
}

.cv-account-logout {
    border: 0;
    padding: 5px 7px;
    color: var(--cv-muted);
    background: transparent;
    font: 500 0.75rem/1 "IBM Plex Mono", monospace;
    cursor: pointer;
}

.cv-account-logout:hover {
    color: var(--cv-text);
}

.cv-auth-gate {
    min-height: 430px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.cv-auth-gate > * {
    position: relative;
    z-index: 1;
}

.cv-auth-mark {
    display: grid;
    place-items: center;
    width: 74px;
    height: 74px;
    margin-bottom: 18px;
    border: 1px solid rgba(240, 195, 106, 0.38);
    border-radius: 22px;
    color: var(--cv-accent);
    background: rgba(240, 195, 106, 0.08);
    font-size: 2.7rem;
}

.cv-auth-gate h2 {
    font-size: clamp(1.7rem, 4vw, 2.7rem);
}

.cv-auth-gate > p:not(.cv-eyebrow) {
    max-width: 560px;
    margin: 12px auto 0;
    color: var(--cv-muted);
}

.cv-auth-button {
    margin-top: 24px;
    text-decoration: none;
}

.cv-auth-gate small {
    margin-top: 14px;
    color: var(--cv-muted);
}

.cv-auth-message.is-error {
    color: #ffd0d0 !important;
}

.cv-hero::after,
.cv-panel::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 30%, transparent 70%, rgba(255, 255, 255, 0.04));
}

.cv-back {
    display: inline-flex;
    margin-bottom: 14px;
    color: var(--cv-muted);
    text-decoration: none;
    font-size: 0.96rem;
}

.cv-back:hover {
    color: var(--cv-accent);
}

.cv-eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.8rem;
    color: var(--cv-accent);
}

.cv-hero h1,
.cv-panel h2,
.cv-empty-state h3 {
    margin: 0;
}

.cv-hero h1 {
    max-width: none;
    font-size: clamp(0.95rem, 2.6vw, 2.15rem);
    line-height: 1.1;
    white-space: nowrap;
}

.cv-intro,
.cv-panel-head p,
.cv-status,
.cv-meta-list dd,
.cv-empty-state p,
.cv-move-note {
    color: var(--cv-muted);
}

.cv-intro {
    max-width: 58rem;
    margin: 8px 0 0;
    font-size: 1rem;
}

.cv-legend {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.cv-legend-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 92px;
    padding: 10px 14px;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.cv-legend-item.is-white {
    color: #fff;
    background: rgba(152, 160, 170, 0.92);
    border: 1px solid rgba(9, 13, 16, 0.1);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.82);
}

.cv-legend-item.is-black {
    color: #090d10;
    background: rgba(152, 160, 170, 0.92);
    border: 1px solid rgba(9, 13, 16, 0.1);
}

.cv-legend-item.is-transposition-primary {
    color: #29051e;
    background: rgba(244, 170, 210, 0.96);
    border: 1px solid rgba(157, 73, 121, 0.38);
}

.cv-legend-item.is-transposition-secondary {
    color: #140d3b;
    background: rgba(184, 158, 246, 0.96);
    border: 1px solid rgba(94, 68, 165, 0.38);
}

.cv-legend-item.is-player-branching {
    color: #102013;
    background: rgba(182, 214, 132, 0.96);
    border: 1px solid rgba(96, 132, 43, 0.38);
}

.cv-legend-item.is-unanswered {
    color: #062242;
    background: rgba(145, 198, 255, 0.96);
    border: 1px solid rgba(49, 101, 163, 0.38);
}

.cv-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.cv-panel {
    padding: 26px;
}

.cv-panel-head {
    position: relative;
    z-index: 1;
    margin-bottom: 18px;
}

.cv-panel-head.compact {
    margin-bottom: 12px;
}

.cv-panel-head h2 {
    margin-bottom: 6px;
    font-size: 1.25rem;
}

.cv-panel-head p {
    margin: 0;
    max-width: 58ch;
}

.cv-form,
.cv-editor-controls,
.cv-examples,
.cv-lichess-import,
.cv-meta-block,
.cv-stats {
    position: relative;
    z-index: 1;
}

.cv-examples {
    margin-bottom: 20px;
}

.cv-lichess-import {
    margin-bottom: 20px;
    padding: 16px;
    border: 1px solid rgba(107, 207, 147, 0.2);
    border-radius: 20px;
    background: rgba(107, 207, 147, 0.055);
}

.cv-input-panel .cv-lichess-import {
    margin-bottom: 0;
}

.cv-study-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
}

.cv-step {
    margin: 0 0 7px !important;
    color: var(--cv-success) !important;
    font: 700 0.72rem/1 "IBM Plex Mono", monospace;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.cv-new-study {
    margin-top: 16px;
    padding: 15px;
    border: 1px solid var(--cv-border);
    border-radius: 16px;
    background: rgba(5, 8, 10, 0.42);
}

.cv-new-study .cv-repertoire-switch {
    margin: 12px 0;
}

.cv-text-field {
    width: 100%;
    min-height: 44px;
    padding: 10px 13px;
    border: 1px solid var(--cv-border);
    border-radius: 14px;
    outline: none;
    color: var(--cv-text);
    background: rgba(5, 8, 10, 0.72);
    font: 500 0.9rem/1.2 "IBM Plex Mono", monospace;
}

.cv-text-field:focus {
    border-color: rgba(240, 195, 106, 0.7);
    box-shadow: 0 0 0 3px rgba(240, 195, 106, 0.14);
}

.cv-editor-controls {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--cv-border);
}

.cv-tree-panel > .cv-editor-controls {
    margin: 0 0 16px;
    padding: 0 0 16px;
    border-top: 0;
    border-bottom: 1px solid var(--cv-border);
}

.cv-study-summary {
    position: relative;
    z-index: 1;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--cv-border);
}

.cv-editor-controls .cv-frequency-field {
    width: 100%;
}

.cv-editor-controls .cv-actions a {
    text-decoration: none;
}

.cv-study-picker .cv-select {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
}

.cv-study-picker .cv-button {
    padding: 10px 13px;
}

.cv-study-status {
    min-height: 1.2em;
    margin: 10px 0 0;
    color: var(--cv-muted);
    font-size: 0.82rem;
}

.cv-study-status.is-error {
    color: #ffbcbc;
}

.cv-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.cv-repertoire-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 18px;
    padding: 5px;
    border: 1px solid var(--cv-border);
    border-radius: 18px;
    background: rgba(5, 8, 10, 0.5);
}

.cv-repertoire-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    border: 1px solid transparent;
    border-radius: 13px;
    color: var(--cv-muted);
    background: transparent;
    font: 600 0.84rem/1.2 "IBM Plex Mono", monospace;
    cursor: pointer;
}

.cv-repertoire-tab.is-active {
    color: #10171b;
    border-color: rgba(240, 195, 106, 0.65);
    background: linear-gradient(145deg, var(--cv-accent), var(--cv-accent-strong));
}

.cv-repertoire-piece {
    font-size: 1.25rem;
}

.cv-example-grid {
    display: grid;
    gap: 14px;
}

.cv-example-card {
    display: block;
    padding: 14px;
    border-radius: 20px;
    border: 1px solid rgba(255, 247, 231, 0.08);
    background: rgba(255, 247, 231, 0.04);
}

.cv-example-body {
    min-width: 0;
}

.cv-example-kicker {
    margin: 0 0 8px;
    color: var(--cv-accent);
    font: 700 0.72rem/1 "IBM Plex Mono", monospace;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.cv-example-title {
    margin: 0;
    font-size: 1.12rem;
}

.cv-example-title-link,
.cv-example-open {
    color: var(--cv-text);
    text-decoration: none;
}

.cv-example-title-link:hover,
.cv-example-open:hover {
    color: var(--cv-accent);
}

.cv-example-meta {
    margin: 8px 0 0;
    color: var(--cv-muted);
    font-size: 0.92rem;
    line-height: 1.45;
}

.cv-example-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
}

.cv-example-open {
    font: 600 0.88rem/1.2 "IBM Plex Mono", monospace;
}

.cv-label {
    display: block;
    margin-bottom: 10px;
    font-size: 0.92rem;
    font-weight: 600;
}

#pgn-input {
    width: 100%;
    min-height: 320px;
    resize: vertical;
    border: 1px solid var(--cv-border);
    border-radius: 18px;
    background: rgba(5, 8, 10, 0.72);
    color: var(--cv-text);
    padding: 16px 18px;
    font: 500 0.94rem/1.6 "IBM Plex Mono", monospace;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

#pgn-input:focus {
    border-color: rgba(240, 195, 106, 0.7);
    box-shadow: 0 0 0 3px rgba(240, 195, 106, 0.14);
    transform: translateY(-1px);
}

.cv-actions {
    display: flex;
    gap: 12px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.cv-actions .cv-button.is-probability {
    margin-top: 0;
}

.cv-button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 12px 18px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease;
}

.cv-button:hover {
    transform: translateY(-1px);
}

.cv-button.is-primary {
    color: #11181c;
    background: linear-gradient(145deg, var(--cv-accent), var(--cv-accent-strong));
    box-shadow: 0 14px 30px rgba(230, 138, 46, 0.26);
}

.cv-button.is-secondary {
    color: var(--cv-text);
    background: rgba(255, 247, 231, 0.05);
    border-color: var(--cv-border);
}

.cv-button.is-quiet {
    color: var(--cv-muted);
    border-color: transparent;
    background: transparent;
}

.cv-button.is-probability {
    margin-top: 12px;
    color: #dcecff;
    background: linear-gradient(145deg, #1f5fa2, #3c88dc);
    box-shadow: 0 12px 28px rgba(60, 136, 220, 0.24);
}

.cv-button.is-probability-alt {
    color: #e8fff5;
    background: linear-gradient(145deg, #18664d, #2ca27b);
    box-shadow: 0 12px 28px rgba(44, 162, 123, 0.22);
}

.cv-probability-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-top: 12px;
}

.cv-probability-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
}

.cv-probability-actions .cv-button {
    flex: 1 1 240px;
    margin-top: 0;
}

.cv-config-field {
    display: inline-grid;
    gap: 6px;
    min-width: 180px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--cv-muted);
}

.cv-select {
    appearance: none;
    min-height: 42px;
    padding: 10px 38px 10px 14px;
    border: 1px solid var(--cv-border);
    border-radius: 14px;
    background:
        linear-gradient(180deg, rgba(255, 247, 231, 0.07), rgba(255, 247, 231, 0.03)),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 5.25L7 9.25L11 5.25' stroke='%23f5efe4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center / 14px 14px;
    color: var(--cv-text);
    color-scheme: dark;
    font: 500 0.9rem/1.2 "IBM Plex Mono", monospace;
    outline: none;
}

.cv-select option {
    color: #f5efe4;
    background: #11181c;
}

.cv-select:focus {
    border-color: rgba(240, 195, 106, 0.7);
    box-shadow: 0 0 0 3px rgba(240, 195, 106, 0.14);
}

.cv-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 19px;
    color: var(--cv-text);
    font-size: 0.88rem;
    font-weight: 600;
}

.cv-check input {
    width: 16px;
    height: 16px;
    accent-color: var(--cv-accent-strong);
}

.cv-frequency-field {
    min-width: 160px;
}

.cv-frequency-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--cv-border);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255, 247, 231, 0.07), rgba(255, 247, 231, 0.03));
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.cv-frequency-input-wrap:focus-within {
    border-color: rgba(240, 195, 106, 0.7);
    box-shadow: 0 0 0 3px rgba(240, 195, 106, 0.14);
}

.cv-frequency-prefix {
    color: var(--cv-text);
    font: 600 0.9rem/1 "IBM Plex Mono", monospace;
}

.cv-text-input {
    width: 100%;
    min-width: 0;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--cv-text);
    font: 500 0.9rem/1.2 "IBM Plex Mono", monospace;
    outline: none;
}

.cv-text-input:disabled {
    opacity: 0.6;
}

.cv-button:disabled {
    cursor: default;
    opacity: 0.5;
    transform: none;
    box-shadow: none;
}

.cv-status {
    position: relative;
    z-index: 1;
    margin: 16px 0 20px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--cv-border);
    background: rgba(255, 247, 231, 0.04);
}

.cv-status.is-error {
    color: #ffd0d0;
    border-color: rgba(255, 120, 120, 0.35);
    background: rgba(120, 12, 12, 0.24);
}

.cv-status.is-success {
    color: #d7ffe5;
    border-color: rgba(107, 207, 147, 0.35);
    background: rgba(23, 81, 53, 0.24);
}

.cv-meta-list {
    display: grid;
    gap: 12px;
    margin: 0;
}

.cv-meta-entry {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 247, 231, 0.08);
    background: rgba(255, 247, 231, 0.04);
}

.cv-meta-list dt {
    margin: 0;
    font-size: 0.75rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--cv-accent);
}

.cv-meta-list dd {
    margin: 0;
    font-size: 0.98rem;
    word-break: break-word;
}

.cv-meta-list a {
    color: var(--cv-text);
    text-decoration-color: rgba(240, 195, 106, 0.5);
}

.cv-meta-list a:hover {
    color: var(--cv-accent);
}

.cv-meta-empty {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px dashed rgba(255, 247, 231, 0.16);
    color: var(--cv-muted);
    background: rgba(255, 247, 231, 0.03);
}

.cv-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.cv-stat-card {
    padding: 16px;
    border-radius: 18px;
    border: 1px solid rgba(255, 247, 231, 0.08);
    background: rgba(255, 247, 231, 0.05);
}

.cv-stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 1.75rem;
    line-height: 1;
}

.cv-stat-label {
    color: var(--cv-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.cv-tree-panel {
    min-height: 720px;
}

.cv-tree-shell {
    position: relative;
    z-index: 1;
    min-height: 600px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 16px;
    border-radius: 22px;
    border: 1px solid rgba(255, 247, 231, 0.08);
    background:
        linear-gradient(180deg, rgba(6, 10, 12, 0.82), rgba(16, 24, 28, 0.82)),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: auto, 30px 30px, 30px 30px;
}

.cv-move-editor {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(150px, 220px) auto auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid rgba(240, 195, 106, 0.4);
    border-radius: 18px;
    background: rgba(240, 195, 106, 0.08);
}

.cv-move-editor p {
    margin: 4px 0 0;
    color: var(--cv-muted);
    font-size: 0.82rem;
}

.cv-move-card {
    position: relative;
}

.cv-move-edit-actions {
    display: flex;
    grid-area: actions;
    align-items: center;
    flex-wrap: nowrap;
    gap: 3px;
    margin-top: 0;
}

.cv-move-edit-button {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 20px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.22);
    border-radius: 7px;
    color: inherit;
    background: rgba(255, 255, 255, 0.22);
    font: 700 1rem/1 "IBM Plex Mono", monospace;
    cursor: pointer;
}

.cv-delete-branch:hover {
    color: #6f1010;
    background: rgba(255, 120, 120, 0.5);
}

.cv-add-root-move {
    margin-bottom: 10px;
    padding: 8px 12px;
    border: 1px dashed rgba(240, 195, 106, 0.6);
    border-radius: 12px;
    color: var(--cv-accent);
    background: rgba(240, 195, 106, 0.08);
    font: 600 0.82rem/1.2 "IBM Plex Mono", monospace;
    cursor: pointer;
}

.cv-hover-preview {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 2500;
    width: 244px;
    padding: 12px;
    border-radius: 18px;
    border: 1px solid rgba(255, 247, 231, 0.16);
    background: rgba(9, 14, 17, 0.96);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(14px);
    pointer-events: none;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 120ms ease, transform 120ms ease;
}

.cv-hover-preview.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.cv-hover-preview-head {
    margin-bottom: 10px;
}

.cv-hover-preview-title {
    display: block;
    color: var(--cv-text);
    font: 700 0.86rem/1.2 "IBM Plex Mono", monospace;
}

.cv-hover-preview-board {
    width: 220px;
    height: 220px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 12px;
}

.cv-hover-preview-board .cm-chessboard {
    width: 220px;
    height: 220px;
}

.cv-empty-state {
    display: grid;
    place-items: center;
    min-height: 560px;
    text-align: center;
    padding: 24px;
}

.cv-tree-scroll {
    width: 100%;
    min-width: 0;
    padding: 2px 0 10px;
}

.cv-tree-root {
    display: block;
    width: 100%;
}

.cv-tree-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.cv-tree-list .cv-tree-list {
    margin-top: 4px;
    margin-left: 15px;
    padding-left: 14px;
    border-left: 1px solid var(--cv-line);
}

.cv-tree-node {
    position: relative;
    margin: 3px 0;
}

.cv-move-line {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 3px 4px;
    min-width: 0;
}

.cv-tree-list:not(.is-root) > .cv-tree-node::before {
    content: "";
    position: absolute;
    top: 12px;
    left: -14px;
    width: 14px;
    height: 1px;
    background: var(--cv-line);
}

.cv-move-card {
    display: inline-grid;
    grid-template-columns: max-content auto;
    grid-template-areas:
        "label actions"
        "note note";
    align-items: center;
    gap: 2px 4px;
    width: auto;
    max-width: min(100%, 320px);
    padding: 4px 8px 5px 10px;
    border-radius: 11px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: none;
    transition: box-shadow 160ms ease, transform 160ms ease;
}

.cv-move-card:not(.is-transposition) {
    cursor: pointer;
}

.cv-move-card:not(.is-transposition):hover,
.cv-move-card:not(.is-transposition):has(.cv-move-label:focus-visible) {
    transform: translateY(-1px);
    box-shadow: 0 0 0 2px rgba(240, 195, 106, 0.66);
}

#pgn-tree .cv-move-card.is-board-selected {
    border-color: #ff3b3b;
    box-shadow: 0 0 0 2px rgba(255, 59, 59, 0.96), 0 10px 22px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.cv-move-card.is-mainline {
    border-color: rgba(240, 195, 106, 0.55);
    box-shadow: inset 2px 0 0 rgba(240, 195, 106, 0.72);
}

.cv-move-card.is-white {
    color: #fff;
    background: rgba(152, 160, 170, 0.92);
    border-color: rgba(9, 13, 16, 0.1);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.82);
}

.cv-move-card.is-black {
    color: #0b1114;
    background: rgba(152, 160, 170, 0.92);
    border-color: rgba(9, 13, 16, 0.1);
}

.cv-move-card.is-transposition-primary {
    background: rgba(244, 170, 210, 0.96);
    border-color: rgba(157, 73, 121, 0.38);
    cursor: pointer;
}

.cv-move-card.is-transposition-primary:hover,
.cv-move-card.is-transposition-primary:has(.cv-move-label:focus-visible) {
    transform: translateY(-1px);
    box-shadow: 0 0 0 2px rgba(244, 170, 210, 0.72);
}

.cv-move-card.is-transposition-secondary {
    background: rgba(184, 158, 246, 0.96);
    border-color: rgba(94, 68, 165, 0.38);
    cursor: pointer;
}

.cv-move-card.is-transposition-target {
    box-shadow: 0 0 0 3px rgba(245, 226, 113, 0.96), 0 10px 22px rgba(20, 24, 33, 0.28);
    transform: translateY(-1px);
}

.cv-move-card.is-unanswered:not(.is-transposition-secondary) {
    background: rgba(145, 198, 255, 0.96);
    border-color: rgba(49, 101, 163, 0.38);
}

.cv-move-card.is-player-branching {
    border-style: dashed;
    border-color: rgba(206, 214, 223, 0.64);
    box-shadow: inset 0 0 0 1px rgba(78, 88, 97, 0.22);
}

.cv-move-card.is-player-branching:not(.is-transposition-primary):not(.is-transposition-secondary) {
    background: rgba(182, 214, 132, 0.96);
}

.cv-move-card.is-transposition-primary.is-player-branching,
.cv-move-card.is-transposition-secondary.is-player-branching {
    box-shadow: inset 0 0 0 2px rgba(78, 88, 97, 0.38);
}

.cv-move-label {
    display: flex;
    grid-area: label;
    align-items: baseline;
    gap: 2px;
    flex-wrap: nowrap;
    white-space: nowrap;
    margin: 0;
    padding: 0;
    border: 0;
    color: inherit;
    background: transparent;
    text-align: left;
    text-shadow: inherit;
    font: 600 0.78rem/1.25 "IBM Plex Mono", monospace;
}

button.cv-move-label {
    cursor: pointer;
}

button.cv-move-label:focus-visible {
    outline: none;
}

.cv-move-prefix {
    opacity: 0.72;
}

.cv-move-san {
    font-weight: 700;
}

.cv-move-probability {
    color: #014c9b;
    font-weight: 700;
}

.cv-move-probability.is-missing {
    color: #8bb4e7;
    opacity: 0.85;
}

.cv-move-note {
    grid-area: note;
    margin: 0;
    font-size: 0.69rem;
    line-height: 1.35;
    max-width: 72ch;
    word-break: break-word;
}

.cv-move-card.is-black .cv-move-note {
    color: rgba(11, 17, 20, 0.7);
}

.cv-move-card.is-white .cv-move-note {
    color: rgba(255, 255, 255, 0.84);
}

@media (max-width: 1180px) {
    .cv-layout {
        grid-template-columns: 1fr;
    }

    .cv-tree-panel {
        min-height: 640px;
    }
}

@media (max-width: 900px) {
    .cv-editor-workspace {
        grid-template-columns: 1fr;
    }

    .cv-main-board {
        top: 8px;
        width: 100%;
        min-width: 0;
        max-width: 460px;
    }
}

@media (max-width: 720px) {
    .cv-page {
        padding: 14px 10px 28px;
    }

    .cv-hero,
    .cv-panel {
        padding: 18px;
        border-radius: 22px;
    }

    .cv-hero {
        flex-direction: column;
    }

    .cv-engine-toolbar {
        grid-template-columns: 38px 48px minmax(0, 1fr);
    }

    .cv-engine-next-moves {
        padding: 1px 0 3px;
    }

    .cv-engine-options {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .cv-account {
        width: 100%;
        align-self: stretch;
    }

    .cv-account form {
        margin-left: auto;
    }

    .cv-study-picker {
        grid-template-columns: 1fr 1fr;
    }

    .cv-study-picker .cv-select {
        grid-column: 1 / -1;
    }

    .cv-study-picker #refresh-lichess-studies {
        grid-column: 1 / -1;
    }

    .cv-repertoire-tab {
        padding: 8px;
        font-size: 0.75rem;
    }

    .cv-move-editor {
        grid-template-columns: 1fr 1fr;
    }

    .cv-move-editor > div,
    .cv-move-editor .cv-select {
        grid-column: 1 / -1;
        width: 100%;
    }

    #pgn-input {
        min-height: 260px;
    }

    .cv-stats {
        grid-template-columns: 1fr;
    }

    .cv-tree-shell {
        min-height: 420px;
    }

    .cv-empty-state {
        min-height: 360px;
    }

    .cv-move-card {
        max-width: 100%;
        padding: 4px 7px 5px 9px;
    }

    .cv-move-label {
        font-size: 0.73rem;
    }

    .cv-probability-controls {
        align-items: stretch;
    }

    .cv-probability-actions {
        align-items: stretch;
    }

    .cv-config-field {
        min-width: min(100%, 220px);
    }

    .cv-check {
        margin-top: 0;
    }
}
