/* ==========================================================================
   themes.css — theme selector panel + theme bundles (board + pieces).
   Loaded from resources/views/layouts/partials/themeSelector.blade.php.
   Markup:  resources/views/layouts/partials/themeSelector.blade.php
   Bundles: config/xq_themes.php   Names: resources/lang/{locale}/themes.php
   ========================================================================== */

/* ==========================================================================
   THEME SELECTOR — design tokens
   Dark values are the original look. The light palette mirrors theme-light.css
   ("Quán trà buổi sáng": cream paper, ink text, terracotta + honey accents) and
   follows <html data-theme="light|dark">, which the header switch and the
   Sáng / Tối control inside this panel both drive.
   ========================================================================== */
.theme-selector-wrapper {
    --ts-panel-bg: rgba(18, 20, 24, 0.85);
    --ts-panel-border: 1px solid rgba(212, 175, 55, 0.2);
    --ts-panel-shadow: 0 20px 50px rgba(0, 0, 0, 0.9), 0 0 30px rgba(212, 175, 55, 0.05);
    --ts-title: #fff2cc;
    --ts-title-shadow: 0 0 10px rgba(212, 175, 55, 0.3);

    --ts-btn-bg: linear-gradient(145deg, #252a36, #121418);
    --ts-btn-bg-hover: linear-gradient(145deg, #2c3240, #1a1c23);
    --ts-btn-text: #fff2cc;
    --ts-btn-text-hover: #fff;
    --ts-btn-border: rgba(212, 175, 55, 0.4);
    --ts-btn-border-hover: rgba(212, 175, 55, 0.9);
    --ts-btn-shadow: 0 8px 20px rgba(0, 0, 0, 0.6), 0 0 15px rgba(212, 175, 55, 0.15);
    --ts-btn-shadow-hover: 0 12px 25px rgba(0, 0, 0, 0.8), 0 0 25px rgba(212, 175, 55, 0.4);

    --ts-opt-bg: rgba(255, 255, 255, 0.03);
    --ts-opt-border: rgba(255, 255, 255, 0.1);
    --ts-opt-hover-bg: rgba(212, 175, 55, 0.05);
    --ts-opt-hover-border: rgba(212, 175, 55, 0.5);
    --ts-opt-hover-shadow: 0 10px 20px rgba(0, 0, 0, 0.6);
    --ts-opt-active-bg: rgba(212, 175, 55, 0.15);
    --ts-opt-active-border: #ffd700;
    --ts-opt-active-shadow: inset 0 0 15px rgba(212, 175, 55, 0.4), 0 0 20px rgba(212, 175, 55, 0.6);
    --ts-check-bg: #ffd700;
    --ts-check-tick: #2a1a05;
    --ts-img-shadow: rgba(0, 0, 0, 0.8);
    --ts-focus: #ffd700;

    --ts-seg-bg: rgba(255, 255, 255, 0.05);
    --ts-seg-border: rgba(212, 175, 55, 0.25);
    --ts-seg-text: rgba(255, 242, 204, 0.72);
    --ts-seg-text-hover: #fff2cc;
    --ts-thumb-bg: linear-gradient(145deg, #ffd98a, #d4af37);
    --ts-thumb-text: #2a1a05;
    --ts-thumb-shadow: 0 2px 8px rgba(212, 175, 55, 0.45);

    --ts-apply-bg: linear-gradient(to right, #8a1515, #e63946);
    --ts-apply-bg-hover: linear-gradient(to right, #e63946, #ff5252);
    --ts-apply-border: #ff5252;
    --ts-apply-shadow: 0 4px 15px rgba(230, 57, 70, 0.4);
    --ts-apply-shadow-hover: 0 6px 20px rgba(230, 57, 70, 0.6), 0 0 15px rgba(255, 255, 255, 0.2);
    --ts-apply-shadow-active: 0 2px 5px rgba(230, 57, 70, 0.4);
}

:root[data-theme="light"] .theme-selector-wrapper {
    --ts-panel-bg: linear-gradient(180deg, rgba(255, 250, 238, 0.97), rgba(247, 231, 198, 0.97));
    --ts-panel-border: 1px solid rgba(138, 74, 36, 0.3);
    --ts-panel-shadow: 0 20px 44px rgba(107, 58, 34, 0.32), 0 0 28px rgba(255, 190, 90, 0.2);
    --ts-title: #8a2f1d;
    --ts-title-shadow: none;

    --ts-btn-bg: linear-gradient(145deg, #d9674c, #b4472f);
    --ts-btn-bg-hover: linear-gradient(145deg, #e0765a, #c4513a);
    --ts-btn-text: #fff6e4;
    --ts-btn-text-hover: #fff;
    --ts-btn-border: rgba(255, 200, 97, 0.75);
    --ts-btn-border-hover: #ffc861;
    --ts-btn-shadow: 0 8px 20px rgba(107, 58, 34, 0.35), 0 0 15px rgba(255, 190, 90, 0.3);
    --ts-btn-shadow-hover: 0 12px 25px rgba(107, 58, 34, 0.45), 0 0 25px rgba(255, 190, 90, 0.5);

    --ts-opt-bg: rgba(255, 253, 246, 0.7);
    --ts-opt-border: rgba(138, 74, 36, 0.25);
    --ts-opt-hover-bg: rgba(196, 81, 58, 0.08);
    --ts-opt-hover-border: #c4513a;
    --ts-opt-hover-shadow: 0 10px 20px rgba(107, 58, 34, 0.25);
    --ts-opt-active-bg: rgba(255, 200, 97, 0.35);
    --ts-opt-active-border: #c4513a;
    --ts-opt-active-shadow: inset 0 0 12px rgba(255, 190, 90, 0.45), 0 0 0 3px rgba(196, 81, 58, 0.25), 0 6px 16px rgba(107, 58, 34, 0.3);
    --ts-check-bg: #c4513a;
    --ts-check-tick: #fff6e4;
    --ts-img-shadow: rgba(107, 58, 34, 0.35);
    --ts-focus: #a8402c;

    --ts-seg-bg: rgba(138, 74, 36, 0.1);
    --ts-seg-border: rgba(138, 74, 36, 0.28);
    --ts-seg-text: #5a2f1b;
    --ts-seg-text-hover: #8a2f1d;
    --ts-thumb-bg: linear-gradient(145deg, #d9674c, #b4472f);
    --ts-thumb-text: #fff6e4;
    --ts-thumb-shadow: 0 2px 8px rgba(180, 71, 47, 0.45);

    --ts-apply-bg: linear-gradient(to right, #b4472f, #d9674c);
    --ts-apply-bg-hover: linear-gradient(to right, #c4513a, #e0765a);
    --ts-apply-border: #8a2f1d;
    --ts-apply-shadow: 0 4px 15px rgba(180, 71, 47, 0.4);
    --ts-apply-shadow-hover: 0 6px 20px rgba(180, 71, 47, 0.55), 0 0 15px rgba(255, 200, 97, 0.35);
    --ts-apply-shadow-active: 0 2px 5px rgba(180, 71, 47, 0.4);
}

/* ==========================================================================
   THEME SELECTOR WRAPPER & PANEL
   ========================================================================== */
.theme-selector-wrapper {
    position: relative;
    display: block;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    text-align: center;
    z-index: 10;
    pointer-events: none;
}

.theme-selector-panel {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);

    /* Glassmorphism panel (lacquer-dark by default, cream paper in light mode) */
    background: var(--ts-panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: var(--ts-panel-border);
    border-radius: 6px;
    padding: 20px;
    display: none;
    min-width: 340px;
    max-width: 420px;
    max-height: min(75vh, 620px);
    overflow-y: auto;

    box-shadow: var(--ts-panel-shadow);
    z-index: 1000;
    pointer-events: all;
}

:root[data-theme="light"] .theme-selector-panel {
    border-top: 2px solid #c4513a;
}

.theme-selector-panel.show {
    display: block;
    animation: floatUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.theme-selector-panel .theme-section + .theme-section {
    margin-top: 16px;
}

@keyframes floatUp {
    from { opacity: 0; transform: translate(-50%, 20px) scale(0.95); }
    to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* Titles */
.theme-title {
    color: var(--ts-title);
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: var(--ts-title-shadow);
}

/* ==========================================================================
   APPEARANCE SWITCH (Sáng / Tối)
   Visuals follow <html data-theme> directly, so the control is correct before
   any script runs; JS only maintains aria-checked and handles input.
   ========================================================================== */
.ts-mode {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 3px;
    background: var(--ts-seg-bg);
    border: 1px solid var(--ts-seg-border);
    border-radius: 8px;
    isolation: isolate;
}

.ts-mode-thumb {
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 3px;
    width: calc(50% - 3px);
    border-radius: 6px;
    background: var(--ts-thumb-bg);
    box-shadow: var(--ts-thumb-shadow);
    transform: translateX(100%); /* dark = right */
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: -1;
}
:root[data-theme="light"] .ts-mode-thumb {
    transform: none; /* light = left */
}

.ts-mode-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ts-seg-text);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    cursor: pointer;
    transition: color 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}
.ts-mode-btn:hover {
    color: var(--ts-seg-text-hover);
}
:root[data-theme="light"] .ts-mode-btn[data-mode="light"],
:root:not([data-theme="light"]) .ts-mode-btn[data-mode="dark"] {
    color: var(--ts-thumb-text);
}
.ts-mode-btn:focus-visible,
.theme-bundle:focus-visible,
.theme-toggle-btn:focus-visible,
#apply-theme-btn:focus-visible {
    outline: 2px solid var(--ts-focus);
    outline-offset: 2px;
}

/* ==========================================================================
   THE THEME TOGGLE BUTTON (.theme-toggle-btn)
   ========================================================================== */
.theme-toggle-btn {
    background: var(--ts-btn-bg);
    color: var(--ts-btn-text);
    border: 1px solid var(--ts-btn-border);
    border-radius: 6px;
    padding: 10px 24px;
    font-size: 15px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 auto;
    pointer-events: all;

    box-shadow: var(--ts-btn-shadow);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.theme-toggle-btn:hover,
.theme-toggle-btn:focus-visible {
    background: var(--ts-btn-bg-hover);
    border-color: var(--ts-btn-border-hover);
    color: var(--ts-btn-text-hover);
    transform: translateY(-4px) scale(1.02);
    box-shadow: var(--ts-btn-shadow-hover);
}

/* ==========================================================================
   THEME BUNDLES (.theme-bundle)
   A theme = board + pieces, previewed together. The board image is passed in
   from the Blade view as --tb-board (single source: config/xq_themes.php);
   the per-theme tokens below only add the accent and a no-image fallback.
   ========================================================================== */
.theme-bundles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.theme-bundle {
    --tb-accent: var(--ts-opt-active-border);
    --tb-fallback: #6b3a22;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 6px;
    background: var(--ts-opt-bg);
    border: 2px solid var(--ts-opt-border);
    border-radius: 8px;
    color: var(--ts-title);
    cursor: pointer;
    position: relative;
    text-align: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Per-theme tokens (accent ring + fallback colour while/if the board SVG is missing) */
.theme-bundle[data-bundle="default"] { --tb-accent: #e63946; --tb-fallback: #5a1d12; }
.theme-bundle[data-bundle="floral"]  { --tb-accent: #e07a9b; --tb-fallback: #f3d9c4; }
.theme-bundle[data-bundle="golden"]  { --tb-accent: #ffd700; --tb-fallback: #e8c66a; }
.theme-bundle[data-bundle="wooden"]  { --tb-accent: #b9783a; --tb-fallback: #b98a58; }

.theme-bundle:hover {
    border-color: var(--tb-accent);
    background: var(--ts-opt-hover-bg);
    transform: translateY(-3px);
    box-shadow: var(--ts-opt-hover-shadow);
}

.theme-bundle.active {
    border-color: var(--tb-accent);
    background: var(--ts-opt-active-bg);
    box-shadow: var(--ts-opt-active-shadow);
}

.theme-bundle-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 84px;
    border-radius: 6px;
    overflow: hidden;
    background-color: var(--tb-fallback);
    background-image: var(--tb-board, none);
    background-size: cover;
    background-position: center;
}

.tb-piece {
    width: 36px;
    height: 36px;
    object-fit: contain;
    filter: drop-shadow(0 2px 3px var(--ts-img-shadow));
}

.theme-bundle-name {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1.2;
    padding-bottom: 2px;
}

/* Selected badge: a CSS-drawn tick, so the state never relies on colour alone. */
.theme-bundle.active::after {
    content: "";
    position: absolute;
    top: -7px;
    right: -7px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ts-check-bg);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.theme-bundle.active::before {
    content: "";
    position: absolute;
    top: -2px;
    right: 0;
    width: 4px;
    height: 9px;
    border: solid var(--ts-check-tick);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    z-index: 1;
}

/* ==========================================================================
   THE APPLY BUTTON (#apply-theme-btn)
   ========================================================================== */
#apply-theme-btn {
    background: var(--ts-apply-bg);
    color: #fff;
    border: 1px solid var(--ts-apply-border);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 6px;
    padding: 10px 30px;
    box-shadow: var(--ts-apply-shadow);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

#apply-theme-btn:hover {
    background: var(--ts-apply-bg-hover);
    transform: translateY(-2px);
    box-shadow: var(--ts-apply-shadow-hover);
}

#apply-theme-btn:active {
    transform: translateY(1px);
    box-shadow: var(--ts-apply-shadow-active);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .theme-selector-panel {
        min-width: 300px;
        padding: 15px;
        bottom: 55px;
    }
    .theme-bundle-preview { height: 72px; }
    .tb-piece { width: 30px; height: 30px; }
    .theme-toggle-btn {
        padding: 8px 18px;
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .theme-selector-panel.show { animation: none; }
    .ts-mode-thumb,
    .theme-bundle,
    .theme-toggle-btn,
    #apply-theme-btn { transition: none; }
}

/* ==========================================================================
   BOARD NOTATION MARGIN — per board
   With coordinate notation, #ban-co gets padding (ban-co.css) and the a-i / 1-10
   labels sit in that margin and over the board's outer frame. Background and
   label colour therefore follow the active board's frame colours
   (html[data-board-theme], set by themes.blade.php + theme-manager.js).
   The :root + html prefix lifts specificity above theme-cozy.css / theme-light.css.
   ========================================================================== */

/* Default / cozy — tan paper edge (#E0C088), dark walnut labels (contrast ~7:1) */
html:root[data-board-theme="banco-cozy"] #ban-co:has(.notation-8c7a2) {
    background: #e0c088 !important;
}
html:root[data-board-theme="banco-cozy"] #ban-co .notation-8c7a2 {
    color: #4a2615 !important;
    text-shadow: none;
}

/* Wooden — dark walnut frame, light cream labels */
html:root[data-board-theme="banco-wood"] #ban-co:has(.notation-8c7a2) {
    background: linear-gradient(145deg, #4a2311, #6e3719 50%, #3b1b0c) !important;
}
html:root[data-board-theme="banco-wood"] #ban-co .notation-8c7a2 {
    color: #f6dfb4 !important;
    text-shadow: 0 1px 1px rgba(20, 5, 0, 0.7);
}

/* Golden — bronze/dark-gold metal frame, pale gold labels */
html:root[data-board-theme="banco-gold"] #ban-co:has(.notation-8c7a2) {
    background: linear-gradient(145deg, #6b4a12, #7d5a18 40%, #3d2907 70%, #5a3d0d) !important;
}
html:root[data-board-theme="banco-gold"] #ban-co .notation-8c7a2 {
    color: #fff0b4 !important;
    text-shadow: 0 1px 1px rgba(30, 18, 0, 0.8);
}

/* Floral — deep green frame, soft blush labels */
html:root[data-board-theme="banco-floral"] #ban-co:has(.notation-8c7a2) {
    background: linear-gradient(145deg, #2f5b46, #1f4535 50%, #173527) !important;
}
html:root[data-board-theme="banco-floral"] #ban-co .notation-8c7a2 {
    color: #fde4e4 !important;
    text-shadow: 0 1px 1px rgba(5, 20, 12, 0.7);
}
