/* ===== CHESS GLOBAL STYLES ===== */
:root {
    --bg-dark: #0f1923;
    --bg-mid: #1a2634;
    --bg-light: #243447;
    --card-bg: rgba(255,255,255,0.06);
    --card-border: rgba(255,255,255,0.12);
    --text-primary: #e8eaf0;
    --text-secondary: #8fa3b8;
    --text-muted: #4a6278;
    --accent: #c9a84c;
    --accent-light: #f0d080;
    --success: #4caf7d;
    --danger: #e05252;
    --shadow: 0 8px 32px rgba(0,0,0,0.5);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;

    /* Board themes */
    --light-sq: #f0d9b5;
    --dark-sq: #b58863;
    --selected-sq: rgba(255,255,0,0.5);
    --legal-sq: rgba(0,0,0,0.2);
    --last-move: rgba(255,255,0,0.3);
    --check-sq: rgba(255,0,0,0.5);
    --capture-sq: rgba(255,0,0,0.3);

    /* Board frame — light ivory/gold (classic, blue, green) */
    --frame-fill: #efe3c8;
    --frame-grain: repeating-linear-gradient(
        2deg,
        rgba(120, 88, 40, 0.10) 0 1px,
        transparent 2px 16px,
        rgba(255, 255, 255, 0.5) 17px,
        transparent 19px 31px
    );
    --frame-decor: linear-gradient(135deg, #fdf6e6 0%, #e8d5ab 22%, #cdb284 45%, #f2e5c4 70%, #d9c396 100%);
    --frame-shadow:
        inset 0 0 0 2px #dfb65d,
        inset 0 0 0 5px #6f5124,
        inset 0 0 0 8px rgba(255, 252, 240, 0.9),
        inset 0 0 14px 9px rgba(90, 66, 30, 0.18),
        0 0 0 2px #54401e,
        0 5px 0 #c7a971,
        0 11px 0 #8f7340,
        0 25px 55px rgba(0,0,0,0.65);
    --frame-ring: rgba(214, 178, 96, 0.9);
    --frame-ring-shadow:
        inset 0 0 0 3px rgba(96, 70, 30, 0.75),
        inset 0 0 0 6px rgba(255, 250, 235, 0.7),
        inset 0 0 0 8px rgba(120, 92, 44, 0.45);

    /* iOS: dvh follows the collapsing Safari toolbar, vh is the fallback */
    --app-vh: 1vh;
}

@supports (height: 100dvh) {
    :root { --app-vh: 1dvh; }
}

[data-theme="wood"] {
    --light-sq: #edc77d;
    --dark-sq: #623217;
    --frame-fill: #5b3015;
    --frame-grain: repeating-linear-gradient(
        2deg,
        rgba(40, 18, 7, 0.14) 0 1px,
        transparent 2px 16px,
        rgba(255, 208, 126, 0.12) 17px,
        transparent 19px 31px
    );
    --frame-decor: linear-gradient(135deg, #d49a4e 0%, #814319 17%, #48220e 38%, #a9682e 66%, #603014 100%);
    --frame-shadow:
        inset 0 0 0 2px #e2b55e,
        inset 0 0 0 5px #4c2812,
        inset 0 0 0 8px rgba(255, 222, 151, 0.76),
        inset 0 0 14px 9px rgba(30, 14, 5, 0.32),
        0 0 0 2px #2b170c,
        0 5px 0 #542c13,
        0 11px 0 #321a0b,
        0 25px 55px rgba(0,0,0,0.65);
    --frame-ring: rgba(250, 211, 139, 0.72);
    --frame-ring-shadow:
        inset 0 0 0 3px rgba(55, 27, 11, 0.9),
        inset 0 0 0 6px rgba(235, 184, 99, 0.58),
        inset 0 0 0 8px rgba(83, 43, 18, 0.5);
}
[data-theme="blue"] {
    --light-sq: #dee3e6;
    --dark-sq: #4a7fa5;
}
[data-theme="green"] {
    --light-sq: #ffffdd;
    --dark-sq: #86a666;
}

* {
    margin: 0; padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body {
    background: radial-gradient(ellipse at top left, #1a2634 0%, #0f1923 60%);
}

.screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: calc(100 * var(--app-vh));
    display: none; flex-direction: column;
    overflow: hidden;
}
.screen.active { display: flex; }



/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; padding: 12px 24px;
    border: none; border-radius: var(--radius-sm);
    font-size: 15px; font-weight: 700;
    letter-spacing: 0.5px; cursor: pointer;
    transition: all var(--transition);
    text-transform: uppercase; min-height: 48px;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent), #a07830);
    color: #1a1a1a;
    box-shadow: 0 4px 15px rgba(201,168,76,0.4);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(201,168,76,0.6); }
.btn-secondary {
    background: var(--card-bg); color: var(--text-primary);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); transform: translateY(-1px); }
.btn-sm { padding: 8px 16px; font-size: 13px; min-height: 36px; }
.btn-icon {
    background: var(--card-bg); border: 1px solid var(--card-border);
    color: var(--text-primary); width: 44px; height: 44px;
    border-radius: var(--radius-sm); font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.btn-icon:hover { background: rgba(255,255,255,0.12); }
.btn-close {
    background: none; border: none; color: var(--text-secondary);
    font-size: 20px; cursor: pointer; width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: all var(--transition);
}
.btn-close:hover { background: rgba(255,255,255,0.1); color: white; }

/* Modals */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 16px;
}
.modal.hidden { display: none; }
.modal-content {
    background: linear-gradient(135deg, #1a2634, #0f1923);
    border: 1px solid var(--card-border);
    border-radius: var(--radius); width: 100%;
    max-width: 500px; max-height: 85vh;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow); overflow: hidden;
}
.modal-small { max-width: 380px; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px 16px; border-bottom: 1px solid var(--card-border);
}
.modal-header h2 { font-size: 18px; font-weight: 800; letter-spacing: 1px; color: var(--accent); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 2px; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* Toggle */
.toggle-btn {
    background: var(--success); color: white; border: none;
    padding: 8px 20px; border-radius: 20px; font-weight: 700;
    font-size: 13px; cursor: pointer; transition: all var(--transition); min-width: 60px;
}
.toggle-btn.off { background: var(--text-muted); }

/* Select */
.select-input {
    background: var(--card-bg); color: var(--text-primary);
    border: 1px solid var(--card-border); padding: 8px 12px;
    border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
}

/* Setting row */
.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 15px;
}

/* HTP */
.htp-step { display: flex; gap: 16px; margin-bottom: 20px; align-items: flex-start; }
.htp-num {
    width: 32px; height: 32px; min-width: 32px;
    background: linear-gradient(135deg, var(--accent), #a07830);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 14px; color: #1a1a1a;
}
.htp-step strong { display: block; margin-bottom: 4px; color: var(--accent); }
.htp-step p { color: var(--text-secondary); font-size: 14px; line-height: 1.5; }

/* Result */
.result-icon { font-size: 64px; margin: 16px 0; line-height: 0; }
.result-winner { font-size: 28px; font-weight: 900; color: var(--accent); letter-spacing: 2px; }
.result-detail { color: var(--text-secondary); margin-top: 8px; font-size: 14px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 3px; }

/* Toast */
.app-toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translate(-50%, 20px);
    max-width: min(420px, calc(100vw - 32px));
    padding: 14px 20px;
    background: linear-gradient(135deg, #1a2634, #0f1923);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px; line-height: 1.45; text-align: center;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 2000;
}
.app-toast.visible { opacity: 1; transform: translate(-50%, 0); }