/* Design tokens */
:root {
    --bg-deep: #0d0c0f;
    --bg-card: #151418;
    --bg-elevated: #1c1b20;
    --bg-input: #121116;

    --gold-dim: #8b7355;
    --gold-muted: #a69070;
    --gold-primary: #d4a853;
    --gold-bright: #e8c068;
    --gold-glow: #f0d990;

    --text-cream: #f5f0e8;
    --text-warm: #d4cdc0;
    --text-muted: #7a7570;

    --success: #7fb069;
    --warning: #e8a840;
    --error: #c96b6b;

    --border-subtle: rgba(212, 168, 83, 0.12);
    --border-medium: rgba(212, 168, 83, 0.25);

    --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px rgba(212, 168, 83, 0.08);

    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Jost', system-ui, sans-serif;

    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    background: var(--bg-deep);
    color: var(--text-cream);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(0.75rem, 2vw, 2rem);
    margin: 0;
    overflow-x: hidden;
    position: relative;
}

.ambient-glow {
    position: fixed;
    top: -50%;
    left: 50%;
    transform: translateX(-50%);
    width: min(1200px, 100vw);
    height: min(1200px, 100vw);
    background: radial-gradient(circle, rgba(212, 168, 83, 0.06) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.game-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: clamp(320px, 90vw, 780px);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    padding: clamp(1.25rem, 4vw, 2.5rem);
    box-shadow: var(--shadow-soft), var(--shadow-glow);
    animation: containerReveal 0.8s var(--ease-out-expo) both;
}

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

.game-header {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeSlideIn 0.6s var(--ease-out-quint) 0.1s both;
}

.header-line {
    width: 60px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-primary), transparent);
    margin: 0 auto 1.25rem;
}

h1 {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 5vw, 2.25rem);
    font-weight: 600;
    color: var(--text-cream);
    margin: 0 0 0.5rem;
    letter-spacing: 0.02em;
}

.tagline {
    font-size: 0.8rem;
    font-weight: 300;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    margin: 0;
}

.game-board {
    animation: fadeSlideIn 0.6s var(--ease-out-quint) 0.2s both;
}

.difficulty-selector {
    margin-bottom: 1.5rem;
}

.label-subtle {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 0.6rem;
}

.segmented-control {
    display: flex;
    background: var(--bg-deep);
    border-radius: 2px;
    padding: 3px;
    gap: 3px;
}

.seg-btn {
    flex: 1;
    padding: 0.6rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 2px;
    transition: all 0.3s var(--ease-out-expo);
}

.seg-btn:hover {
    color: var(--text-warm);
}

.seg-btn.active {
    background: var(--bg-elevated);
    color: var(--gold-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.range-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.range-number {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gold-muted);
    min-width: 2.5rem;
}

.range-line {
    flex: 1;
    height: 2px;
    background: var(--border-subtle);
    position: relative;
    overflow: hidden;
}

.range-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold-dim), var(--gold-primary));
    transition: width 0.5s var(--ease-out-expo);
}

.input-zone {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

input[type="number"] {
    flex: 1;
    padding: clamp(0.75rem, 2vw, 1rem) clamp(1rem, 3vw, 1.5rem);
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    color: var(--text-cream);
    font-family: var(--font-body);
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    font-weight: 400;
    transition: all 0.3s var(--ease-out-expo);
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"]::placeholder {
    color: var(--text-muted);
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--gold-primary);
    box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.1);
}

.btn-primary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 1.5rem;
    background: var(--gold-primary);
    border: none;
    border-radius: 2px;
    color: var(--bg-deep);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
}

.btn-primary:hover {
    background: var(--gold-bright);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(212, 168, 83, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--gold-dim);
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.secondary-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-ghost {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.7rem 1rem;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
}

.btn-ghost svg {
    opacity: 0.7;
    transition: opacity 0.3s;
}

.btn-ghost:hover {
    border-color: var(--border-medium);
    color: var(--text-warm);
}

.btn-ghost:hover svg {
    opacity: 1;
}

.btn-ghost:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-ghost:disabled:hover {
    border-color: var(--border-subtle);
    color: var(--text-muted);
}

.feedback-zone {
    margin: 1.5rem 0;
    animation: fadeSlideIn 0.6s var(--ease-out-quint) 0.3s both;
}

.result-message {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.25rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    text-align: center;
    min-height: 64px;
}

.result-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gold-muted);
}

.result-text {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-warm);
    transition: all 0.3s;
}

.result-message.warm .result-icon { color: var(--warning); }
.result-message.warm .result-text { color: var(--warning); }

.result-message.cold .result-icon { color: var(--error); }
.result-message.cold .result-text { color: var(--error); }

.result-message.success .result-icon { color: var(--success); }
.result-message.success .result-text { color: var(--success); }

