/* Root Variables */
:root {
    --primary-color: #8B4513;
    --secondary-color: #DAA520;
    --accent-color: #CD853F;
    --success-color: #2E8B57;
    --error-color: #DC143C;
    --text-color: #2C1810;
    --bg-color: #FFF8DC;
    --card-bg: #FAEBD7;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: linear-gradient(135deg, var(--bg-color) 0%, #F5DEB3 100%);
    color: var(--text-color);
    min-height: 100vh;
    padding: 10px;
}

/* Container */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Screen Management */
.screen {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typography */
h1, h2, h3, h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

/* ── Brand block (icon + title + subtitle) ── */
.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 30px;
}

.brand-icon {
    width: 11rem;
    height: 11rem;
    flex-shrink: 0;
    filter: drop-shadow(2px 2px 10px rgba(0,0,0,0.4));
}

.brand-text {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-title {
    font-size: 2.5rem;
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    margin: 0;
}

.subtitle {
    text-align: center;
    font-size: 1.1rem;
    color: var(--accent-color);
    font-style: italic;
    margin: 6px 0 0;
}

/* Desktop/tablet: side-by-side */
@media (min-width: 640px) {
    .brand {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 24px;
    }

    .brand-icon {
        width: 7rem;
        height: 7rem;
    }

    .brand-text {
        align-items: flex-start;
    }

    .game-title {
        text-align: left;
    }

    .subtitle {
        text-align: left;
    }
}

/* Buttons */
.btn {
    padding: 12px 24px;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    font-weight: bold;
    box-shadow: var(--shadow);
    display: inline-block;
    text-align: center;
    margin: 5px;
}

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

.btn-primary:hover {
    background: #6D3611;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--text-color);
}

.btn-secondary:hover {
    background: #B8860B;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-tertiary {
    background: #2E8B57;
    color: white;
}

.btn-tertiary:hover {
    background: #236B43;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-back {
    background: #999;
    color: white;
}

.btn-back:hover {
    background: #777;
}

.btn-hint {
    background: var(--accent-color);
    color: white;
}

.btn-hint:hover {
    background: #B8824A;
}

/* Menu Options */
.menu-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 30px 0;
}

.menu-options .btn {
    width: 100%;
    padding: 20px;
    font-size: 1.2rem;
    margin: 0;
}

/* Game Info Box */
.game-info {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    margin-top: 30px;
    box-shadow: var(--shadow);
    border: 2px solid var(--accent-color);
}

.game-info h3 {
    margin-top: 0;
}

/* Civilization Grid */
.civilization-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.civilization-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
    border: 3px solid transparent;
}

.civilization-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--secondary-color);
}

.civilization-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.civilization-card .icon {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 10px;
}

.civilization-card .name {
    font-size: 1.3rem;
    font-weight: bold;
    text-align: center;
    color: var(--primary-color);
}

.civilization-card .difficulty {
    text-align: center;
    margin-top: 5px;
    font-size: 0.9rem;
    color: var(--accent-color);
}

/* Story Content */
#story-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    line-height: 1.8;
    margin-bottom: 20px;
    border-left: 5px solid var(--secondary-color);
}

#story-content h3 {
    margin-top: 20px;
}

#story-content h3:first-child {
    margin-top: 0;
}

