/* ===== CSS Variables ===== */
:root {
    --forest: #216036;
    --forest-bright: #4DB873;
    --baby-blue: #87C2ED;
    --baby-blue-bright: #8CC7F2;
    --gold: #CCA61A;

    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --text-muted: #8c8c8c;
    --background: #ffffff;

    --clue-bg: rgba(33, 96, 54, 0.07);
    --clue-border: rgba(33, 96, 54, 0.18);

    --row-fill: #f5f7f5;
    --row-border: rgba(33, 96, 54, 0.15);

    --selected-fill: rgba(135, 194, 237, 0.12);
    --selected-border: #87C2ED;

    --solved: #278C4D;
    --solved-fill: rgba(39, 140, 77, 0.10);
    --solved-border: rgba(39, 140, 77, 0.35);

    --wrong: #BF2626;
    --wrong-fill: rgba(191, 38, 38, 0.08);
    --wrong-border: rgba(191, 38, 38, 0.30);
}

[data-theme="dark"] {
    --forest: #4DB873;
    --baby-blue: #8CC7F2;
    --gold: #F2CC40;

    --text-primary: #ffffff;
    --text-secondary: #b8b8b8;
    --text-muted: #8c8c8c;
    --background: #141416;

    --clue-bg: rgba(77, 184, 115, 0.10);
    --clue-border: rgba(77, 184, 115, 0.30);

    --row-fill: #242826;
    --row-border: rgba(77, 184, 115, 0.25);

    --selected-fill: rgba(140, 199, 242, 0.15);
    --selected-border: #8CC7F2;

    --solved: #59C880;
    --solved-fill: rgba(89, 200, 128, 0.12);
    --solved-border: rgba(89, 200, 128, 0.40);

    --wrong: #F26666;
    --wrong-fill: rgba(242, 102, 102, 0.12);
    --wrong-border: rgba(242, 102, 102, 0.35);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100dvh;
    transition: background 0.3s, color 0.3s;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    position: relative;
}

/* ===== Top Bar ===== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0 0;
    position: relative;
}

.header-logo {
    position: absolute;
    left: 0;
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--forest);
}

.menu-btn {
    position: absolute;
    right: 0;
    background: none;
    border: none;
    color: var(--forest);
    cursor: pointer;
    padding: 4px;
}

.date-label {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 4px 0 12px;
}

/* ===== Landing Page ===== */
.landing-page {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--baby-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.35s ease;
}
.landing-content {
    text-align: center;
    padding: 0 32px;
}
.landing-logo {
    width: 100px;
    height: 100px;
    object-fit: contain;
    margin-bottom: 16px;
}
.landing-title {
    font-size: 38px;
    font-weight: 900;
    letter-spacing: 5px;
    color: #fff;
    margin: 0 0 8px;
}
.landing-tagline {
    font-size: 15px;
    color: rgba(255,255,255,0.85);
    margin: 0 0 32px;
    line-height: 1.5;
}
.landing-play-btn {
    display: inline-block;
    width: 200px;
    padding: 14px 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--forest);
    background: #fff;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.15s ease, opacity 0.2s;
    margin-bottom: 24px;
}
.landing-play-btn:disabled {
    opacity: 0.5;
    cursor: default;
}
.landing-play-btn:not(:disabled):active {
    transform: scale(0.97);
}
.landing-info {
    min-height: 40px;
}
.landing-date {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255,255,255,0.8);
    margin: 0 0 4px;
}
.landing-puzzle-num {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.6);
    margin: 0;
}
.landing-loading {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255,255,255,0.6);
    margin: 0;
}
.landing-app-link {
    display: inline-block;
    margin-top: 32px;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    transition: color 0.2s;
}
.landing-app-link:hover {
    color: #fff;
}

/* ===== Loading Message ===== */
.loading-message {
    text-align: center;
    padding: 80px 0;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
}

/* ===== Game Area ===== */
.game-area {
    flex: 1;
    overflow-y: auto;
}

/* ===== Clues Card ===== */
.clues-card {
    background: var(--clue-bg);
    border: 1px solid var(--clue-border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
}

.clue-row {
    display: grid;
    grid-template-columns: 48px auto 1fr;
    gap: 0 8px;
    align-items: baseline;
    padding: 4px 0;
}

.clue-label {
    font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
    font-weight: 700;
    color: var(--forest);
    text-align: right;
    white-space: nowrap;
}

.clue-equals {
    font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
    font-weight: 700;
    color: var(--forest);
}

.clue-text {
    font-size: 13px;
    color: var(--text-primary);
}

/* ===== Letter Rows ===== */
.letter-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.letter-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--row-fill);
    border: 1px solid var(--row-border);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.letter-row:hover:not(.solved):not(.revealed):not(.disabled) {
    border-color: var(--selected-border);
}

