/* ═══════════════════════════════════════════════════
   Web Chess Pro — Premium Styles
   ═══════════════════════════════════════════════════ */

:root {
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-highlight: rgba(155, 199, 0, 0.45);
    --board-selected: rgba(20, 85, 30, 0.55);
    --board-check: rgba(220, 38, 38, 0.65);
    --board-valid-move: rgba(0, 0, 0, 0.15);
    --board-capture-ring: rgba(0, 0, 0, 0.15);
    
    --panel-bg: rgba(25, 25, 35, 0.6);
    --panel-border: rgba(255, 255, 255, 0.08);
    --primary-color: #6366f1;
    --surface: #12121e;
    --text: #e2e8f0;
    --text-muted: #888;
}

[data-theme="light"] {
    --panel-bg: rgba(255, 255, 255, 0.92);
    --panel-border: rgba(0, 0, 0, 0.1);
    --surface: #f8fafc;
    --text: #1e293b;
    --text-muted: #64748b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--surface);
    color: var(--text);
    min-height: 100vh;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

/* ─── Navbar ─── */
.navbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    background: rgba(18, 18, 30, 0.75);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--panel-border);
}
.nav-inner {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.6rem 1rem; gap: 1rem;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 6px; }
.nav-links { display: flex; gap: 12px; align-items: center; }
.nav-links a { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; transition: color 0.2s; }
.nav-links a:hover { color: #fff; }
.kofi-link { color: #ff5e5b !important; font-weight: 600; }
.theme-btn { background: transparent; border: 1px solid var(--panel-border); color: var(--text); padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 1rem; }

/* ─── Hero ─── */
.hero { text-align: center; }
.hero h1 { font-size: 2.2rem; font-weight: 800; margin-bottom: 0.5rem; }
.hero-sub { color: var(--text-muted); font-size: 1.05rem; }
.gradient-text {
    background: linear-gradient(135deg, #6366f1 0%, #a78bfa 50%, #818cf8 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ─── Glass Card ─── */
.glass-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 1.25rem;
    backdrop-filter: blur(12px);
}

/* ─── Main Layout ─── */
.chess-layout {
    display: flex; flex-direction: column; gap: 1.5rem;
    max-width: 1100px; margin: 0 auto; padding-bottom: 3rem;
}

@media (min-width: 900px) {
    .chess-layout { flex-direction: row; align-items: flex-start; }
}

.board-column {
    flex: 0 0 auto; display: flex; gap: 0.5rem; align-items: stretch;
    width: 100%; max-width: 520px; margin: 0 auto;
}

@media (min-width: 900px) {
    .board-column { margin: 0; }
}

.controls-column {
    flex: 1 1 300px; display: flex; flex-direction: column; gap: 1rem;
    min-width: 0;
}

/* ─── Evaluation Bar ─── */
.eval-container {
    width: 28px; min-width: 28px;
    border-radius: 8px; overflow: hidden;
    position: relative; background: #1e293b; flex-shrink: 0;
    padding: 0;
}
.eval-bar {
    width: 100%; background: #e2e8f0;
    height: 50%; transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: absolute; bottom: 0;
}
.eval-text {
    position: absolute; width: 100%; text-align: center;
    font-size: 0.65rem; font-weight: 800; writing-mode: vertical-lr;
    top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(180deg);
    color: #fff; z-index: 2; mix-blend-mode: difference;
    letter-spacing: 1px;
}

/* ─── Chess Board ─── */
.board-wrapper {
    flex-grow: 1; aspect-ratio: 1 / 1; padding: 0; overflow: hidden;
    position: relative; width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35), inset 0 0 0 2px rgba(255,255,255,0.05);
    border-radius: 8px;
}
.chess-board {
    display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
    width: 100%; height: 100%; user-select: none;
}

.square {
    position: relative; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background-color 0.1s;
}
.square.light { background-color: var(--board-light); color: var(--board-dark); }
.square.dark  { background-color: var(--board-dark);  color: var(--board-light); }

.square.highlight { background-color: var(--board-highlight) !important; }
.square.selected  { background-color: var(--board-selected) !important; }
.square.in-check  {
    background: radial-gradient(circle at center, rgba(255,0,0,0.8), rgba(220,38,38,0.4) 70%) !important;
}

/* Valid move indicators */
.move-dot {
    width: 32%; height: 32%; border-radius: 50%;
    background-color: var(--board-valid-move);
    pointer-events: none; z-index: 5;
    position: absolute;
}
.square.can-capture > .move-dot {
    width: 100%; height: 100%; background: transparent;
    border: 5px solid var(--board-capture-ring);
    border-radius: 50%;
}

/* Board coordinates */
.coord-rank, .coord-file {
    position: absolute; font-size: min(0.7rem, 2.2vw); font-weight: 700;
    pointer-events: none; padding: 1px 3px; opacity: 0.7;
    font-family: 'Inter', sans-serif;
}
.coord-rank { top: 1px; left: 2px; }
.coord-file { bottom: 1px; right: 2px; }

/* ─── Pieces ─── */
.piece {
    width: 85%; height: 85%; background-size: contain;
    background-position: center; background-repeat: no-repeat;
    z-index: 10; position: relative;
    filter: drop-shadow(1px 2px 2px rgba(0,0,0,0.3));
    pointer-events: none; /* clicks go to the square */
    animation: piece-drop 0.1s ease-out forwards;
}

@keyframes piece-drop {
    from { opacity: 0; transform: translateY(-3px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Promotion Modal ─── */
.promotion-modal {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.65); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}
.promo-pieces {
    display: flex; background: #fff; padding: 12px; border-radius: 12px;
    gap: 8px; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.piece-opt {
    width: 56px; height: 56px; background-size: contain; background-repeat: no-repeat;
    background-position: center; cursor: pointer; border-radius: 8px;
    border: 2px solid transparent; transition: all 0.15s;
}
.piece-opt:hover { background-color: #e2e8f0; border-color: var(--primary-color); transform: scale(1.1); }

/* ─── Controls & UI ─── */
.card-title { font-size: 1rem; font-weight: 700; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--panel-border); }
.tab-btn {
    flex: 1; padding: 10px; background: transparent; border: none;
    color: var(--text-muted); font-weight: 600; cursor: pointer;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    font-family: inherit; font-size: 0.9rem; transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }

.tab-content { }

.control-group { margin-bottom: 1rem; }
.control-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }

.input-modern, .textarea-modern {
    width: 100%; padding: 10px 14px;
    background: rgba(0,0,0,0.2); border: 1px solid var(--panel-border);
    color: inherit; border-radius: 8px; font-family: inherit; font-size: 0.9rem;
    transition: border-color 0.2s;
}
.input-modern:focus, .textarea-modern:focus { border-color: var(--primary-color); outline: none; }
[data-theme="light"] .input-modern, [data-theme="light"] .textarea-modern { background: rgba(0,0,0,0.04); }

.btn {
    padding: 10px 16px; border: none; border-radius: 8px; cursor: pointer;
    font-weight: 600; font-family: inherit; font-size: 0.9rem;
    transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center;
}
.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn-secondary { background: rgba(255,255,255,0.08); color: var(--text-muted); border: 1px solid var(--panel-border); }
.btn-secondary:hover { background: rgba(255,255,255,0.15); color: var(--text); }

/* ─── Moves List ─── */
.moves-list {
    flex-grow: 1; overflow-y: auto; max-height: 280px;
    display: flex; flex-wrap: wrap; gap: 2px;
    font-family: 'JetBrains Mono', monospace; font-size: 0.85rem;
    padding: 2px;
}
.move-row {
    display: contents;
}
.move-quality {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
}
.quality-brilliant { background: #1cb5a2; box-shadow: 0 0 5px #1cb5a2; }
.quality-good { background: #81b64c; }
.quality-inaccuracy { background: #fccc4b; }
.quality-mistake { background: #f7a030; }
.quality-blunder { background: #fa3c28; }
.move-num {
    color: var(--text-muted); font-size: 0.75rem; width: 28px;
    display: inline-flex; align-items: center; justify-content: flex-end;
    padding-right: 4px; flex-shrink: 0;
}
.move-btn {
    background: transparent; border: none; color: inherit;
    padding: 4px 8px; border-radius: 4px; cursor: pointer;
    font-family: inherit; font-size: inherit; text-align: left;
    transition: all 0.15s; min-width: 50px;
}
.move-btn:hover { background: rgba(255,255,255,0.1); }
.move-btn.active { background: var(--primary-color); color: white; font-weight: 700; }

.move-controls { display: flex; justify-content: center; gap: 6px; }
.btn-icon {
    width: 36px; height: 36px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; font-size: 0.9rem;
    background: rgba(255,255,255,0.06); border: 1px solid var(--panel-border);
    color: var(--text); cursor: pointer; transition: all 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); transform: scale(1.05); }

.game-result {
    text-align: center; padding: 12px; margin-top: 8px;
    font-weight: 700; font-size: 1rem; border-radius: 8px;
    background: rgba(99, 102, 241, 0.15); color: var(--primary-color);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

/* ─── Engine Status ─── */
.engine-status { font-size: 0.8rem; display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #fbbf24; flex-shrink: 0; }
.status-dot.ready { background: #10b981; }
.status-dot.thinking { background: #6366f1; animation: pulse 0.8s infinite alternate; }
.status-dot.error { background: #ef4444; }

@keyframes pulse {
    0% { opacity: 0.4; transform: scale(0.9); }
    100% { opacity: 1; transform: scale(1.1); }
}

/* ─── Footer ─── */
.footer {
    padding: 1.5rem 0; text-align: center; border-top: 1px solid var(--panel-border);
    margin-top: 2rem;
}
.copyright { color: var(--text-muted); font-size: 0.85rem; }
.copyright a { color: var(--primary-color); text-decoration: none; }

/* ─── Player Info ─── */
.player-info {
    font-size: 0.9rem; font-weight: 600;
}
.captured-piece-img {
    width: 16px; height: 16px; background-size: contain;
    display: inline-block; filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.4));
}
.capture-score {
    font-size: 0.8rem; color: #888; font-weight: 600; margin-left: 4px;
}

/* ─── Utilities ─── */
.hidden { display: none !important; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.w-100 { width: 100%; }
.m-0 { margin: 0; }
.text-center { text-align: center; }
.flex-spread { display: flex; justify-content: space-between; align-items: center; }
.flex-grow { flex-grow: 1; display: flex; flex-direction: column; }

/* ─── Mobile ─── */
@media (max-width: 899px) {
    .chess-layout { align-items: center; }
    .board-column { max-width: 400px; }
    .controls-column { width: 100%; max-width: 520px; }
    .hero h1 { font-size: 1.8rem; }
}

@media (max-width: 480px) {
    .board-column { max-width: 100vw; padding: 0; }
    .board-wrapper { border-radius: 4px; }
    .eval-container { width: 22px; min-width: 22px; }
    .hero h1 { font-size: 1.5rem; }
}

/* Patched CSS */
.board-wrapper { min-width: 320px; min-height: 320px; flex-shrink: 0; }
.piece { transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1); }
.animate-in-piece { animation: piece-drop 0.3s ease-out forwards; }

/* Patched CSS */
.board-wrapper { min-width: 320px; min-height: 320px; flex-shrink: 0; }
.piece { transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1); }
.animate-in-piece { animation: piece-drop 0.3s ease-out forwards; }