/* Game Header */
.game-header {
    display: flex;
    justify-content: space-around;
    background: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
    gap: 10px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat .label {
    font-size: 0.9rem;
    color: var(--accent-color);
}

.stat .value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* Scene Box */
.scene-box {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border-left: 5px solid var(--accent-color);
    line-height: 1.6;
}

/* Info Box */
.info-box {
    background: #E8F4F8;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #4A90A4;
}

.info-box h4 {
    margin-top: 0;
    color: #2C5F6F;
}

/* Challenge Area */
.challenge-area {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 20px;
}

.problem-display {
    text-align: center;
    margin: 30px 0;
}

.problem {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    padding: 20px;
    background: var(--bg-color);
    border-radius: 10px;
    display: inline-block;
    min-width: 200px;
}

/* Answer Section */
.answer-section {
    margin: 20px 0;
}

/* Answer Builder */
.answer-builder {
    background: white;
    border: 3px solid var(--secondary-color);
    border-radius: 10px;
    padding: 20px;
    min-height: 80px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.built-answer {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    min-height: 40px;
    letter-spacing: 2px;
    word-break: break-all;
}

.built-answer.empty::before {
    content: 'Click symbols below to build your answer';
    font-size: 1rem;
    color: #999;
    font-weight: normal;
}

/* Symbol Pad */
.symbol-pad {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 10px;
    margin: 15px 0;
    padding: 15px;
    background: var(--bg-color);
    border-radius: 10px;
}

.symbol-button {
    background: white;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    padding: 15px 10px;
    font-size: 1.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    user-select: none;
}

.symbol-button:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.symbol-button:active {
    transform: translateY(0);
}

.symbol-button .symbol-label {
    display: block;
    font-size: 0.7rem;
    color: #666;
    margin-top: 5px;
}

/* Answer Controls */
.answer-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.answer-controls .btn {
    flex: 1;
    min-width: 100px;
}

.btn-clear {
    background: #999;
    color: white;
}

.btn-clear:hover {
    background: #777;
}

.btn-backspace {
    background: #e67e22;
    color: white;
}

.btn-backspace:hover {
    background: #d35400;
}

/* OR Divider */
.or-divider {
    text-align: center;
    margin: 20px 0 10px 0;
    position: relative;
}

.or-divider::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background: #ddd;
    z-index: 0;
}

.or-divider span {
    background: white;
    padding: 0 15px;
    position: relative;
    z-index: 1;
    color: #999;
    font-size: 0.9rem;
    font-style: italic;
}

#answer-input {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-family: inherit;
}

#answer-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(218, 165, 32, 0.2);
}

/* Feedback */
.feedback {
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
    text-align: center;
    font-weight: bold;
    display: none;
    animation: slideIn 0.3s ease;
}

.feedback.show {
    display: block;
}

.feedback.correct {
    background: #D4EDDA;
    color: var(--success-color);
    border: 2px solid var(--success-color);
}

.feedback.incorrect {
    background: #F8D7DA;
    color: var(--error-color);
    border: 2px solid var(--error-color);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Hint Section */
.hint-section {
    margin-top: 20px;
}

.hint-display {
    background: #FFF9E6;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    border-left: 4px solid var(--secondary-color);
    display: none;
}

.hint-display.show {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* Oracle Pieces */
.oracle-pieces {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.oracle-pieces h4 {
    margin-top: 0;
}

.pieces-grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.piece {
    width: 50px;
    height: 50px;
    background: var(--accent-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
}

.piece.collected {
    background: var(--secondary-color);
    animation: collectPiece 0.5s ease;
}

@keyframes collectPiece {
    0% {
        transform: scale(0) rotate(0deg);
    }
    50% {
        transform: scale(1.2) rotate(180deg);
    }
    100% {
        transform: scale(1) rotate(360deg);
    }
}

/* Results */
.results-box {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin: 20px 0;
    text-align: center;
}

.results-box .final-score {
    font-size: 3rem;
    color: var(--secondary-color);
    font-weight: bold;
    margin: 20px 0;
}

.results-box .stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.results-box .stat-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
}

.results-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.results-actions .btn {
    width: 100%;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 10px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    margin: 20px;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.close {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 2rem;
    cursor: pointer;
    color: var(--accent-color);
}

.close:hover {
    color: var(--primary-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-title {
        font-size: 2rem;
    }

    .container {
        padding: 10px;
    }

    .problem {
        font-size: 1.5rem;
    }

    .answer-section {
        flex-direction: column;
    }

    .answer-section .btn {
        width: 100%;
    }

    .civilization-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .game-title {
        font-size: 1.5rem;
    }

    .stat .value {
        font-size: 1.2rem;
    }

    .problem {
        font-size: 1.2rem;
        padding: 15px;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--accent-color);
    border-radius: 50%;
    border-top-color: var(--secondary-color);
    animation: spin 1s linear infinite;
}

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

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    margin: 10px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary-color), var(--accent-color));
    transition: width 0.3s ease;
    border-radius: 10px;
}

/* Celebration Effects */
@keyframes celebrate {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
}

.celebrating {
    animation: celebrate 0.5s ease;
}

/* Shake Animation for Errors */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.shake {
    animation: shake 0.3s ease;
}

/* Pulse Animation */
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.9; }
}

