/* Fonts (Geist, Geist Mono) are loaded by a <link> in each page head. */
:root {
    color-scheme: dark;

    /* Ground and surfaces */
    --ground: #0b0c0e;
    --surface: #111214;
    --surface-2: #17181b;

    /* Ink */
    --ink: #ededef;
    --ink-2: #8b9099;
    --ink-3: #80858f;

    /* Rules */
    --hair: rgba(255, 255, 255, 0.07);
    --hair-strong: rgba(255, 255, 255, 0.12);
    --rule: 1px solid rgba(255, 255, 255, 0.12);

    /* One accent: cyan. Dark text on cyan fills. */
    --blue: #3ddbe9;
    --on-accent: #061416;
    --blue-soft: rgba(61, 219, 233, 0.12);
    --blue-line: rgba(61, 219, 233, 0.35);

    /* Meaning colours, never decorative: always with a glyph or text */
    --red: #f87171;
    --yellow: #fbbf24;
    --green: #4ade80;

    /* Board: graphite by default. Other themes set --board-light / --board-dark inline (nav-rail.js, on every page). */
    --board-light: #c8ccd3;
    --board-dark: #7d8796;
    --board-last: rgba(61, 219, 233, 0.25);
    --board-select: var(--blue);
    --board-bad: var(--red);
    --arrow-attack: #ef4444;

    /* Type */
    --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --fs-xs: 12px;
    --fs-sm: 13px;
    --fs-md: 14px;
    --fs-lg: 16px;
    --fs-xl: 20px;
    --fs-2xl: 24px;
    --fs-3xl: 32px;

    /* Space */
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-5: 24px; --space-6: 32px; --space-8: 48px; --space-10: 64px;

    /* Shape: 8px cards, 6px controls, no shadows */
    --radius-card: 8px;
    --radius-ctl: 6px;
}

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

html {
    background: var(--ground);
}

body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--fs-md);
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font);
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }

button, input, select, textarea {
    font-family: var(--font);
}

/* Browser surfaces */
::selection {
    background: var(--blue-line);
    color: var(--ink);
}

input, textarea, [contenteditable] {
    caret-color: var(--blue);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--hair-strong) transparent;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--hair-strong);
    border-radius: 999px;
    border: 2px solid var(--ground);
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

a {
    color: var(--blue);
    text-underline-offset: 3px;
}

:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

/* Data */
table, .tabular, .mono {
    font-variant-numeric: tabular-nums;
}

.mono {
    font-family: var(--font-mono);
}

kbd {
    display: inline-block;
    min-width: 20px;
    padding: 1px 6px;
    border: 1px solid var(--hair-strong);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.5;
    text-align: center;
}

.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;
}

/* "This week's focus" beside a weakness name on Home and History */
.weak-focus-tag {
    margin-left: var(--space-2);
    color: var(--red);
    font-size: var(--fs-xs);
    font-weight: 500;
}

.hidden {
    display: none !important;
}

/* Buttons. .auth-button is the class the pages already use; .btn is the same thing for new markup.
   Default: a raised panel with a 1px border. .primary: cyan fill. .ghost: no fill, no border. */
.btn,
.auth-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 36px;
    padding: 8px 16px;
    border: var(--rule);
    border-radius: var(--radius-ctl);
    background: var(--surface-2);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--fs-md);
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover:not(:disabled),
.auth-button:hover:not(:disabled) {
    background: #1e1f23;
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--ink);
}

.btn.primary,
.auth-button.primary {
    background: var(--blue);
    border-color: var(--blue);
    color: var(--on-accent);
    font-weight: 600;
}

.btn.primary:hover:not(:disabled),
.auth-button.primary:hover:not(:disabled) {
    background: #66e5f0;
    border-color: #66e5f0;
    color: var(--on-accent);
}

.btn.ghost,
.auth-button.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--ink-2);
}

.btn.ghost:hover:not(:disabled),
.auth-button.ghost:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: transparent;
    color: var(--ink);
}

.btn.danger,
.auth-button.danger {
    border-color: rgba(248, 113, 113, 0.4);
    background: transparent;
    color: var(--red);
}

.btn.danger:hover:not(:disabled),
.auth-button.danger:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.12);
    border-color: var(--red);
    color: var(--red);
}

