/* ============================================
   CloseWord — NYT-inspired Word Game Styles
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --bg: #ffffff;
    --bg-secondary: #f7f7f5;
    --text: #121212;
    --text-secondary: #6b6b6b;
    --text-tertiary: #999999;
    --border: #e0e0e0;
    --border-light: #f0f0f0;

    /* Rank colors — Contexto-style */
    --rank-hot: #4caf50;
    --rank-hot-bg: #a8d8a8;
    --rank-warm: #d4a843;
    --rank-warm-bg: #f0d898;
    --rank-cool: #c4956a;
    --rank-cool-bg: #e8cdb0;
    --rank-cold: #b0856a;
    --rank-cold-bg: #e0c8b0;

    /* Accent */
    --accent: #121212;
    --accent-hover: #333333;

    /* Spacing */
    --header-height: 56px;
    --max-width: 520px;

    /* Animation */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Libre Franklin', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Header --- */
.header {
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}

.header-inner {
    width: 100%;
    max-width: var(--max-width);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

a.header-title {
    text-align: center;
    text-decoration: none;
    color: inherit;
}

.header-title h1 {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.header-subtitle {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 500;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    border-radius: 50%;
    transition: background 0.15s ease;
}

a.icon-btn {
    text-decoration: none;
}

.icon-btn:hover {
    background: var(--bg-secondary);
}

/* --- Main --- */
.main {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 20px 16px 40px;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Game Info --- */
.game-info {
    text-align: center;
    margin-bottom: 20px;
}

.game-number {
    font-family: 'Noto Serif', Georgia, serif;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text);
}

.game-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-left: 8px;
}

/* --- Input Area --- */
.input-area {
    margin-bottom: 32px;
    position: relative;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

#guessInput {
    flex: 1;
    height: 48px;
    padding: 0 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 16px; /* must be >= 16px to prevent iOS auto-zoom */
    font-weight: 500;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#guessInput:focus {
    border-color: var(--text);
    box-shadow: 0 0 0 1px var(--text);
}

#guessInput::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

.submit-btn {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.submit-btn:hover {
    background: var(--accent-hover);
}

.submit-btn:active {
    transform: scale(0.95);
}

.input-feedback {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: 6px;
    padding: 4px 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: center;
    z-index: 10;
}

.input-feedback:empty {
    display: none;
}

.input-feedback.error {
    color: #9a3412;
}

.input-feedback.success {
    color: #166534;
}

[data-theme="dark"] .input-feedback.error {
    color: #fb923c;
}

[data-theme="dark"] .input-feedback.success {
    color: #4ade80;
}

/* --- Stats Bar --- */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 32px;
    padding: 12px 0;
    margin-bottom: 16px;
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

.stat {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-value {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

.hint-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.hint-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--text-tertiary);
}

.hint-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.giveup-btn {
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: none;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.giveup-btn:hover {
    background: #fef2f2;
    border-color: #c0392b;
    color: #c0392b;
}

[data-theme="dark"] .giveup-btn:hover {
    background: #3a1a1a;
}

.giveup-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Give up / New game container — below guess list */
.giveup-container {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 16px 0 8px;
}

.giveup-container.hidden {
    display: none;
}

.giveup-container .giveup-btn {
    padding: 10px 28px;
    font-size: 0.85rem;
}

.giveup-container .new-game-bottom:hover {
    background: var(--bg-secondary);
    border-color: var(--text-secondary);
    color: var(--text);
}

/* --- Guess List --- */
.guess-list-container {
    flex: 1;
    position: relative;
    overflow-x: hidden;
}

/* Sort toggle */
.sort-toggle.hidden {
    display: none;
}

.sort-toggle {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 3px;
}

.sort-btn {
    flex: 1;
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sort-btn.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.sort-btn:hover:not(.active) {
    color: var(--text);
}

.guess-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.guess-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--rank-cold-bg);
    border: none;
    animation: slideIn 0.35s var(--ease-out) both;
    position: relative;
    overflow: hidden;
    min-height: 44px;
}

/* Rank tier — item base tint + bar fill */
.guess-item.tier-hot {
    background: #d4edda;
}
.guess-item.tier-hot .guess-bar {
    background: var(--rank-hot-bg);
}

.guess-item.tier-warm {
    background: #fdf0d5;
}
.guess-item.tier-warm .guess-bar {
    background: var(--rank-warm-bg);
}

.guess-item.tier-cool {
    background: #f5e6d8;
}
.guess-item.tier-cool .guess-bar {
    background: var(--rank-cool-bg);
}

.guess-item.tier-cold {
    background: #f0e4d8;
}
.guess-item.tier-cold .guess-bar {
    background: var(--rank-cold-bg);
}

/* Correct answer */
.guess-item.correct {
    background: #4caf50;
}
.guess-item.correct .guess-bar {
    background: #66bb6a;
}
.guess-item.correct .guess-rank {
    color: white;
}
.guess-item.correct .guess-word {
    color: white;
    font-weight: 700;
}

.guess-word {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    z-index: 1;
    position: relative;
}

.guess-rank {
    font-family: 'Noto Serif', Georgia, serif;
    font-weight: 700;
    font-size: 0.9rem;
    min-width: 40px;
    text-align: right;
    color: var(--text);
    z-index: 1;
    position: relative;
    flex-shrink: 0;
}

.guess-bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: var(--rank-cold-bg);
    border-radius: 6px 0 0 6px;
    animation: barGrow 0.6s var(--ease-out) 0.15s both;
}

.guess-item.hint-item .guess-word::after {
    content: 'hint';
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(0,0,0,0.08);
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    font-weight: 600;
    color: var(--text-secondary);
}

/* --- Empty State --- */
.empty-state {
    padding: 24px 0;
}

.empty-state.hidden {
    display: none;
}

.empty-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px 20px;
    background: var(--bg-secondary);
}