.pulse {
    animation: pulse 1s ease infinite;
}

/* Civilization Completion Badge */
.completion-badge {
    display: inline-block;
    background: var(--success-color);
    color: white;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.8rem;
    margin-top: 10px;
}

/* Number Display Styling */
.number-display {
    font-family: 'Georgia', 'Times New Roman', serif;
    padding: 10px 20px;
    background: linear-gradient(135deg, #fff 0%, #f9f9f9 100%);
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    display: inline-block;
    margin: 5px;
}

/* Tooltip */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -100px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.9rem;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

/* Achievement Popup */
.achievement-popup {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, var(--secondary-color), var(--accent-color));
    color: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideInRight 0.5s ease;
    max-width: 300px;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Mobile Keyboard Optimization */
@media (max-width: 768px) {
    #answer-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .problem {
        font-size: 1.8rem;
    }
    
    .game-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--card-bg);
        margin-inline: -20px;
        padding-inline: 20px;
        border-radius: 0;
    }
}

/* ===== NUMERAL SVG SYMBOLS ===== */

/* Inline SVG wrapper — sizes the SVG relative to surrounding text */
.numeral-svg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    line-height: 1;
}
.numeral-svg svg {
    width: 2.2rem;
    height: 2.2rem;
    flex-shrink: 0;
}

/* Compact inline variant for reference tables and examples */
.ref-svg-inline {
    display: inline-flex;
    vertical-align: middle;
}
.ref-svg-inline svg {
    width: 1.4rem;
    height: 1.4rem;
}

/* Reference grid icons (slightly larger than inline) */
.ref-svg svg {
    width: 1.8rem;
    height: 1.8rem;
}

/* Symbol reference grid item */
.symbol-ref {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Symbol pad button icons */
.symbol-button .numeral-svg svg {
    width: 2.4rem;
    height: 2.4rem;
}

/* Babylonian group-separator button */
.sep-icon {
    font-size: 1.6rem;
    line-height: 1;
    color: currentColor;
    opacity: 0.6;
}

/* Babylonian positional groups (wedge clusters separated by space) */
.babylonian-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 2px;
    margin: 0 6px;
}
.babylonian-sep {
    display: inline-block;
    width: 12px;
}

/* Problem display numeral containers */
.problem-numerals {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    font-size: 1rem;
}
.problem-numerals > div {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
}