.result-message.victory {
    background: linear-gradient(135deg, rgba(212, 168, 83, 0.15), rgba(212, 168, 83, 0.05));
    border-color: var(--gold-primary);
}

.result-message.victory .result-icon { color: var(--gold-bright); }
.result-message.victory .result-text {
    color: var(--gold-bright);
    font-weight: 600;
}

.stats-zone {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    animation: fadeSlideIn 0.6s var(--ease-out-quint) 0.4s both;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    transition: all 0.3s var(--ease-out-expo);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-cream);
    line-height: 1;
    transition: all 0.3s;
}

.stat-label {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-top: 0.4rem;
}

.stat-card.score .stat-value { color: var(--gold-primary); }

.stat-card.best {
    background: linear-gradient(135deg, rgba(212, 168, 83, 0.08), transparent);
}

.stat-card.best .stat-value { color: var(--gold-muted); }

.history-zone {
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-subtle);
    animation: fadeSlideIn 0.6s var(--ease-out-quint) 0.5s both;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.history-count {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--gold-dim);
}

.guess-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 2rem;
}

.guess-chips span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.8rem;
    background: var(--bg-deep);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-warm);
    animation: chipEnter 0.3s var(--ease-out-expo) both;
}

@keyframes chipEnter {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.game-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
    text-align: center;
}

.warmth-indicator {
    height: 3px;
    background: var(--bg-deep);
    border-radius: 2px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.warmth-fill {
    height: 100%;
    background: linear-gradient(90deg, #6b9bd1, #7fb069, #e8a840, #c96b6b);
    border-radius: 2px;
    transition: width 0.5s var(--ease-out-expo);
}

.hint-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.hint-text kbd {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    font-family: var(--font-body);
    font-size: 0.7rem;
}

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

/* Victory overlay */
.victory-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 12, 15, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s var(--ease-out-expo);
}

.victory-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.victory-content {
    text-align: center;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.6s var(--ease-out-expo);
}

.victory-overlay.active .victory-content {
    transform: scale(1) translateY(0);
}

.victory-icon {
    width: clamp(60px, 15vw, 100px);
    height: clamp(60px, 15vw, 100px);
    margin: 0 auto 1.5rem;
    color: var(--gold-bright);
    animation: victoryPulse 2s var(--ease-out-expo) infinite;
}

@keyframes victoryPulse {
    0%, 100% { filter: drop-shadow(0 0 20px rgba(212, 168, 83, 0.4)); }
    50%       { filter: drop-shadow(0 0 40px rgba(212, 168, 83, 0.6)); }
}

.victory-icon svg {
    width: 100%;
    height: 100%;
}

.victory-title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 8vw, 4rem);
    font-weight: 600;
    color: var(--gold-bright);
    margin: 0 0 1rem;
    letter-spacing: 0.05em;
}

.victory-number {
    font-size: clamp(1rem, 3vw, 1.25rem);
    color: var(--text-warm);
    margin: 0 0 0.5rem;
}

.victory-number strong {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    color: var(--text-cream);
}

.victory-score {
    font-size: clamp(0.85rem, 2vw, 1rem);
    color: var(--text-muted);
    margin: 0;
}

.victory-score span {
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 4vw, 2rem);
    font-weight: 600;
    color: var(--gold-primary);
}

/* Sound toggle */
.sound-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
}

.sound-toggle:hover {
    border-color: var(--border-medium);
    color: var(--gold-primary);
    transform: scale(1.08);
}

/* Player name input */
.player-setup {
    margin-bottom: 1.5rem;
    animation: fadeSlideIn 0.6s var(--ease-out-quint) 0.15s both;
}

.player-input-row {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.player-input-row input[type="text"] {
    flex: 1;
    padding: 0.65rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    color: var(--text-cream);
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: all 0.3s var(--ease-out-expo);
}

.player-input-row input[type="text"]::placeholder {
    color: var(--text-muted);
}

.player-input-row input[type="text"]:focus {
    outline: none;
    border-color: var(--gold-primary);
    box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.1);
}

.btn-icon {
    gap: 0.35rem;
    white-space: nowrap;
    flex: unset;
    padding: 0.65rem 0.9rem;
}

/* Timer */
.timer-zone {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.timer-bar-track {
    flex: 1;
    height: 6px;
    background: var(--bg-deep);
    border-radius: 3px;
    overflow: hidden;
}

.timer-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #7fb069, #a8d08d);
    border-radius: 3px;
    transition: width 0.9s linear, background 0.5s ease;
}

.timer-bar-fill.timer-urgent {
    animation: timerPulse 0.5s ease-in-out infinite alternate;
}

@keyframes timerPulse {
    from { opacity: 1; }
    to   { opacity: 0.55; }
}

