:root {
    --bg-primary: #0a0c10;
    --bg-secondary: #121620;
    --bg-card: rgba(18, 22, 32, 0.7);
    --border-color: rgba(223, 177, 91, 0.2);
    --border-color-glow: rgba(223, 177, 91, 0.4);
    
    --color-gold: #dfb15b;
    --color-gold-hover: #ebd098;
    --color-gold-light: rgba(223, 177, 91, 0.1);
    --color-gold-glow: rgba(223, 177, 91, 0.3);
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --light-square: #eedfd2;
    --dark-square: #56473e;
    
    --color-selected: rgba(223, 177, 91, 0.45);
    --color-last-move: rgba(223, 177, 91, 0.2);
    --color-check: rgba(239, 68, 68, 0.5);
    
    --font-heading: 'Playfair Display', Georgia, serif;
    --font-ui: 'Outfit', sans-serif;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-ui);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Background Ambient Glows */
.app-bg-accent-left {
    position: absolute;
    width: 600px;
    height: 600px;
    top: -200px;
    left: -200px;
    background: radial-gradient(circle, rgba(223, 177, 91, 0.05) 0%, rgba(0,0,0,0) 70%);
    z-index: -1;
    pointer-events: none;
}

.app-bg-accent-right {
    position: absolute;
    width: 600px;
    height: 600px;
    bottom: -200px;
    right: -200px;
    background: radial-gradient(circle, rgba(223, 177, 91, 0.05) 0%, rgba(0,0,0,0) 70%);
    z-index: -1;
    pointer-events: none;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-gold);
}

/* Container & Header */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 30px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 2rem;
    text-shadow: 0 0 10px var(--color-gold-glow);
}

.logo h1 {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

.logo h1 .domain {
    color: var(--color-gold);
    font-size: 1.2rem;
    font-weight: 300;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    font-family: var(--font-ui);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-gold) 0%, #b88d38 100%);
    color: #000;
    border: none;
    box-shadow: 0 4px 15px rgba(223, 177, 91, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(223, 177, 91, 0.4);
    background: linear-gradient(135deg, var(--color-gold-hover) 0%, var(--color-gold) 100%);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.03);
    color: var(--color-gold);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--color-gold-light);
    border-color: var(--color-gold);
    transform: translateY(-2px);
}

/* Layout Grid */
.main-layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 40px;
    flex-grow: 1;
    align-items: start;
}

/* Game Board Section */
.game-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.board-outer-container {
    position: relative;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    margin-bottom: 20px;
    display: grid;
    grid-template-areas: 
        ".     files"
        "ranks board";
    grid-template-columns: 24px 1fr;
    grid-template-rows: 24px auto;
    width: min(90vw, 610px);
    box-sizing: border-box;
}

/* Grid-area mappings */
.coordinates.ranks {
    grid-area: ranks;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding-right: 8px;
}

.coordinates.files {
    grid-area: files;
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding-top: 8px;
}

.board-inner-container {
    grid-area: board;
    border-radius: 6px;
    overflow: hidden;
    border: 4px solid var(--bg-primary);
    box-shadow: 0 0 0 2px var(--border-color);
    width: 100%;
    aspect-ratio: 1 / 1;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
}

/* Board Squares */
.square {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    transition: background-color 0.15s ease;
}

/* Subtle Cat Head Silhouettes */
.square.light {
    background-color: var(--light-square);
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M 25 45 L 20 15 L 42 35 Q 50 38 58 35 L 80 15 L 75 45 C 80 55, 80 70, 70 80 C 60 90, 40 90, 30 80 C 20 70, 20 55, 25 45 Z" fill="black" opacity="0.05"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 72%;
}

.square.dark {
    background-color: var(--dark-square);
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M 25 45 L 20 15 L 42 35 Q 50 38 58 35 L 80 15 L 75 45 C 80 55, 80 70, 70 80 C 60 90, 40 90, 30 80 C 20 70, 20 55, 25 45 Z" fill="white" opacity="0.05"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 72%;
}

/* Highlights & Markers */
.square.selected {
    background-color: var(--color-selected) !important;
}

.square.last-move {
    box-shadow: inset 0 0 0 4px var(--color-last-move);
}

.square.check {
    background-color: var(--color-check) !important;
    animation: pulse-check 1.5s infinite alternate;
}

.legal-move-marker {
    width: 24%;
    height: 24%;
    background-color: rgba(223, 177, 91, 0.45);
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
}

.legal-move-marker.capture {
    width: 80%;
    height: 80%;
    border: 5px solid rgba(223, 177, 91, 0.35);
    background-color: transparent;
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
}

/* Chess Pieces */
.piece {
    width: 90%;
    height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
    z-index: 3;
    transition: transform 0.1s ease;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}

.piece svg {
    width: 100%;
    height: 100%;
    display: block;
}

.piece:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.piece.dragging {
    opacity: 0.5;
}

/* Player Indicator Bars */
.player-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: min(70vw + 48px, 608px);
    background: var(--bg-card);
    padding: 12px 20px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.95rem;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(255,255,255,0.2);
}

.player-color.white {
    background-color: #fff;
}

.player-color.black {
    background-color: #1a1a1a;
}

.player-name {
    font-weight: 500;
}

.captured-pieces {
    display: flex;
    gap: 4px;
    min-height: 24px;
    align-items: center;
}

.captured-icon {
    font-size: 1.1rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Sidebar Section (Chester & Chat) */
.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Chester Card */
.chester-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.chester-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--color-gold);
}

.avatar-wrapper {
    position: relative;
    width: 72px;
    height: 72px;
}