.btn:disabled,
.auth-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn:focus-visible,
.auth-button:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

.auth-button.full,
.btn.full {
    width: 100%;
}

/* Button press: a brief push-down */
.btn,
.auth-button,
.fc-select-button {
    transition: transform 80ms cubic-bezier(0.2, 0.8, 0.2, 1), background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn:active:not(:disabled),
.auth-button:active:not(:disabled),
.fc-select-button:active:not(:disabled) {
    transform: translateY(1px) scale(0.98);
}

/* Segmented controls: one joined control, the active segment is a raised panel with cyan text */
.segmented,
.chip-row,
.openings-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0;
    padding-left: 1px;
}

.openings-tabs {
    margin-bottom: var(--space-4);
}

.tab,
.chip {
    min-height: 32px;
    padding: 6px 14px;
    margin-left: -1px;
    border: var(--rule);
    border-radius: 0;
    background: var(--surface);
    color: var(--ink-2);
    font-family: var(--font);
    font-size: var(--fs-md);
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
}

.tab:first-child,
.chip:first-child {
    border-radius: var(--radius-ctl) 0 0 var(--radius-ctl);
}

.tab:last-child,
.chip:last-child {
    border-radius: 0 var(--radius-ctl) var(--radius-ctl) 0;
}

.tab:only-child,
.chip:only-child {
    border-radius: var(--radius-ctl);
}

.tab:hover:not(:disabled),
.chip:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--ink);
}

.tab.active,
.chip.active {
    background: var(--surface-2);
    border-color: var(--blue-line);
    color: var(--blue);
    position: relative;
}

.tab:disabled,
.chip:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tab:focus-visible,
.chip:focus-visible {
    position: relative;
    z-index: 1;
}

/* Inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
    min-height: 36px;
    padding: 8px 12px;
    border: var(--rule);
    border-radius: var(--radius-ctl);
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--fs-md);
}

input[type="text"]:hover:not(:disabled),
input[type="email"]:hover:not(:disabled),
input[type="password"]:hover:not(:disabled),
input[type="number"]:hover:not(:disabled),
input[type="search"]:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.2);
}

input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
input[type="password"]:focus-visible,
input[type="number"]:focus-visible,
input[type="search"]:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

textarea {
    min-height: 88px;
}

input::placeholder,
textarea::placeholder {
    color: var(--ink-3);
    opacity: 1;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.table th {
    color: var(--ink-2);
    font-size: var(--fs-xs);
    font-weight: 500;
    text-align: left;
    border-bottom: 1px solid var(--hair-strong);
}

.table td {
    border-bottom: 1px solid var(--hair);
}

.table tbody tr:hover {
    background: var(--surface);
}

/* Form markers: the system's icon language */
.mark-sq,
.mark-tri,
.mark-ci,
.mark-new {
    display: inline-block;
    flex-shrink: 0;
    vertical-align: middle;
}

.mark-sq {
    width: 12px;
    height: 12px;
    background: var(--red);
}

.mark-ci {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--blue);
}

.mark-tri {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 12px solid var(--yellow);
}

/* New marker: hollow light square */
.mark-new {
    width: 12px;
    height: 12px;
    border: 2px solid var(--ink);
    background: transparent;
}

.mark-sq.mark--lg { width: 18px; height: 18px; }
.mark-ci.mark--lg { width: 18px; height: 18px; }
.mark-tri.mark--lg {
    border-left-width: 9px;
    border-right-width: 9px;
    border-bottom-width: 18px;
}