.empty-title {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 20px;
    color: var(--text);
}

.empty-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.empty-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.empty-step strong {
    color: var(--text);
}

.empty-step-num {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text);
    color: var(--bg);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

.empty-example {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.empty-example-row {
    display: flex;
    align-items: center;
    height: 32px;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
    background: var(--border-light);
}

.empty-ex-bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-radius: 6px;
    transition: width 0.6s var(--ease-out);
}

.empty-example-row.tier-hot .empty-ex-bar {
    background: var(--rank-hot-bg);
}

.empty-example-row.tier-warm .empty-ex-bar {
    background: var(--rank-warm-bg);
}

.empty-example-row.tier-cold .empty-ex-bar {
    background: var(--rank-cold-bg);
}

.empty-ex-word {
    position: relative;
    z-index: 1;
    padding-left: 12px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}

.empty-ex-rank {
    position: relative;
    z-index: 1;
    margin-left: auto;
    padding-right: 12px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg);
    border-radius: 16px;
    width: 100%;
    max-width: 420px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 32px 28px;
    position: relative;
    transform: translateY(16px) scale(0.97);
    transition: transform 0.3s var(--ease-out);
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.modal::-webkit-scrollbar {
    width: 6px;
}

.modal::-webkit-scrollbar-track {
    background: transparent;
    margin: 12px 0;
}

.modal::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 6px;
}

.modal::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

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

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 50%;
    transition: background 0.15s ease;
}

.modal-close:hover {
    background: var(--bg-secondary);
}

.modal h2 {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
}

/* --- Victory Modal --- */
.victory-content {
    text-align: center;
}

.victory-word {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 2rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 24px;
    color: var(--rank-hot);
}

.victory-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 28px;
}

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

.victory-stat-value {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 2rem;
    font-weight: 700;
}

.victory-stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

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

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 24px;
    border-radius: 40px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: none;
    border: 1.5px solid var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--text-tertiary);
}

.share-feedback {
    min-height: 24px;
    padding-top: 10px;
    font-size: 0.8rem;
    color: var(--rank-hot);
    font-weight: 500;
}

.victory-countdown {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.victory-countdown.hidden {
    display: none;
}

.victory-countdown-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.victory-countdown-timer {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text);
}

/* --- Help Modal --- */
.help-lead {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.95rem;
}

.help-rules {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 24px;
}