.chester-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    border: 2px solid var(--color-gold);
    box-shadow: 0 0 10px var(--color-gold-glow);
}

.status-indicator {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

.status-indicator.online {
    background-color: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.chester-info h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--text-primary);
}

.chester-title {
    font-size: 0.85rem;
    color: var(--color-gold);
    font-weight: 500;
}

/* Chat Speech Bubble */
.chat-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 150px;
}

.chat-bubble {
    position: relative;
    background: linear-gradient(135deg, rgba(22, 28, 42, 0.9) 0%, rgba(13, 17, 26, 0.9) 100%);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    animation: slide-up 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.chat-bubble p {
    font-size: 1.05rem;
    line-height: 1.6;
    color: var(--text-secondary);
    font-style: italic;
}

.bubble-tail {
    position: absolute;
    top: 30px;
    left: -12px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 12px solid var(--border-color);
}

.bubble-tail::after {
    content: '';
    position: absolute;
    top: -10px;
    left: 1px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 12px solid var(--bg-primary);
}

/* Thinking Indicator */
.chester-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 10px;
    color: var(--color-gold);
    font-size: 0.9rem;
    font-weight: 500;
}

.chester-status.hidden {
    display: none;
}

.typing-indicator {
    display: flex;
    gap: 4px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: var(--color-gold);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

/* Move History Card */
.history-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.history-card h3 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 8px;
}

.move-history {
    max-height: 200px;
    overflow-y: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.history-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    padding-bottom: 8px;
}

.history-table td {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.history-table tr:hover td {
    color: var(--color-gold);
}

.history-table td:first-child {
    color: var(--text-muted);
    font-weight: 600;
    width: 40px;
}

.history-empty {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 20px 0;
}

/* Footer */
.app-footer {
    text-align: center;
    margin-top: 50px;
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(5, 6, 8, 0.85);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-smooth);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-card {
    background: #12151e;
    border: 1px solid var(--color-gold);
    box-shadow: 0 15px 40px rgba(223, 177, 91, 0.15);
    border-radius: 16px;
    width: min(90vw, 580px);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: scale-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    color: var(--color-gold);
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: var(--transition-smooth);
}

.modal-close-btn:hover {
    color: var(--color-gold);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.modal-body h3 {
    margin-top: 15px;
    margin-bottom: 10px;
    color: var(--text-primary);
    font-family: var(--font-heading);
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.modal-body li {
    margin-bottom: 8px;
}

.piece-rules {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
}

.piece-rule {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255,255,255,0.02);
    padding: 8px 12px;
    border-radius: 8px;
}

.piece-sym {
    font-size: 2.2rem;
    color: var(--color-gold);
    width: 40px;
    text-align: center;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.05);
    display: flex;
    justify-content: flex-end;
}

/* Animations */
@keyframes pulse-check {
    0% { background-color: rgba(239, 68, 68, 0.4); }
    100% { background-color: rgba(239, 68, 68, 0.7); }
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scale-up {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr;
        gap: 30px;
    }
    
    .sidebar-section {
        flex-direction: column;
    }
    
    .chat-bubble {
        margin-top: 10px;
    }
    
    .bubble-tail {
        top: -12px;
        left: 40px;
        border-right: 10px solid transparent;
        border-left: 10px solid transparent;
        border-bottom: 12px solid var(--border-color);
        border-top: none;
    }
    
    .bubble-tail::after {
        top: 2px;
        left: -10px;
        border-right: 10px solid transparent;
        border-left: 10px solid transparent;
        border-bottom: 12px solid var(--bg-secondary);
        border-top: none;
    }
}

@media (max-width: 640px) {
    .app-container {
        padding: 10px;
    }
    
    .app-header {
        flex-direction: column;
        gap: 15px;
        align-items: center;
        text-align: center;
    }
    
    .chess-board {
        width: 100%;
        height: 100%;
    }
    
    .board-outer-container {
        padding: 12px;
        width: 92vw;
    }
    
    .player-bar {
        width: 92vw;
    }
}

/* More Games Modal Custom Styling */
.modal-intro {
    margin-bottom: 20px;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.modal-link {
    color: var(--color-gold);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.modal-link:hover {
    color: var(--color-gold-hover);
    text-decoration: underline;
}

.games-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-primary);
    transition: var(--transition-smooth);
}

.game-item:hover {
    background: var(--color-gold-light);
    border-color: var(--color-gold);
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(223, 177, 91, 0.1);
}

.game-item-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.game-item-icon-wrapper {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: var(--transition-smooth);
}

.game-item:hover .game-item-icon-wrapper {
    background: rgba(223, 177, 91, 0.1);
    border-color: var(--color-gold);
}

.game-item-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.game-item-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.game-item-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    transition: var(--transition-smooth);
}

.game-item:hover .game-item-title {
    color: var(--color-gold);
}

.game-item-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.game-item-right {
    display: flex;
    align-items: center;
}

.game-item-arrow {
    font-size: 1.2rem;
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

.game-item:hover .game-item-arrow {
    color: var(--color-gold);
    transform: translateX(4px);
}



/* Sound / Mute Toggle Button */
.sound-toggle-btn, #sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-sizing: border-box;
}
@media (max-width: 600px) {
  .sound-toggle-btn, #sound-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    font-size: 0.85rem;
  }
}

/* Clear visual distinction for Muted state */
.sound-toggle-btn.muted, #sound-btn.muted {
  opacity: 0.55 !important;
  background: rgba(20, 20, 25, 0.7) !important;
  border-color: rgba(255, 255, 255, 0.25) !important;
  color: #94a3b8 !important;
  box-shadow: none !important;
}