/* Eval chips */
.eval-chip {
    display: inline-block;
    padding: 2px 8px;
    background: var(--surface-2);
    border: 1px solid var(--hair-strong);
    border-radius: 4px;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.eval-chip.bad {
    background: var(--red);
    border-color: var(--red);
    color: var(--on-accent);
}

.eval-chip.up {
    background: var(--green);
    border-color: var(--green);
    color: var(--on-accent);
}

/* White / draw / Black block bar */
.wdl {
    display: flex;
    height: 14px;
    min-width: 96px;
    border: 1px solid var(--hair-strong);
    border-radius: 4px;
    overflow: hidden;
    background: var(--surface);
}

.wdl span {
    display: block;
    height: 100%;
}

.wdl-w { background: var(--ink); }
.wdl-d { background: var(--hair); }
.wdl-b { background: var(--ground); }

/* Toasts (scripts/ui.js) */
.fc-toasts {
    position: fixed;
    left: 50%;
    bottom: var(--space-5);
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    width: max-content;
    max-width: min(420px, calc(100vw - 2 * var(--space-3)));
    pointer-events: none;
}

.fc-toast {
    pointer-events: auto;
    padding: var(--space-3) var(--space-4);
    background: var(--surface-2);
    border: var(--rule);
    border-radius: var(--radius-card);
    color: var(--ink);
    font-size: var(--fs-sm);
    animation: toastIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.fc-toast.leaving {
    opacity: 0;
    transform: translateY(8px);
}

.fc-toast--error {
    border-color: var(--red);
}

.fc-toast--success {
    border-color: var(--green);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}

@media (max-width: 760px) {
    /* sit above the bottom tab bar */
    .fc-toasts {
        bottom: calc(64px + env(safe-area-inset-bottom) + var(--space-3));
    }
}

/* Ask the tutor (scripts/ui.js createAskBox) */
.fc-ask {
    margin-top: var(--space-3);
    border: var(--rule);
    border-radius: var(--radius-card);
    background: var(--surface);
}

.fc-ask > summary {
    padding: var(--space-2) var(--space-3);
    color: var(--ink-2);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
}

.fc-ask[open] > summary {
    border-bottom: 1px solid var(--hair);
}

.fc-ask-log {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 180px;
    overflow-y: auto;
    padding: 0 var(--space-3);
}

.fc-ask-log:not(:empty) {
    padding-top: var(--space-3);
}

.fc-ask-q {
    align-self: flex-end;
    max-width: 90%;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-ctl);
    background: var(--blue-soft);
    font-size: var(--fs-sm);
}

.fc-ask-a {
    color: var(--ink);
    font-size: var(--fs-sm);
    line-height: 1.5;
}

.fc-ask-error {
    color: var(--red);
}

.fc-ask-meta {
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
}

.fc-ask-form {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3);
}

.fc-ask-form input {
    flex: 1;
    min-width: 0;
    padding: 8px var(--space-3);
    border: var(--rule);
    border-radius: var(--radius-ctl);
    background: var(--surface-2);
    color: var(--ink);
    font-size: var(--fs-sm);
}

/* Spinner (scripts/ui.js) */
.fc-spinner {
    display: inline-block;
    box-sizing: border-box;
    width: var(--fc-spinner-size, 16px);
    height: var(--fc-spinner-size, 16px);
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -0.2em;
    animation: fcSpin 0.7s linear infinite;
}

@keyframes fcSpin {
    to { transform: rotate(360deg); }
}

/* Custom dropdown (scripts/ui.js enhanceSelect) */
.fc-select {
    position: relative;
    display: inline-block;
    min-width: 0;
    max-width: 100%;
    vertical-align: middle;
}

.fc-select-native {
    display: none !important;
}

.fc-select-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    width: 100%;
    min-height: 36px;
    padding: 8px 12px;
    border: var(--rule);
    border-radius: var(--radius-ctl);
    background: var(--surface-2);
    color: var(--ink);
    font-family: var(--font);
    font-size: inherit;
    text-align: left;
    cursor: pointer;
}

.fc-select-button:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.2);
    background: #1e1f23;
}

.fc-select.open .fc-select-button {
    border-color: var(--blue-line);
}

.fc-select-button:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

.fc-select-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.fc-select-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fc-select-chevron {
    flex: none;
    width: 7px;
    height: 7px;
    margin-top: -3px;
    border-right: 1.5px solid var(--ink-2);
    border-bottom: 1.5px solid var(--ink-2);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.fc-select.open .fc-select-chevron {
    margin-top: 3px;
    transform: rotate(225deg);
}

.fc-select-list {
    position: fixed;
    z-index: 3500;
    overflow-y: auto;
    padding: var(--space-1);
    background: var(--surface-2);
    border: var(--rule);
    border-radius: var(--radius-ctl);
    box-shadow: none;
    font-size: var(--fs-sm);
    animation: fcSelectIn 0.12s ease;
}

.fc-select-list[hidden] {
    display: none;
}

@keyframes fcSelectIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: none; }
}

.fc-select-list.up {
    animation-name: fcSelectInUp;
}