.help-rule {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.help-rule-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
    padding-top: 2px;
}

.help-rule strong {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.help-rule p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.color-sample {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 2px;
}

.color-sample.hot {
    background: var(--rank-hot);
}

.color-sample.warm {
    background: var(--rank-warm);
}

.color-sample.cold {
    background: var(--rank-cool);
}

.help-footer {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-tertiary);
    font-style: italic;
}

/* --- Tutorial Overlay --- */

.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.tutorial-overlay.hidden {
    display: none;
}

.tutorial-overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    pointer-events: none;
}

.tutorial-spotlight {
    position: absolute;
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    transition: all 0.4s var(--ease-out);
    z-index: 1;
    pointer-events: none;
}

.tutorial-card {
    position: absolute;
    z-index: 2;
    background: var(--bg);
    border-radius: 16px;
    padding: 24px;
    max-width: 340px;
    width: calc(100% - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    animation: tutorialFadeIn 0.35s var(--ease-out);
}

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

.tutorial-step-indicator {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 16px;
}

.tutorial-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s ease;
}

.tutorial-dot.active {
    background: var(--accent);
}

.tutorial-dot.done {
    background: var(--rank-hot);
}

.tutorial-title {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-align: center;
}

.tutorial-text {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.6;
    text-align: center;
    margin-bottom: 20px;
}

.tutorial-example {
    margin: -8px 0 20px;
    border-radius: 10px;
    overflow: hidden;
}

.tutorial-example.hidden {
    display: none;
}

.tutorial-example-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    position: relative;
    overflow: hidden;
    margin-bottom: 4px;
    border-radius: 8px;
}

.tutorial-example-row .guess-bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-radius: 8px;
}

.tutorial-example-row.tier-hot .guess-bar { background: var(--rank-hot-bg); }
.tutorial-example-row.tier-warm .guess-bar { background: var(--rank-warm-bg); }
.tutorial-example-row.tier-cold .guess-bar { background: var(--rank-cold-bg); }
.tutorial-example-row.tier-correct .guess-bar { background: var(--rank-hot); }

.tutorial-example-row .example-word {
    position: relative;
    font-weight: 600;
    font-size: 0.85rem;
    z-index: 1;
}

.tutorial-example-row .example-rank {
    position: relative;
    margin-left: auto;
    font-weight: 700;
    font-size: 0.85rem;
    z-index: 1;
}

.tutorial-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.tutorial-btn {
    padding: 10px 20px;
    border-radius: 24px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.tutorial-skip {
    background: none;
    color: var(--text-tertiary);
}

.tutorial-skip:hover {
    color: var(--text-secondary);
}

.tutorial-next {
    background: var(--accent);
    color: var(--bg);
    flex: 1;
    max-width: 180px;
}

.tutorial-next:hover {
    background: var(--accent-hover);
}

/* --- Statistics Modal --- */
.stats-tab-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 16px;
}

.stats-tab {
    flex: 1;
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.stats-tab:hover {
    color: var(--text-secondary);
}

.stats-tab.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .stats-tab.active {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 24px;
}

.stats-grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 4px;
    background: var(--bg-secondary);
    border-radius: 10px;
}

.stats-grid-value {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.stats-grid-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-top: 2px;
}

.stats-section-title {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 12px;
    text-align: left;
    color: var(--text);
}

.stats-distribution {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stats-dist-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stats-dist-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 48px;
    text-align: right;
    flex-shrink: 0;
}

