@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;600;700&display=swap');

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

:root {
    --bg: #0a0a1a;
    --bg-card: rgba(255,255,255,0.04);
    --bg-card-hover: rgba(255,255,255,0.08);
    --border: rgba(255,255,255,0.08);
    --text: #e8e8f0;
    --text-dim: #8888a0;
    --gold: #f0c040;
    --gold-dim: #a08020;
    --red: #e74c3c;
    --green: #2ecc71;
    --blue: #3498db;
    --sidebar-w: 300px;
}

html, body {
    min-height: 100%;
    font-family: 'Noto Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: auto;
}

/* Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: linear-gradient(180deg, #0f0f28 0%, #0a0a1a 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 18px;
    color: var(--gold);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header p {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
}

#opening-menu {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

#opening-menu::-webkit-scrollbar { width: 4px; }
#opening-menu::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 2px; }

.menu-group { border-bottom: 1px solid var(--border); }

.menu-group-header {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gold);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.menu-group-header:hover { background: var(--bg-card-hover); }

.chevron { transition: transform 0.3s; font-size: 11px; }
.menu-group.collapsed .chevron { transform: rotate(-90deg); }
.menu-group.collapsed .menu-group-list { display: none; }

.menu-item {
    padding: 8px 16px 8px 28px;
    font-size: 12.5px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.menu-item:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}
.menu-item.active {
    background: rgba(240,192,64,0.08);
    color: var(--gold);
    border-left-color: var(--gold);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Top Bar */
.top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: rgba(15,15,40,0.8);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

#mobile-menu-btn {
    display: none;
    background: none;
    border: 1px solid var(--border);
    color: var(--gold);
    font-size: 20px;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.mode-switch {
    display: flex;
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.mode-btn {
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    background: none;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.25s;
    font-family: inherit;
}
.mode-btn.active {
    background: linear-gradient(135deg, var(--gold-dim), var(--gold));
    color: #0a0a1a;
}
.mode-btn:hover:not(.active) { color: var(--text); }

/* Theme Selector */
.theme-selector {
    display: flex;
    align-items: center;
    gap: 6px;
}
.theme-selector label {
    font-size: 16px;
    cursor: pointer;
}
#theme-select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}
#theme-select:hover, #theme-select:focus {
    border-color: var(--gold-dim);
}
#theme-select option {
    background: #1a1a2e;
    color: var(--text);
}

/* Sound Toggle */
.sound-toggle-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.sound-toggle-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--gold-dim);
    color: var(--gold);
}

#opening-name {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Board Area */
.board-area {
    flex: 1;
    display: flex;
    gap: 16px;
    padding: 16px 20px;
    overflow-y: auto;
}

/* Profile Section */
.profile-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    gap: 8px;
    overflow-y: auto;
    max-width: 160px;
}

.profile-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: box-shadow 0.3s, transform 0.3s;
}

.profile-card.winner {
    box-shadow: 0 0 20px rgba(240, 192, 64, 0.15);
    border-color: rgba(240, 192, 64, 0.3);
}

.profile-card.winner:hover {
    box-shadow: 0 0 30px rgba(240, 192, 64, 0.3);
    transform: translateY(-2px);
}

.profile-card.loser {
    box-shadow: 0 0 20px rgba(231, 76, 60, 0.1);
    border-color: rgba(231, 76, 60, 0.2);
}

.profile-card.loser:hover {
    box-shadow: 0 0 30px rgba(231, 76, 60, 0.25);
    transform: translateY(-2px);
}

.profile-img {
    width: 120px;
    height: 150px;
    border-radius: 10px;
    border: 2px solid var(--gold-dim);
    object-fit: cover;
    transition: border-color 0.3s;
}

.profile-card.loser .profile-img {
    border-color: rgba(231, 76, 60, 0.4);
}

.profile-card.winner:hover .profile-img {
    border-color: var(--gold);
}

.profile-card.loser:hover .profile-img {
    border-color: var(--red);
}

.profile-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--gold);
    text-align: center;
    letter-spacing: 0.3px;
}

.profile-card.loser .profile-title {
    color: var(--red);
}

#board-container {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 16px;
    transition: box-shadow 0.3s;
    flex-shrink: 0;
}

#board-container.flash-correct { box-shadow: 0 0 30px rgba(46,204,113,0.4); }
#board-container.flash-wrong { box-shadow: 0 0 30px rgba(231,76,60,0.4); }

#game-board { cursor: pointer; }

/* Info Panel */
.info-panel {
    flex: 1;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.panel-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    backdrop-filter: blur(8px);
}

.panel-card h3 {
    font-size: 13px;
    color: var(--gold);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

#opening-desc {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.6;
}

/* Explanation */
#explanation-text {
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text);
    min-height: 40px;
}

/* Controls */
.controls-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ctrl-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-family: inherit;
}
.ctrl-btn:hover:not(:disabled) {
    background: var(--bg-card-hover);
    border-color: var(--gold-dim);
    color: var(--gold);
}
.ctrl-btn:disabled { opacity: 0.3; cursor: default; }
.ctrl-btn.playing { background: var(--gold-dim); color: #0a0a1a; }

#move-counter {
    font-size: 13px;
    color: var(--text-dim);
    margin-left: 8px;
}