@keyframes fcSelectInUp {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.fc-select-group {
    padding: var(--space-2) var(--space-3) var(--space-1);
    color: var(--ink-3);
    font-size: var(--fs-xs);
    font-weight: 500;
}

.fc-select-option {
    position: relative;
    padding: 7px 36px 7px 10px;
    border-radius: 4px;
    color: var(--ink);
    cursor: pointer;
}

.fc-select-option.active {
    background: var(--hair);
}

.fc-select-option.disabled {
    color: var(--ink-3);
    cursor: not-allowed;
}

.fc-select-option[aria-selected="true"] {
    color: var(--blue);
}

.fc-select-option[aria-selected="true"]::after {
    content: "";
    position: absolute;
    right: 14px;
    top: 50%;
    width: 5px;
    height: 10px;
    margin-top: -7px;
    border-right: 2px solid var(--blue);
    border-bottom: 2px solid var(--blue);
    transform: rotate(45deg);
}

@media (prefers-reduced-motion: reduce) {
    .fc-toast,
    .fc-spinner,
    .fc-select-list,
    .fc-select-chevron {
        animation: none;
        transition: none;
    }
}

@keyframes authCardIn {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes authChildIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .auth-card,
    .auth-card-wordmark,
    .auth-card #auth-modal-title,
    .auth-card #auth-modal-subtitle,
    .auth-card #google-signin,
    .auth-card .auth-divider,
    .auth-card .auth-form {
        animation: none !important;
    }
}

/* Sign-in modal */
.auth-user-label {
    font-size: var(--fs-sm);
    color: var(--ink-2);
}

.auth-modal {
    position: fixed;
    inset: 0;
    background: rgba(11, 12, 14, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--hair-strong);
    border-radius: var(--radius-card);
    width: min(420px, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: 40px 32px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: authCardIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-card-wordmark {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-weight: 600;
    font-size: var(--fs-xl);
    letter-spacing: -0.01em;
    margin-bottom: 4px;
    animation: authChildIn 0.4s ease-out 0.1s both;
}

.auth-card #auth-modal-title {
    animation: authChildIn 0.4s ease-out 0.2s both;
}

.auth-card #auth-modal-subtitle {
    color: var(--ink-2);
    animation: authChildIn 0.4s ease-out 0.3s both;
}

.auth-card #google-signin {
    animation: authChildIn 0.4s ease-out 0.4s both;
}

.auth-card .auth-divider,
.auth-card .auth-form {
    animation: authChildIn 0.4s ease-out 0.5s both;
}

.auth-close {
    min-width: 44px;
    min-height: 44px;
    background: transparent;
    border: none;
    border-radius: var(--radius-ctl);
    color: var(--ink-2);
    position: absolute;
    top: 4px;
    right: 4px;
    font-family: var(--font);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
}

.auth-close:hover {
    color: var(--ink);
    background: var(--surface-2);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.auth-field input,
.auth-field select {
    width: 100%;
    box-sizing: border-box;
}

.auth-divider {
    text-align: center;
    color: var(--ink-3);
}

.auth-divider span {
    padding: 0 8px;
}

.auth-toggle-text {
    font-size: var(--fs-sm);
    text-align: center;
    color: var(--ink-2);
}

.auth-toggle-text button {
    background: none;
    border: none;
    color: var(--blue);
    cursor: pointer;
    font-size: var(--fs-sm);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

#secondary-message.trainer-error {
    color: var(--red);
}

/* Side picker: a two-segment switch; the radio stays for keyboard and form, hidden from view */
.trainer-sides {
    display: flex;
    padding-left: 1px;
}

.trainer-sides label {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    margin-left: -1px;
    border: var(--rule);
    background: var(--surface);
    color: var(--ink-2);
    font-size: var(--fs-md);
    font-weight: 500;
    cursor: pointer;
}

.trainer-sides label:first-child {
    border-radius: var(--radius-ctl) 0 0 var(--radius-ctl);
}

.trainer-sides label:last-child {
    border-radius: 0 var(--radius-ctl) var(--radius-ctl) 0;
}

.trainer-sides label:has(input:checked) {
    background: var(--surface-2);
    color: var(--blue);
}

.trainer-sides label:has(input:focus-visible) {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

.auth-field .trainer-sides input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

/* One board style. A board is a .fc-board grid of .fc-sq squares holding .fc-piece images. */
.fc-board {
    width: 100%;
    max-width: 720px;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 1px solid var(--hair-strong);
    user-select: none;
    position: relative;
}

/* Boards built by scripts/board-ui.js take touches themselves (drag), so the page must not scroll under them */
.fc-board.fc-live { touch-action: none; }

.fc-sq {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.fc-sq.light { background: var(--board-light); }
.fc-sq.dark { background: var(--board-dark); }

.fc-sq.last::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--board-last);
}

.fc-sq.selected { box-shadow: inset 0 0 0 4px var(--board-select); }
.fc-sq.wrong { box-shadow: inset 0 0 0 4px var(--board-bad); }
.fc-sq.right { box-shadow: inset 0 0 0 4px var(--green); }
.fc-sq.hint { box-shadow: inset 0 0 0 4px var(--board-select); }
.fc-sq.hover { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.8); }

