/* ── RESET & BASE ──────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0e0f17;
    --bg2: #141522;
    --bg3: #1b1d2e;
    --bg4: #22253a;
    --border: #2a2d47;
    --border2: #363a5a;

    --text: #c8cce0;
    --text2: #7a7fa8;
    --text3: #454870;
    --text4: #111;

    --gold: #d4a843;
    --gold2: #f0c866;
    --green: #2ecc71;
    --red: #e74c3c;

    --mono: 'JetBrains Mono', monospace;
    --sans: 'Inter', sans-serif;
    --serif: 'Playfair Display', serif;

    --sq: 60px;
    /* розмір поля */
    --board: calc(var(--sq) * 8);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.5;
    min-height: 100vh;
    padding: 18px 20px;
    /* subtle grain */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.025'/%3E%3C/svg%3E");
}

/* ── TITLE ─────────────────────────────────────────────── */
#app-title {
    text-align: center;
    font-family: var(--sans);
    font-size: 1.55rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: .02em;
    margin-bottom: 16px;
}

/* ── LAYOUT ─────────────────────────────────────────────── */
.layout {
    display: flex;
    gap: 20px;
    max-width: 1060px;
    margin: 0 auto;
    align-items: flex-start;
}

/* ── BOARD COLUMN ──────────────────────────────────────── */
.left-col {
    flex: 0 0 auto;
    /*flex: 1;*/
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#board-wrap {
    position: relative;
    width: var(--board);
    height: var(--board);
    /*border: 2px solid var(--border2);*/
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .6), 0 0 0 1px var(--border);
}

#board {
    display: grid;
    grid-template-columns: repeat(8, var(--sq));
    grid-template-rows: repeat(8, var(--sq));
    width: var(--board);
    height: var(--board);
}

.sq {
    width: var(--sq);
    height: var(--sq);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: filter .08s;
}

/* .sq:hover {
    filter: brightness(1.12);
} */

.sq.lt:hover {
    box-shadow: inset 0 0 0 60px rgba(0, 0, 0, 0.10);
}

.sq.dk:hover {
    box-shadow: inset 0 0 0 60px rgba(255, 255, 255, 0.15);
}

.sq.lt {
    background: #f0d9b5;
}

.sq.dk {
    background: #b58863;
}

.sq.sel {
    background: #7fc97f !important;
}

.sq.lm-from,
.sq.lm-to {
    background: var(--lm-color, #cdd26a) !important;
}

.coord-r {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 9px;
    font-weight: 600;
    color: rgba(0, 0, 0, .28);
    pointer-events: none;
    line-height: 1;
    font-family: var(--mono);
}

.coord-f {
    position: absolute;
    bottom: 1px;
    right: 2px;
    font-size: 9px;
    font-weight: 600;
    color: rgba(0, 0, 0, .28);
    pointer-events: none;
    line-height: 1;
    font-family: var(--mono);
}

.piece {
    width: 90%;
    height: 90%;
    position: relative;
    z-index: 20;
    transition: transform .07s;
    object-fit: contain;
    pointer-events: auto;
    cursor: grab;
}

.mv-dot {
    position: absolute;
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, .22);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
}

.mv-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 6px solid rgba(0, 0, 0, .24);
    pointer-events: none;
    z-index: 3;
}

/* ── BOARD CONTROLS ────────────────────────────────────── */
.board-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
}

.spacer {
    flex: 1;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--sans);
    font-weight: 600;
    transition: filter .12s, transform .08s;
    white-space: nowrap;
}

.btn:hover {
    filter: brightness(1.15);
}

.btn:active {
    transform: scale(.96);
}

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

.btn-gold {
    width: 110px;
    background: var(--gold);
    color: var(--text4);
    padding: 7px 15px;
    font-size: 13px;
}

.btn-outline {
    background: transparent;
    color: var(--text2);
    padding: 6px 11px;
    font-size: 14px;
    border: 1px solid var(--border2);
    min-width: 36px;
}

.btn-outline:hover {
    background: var(--bg3);
    color: var(--text);
}

.btn-danger {
    background: #4a1010;
    color: #e88;
    padding: 6px 11px;
    font-size: 14px;
    border: 1px solid #6a1515;
    min-width: 36px;
}

.btn-danger:hover {
    background: #6a1515;
    color: #faa;
}

.btn-import {
    width: 110px;
    background: var(--green);
    color: var(--text4);
    padding: 7px 15px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--sans);
}

.turn-info {
    font-size: 28px;
    color: var(--text);
    margin-top: 5px;
    font-family: var(--mono);
    letter-spacing: .03em;
}

/* ── RIGHT PANEL ─────────────────────────────────────────── */
.right-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
}

/* Correct */
.correct-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.correct-box {
    width: 34px;
    height: 34px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    border: 2px solid;
    transition: background .18s, border-color .18s;
}

.correct-box.sn {
    background: var(--bg);
    border-color: var(--border2);
    color: var(--text3);
}

.correct-box.st {
    background: #0e2f1c;
    border-color: #27ae60;
    color: var(--green);
}