.letter-row.selected {
    background: var(--selected-fill);
    border-color: var(--selected-border);
    border-width: 2px;
    padding: 9px 13px;
}

.letter-row.solved {
    background: var(--solved-fill);
    border-color: var(--solved-border);
    cursor: default;
}

.letter-row.revealed {
    background: var(--wrong-fill);
    border-color: var(--wrong-border);
    cursor: default;
}

.letter-row.disabled {
    cursor: default;
}

.letter-badge {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: white;
    background: var(--forest);
    flex-shrink: 0;
}

.letter-row.selected .letter-badge {
    background: var(--baby-blue);
}

.letter-row.solved .letter-badge {
    background: var(--solved);
}

.letter-row.revealed .letter-badge {
    background: var(--wrong);
}

.row-content {
    flex: 1;
    margin-left: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.row-word {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.row-word.revealed-word {
    color: var(--wrong);
}

.row-hint {
    font-size: 14px;
    color: var(--text-muted);
}

.row-prompt {
    font-size: 14px;
    color: var(--text-muted);
}

.homophone-hint {
    font-size: 9px;
    color: var(--text-muted);
}

.row-status {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 18px;
}

.status-check {
    color: var(--solved);
}

.status-x {
    color: var(--wrong);
}

.status-chevron {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
}

/* ===== Bottom Bar ===== */
.bottom-bar {
    padding: 8px 0 16px;
}

.feedback {
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    min-height: 20px;
    transition: color 0.3s;
}

.feedback.correct {
    color: var(--solved);
}

.feedback.wrong {
    color: var(--wrong);
}

.wrong-counter {
    text-align: center;
    font-size: 12px;
    color: var(--wrong);
    min-height: 16px;
}

/* ===== Game Over ===== */
.game-over {
    text-align: center;
    padding: 12px 0;
}

.game-over-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 12px;
}

.game-over-title.win {
    color: var(--gold);
}

.game-over-title.lose {
    color: var(--wrong);
}

.game-over-title.completed {
    color: var(--text-secondary);
}

.share-preview {
    font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
    text-align: center;
    padding: 12px;
    background: var(--clue-bg);
    border: 1px solid var(--clue-border);
    border-radius: 12px;
    margin-bottom: 12px;
    white-space: pre-line;
    line-height: 1.6;
}

/* ===== Input Bar ===== */
.input-bar {
    text-align: center;
}

.input-prompt {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.input-prompt.active {
    font-weight: 700;
    color: var(--forest);
}

.input-row {
    display: flex;
    gap: 10px;
}

.input-row input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--row-border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--background);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

.input-row input:focus {
    border-color: var(--forest);
}

.input-row input:disabled {
    opacity: 0.5;
}

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

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

.btn-primary:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-outline {
    background: transparent;
    color: var(--forest);
    border: 1.5px solid var(--forest);
}

.btn-outline:hover:not(:disabled) {
    background: var(--clue-bg);
}

/* ===== Menu Dropdown ===== */
.menu-dropdown {
    position: absolute;
    top: 50px;
    right: 16px;
    background: var(--background);
    border: 1px solid var(--clue-border);
    border-radius: 12px;
    padding: 8px 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    z-index: 100;
    min-width: 220px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 15px;
    cursor: pointer;
    text-align: left;
}

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

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

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.menu-toggle label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    color: var(--text-primary);
    cursor: pointer;
}

.menu-toggle label svg {
    color: var(--forest);
    flex-shrink: 0;
}

/* Toggle Switch */
.toggle-switch {
    -webkit-appearance: none;
    appearance: none;
    width: 44px;
    height: 24px;
    border-radius: 12px;
    background: var(--text-muted);
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle-switch:checked {
    background: var(--forest);
}

.toggle-switch::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    transition: transform 0.3s;
}

.toggle-switch:checked::before {
    transform: translateX(20px);
}

/* ===== Modals ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal {
    background: var(--background);
    border-radius: 16px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-content {
    text-align: center;
}

.modal-content h2 {
    font-size: 22px;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.modal-content p {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 12px;
}

.modal-content .icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.page-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 16px 0;
}

.page-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    opacity: 0.3;
    transition: opacity 0.3s, background 0.3s;
}

.page-dot.active {
    background: var(--forest);
    opacity: 1;
}

.modal-nav {
    display: flex;
    gap: 12px;
}

.modal-nav .btn {
    flex: 1;
    padding: 14px;
}

/* ===== How to Play specific ===== */
.example-box {
    background: var(--clue-bg);
    border: 1px solid var(--clue-border);
    border-radius: 12px;
    padding: 16px;
    margin: 12px 0;
    text-align: left;
}