/* King in check: red glow from the centre (the square keeps its wood colour underneath) */
.fc-sq.check {
    background-image: radial-gradient(circle, rgba(239, 68, 68, 0.95) 0%, rgba(239, 68, 68, 0.6) 40%, rgba(239, 68, 68, 0) 72%);
}

.fc-sq.legal::after {
    content: "";
    position: absolute;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background: rgba(11, 12, 14, 0.3);
}

.fc-sq.capture::after {
    content: "";
    position: absolute;
    inset: 6%;
    border-radius: 50%;
    border: 4px solid rgba(11, 12, 14, 0.35);
    background: transparent;
}

.fc-piece {
    position: relative;
    z-index: 1;
    width: 90%;
    height: 90%;
    object-fit: contain;
    pointer-events: none;
}

/* Piece motion (scripts/board-ui.js sets the transforms) */
.fc-piece.fc-sliding { z-index: 5; }
.fc-piece.fc-dragging {
    z-index: 20;
    transition: none;
    will-change: transform;
    filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.4));
}

/* A captured piece, leaving; it must not take a flex slot next to the piece that captured it */
.fc-piece.fc-ghost {
    position: absolute;
    inset: 0;
    margin: auto;
    z-index: 0;
}

/* Small badge in the corner of a flashed square */
.fc-badge {
    position: absolute;
    top: 3%;
    right: 3%;
    z-index: 6;
    width: 36%;
    height: 36%;
    border-radius: 50%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: 62%;
    pointer-events: none;
}

.fc-badge--wrong {
    background-color: var(--red);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 2 8 8M8 2 2 8' stroke='white' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
}