/* Greek problem: inline layout (short numeral strings) */
.greek-problem,
.chinese-problem {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

/* Chinese numerals — prioritise CJK fonts */
.chinese-numeral {
    font-family:
        'Noto Sans CJK SC', 'Noto Sans SC',
        'Source Han Sans CN', 'Microsoft YaHei', '微软雅黑',
        'PingFang SC', 'Hiragino Sans GB', 'SimSun', '宋体',
        sans-serif;
    font-size: inherit;
}

/* Greek alphabetic numerals — prioritise serif fonts with good Unicode coverage */
.greek-char {
    font-family:
        'Noto Serif', 'GFS Porson', 'Palatino Linotype',
        'Book Antiqua', 'Times New Roman', Georgia, serif;
    font-style: italic;
    font-size: inherit;
}

/* Maya vigesimal numerals */
.mayan-number {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.mayan-digit {
    display: block;
}

.mayan-digit svg {
    width: 3rem;
    height: auto;
    display: block;
}

.mayan-ref svg {
    width: 2rem;
    height: auto;
}

.mayan-pos-sep {
    display: block;
    width: 75%;
    border-top: 2px dashed currentColor;
    opacity: 0.35;
    margin: 2px auto;
}

.mayan-problem {
    align-items: flex-start;
}

/* Reverse challenge display */
.reverse-problem {
    align-items: center;
    gap: 8px;
}

.reverse-prompt {
    font-size: 1rem;
    color: #666;
    font-style: italic;
}

.reverse-number {
    font-size: 3rem;
    font-weight: bold;
    color: #CD853F;
    line-height: 1.1;
}

/* ===== END NUMERAL SVG SYMBOLS ===== */

/* Story intro boxes */
.story-box {
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
}

.story-setting-box  { background: #f0f0f0; }
.story-objective-box { background: #e8f4f8; }
.story-character-box { background: #fff9e6; }
.story-numsystem-box { background: #f5f5f5; }

.civ-best-score {
    margin-top: 8px;
    font-size: 0.85rem;
    color: #666;
}

/* ===== CIVILIZATION VISUAL THEMES (light mode) ===== */
/* Applied via body[data-civ="..."] when a civilization is active */

body[data-civ="roman"] {
    --primary-color:   #8B0000;
    --secondary-color: #C0A050;
    --accent-color:    #A0522D;
    --bg-color:        #FAF0E6;
    --card-bg:         #F0E8D8;
}
body[data-civ="roman"] body {
    background: linear-gradient(135deg, #FAF0E6 0%, #E8D8C0 100%);
}

body[data-civ="egyptian"] {
    --primary-color:   #8B6914;
    --secondary-color: #DAA520;
    --accent-color:    #2C7873;
    --bg-color:        #FFFACD;
    --card-bg:         #FFF0A0;
}

body[data-civ="greek"] {
    --primary-color:   #1C4E80;
    --secondary-color: #4A90A4;
    --accent-color:    #1565C0;
    --bg-color:        #EFF6FF;
    --card-bg:         #DBEAFE;
}

body[data-civ="babylonian"] {
    --primary-color:   #5C2D1A;
    --secondary-color: #C84B31;
    --accent-color:    #9C6B2A;
    --bg-color:        #FDF3E7;
    --card-bg:         #FAE5CC;
}

body[data-civ="chinese"] {
    --primary-color:   #8B0000;
    --secondary-color: #D4AF37;
    --accent-color:    #C41E3A;
    --bg-color:        #FFF5F5;
    --card-bg:         #FFE8E8;
}

body[data-civ="mayan"] {
    --primary-color:   #1B5E20;
    --secondary-color: #558B2F;
    --accent-color:    #8D4004;
    --bg-color:        #F1F8E9;
    --card-bg:         #DCEDC8;
}

body[data-civ="hindu-arabic"] {
    --primary-color:   #4527A0;
    --secondary-color: #7B5EA7;
    --accent-color:    #8B6914;
    --bg-color:        #EDE7F6;
    --card-bg:         #D1C4E9;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --text-color: #f0ebe4;
        --bg-color: #2C1810;
        --card-bg: #3C2820;
    }

    body {
        background: linear-gradient(135deg, #2C1810 0%, #3C2820 100%);
    }

    .challenge-area,
    .answer-builder,
    .modal-content,
    .results-box .stat-item,
    .number-display {
        background: #2C1810;
        color: var(--text-color);
    }

    .or-divider span {
        background: #2C1810;
        color: #aaa;
    }

    .or-divider::before {
        background: #555;
    }

    #answer-input {
        background: #3C2820;
        color: var(--text-color);
        border-color: #5a3e30;
    }

    .symbol-button {
        background: #3C2820;
        color: var(--text-color);
    }

    .symbol-button .symbol-label {
        color: #aaa;
    }

    .built-answer.empty::before {
        color: #aaa;
    }

    .info-box {
        background: #1a2530;
        border-left-color: #4A90A4;
    }

    .info-box h4 {
        color: #8cb8c8;
    }

    .hint-display {
        background: #2a2415;
    }

    .feedback.correct {
        background: #1a3a25;
    }

    .feedback.incorrect {
        background: #3a1a1f;
    }

    .progress-bar {
        background: #555;
    }

    .reverse-prompt {
        color: #aaa;
    }

    .story-setting-box,
    .story-objective-box,
    .story-character-box,
    .story-numsystem-box { color: var(--text-color); }
    .story-setting-box  { background: #252525; }
    .story-objective-box { background: #1a2530; }
    .story-character-box { background: #2a2415; }
    .story-numsystem-box { background: #1e1e1e; }

    .civ-best-score {
        color: #aaa;
    }

    /* Civilization themes in dark mode */
    body[data-civ="roman"]        { --bg-color: #1a0505; --card-bg: #2a0e0e; }
    body[data-civ="egyptian"]     { --bg-color: #1a1505; --card-bg: #2a2010; }
    body[data-civ="greek"]        { --bg-color: #050d1a; --card-bg: #0e1a2a; }
    body[data-civ="babylonian"]   { --bg-color: #120a1a; --card-bg: #1e1028; }
    body[data-civ="chinese"]      { --bg-color: #1a0505; --card-bg: #1a0a0a; }
    body[data-civ="mayan"]        { --bg-color: #051205; --card-bg: #0e1e0e; }
    body[data-civ="hindu-arabic"] { --bg-color: #100a1a; --card-bg: #1a1228; }

}

/* ===== MAIN MENU NEW ELEMENTS ===== */

.btn-daily {
    background: #1565C0;
    color: white;
}

.btn-daily:hover {
    background: #0D47A1;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-about-link {
    display: block;
    margin-top: 20px;
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 0.9rem;
    text-decoration: underline;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
}

.btn-about-link:hover {
    color: var(--primary-color);
}

/* Sound toggle button in game header */
.btn-sound-toggle {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-sound-toggle:hover {
    opacity: 1;
}

.btn-game-back {
    background: none;
    border: 1px solid var(--secondary-color);
    color: var(--text-color);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    opacity: 0.75;
    transition: opacity 0.2s;
    font-family: inherit;
}

.btn-game-back:hover {
    opacity: 1;
    background: rgba(0,0,0,0.08);
}

/* ===== CIVILIZATION CARD ADDITIONS ===== */

.civ-locked-hint {
    margin-top: 10px;
    font-size: 0.9rem;
}

.btn-codex-card {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    font-size: 0.8rem;
    background: var(--secondary-color);
    color: var(--text-color);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    transition: background 0.2s;
}

.btn-codex-card:hover {
    background: var(--primary-color);
    color: white;
}

/* ===== RESULTS SCREEN ===== */

.results-score-label {
    font-size: 1.2rem;
    margin-bottom: 20px;
}

.results-timeout-msg {
    font-size: 1.2rem;
    margin: 20px 0;
}

.results-retry-msg {
    margin-top: 20px;
}

.oracle-collected-box {
    background: #FFF9E6;
    padding: 20px;
    border-radius: 10px;
    margin-top: 20px;
    border: 2px solid #DAA520;
}

.oracle-collected-box p {
    margin-top: 8px;
}

.btn-codex {
    background: #6B4F9E;
    color: white;
}

.btn-codex:hover {
    background: #52397A;
    transform: translateY(-2px);
}

/* ===== HYPATIA GUIDE ===== */

.hypatia-guide {
    background: #f5eeff;
    border-left: 4px solid #7B5EA7;
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 20px;
}

.hypatia-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.hypatia-avatar {
    font-size: 1.6rem;
}

.hypatia-name {
    font-size: 1rem;
    color: var(--primary-color);
}

.hypatia-quote {
    font-style: italic;
    color: #7B5EA7;
    margin: 0 0 8px 0;
    font-size: 0.95rem;
    border: none;
    padding: 0;
}

.hypatia-guidance {
    font-size: 0.9rem;
    color: var(--text-color);
    margin: 0;
    line-height: 1.6;
}

/* ===== HINDU-ARABIC NUMERAL DISPLAY ===== */

.hindu-arabic-numeral {
    font-family:
        'Noto Naskh Arabic', 'Noto Sans Arabic',
        'Arabic Typesetting', 'Segoe UI', Arial, sans-serif;
    font-size: 1.4em;
    direction: ltr;
    unicode-bidi: bidi-override;
}

/* ===== CODEX MODAL ===== */

.codex-modal-content {
    max-width: 650px;
}

.codex-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--accent-color);
    margin-bottom: 20px;
}

.codex-icon {
    font-size: 3rem;
    line-height: 1;
}

.codex-title {
    margin: 0 0 4px 0;
    color: var(--primary-color);
    font-size: 1.4rem;
}

.codex-meta {
    font-size: 0.85rem;
    color: var(--accent-color);
    font-style: italic;
    margin: 0;
}

.codex-section {
    padding: 14px 0;
    border-bottom: 1px solid #eee;
}

.codex-section:last-child {
    border-bottom: none;
}

.codex-section-heading {
    color: var(--primary-color);
    margin: 0 0 8px 0;
    font-size: 1rem;
}

/* ===== DAILY CHALLENGE SCREEN ===== */

.daily-info {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.daily-date {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.daily-streak {
    font-size: 1rem;
    color: var(--accent-color);
}

.daily-civ-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 10px;
    text-align: center;
    border: 3px solid var(--secondary-color);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.daily-civ-icon {
    font-size: 3.5rem;
    margin-bottom: 8px;
}

.daily-civ-name {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.daily-civ-system {
    font-size: 0.95rem;
    color: var(--accent-color);
    font-style: italic;
    margin-bottom: 6px;
}

.daily-civ-difficulty {
    font-size: 0.9rem;
    color: var(--text-color);
}

.daily-completed-msg {
    background: #D4EDDA;
    color: #2E8B57;
    border: 2px solid #2E8B57;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    margin-bottom: 16px;
}

.daily-description {
    text-align: center;
    margin-bottom: 20px;
    line-height: 1.6;
}

/* ===== ABOUT SCREEN ===== */

.about-intro, .about-creator, .about-why {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.about-intro {
    border-left: 4px solid var(--secondary-color);
}

.about-why ul {
    padding-left: 20px;
    margin-top: 10px;
    line-height: 1.8;
}

.timeline-heading {
    margin: 30px 0 20px;
    text-align: center;
}

/* Vertical timeline */
.timeline {
    position: relative;
    padding: 10px 0;
    margin-bottom: 30px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--secondary-color);
    transform: translateX(-50%);
}

.timeline-item {
    display: flex;
    justify-content: flex-end;
    padding-right: calc(50% + 30px);
    margin-bottom: 30px;
    position: relative;
}

.timeline-item.timeline-right {
    justify-content: flex-start;
    padding-right: 0;
    padding-left: calc(50% + 30px);
}

.timeline-dot {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 36px;
    background: var(--card-bg);
    border: 3px solid var(--secondary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    z-index: 1;
    top: 10px;
}

.timeline-card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid #e0d5c5;
    max-width: 320px;
}

.timeline-date {
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.timeline-title {
    color: var(--primary-color);
    margin: 0 0 8px 0;
    font-size: 1rem;
}

.timeline-text {
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 0;
}

.timeline-proof {
    margin-top: 8px;
    font-size: 0.8rem;
    background: #f5f5f5;
    padding: 6px 10px;
    border-radius: 4px;
    font-family: monospace;
    color: #555;
}

.about-screenshots {
    margin-top: 20px;
}

.screenshot-placeholder {
    background: #f5f5f5;
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    margin: 12px 0;
    color: #888;
    font-style: italic;
}

.screenshot-figure {
    margin: 16px 0;
    text-align: center;
}

.screenshot-img {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid #ccc;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.screenshot-figure figcaption {
    margin-top: 6px;
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

/* Responsive timeline — single column on mobile */
@media (max-width: 640px) {
    .timeline::before {
        left: 18px;
    }

    .timeline-item,
    .timeline-item.timeline-right {
        justify-content: flex-start;
        padding-right: 0;
        padding-left: 52px;
    }

    .timeline-dot {
        left: 18px;
        transform: translateX(-50%);
    }

    .timeline-card {
        max-width: 100%;
    }
}

/* ===== DARK MODE — late component overrides =====
   Must appear AFTER all base component rules to win the cascade. */
@media (prefers-color-scheme: dark) {
    .hypatia-guide        { background: #1a1a2e; border-left-color: #9c85d0; }
    .hypatia-quote        { color: #c4a0e8; }
    .hypatia-guidance     { color: #f0ebe4; }

    .oracle-collected-box { background: #2a2415; border-color: #b8960a; }

    .codex-header         { border-bottom-color: #5a3e30; }
    .codex-section        { border-bottom-color: #3a2a20; }
    .codex-section-heading { color: #c8a060; }
    .codex-meta           { color: #aaa; }

    .daily-info           { background: #2C1810; }
    .daily-civ-card       { background: #3C2820; }
    .btn-daily            { background: #1a3a50; }
    .btn-daily:hover      { background: #254d6b; }

    .about-intro, .about-creator, .about-why { background: #3C2820; }
    .timeline-card        { background: #3C2820; border-color: #5a3e30; }

    .screenshot-placeholder { background: #252525; border-color: #555; color: #aaa; }
    .screenshot-img         { border-color: #444; }
    .screenshot-figure figcaption { color: #aaa; }
}