.example-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 0 8px;
    padding: 4px 0;
}

.example-label {
    font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--forest);
    text-align: right;
}

.example-eq {
    font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--forest);
}

.example-text {
    font-size: 14px;
    color: var(--text-primary);
}

.rule-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    text-align: left;
    margin-bottom: 12px;
}

.rule-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.rule-text {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

.badge-example {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 700;
    vertical-align: middle;
}

.badge-filled {
    background: var(--forest);
    color: white;
}

.badge-outlined {
    border: 2.5px solid var(--forest);
    color: var(--forest);
    background: rgba(33, 96, 54, 0.15);
}

.hint-box {
    background: var(--selected-fill);
    border: 1px solid var(--selected-border);
    border-radius: 12px;
    padding: 16px;
    margin-top: 12px;
}

/* ===== Stats ===== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 16px;
}

.stats-grid-4 {
    grid-template-columns: 1fr 1fr 1fr 1fr;
}

.streak-number {
    color: var(--forest) !important;
}

.best-streak-number {
    color: var(--gold) !important;
}

.stat-card {
    background: var(--clue-bg);
    border: 1px solid var(--clue-border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.stat-number {
    font-size: 28px;
    font-weight: 800;
    color: var(--forest);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.stat-bars {
    display: grid;
    grid-template-columns: 70px 1fr 60px;
    gap: 8px 12px;
    align-items: center;
    margin-top: 20px;
}

.stat-bar-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
}

.stat-bar-track {
    height: 24px;
    background: var(--clue-bg);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--forest);
    min-width: 4px;
    transition: width 0.5s;
}

.stat-bar-count {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: left;
}

/* ===== Archive Calendar ===== */
.archive-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}

.archive-nav-btn {
    background: none;
    border: none;
    font-size: 24px;
    font-weight: 700;
    color: var(--forest);
    cursor: pointer;
    padding: 4px 12px;
}

.archive-nav-btn:disabled {
    color: var(--text-muted);
    opacity: 0.3;
    cursor: default;
}

.archive-month {
    font-size: 18px;
    font-weight: 700;
    color: var(--forest);
    min-width: 160px;
    text-align: center;
}

.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 4px;
}

.calendar-header-day {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
    padding: 4px 0;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    cursor: default;
    color: var(--text-muted);
    position: relative;
}

.calendar-day.playable {
    font-weight: 700;
    color: var(--forest);
    background: var(--selected-fill);
    cursor: pointer;
}

.calendar-day.playable:hover {
    background: var(--selected-border);
    color: white;
}

.calendar-day.completed {
    font-weight: 700;
    color: var(--solved);
    background: var(--solved-fill);
    cursor: pointer;
}

.calendar-day.completed:hover {
    background: var(--solved-border);
    color: white;
}

.calendar-day.today {
    outline: 2px solid var(--forest);
    outline-offset: -2px;
}

.calendar-day.empty {
    visibility: hidden;
}

/* ===== Modal Header & Close ===== */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--clue-border);
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

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

/* ===== Settings Modal ===== */
.settings-modal {
    max-width: 400px;
    width: 90%;
    padding: 24px 28px;
}

.settings-section {
    padding: 16px 0;
    border-bottom: 1px solid var(--clue-border);
}

.settings-section:last-child {
    border-bottom: none;
    padding-bottom: 8px;
}

.settings-section h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 14px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}

.settings-row label {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 15px;
    color: var(--text-primary);
}

.settings-row label svg {
    color: var(--forest);
    flex-shrink: 0;
}

.settings-contact {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    padding: 10px 0;
}

.settings-contact svg {
    color: var(--forest);
    flex-shrink: 0;
}

.settings-contact:hover {
    color: var(--forest);
}

/* ===== Coffee Link ===== */
.coffee-fixed {
    display: block;
    text-align: center;
    padding: 16px 0 24px;
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.coffee-fixed:hover {
    color: var(--forest);
}

@media (max-width: 400px) {
    .title {
        font-size: 24px;
        letter-spacing: 3px;
    }

    .modal {
        padding: 16px;
        max-height: 90vh;
    }

    .menu-dropdown {
        right: 8px;
        min-width: 200px;
    }
}