.fc-badge--right {
    background-color: var(--green);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.8 5.4 4.1 7.7 8.3 2.6' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Rank and file labels: the opposite square colour, so they read on both */
.fc-coord {
    position: absolute;
    z-index: 1;
    font-family: var(--font-mono);
    font-size: var(--fc-coord-size, 10px);
    font-weight: 500;
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

.fc-coord--file { right: 4%; bottom: 3%; }
.fc-coord--rank { left: 4%; top: 3%; }
.fc-sq.light .fc-coord { color: color-mix(in srgb, var(--board-dark) 62%, #000); }
.fc-sq.dark .fc-coord { color: color-mix(in srgb, var(--board-light) 70%, #fff); }

/* setBadge: a move classification icon in the corner of a square */
.fc-square-badge {
    position: absolute;
    top: 1%;
    right: 1%;
    z-index: 6;
    width: 34%;
    height: 34%;
    pointer-events: none;
}

.fc-sq.fc-shake { animation: fcShake 0.3s ease-in-out; }

@keyframes fcShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7%); }
    40% { transform: translateX(6%); }
    60% { transform: translateX(-4%); }
    80% { transform: translateX(3%); }
}

/* Arrow overlay */
.fc-arrows {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 7;
    pointer-events: none;
}

/* Promotion picker: four pieces in a column over the target square */
.fc-promo {
    position: absolute;
    z-index: 30;
    width: 12.5%;
    height: 50%;
    display: flex;
    background: var(--surface-2);
    border: 2px solid var(--blue);
    border-radius: var(--radius-ctl);
    overflow: hidden;
}

.fc-promo-btn {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

.fc-promo-btn:hover,
.fc-promo-btn:focus-visible {
    background: var(--board-light);
    outline: none;
}

.fc-promo-btn img {
    width: 88%;
    height: 88%;
    object-fit: contain;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .btn,
.auth-button,
.fc-select-button {
        transition: none;
    }

    .btn:active:not(:disabled),
.auth-button:active:not(:disabled),
.fc-select-button:active:not(:disabled) {
        transform: none;
    }

    .fc-sq.fc-shake { animation: none; }
    .fc-piece { transition: none !important; }
}

/* Google's standard sign-in button: white, the four-colour G, dark text */
.btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 20px;
    background: #ffffff;
    border: 1px solid #dadce0;
    border-radius: var(--radius-ctl);
    color: #1f1f1f;
    font-family: var(--font);
    font-size: var(--fs-md);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.btn-google.full {
    width: 100%;
}

.btn-google:hover {
    background: #f2f2f2;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.btn-google:active {
    transform: translateY(1px);
}

.btn-google:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* ---- Progress, Reports, Practice and Settings pages: the same content column and status line ---- */
.history-layout,
.reports-layout,
.practice-layout,
.settings-layout {
    max-width: 1100px;
    padding: var(--space-6) var(--space-6) var(--space-10);
}

.section-status,
.reports-status {
    margin: 0 0 var(--space-3);
    color: var(--ink-2);
}

@media (max-width: 760px) {
    .history-layout,
    .reports-layout,
    .practice-layout,
    .settings-layout {
        padding: var(--space-5) var(--space-4) var(--space-8);
    }
}

/* ---- Board pages (Puzzles, Lab, Report): top strip, player strips, eval bar, nav row ---- */

/* Top strip: breadcrumb left, session or mode tabs in the middle, shortcuts hint right */
.strip {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    height: var(--strip, 48px);
    padding: 0 var(--pad);
    border-bottom: 1px solid var(--hair);
}

.strip-crumb {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    margin: 0;
    font-size: var(--fs-sm);
    color: var(--ink-2);
    white-space: nowrap;
}

.crumb-sep { color: var(--ink-3); }

.crumb-here {
    color: var(--ink);
    font-weight: 500;
}

.strip-mid {
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-width: 0;
}

.strip-count {
    font-size: var(--fs-xs);
    color: var(--ink-2);
    white-space: nowrap;
}

.keys-hint {
    flex: 1 1 0;
    display: flex;
    justify-content: flex-end;
    margin: 0;
}

/* Session progress: three segments (Lines, Drills, Puzzles) that fill as each stage clears. The text stays for screen readers. */
.steps {
    display: flex;
    gap: 6px;
    width: min(340px, 40vw);
    margin: 0;
    padding: 0;
    list-style: none;
}

.step {
    position: relative;
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--hair-strong);
    overflow: hidden;
}

.step::before {
    content: "";
    position: absolute;
    inset: 0;
    width: calc(var(--fill, 0) * 100%);
    border-radius: 2px;
    background: var(--blue);
    transition: width 250ms ease;
}

.step.current { background: rgba(255, 255, 255, 0.22); }

.step > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Player strips and the nav row line up with the board, not the eval bar */
.player-strip {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 28px;
    margin-left: calc(var(--bar) + var(--bar-gap));
}

.player-strip .nm { font-weight: 500; }
.player-strip .rt { font-size: var(--fs-xs); color: var(--ink-3); }

.pc {
    display: inline-block;
    flex: none;
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.pc.w { background: var(--ink); }
.pc.b { background: var(--ground); border: 1px solid rgba(255, 255, 255, 0.35); }

.board-wrap {
    position: relative;
    padding-left: calc(var(--bar) + var(--bar-gap));
}

/* Eval bar: slim, ink block above and white below. The ink block's height is set from JS. */
.eval-bar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--bar);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--hair-strong);
    border-radius: 3px;
    background: var(--surface-2);
}

.eval-bar.flipped { flex-direction: column-reverse; }

.eval-ink {
    display: block;
    border-radius: 2px 2px 0 0;
    background: #23252a;
    transition: height 250ms ease;
}

.eval-bar.flipped .eval-ink { border-radius: 0 0 2px 2px; }

.eval-white {
    display: block;
    flex: 1;
    border-radius: 0 0 2px 2px;
    background: #e6e8ec;
}

.eval-bar.flipped .eval-white { border-radius: 2px 2px 0 0; }

.eval-tip {
    display: none;
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    padding: 2px var(--space-2);
    border: var(--rule);
    border-radius: var(--radius-ctl);
    background: var(--surface-2);
    color: var(--ink);
    font-size: var(--fs-xs);
    white-space: nowrap;
    z-index: 5;
    pointer-events: none;
}

.eval-bar:hover .eval-tip,
.eval-bar:focus-visible .eval-tip { display: block; }

.navrow {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    height: 32px;
    margin-left: calc(var(--bar) + var(--bar-gap));
}

.ib {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-ctl);
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
}

