/* Star Genius - Dark Theme Styling */

:root {
    --bg-dark: #0d1117;
    --bg-card: #161b22;
    --bg-board: #1b2856;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-yellow: #d29922;
    --accent-red: #f85149;
    --border-color: #30363d;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark) url('bg_pastel.jpg') center/cover fixed;
    color: var(--text-primary);
    min-height: 100vh;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
}

.modal-content h1 {
    font-size: 2.5rem;
    margin-bottom: 16px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Button Styles */
.btn {
    padding: 12px 24px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    background: #21262d;
    border-color: var(--text-secondary);
}

.btn-primary {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: #4c9aed;
}

.btn-secondary {
    background: #21262d;
}

.btn-warning {
    background: var(--accent-red);
    border-color: var(--accent-red);
}

.btn-warning:hover {
    background: #da3633;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.875rem;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
}

header h1 {
    font-size: 1.5rem;
}

/* Main Layout */
main {
    display: grid;
    grid-template-columns: 200px 1fr 220px;
    gap: 20px;
    padding: 20px;
    height: calc(100vh - 100px);
    /* Restore fixed height to force internal scrolling */
    overflow: hidden;
    /* Prevent body scroll */
    background: transparent;
}

#board-container {
    overflow: auto;
    /* Allow board to scroll if needed within the container */
    background: transparent;
}

/* Palette */
#palette {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    overflow-y: auto;
}

#palette h2 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

#piece-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.piece-item {
    background: var(--bg-dark);
    border: 2px solid transparent;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.piece-item:hover {
    border-color: var(--text-secondary);
}

.piece-item.selected {
    border-color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.1);
}

.piece-item.placed {
    opacity: 0.4;
    cursor: not-allowed;
}

.piece-item svg {
    width: 50px;
    height: 40px;
}

.piece-item .piece-name {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Board Container */
#board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#board-svg {
    max-height: 100%;
    /* Fit height first to avoid scroll */
    width: auto;
    /* Width adjusts to aspect ratio */
    display: block;
    /* Remove inline spacing */
    margin: 0 auto;
    /* Center horizontally */
    overflow: visible;
    /* Allow pieces to overhang */
    filter: drop-shadow(0 4px 20px rgba(0, 0, 0, 0.5));
}

#header-status {
    flex-grow: 1;
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 500;
}

/* Controls */
#controls {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
}

#controls h2 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.control-group .btn {
    width: 100%;
}

#controls-info {
    margin-top: 24px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#controls-info p {
    margin-bottom: 8px;
}

#controls-info ul {
    list-style: none;
    margin-bottom: 16px;
}

#controls-info li {
    margin-bottom: 4px;
}

kbd {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 2px 6px;
    font-family: monospace;
}

/* Board Cells */
.board-cell {
    cursor: pointer;
    /* transition: filter 0.1s; - disabled for testing */
}

.board-cell.valid-placement {
    filter: brightness(1.5);
    stroke-width: 2;
}

.board-cell.invalid-placement {
    filter: brightness(0.7);
}

.ghost-piece {
    opacity: 0.5;
    pointer-events: none;
}

/* Loading Overlay */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Win Animation */
@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

.win-animation {
    animation: pulse 0.5s ease-in-out 3;
}

/* Dice Selection Modal */
.dice-modal-content {
    max-width: 600px;
    width: 90%;
}

.dice-modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.dice-instructions {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

#dice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}

#dice-table tr {
    border-bottom: 1px solid var(--border-color);
}

#dice-table tr:last-child {
    border-bottom: none;
}

.die-label {
    font-weight: 600;
    color: var(--text-secondary);
    padding: 12px 16px 12px 0;
    white-space: nowrap;
    width: 60px;
    text-align: left;
}

.die-options {
    padding: 8px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start;
}

.dice-value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 36px;
    padding: 0 10px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.dice-value:hover {
    border-color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.15);
}

.dice-value.selected {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
    box-shadow: 0 0 12px rgba(88, 166, 255, 0.5);
    transform: scale(1.05);
}

.dice-modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.dice-modal-buttons .btn {
    min-width: 120px;
}

#btn-start-dice:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}