.stats-dist-bar-bg {
    flex: 1;
    height: 24px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.stats-dist-bar {
    height: 100%;
    background: var(--rank-cool);
    border-radius: 4px;
    min-width: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    transition: width 0.5s var(--ease-out);
}

.stats-dist-bar.highlight {
    background: var(--rank-hot);
}

.stats-dist-count {
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
}

.stats-dist-count.outside {
    color: var(--text-secondary);
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.stats-empty {
    text-align: center;
    padding: 24px 0;
    color: var(--text-tertiary);
    font-size: 0.85rem;
    font-style: italic;
}

/* --- Animations --- */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

@keyframes barGrow {
    from { transform: scaleX(0); transform-origin: left; }
    to   { transform: scaleX(1); transform-origin: left; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.guess-item.just-added {
    animation: slideIn 0.35s var(--ease-out) both, pulse 0.4s var(--ease-in-out) 0.5s;
}
.guess-item.just-added .guess-bar {
    animation: barGrow 0.5s var(--ease-out) 0.25s both;
}

/* --- Responsive --- */
@media (max-width: 480px) {
    .header-title h1 {
        font-size: 1.15rem;
    }

    .stats-bar {
        gap: 20px;
    }

    .victory-stats {
        gap: 28px;
    }

    .modal {
        padding: 24px 20px;
    }
}

@media (min-width: 768px) {
    :root {
        --max-width: 560px;
    }

    .main {
        padding-top: 32px;
    }
}

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

/* Scrollbar styling */
.guess-list-container {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.guess-list-container::-webkit-scrollbar {
    width: 4px;
}

.guess-list-container::-webkit-scrollbar-track {
    background: transparent;
}

.guess-list-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
}

/* --- Loading spinner (shown in submit button during API calls) --- */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

#guessInput:disabled {
    opacity: 0.6;
}

.submit-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

/* ============================================
   Dark Mode
   ============================================ */

[data-theme="dark"] {
    --bg: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --text: #e8e8e8;
    --text-secondary: #a0a0a0;
    --text-tertiary: #707070;
    --border: #3a3a3a;
    --border-light: #2d2d2d;

    --rank-hot: #66bb6a;
    --rank-hot-bg: #2e5a30;
    --rank-warm: #d4a843;
    --rank-warm-bg: #4a3d1a;
    --rank-cool: #a07850;
    --rank-cool-bg: #3d2e1e;
    --rank-cold: #8a6a50;
    --rank-cold-bg: #352a20;

    --accent: #e8e8e8;
    --accent-hover: #cccccc;
}

[data-theme="dark"] .submit-btn {
    color: #1a1a1a;
}

[data-theme="dark"] .guess-item {
    background: #2a2a2a;
}
[data-theme="dark"] .guess-item.tier-hot {
    background: #1e3a1e;
}
[data-theme="dark"] .guess-item.tier-warm {
    background: #3a3018;
}
[data-theme="dark"] .guess-item.tier-cool {
    background: #332a20;
}
[data-theme="dark"] .guess-item.tier-cold {
    background: #2c2420;
}

[data-theme="dark"] .guess-item.correct {
    background: #2d7a2d;
}

[data-theme="dark"] .guess-item.correct .guess-rank {
    color: #e0e0e0;
}

[data-theme="dark"] .modal {
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

[data-theme="dark"] .spinner {
    border-color: rgba(0, 0, 0, 0.3);
    border-top-color: #1a1a1a;
}

/* ============================================
   Settings Modal
   ============================================ */

.settings-group {
    background: var(--bg-secondary);
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    gap: 12px;
}

.settings-row-btn {
    cursor: pointer;
    transition: background 0.15s ease;
    text-decoration: none;
    color: inherit;
}

.settings-row-btn:hover {
    background: var(--border-light);
}

a.settings-row-btn {
    display: flex;
}

.settings-row-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.settings-row-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}

.settings-row-info strong {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
}

.settings-row-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-top: 1px;
}

.settings-row-arrow {
    flex-shrink: 0;
    color: var(--text-tertiary);
}

/* ── Header Mode Row ── */

.header-mode-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 14px;
}

.header-mode-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 3px;
    width: 200px;
}

/* ── New Game Button ── */

.new-game-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.new-game-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--text-tertiary);
    color: var(--text);
}

.new-game-btn:active {
    transform: scale(0.96);
}

.new-game-btn svg {
    transition: transform 0.3s var(--ease-out);
}

.new-game-btn:hover svg {
    transform: rotate(-45deg);
}

.header-mode-btn {
    flex: 1;
    padding: 6px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.02em;
}

.header-mode-btn:hover {
    color: var(--text-secondary);
}