.ib:hover { background: var(--surface-2); color: var(--ink); }
.ib:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }

.sp {
    width: 1px;
    height: 16px;
    margin: 0 var(--space-1);
    background: var(--hair);
}

@media (max-width: 900px) {
    .keys-hint { display: none; }
}

@media (max-width: 760px) {
    .strip-mid {
        order: 3;
        flex: 1 1 100%;
        justify-content: space-between;
    }

    .steps { flex: 1; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
    .eval-ink,
    .step::before { transition: none; }
}

/* Stacked table: on a phone each row becomes a block and each cell shows its data-label before the value.
   Put class "stacked-table" on a .table; page rules for a cell kind need td.kind to outweigh these. */
@media (max-width: 760px) {
    /* The same declarations as .sr-only: column heads are dropped, the labels carry the meaning */
    .table.stacked-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    .table.stacked-table,
    .table.stacked-table tbody,
    .table.stacked-table tr,
    .table.stacked-table td {
        display: block;
    }

    .table.stacked-table tr {
        padding: var(--space-3) 0;
        border-bottom: 1px solid var(--hair);
    }

    .table.stacked-table td {
        display: flex;
        justify-content: space-between;
        gap: var(--space-4);
        padding: var(--space-1) 0;
        border-bottom: none;
        text-align: right;
    }

    .table.stacked-table td[data-label]::before {
        flex-shrink: 0;
        font-weight: 400;
        content: attr(data-label);
        color: var(--ink-3);
        font-size: var(--fs-sm);
        text-align: left;
    }
}

/* Board pages (Game Report, Opening Lab): board column left, panel right. These sizes are shared;
   a page sets only what differs: --strip-h (strip above the board), --below (extra room under it),
   --scrollbar (width kept free when the page itself scrolls). */
.board-page {
    --pad: 24px;
    --bar: 10px;
    --bar-gap: 10px;
    --col-gap: 48px;
    --side-min: 400px;
    --sidebar: 232px;
    --strip-h: 0px;
    --below: 0px;
    --scrollbar: 0px;
    /* Board: as tall as the screen allows (118px for the player strips and nav row), never wider than what is left beside the panel */
    --board-size: min(900px, calc(100vh - var(--strip-h) - 2 * var(--pad) - 118px - var(--below)), calc(100vw - var(--scrollbar) - var(--sidebar) - 2 * var(--pad) - var(--bar) - var(--bar-gap) - var(--col-gap) - var(--side-min)));
}

/* Work mode (the 56px rail) is set on body: wide screens keep the rail, narrow laptops get it from nav-rail.css */
@media (min-width: 1209px) {
    body.work-mode .board-page,
    body.rail-collapsed .board-page { --sidebar: 56px; }
}

/* Narrow laptop and tablet (761-1208px): the sidebar is the 56px rail (nav-rail.css), no Menu button */
@media (min-width: 761px) and (max-width: 1208px) {
    .board-page {
        --sidebar: 56px;
        --col-gap: 32px;
    }
}

/* Not enough room for two columns: board on top, panel below */
@media (max-width: 900px) {
    .board-page {
        --board-size: min(720px, calc(100vw - var(--sidebar) - 2 * var(--pad) - var(--bar) - var(--bar-gap)), 62vh);
    }
}

/* Phone: no rail (bottom tab bar), thin eval bar, board full width */
@media (max-width: 760px) {
    .board-page {
        --pad: 0px;
        --bar: 8px;
        --bar-gap: 4px;
        --sidebar: 0px;
        --board-size: calc(100vw - 24px - var(--bar) - var(--bar-gap));
    }
}