/* Progress */
.progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}
#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dim), var(--gold));
    border-radius: 2px;
    transition: width 0.3s;
    width: 0%;
}

/* Move List */
.move-list-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#move-list {
    flex: 1;
    overflow-y: auto;
    max-height: 300px;
}
#move-list::-webkit-scrollbar { width: 3px; }
#move-list::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 2px; }

.move-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    font-size: 12.5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}
.move-item:hover { background: var(--bg-card-hover); }
.move-item.active { background: rgba(240,192,64,0.12); }
.move-num { color: var(--text-dim); min-width: 24px; }
.move-side { font-weight: 600; font-size: 11px; padding: 1px 6px; border-radius: 3px; }
.move-side.red { background: rgba(231,76,60,0.2); color: #e74c3c; }
.move-side.black { background: rgba(100,100,120,0.25); color: #b0b0c0; }
.move-text { color: var(--text-dim); }

/* Quiz */
#quiz-controls {
    display: none;
    align-items: center;
    gap: 8px;
}

#quiz-score {
    font-size: 14px;
    font-weight: 600;
    margin-left: auto;
}

.quiz-btn {
    padding: 7px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.quiz-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--gold-dim);
}
.quiz-btn.primary {
    background: linear-gradient(135deg, #c62828, #e53935);
    border-color: transparent;
    color: #fff;
}
.quiz-btn.secondary {
    background: linear-gradient(135deg, #37474f, #455a64);
    border-color: transparent;
    color: #eceff1;
}

#quiz-options {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
}
#quiz-options p { font-size: 14px; color: var(--text-dim); }
.quiz-side-btns { display: flex; gap: 12px; }

/* Play Mode */
.play-ai-btn {
    background: linear-gradient(135deg, #ff6b35, #f7931e) !important;
    border-color: transparent !important;
    color: #fff !important;
    font-size: 14px !important;
    margin-left: 8px;
    animation: pulse-glow 2s ease-in-out infinite;
}
.play-ai-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255,107,53,0.5);
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 5px rgba(255,107,53,0.3); }
    50% { box-shadow: 0 0 15px rgba(255,107,53,0.5); }
}

#play-controls {
    flex-wrap: wrap;
    gap: 8px;
}

.play-status {
    font-size: 13px;
    font-weight: 600;
    color: var(--gold);
    flex: 1;
    min-width: 150px;
}

.play-move-count {
    font-size: 12px;
    color: var(--text-dim);
    margin-right: 8px;
}

/* Overlay */
.overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 90;
}
.overlay.show { display: block; }

/* Tablet (iPad landscape ~1024px) */
@media (max-width: 1100px) {
    .profile-section { flex-direction: row; justify-content: center; order: -1; gap: 8px; }
    .profile-card { padding: 5px; border-radius: 8px; }
    .profile-img { width: 60px; height: 75px; border-radius: 6px; }
    .profile-title { font-size: 9px; }
    .board-area { flex-direction: column; align-items: center; overflow-y: auto; gap: 10px; padding: 10px 16px; }
    #game-board {
        max-height: 55vh !important;
        max-width: 55vh !important;
    }
    #board-container { padding: 8px; flex-shrink: 0; }
    .info-panel { min-width: 100%; flex-shrink: 0; }
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: -320px;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: left 0.3s;
    }
    .sidebar.open { left: 0; }
    #mobile-menu-btn { display: block; }
    .profile-section { flex-direction: row; justify-content: center; order: -1; gap: 6px; }
    .profile-card { padding: 6px; border-radius: 8px; }
    .profile-img { width: 70px; height: 90px; border-radius: 6px; }
    .profile-title { font-size: 10px; }
    .board-area { flex-direction: column; align-items: center; padding: 10px; gap: 10px; flex-wrap: wrap; overflow-y: auto; }
    .info-panel { min-width: 100%; }
    #board-container { padding: 8px; }
    .controls-row { gap: 6px; }
    .quiz-btn { padding: 6px 12px; font-size: 12px; }
}

@media (max-width: 580px) {
    #game-board {
        max-width: calc(100vw - 40px) !important;
        max-height: calc(100vw - 40px) !important;
    }
    .top-bar { padding: 8px 10px; gap: 8px; }
    #opening-name { font-size: 12px; }
    .mode-btn { padding: 6px 12px; font-size: 12px; }
    /* theme-selector stays visible on mobile */
    .panel-card { padding: 10px; }
    .panel-card h3 { font-size: 12px; }
    #explanation-text { font-size: 12.5px; }
    .play-status { font-size: 12px; min-width: 100px; }
    .play-move-count { font-size: 11px; }
}

/* PWA standalone mode */
@media (display-mode: standalone) {
    body { padding-top: env(safe-area-inset-top); }
}

/* Touch-friendly */
#game-board {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