.header-mode-btn.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .header-mode-btn.active {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* ── Settings Radio Group ── */

.settings-radio-group {
    padding: 0 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-radio {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.settings-radio:hover {
    background: var(--bg);
}

.settings-radio input[type="radio"] {
    display: none;
}

.radio-mark {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    margin-top: 1px;
    position: relative;
    transition: border-color 0.2s ease;
}

.radio-mark::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--accent);
    transform: scale(0);
    transition: transform 0.2s var(--ease-out);
}

.settings-radio input[type="radio"]:checked ~ .radio-mark {
    border-color: var(--accent);
}

.settings-radio input[type="radio"]:checked ~ .radio-mark::after {
    transform: scale(1);
}

.radio-content strong {
    display: block;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

.radio-content p {
    font-size: 0.76rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin-top: 1px;
}

.settings-divider {
    height: 1px;
    background: var(--border-light);
    margin: 0 16px;
}

.settings-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 20px;
    padding-top: 4px;
}

/* ── Toggle Switch ── */

.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 28px;
    transition: background 0.25s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s var(--ease-out);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider {
    background: var(--rank-hot);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle input:focus-visible + .toggle-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================
   Privacy Policy Modal
   ============================================ */

.privacy-body {
    text-align: left;
}

.privacy-updated {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    font-style: italic;
    margin-bottom: 20px;
}

.privacy-body h3 {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1rem;
    font-weight: 700;
    margin-top: 20px;
    margin-bottom: 6px;
    color: var(--text);
}

.privacy-body p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.65;
    margin-bottom: 8px;
}

.privacy-body a {
    color: var(--rank-hot);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.privacy-body a:hover {
    opacity: 0.8;
}

/* ── Challenge Page ── */

.challenge-creator {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
    padding: 20px;
}

.challenge-card {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.challenge-title {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.challenge-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.challenge-feedback {
    min-height: 24px;
    padding-top: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

.challenge-feedback.error {
    color: #c0392b;
}

.challenge-feedback.success {
    color: var(--rank-hot);
}

.challenge-link-box {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    text-align: left;
}

.challenge-link-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.challenge-link-row {
    display: flex;
    gap: 8px;
}

.challenge-link-input {
    flex: 1;
    height: 40px;
    padding: 0 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text);
    background: var(--bg);
    outline: none;
}

.challenge-copy-btn {
    padding: 8px 16px;
    font-size: 0.8rem;
    border-radius: 8px;
}

.challenge-copy-feedback {
    min-height: 20px;
    padding-top: 6px;
    font-size: 0.75rem;
    color: var(--rank-hot);
    font-weight: 500;
}

#challengeWordInput {
    flex: 1;
    height: 48px;
    padding: 0 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#challengeWordInput:focus {
    border-color: var(--text);
    box-shadow: 0 0 0 1px var(--text);
}

#challengeWordInput::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

#challengeWordInput:disabled {
    opacity: 0.6;
}

/* ============================================
   Burger Menu (Mobile)
   ============================================ */

.burger-btn {
    width: 40px;
    height: 40px;
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    border-radius: 50%;
    transition: background 0.15s ease;
}

.burger-btn:hover {
    background: var(--bg-secondary);
}

.burger-menu {
    display: none;
    position: absolute;
    top: var(--header-height);
    right: 0;
    left: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    z-index: 99;
    flex-direction: column;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s var(--ease-out), opacity 0.2s ease;
}

.burger-menu.open {
    max-height: 280px;
    opacity: 1;
}

.burger-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s ease;
    text-decoration: none;
}

.burger-menu-item:hover {
    background: var(--bg-secondary);
}

.burger-menu-item svg {
    flex-shrink: 0;
    color: var(--text-secondary);
}

[data-theme="dark"] .burger-menu {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@media (max-width: 480px) {
    .burger-btn {
        display: flex;
    }

    .burger-menu {
        display: flex;
    }

    .header-actions {
        display: none !important;
    }

    .header-left {
        display: none !important;
    }

    .header-inner {
        padding: 0 8px 0 16px;
    }

    a.header-title {
        text-align: left;
        flex: 1;
    }

    .header-subtitle {
        display: none;
    }

    .header-title h1 {
        font-size: 1.2rem;
    }
}
