:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #0d1714;
    color: #f3f5ee;
    --surface: #15221e;
    --surface-raised: #1b2c26;
    --border: rgba(231, 238, 225, 0.12);
    --muted: #9eaea6;
    --accent: #d5f36b;
    --accent-ink: #172008;
    --focus: #f0d87c;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 10% 0%, rgba(69, 112, 85, 0.28), transparent 34rem),
        linear-gradient(145deg, #0c1512, #101c18 58%, #0b1411);
}

button,
select,
textarea {
    font: inherit;
}

button,
select {
    min-height: 44px;
}

.app-shell {
    width: min(1320px, calc(100% - 32px));
    margin: 0 auto;
    padding: 38px 0 48px;
}

.app-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 7px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2.5rem, 6vw, 4.8rem);
    font-weight: 500;
    letter-spacing: -0.055em;
    line-height: 0.95;
}

h2 {
    margin-bottom: 0;
    font-size: 1.15rem;
}

.subtitle,
.help-text,
.interaction-hint {
    color: var(--muted);
    line-height: 1.55;
}

.subtitle {
    max-width: 560px;
    margin-bottom: 0;
}

.engine-badge {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(21, 34, 30, 0.78);
    color: #c8d2cc;
    font-size: 0.82rem;
    white-space: nowrap;
}

.engine-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 14px rgba(213, 243, 107, 0.7);
}

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

.board-column {
    min-width: 0;
}

.board-frame {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #0a110f;
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.35);
}

#chessboard {
    display: block;
    width: min(100%, 620px);
    height: auto;
    border-radius: 8px;
    touch-action: none;
}

.chess-clocks {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    max-width: 620px;
    margin: 14px auto 0;
}

.chess-clock {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: rgba(21, 34, 30, 0.86);
    color: var(--muted);
    transition: border-color 160ms ease, background 160ms ease;
}

.chess-clock span {
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.chess-clock time {
    color: #f3f5ee;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 1.35rem;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
    line-height: 1;
}

.chess-clock--active {
    border-color: rgba(213, 243, 107, 0.55);
    background: rgba(213, 243, 107, 0.08);
}

.chess-clock--danger time {
    color: #f0d87c;
}

.chess-clock--expired {
    border-color: rgba(255, 112, 112, 0.55);
}

.chess-clock--expired time {
    color: #ff8f8f;
}

.status-grid {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr;
    gap: 10px;
    max-width: 720px;
    margin: 14px auto 0;
}

.status-card {
    min-width: 0;
    padding: 14px 15px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: rgba(21, 34, 30, 0.86);
}

.status-card--primary {
    border-color: rgba(213, 243, 107, 0.25);
}

.status-label {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.status-card strong {
    display: block;
    overflow: hidden;
    font-size: 0.92rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.control-panel {
    display: grid;
    gap: 14px;
}

.panel-section {
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(21, 34, 30, 0.92);
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.18);
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #d6ded9;
    font-size: 0.82rem;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch-track {
    position: relative;
    width: 38px;
    height: 22px;
    border-radius: 999px;
    background: #52615a;
    transition: 160ms ease;
}

.switch-track::after {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    content: "";
    transition: 160ms ease;
}

.switch input:checked + .switch-track {
    background: var(--accent);
}

.switch input:checked + .switch-track::after {
    transform: translateX(16px);
    background: var(--accent-ink);
}

.switch input:focus-visible + .switch-track {
    outline: 3px solid rgba(240, 216, 124, 0.35);
    outline-offset: 2px;
}

.field-grid,
.fen-panel,
.pgn-panel {
    display: grid;
    gap: 14px;
}

.field {
    display: grid;
    gap: 7px;
    color: #cbd5cf;
    font-size: 0.78rem;
    font-weight: 650;
}

select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0f1b17;
    color: #f3f5ee;
    outline: none;
}

select {
    padding: 0 12px;
}

textarea {
    min-height: 88px;
    padding: 11px 12px;
    resize: vertical;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.75rem;
    line-height: 1.5;
}

textarea[readonly] {
    color: #dce4df;
    cursor: text;
}

select:focus,
textarea:focus {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px rgba(240, 216, 124, 0.13);
}

.button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-top: 18px;
}

.export-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}

.button {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0 13px;
    font-weight: 750;
    cursor: pointer;
    transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

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

.button:focus-visible {
    outline: 3px solid rgba(240, 216, 124, 0.35);
    outline-offset: 2px;
}

.button--lichess {
    border-color: rgba(255, 255, 255, 0.16);
    background: #262522;
    color: #f3f3f3;
}

.button--lichess:hover {
    border-color: rgba(255, 255, 255, 0.3);
    background: #33312d;
}

.button--primary {
    background: var(--accent);
    color: var(--accent-ink);
}

.button--secondary {
    border-color: var(--border);
    background: var(--surface-raised);
    color: #eef2ed;
}

.button--full {
    width: 100%;
}

.help-text {
    margin: 7px 0 0;
    font-size: 0.8rem;
}

.feedback {
    min-height: 1.2em;
    margin: 0;
    color: var(--accent);
    font-size: 0.78rem;
}

.feedback--error {
    color: #ff9e93;
}

.interaction-hint {
    margin: 0;
    padding: 0 8px;
    font-size: 0.76rem;
}

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

    .control-panel {
        grid-template-columns: 1fr 1fr;
    }

    .interaction-hint {
        grid-column: 1 / -1;
    }
}

@media (max-width: 620px) {
    .app-shell {
        width: min(100% - 20px, 520px);
        padding-top: 24px;
    }

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

    .engine-badge {
        display: none;
    }

    .board-frame {
        padding: 7px;
        border-radius: 12px;
    }

    .status-grid,
    .control-panel {
        grid-template-columns: 1fr;
    }

    .status-card strong {
        white-space: normal;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