.timer-label {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-warm);
    min-width: 4rem;
    text-align: right;
    letter-spacing: 0.03em;
}

/* Leaderboard modal */
.leaderboard-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 12, 15, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s var(--ease-out-expo);
    padding: 1rem;
}

.leaderboard-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.leaderboard-modal {
    width: 100%;
    max-width: 480px;
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 60px rgba(212, 168, 83, 0.06);
    transform: scale(0.94) translateY(16px);
    transition: transform 0.4s var(--ease-out-expo);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.leaderboard-overlay.active .leaderboard-modal {
    transform: scale(1) translateY(0);
}

.leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.leaderboard-header h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--gold-bright);
    margin: 0;
    letter-spacing: 0.03em;
}

.btn-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-close:hover {
    border-color: var(--border-medium);
    color: var(--text-cream);
}

.leaderboard-tabs {
    display: flex;
    gap: 2px;
    padding: 0.75rem 1.5rem 0;
    background: var(--bg-elevated);
}

.lb-tab {
    padding: 0.45rem 0.9rem;
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.25s;
}

.lb-tab:hover { color: var(--text-warm); }

.lb-tab.active {
    color: var(--gold-primary);
    border-bottom-color: var(--gold-primary);
}

.leaderboard-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1.5rem;
}

.leaderboard-list::-webkit-scrollbar { width: 4px; }
.leaderboard-list::-webkit-scrollbar-track { background: transparent; }
.leaderboard-list::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 2px;
}

.lb-row {
    display: grid;
    grid-template-columns: 2rem 1fr 4rem 2.5rem 5rem;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.85rem;
    transition: background 0.2s;
}

.lb-row:last-child { border-bottom: none; }

.lb-row.lb-top {
    background: linear-gradient(90deg, rgba(212, 168, 83, 0.08), transparent);
    border-radius: 2px;
}

.lb-rank {
    font-size: 1rem;
    text-align: center;
}

.lb-name {
    font-weight: 500;
    color: var(--text-cream);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-diff {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    padding: 0.2rem 0.4rem;
    border-radius: 2px;
    text-align: center;
}

.lb-diff-easy   { color: #7fb069; background: rgba(127, 176, 105, 0.12); }
.lb-diff-medium { color: var(--gold-primary); background: rgba(212, 168, 83, 0.12); }
.lb-diff-hard   { color: var(--error); background: rgba(201, 107, 107, 0.12); }

.lb-score {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold-bright);
    text-align: right;
}

.lb-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
}

.lb-empty {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.btn-clear {
    display: block;
    width: calc(100% - 3rem);
    margin: 0 1.5rem 1.25rem;
    padding: 0.6rem;
    background: transparent;
    border: 1px solid rgba(201, 107, 107, 0.3);
    border-radius: 2px;
    color: var(--error);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s;
}

.btn-clear:hover {
    background: rgba(201, 107, 107, 0.08);
    border-color: var(--error);
}

/* Start button */
.btn-start {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    margin-top: 1rem;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--gold-primary), var(--gold-bright));
    border: none;
    border-radius: 2px;
    color: var(--bg-deep);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(212, 168, 83, 0.3);
    transition: all 0.3s var(--ease-out-expo);
    animation: startPulse 2s ease-in-out infinite;
}

.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(212, 168, 83, 0.45);
    background: linear-gradient(135deg, var(--gold-bright), var(--gold-glow));
}

.btn-start:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(212, 168, 83, 0.2);
}

@keyframes startPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(212, 168, 83, 0.3); }
    50%       { box-shadow: 0 4px 36px rgba(212, 168, 83, 0.6); }
}

/* Responsive tweaks */
@media (max-width: 480px) {
    .input-zone {
        flex-direction: column;
    }

    .btn-primary {
        justify-content: center;
    }

    .stats-zone {
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem 0.5rem;
    }
}

@media (min-width: 600px) {
    .leaderboard-modal {
        max-width: min(640px, 90vw);
    }
}

@media (min-width: 768px) {
    .game-header {
        margin-bottom: 2.5rem;
    }

    .tagline {
        font-size: 0.85rem;
    }

    .stats-zone {
        gap: 1rem;
    }

    .stat-card {
        padding: 1.25rem;
    }

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

    .result-message {
        padding: 1.5rem;
    }

    .secondary-actions {
        gap: 1rem;
    }

    .input-zone input[type="number"] {
        font-size: 1.35rem;
    }

    .guess-chips span {
        font-size: 0.9rem;
        padding: 0.45rem 1rem;
    }
}

@media (max-width: 420px) {
    .lb-row {
        grid-template-columns: 2rem 1fr 3.5rem 2rem;
    }

    .lb-date {
        display: none;
    }
}