.correct-box.sf {
    background: #2f0e0e;
    border-color: #c0392b;
    color: var(--red);
}

.correct-lbl {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

/* Fields */
.field-lbl {
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.text-in {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: var(--sans);
    resize: vertical;
    line-height: 1.5;
    outline: none;
}

.text-in:focus {
    border-color: var(--border2);
}

/* Variations */
.var-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 7px;
}

.var-chip {
    background: var(--bg4);
    color: var(--text2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 3px 9px;
    font-size: 12px;
    font-family: var(--mono);
    cursor: pointer;
    transition: background .1s, color .1s;
}

.var-chip:hover {
    background: var(--border2);
    color: var(--text);
}

.no-vars {
    font-size: 11px;
    color: var(--text3);
    font-style: italic;
}

/* FEN / PGN / JSON */
.mono-lbl {
    font-size: 9.5px;
    color: var(--text2);
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-top: 10px;
    margin-bottom: 3px;
}

.mono-in {
    width: 100%;
    background: var(--bg);
    color: #4da8d0;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 5px 8px;
    font-family: var(--mono);
    font-size: 10.5px;
    outline: none;
}

.mono-in:focus {
    border-color: var(--border2);
}

/* ── JSON ──────────────────────────────────────────────── */
.json-wrap {
    margin-top: 14px;
}

.section-lbl {
    font-size: 11px;
    font-weight: 600;
    color: var(--text3);
    letter-spacing: .08em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.textarea-out {
    width: 100%;
    height: 155px;
    background: var(--bg);
    color: #4da8d0;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
    font-family: var(--mono);
    font-size: 10.5px;
    line-height: 1.6;
    resize: vertical;
}

/* ── MODALS ──────────────────────────────────────────────── */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .82);
    z-index: 400;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.overlay.open {
    display: flex;
}

.modal {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 9px;
    padding: 24px 26px;
    min-width: 340px;
    max-width: 530px;
    width: 92%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .8);
    animation: modalIn .18s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(.97);
    }
}

.modal h2 {
    font-size: 1.75rem;
    color: #eee;
    margin-bottom: 16px;
}

.mf {
    margin-bottom: 13px;
}

.mf>label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text2);
    letter-spacing: .06em;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.mf input[type=text],
.mf textarea {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border2);
    border-radius: 5px;
    padding: 8px 11px;
    font-size: 13px;
    font-family: var(--sans);
    outline: none;
}

.mf input[type=text]:focus,
.mf textarea:focus {
    border-color: var(--gold);
}

.mf textarea {
    resize: vertical;
    height: 95px;
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.6;
}

.radio-row {
    display: flex;
    gap: 20px;
    margin-top: 6px;
}

.radio-row label {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}

.radio-row input[type=radio] {
    accent-color: var(--gold);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.btn-ok {
    background: var(--gold);
    color: #111;
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-family: var(--sans);
}

.btn-ok:hover {
    background: var(--gold2);
}

.btn-cancel {
    background: transparent;
    color: var(--text2);
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 5px;
    border: 1px solid var(--border2);
    cursor: pointer;
    font-family: var(--sans);
}

.btn-cancel:hover {
    background: var(--bg3);
}

.err-msg {
    color: #e74c3c;
    font-size: 12px;
    margin-top: 6px;
}

/* Promotion */
#promo-modal .modal {
    background: #4f5585;
}

.promo-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin: 16px 0;
}

.promo-p {
    font-size: 52px;
    line-height: 1;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    border: 2px solid transparent;
    transition: border-color .12s, background .12s;
}

.promo-p:hover {
    border-color: var(--gold);
    background: var(--bg4);
}

.promo-p.w {
    color: #fff;
    -webkit-text-stroke: 1.4px #000;
}

.promo-p.b {
    color: #141414;
    -webkit-text-stroke: .9px #aaa;
}

/* Divider */
.divider {
    width: 100%;
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* Study title */

#app-title {
    font-size: 33px;
    cursor: default;
    border-radius: 4px;
    transition: background .15s;
}

#app-title:hover {
    background: var(--bg3);
}

#app-title.editing {
    outline: 2px solid var(--gold);
    background: var(--bg2);
    cursor: text;
    padding: 2px 10px;
}


/* ── ARROWS ─────────────────────────────────────────────── */
#arrow-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.sq-hl {
    position: absolute;
    inset: 0;
    opacity: .48;
    pointer-events: none;
    z-index: 1;
}

/* ── COPY BUTTONS ─────────────────────────────────────────────── */
.btn-copy {
    background: var(--bg4);
    color: var(--text2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 9px;
    cursor: pointer;
    font-size: 13px;
    transition: background .12s, color .12s;
    white-space: nowrap;
    flex-shrink: 0;
    align-self: flex-start;
}

.btn-copy:hover {
    background: var(--border2);
    color: var(--text);
}

.btn-copy.copied {
    background: #0e2f1c;
    border-color: #27ae60;
    color: var(--green);
}

/* ── DRAG PIECE ─────────────────────────────────────────────── */

.piece {
    cursor: grab;
}

.piece:active {
    cursor: grabbing;
}