:root {
    --nyt-green: #6aaa64;
    --nyt-yellow: #c9b458;
    --nyt-gray: #787c7e;
    --nyt-light-gray: #d3d6da;
    --nyt-bg: #ffffff;
    --nyt-black: #121212;
    --nyt-off-white: #f8f8f8;
    --correct: var(--nyt-green);
    --warning: var(--nyt-yellow);
    --error-red: #e02424;
    --border-color: var(--nyt-light-gray);
    --filled-border: #878a8c;
    --text-primary: var(--nyt-black);
}

body {
    margin: 0;
    background-color: var(--nyt-bg);
    color: var(--text-primary);
    font-family: 'Helvetica Neue', Arial, sans-serif;
    min-height: 100vh; /* Changed from height: 100vh to min-height */
    display: flex;
    flex-direction: column;
    user-select: none;
    overflow-y: auto; /* Allow vertical scrolling */
}

/* --- HEADER --- */
.nyt-header {
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.header-content {
    width: 100%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}
.game-title {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-weight: 700;
    font-size: 30px;
    margin: 0;
    text-align: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    letter-spacing: -0.5px;
    white-space: nowrap;
}
.header-left, .header-right {
    display: flex;
    align-items: center;
    width: 80px;
}
.header-right { justify-content: flex-end; gap: 6px; }

.date-text {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 18px;
    font-weight: 500;
    white-space: nowrap;
}
.info-btn {
    background: none;
    border: 2px solid var(--nyt-black);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    color: var(--nyt-black);
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: serif;
    transition: all 0.2s;
}
.info-btn:hover {
    background: var(--nyt-black);
    color: white;
}
.stats-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--nyt-black);
    font-size: 20px;
    line-height: 1;
    padding: 2px 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stats-btn:hover { color: var(--nyt-gray); }

/* --- LAYOUT --- */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 20px 20px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    /* Removed overflow: hidden so content can expand */
}

/* --- BOARD --- */
.board-area {
    width: 100%;
    display: flex;
    justify-content: center;
    /* Removed flex-shrink: 0 */
}
.board {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 100%;
    padding-bottom: 10px;
}
.board-row {
    height: 55px;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.2s, background-color 0.2s;
    background-color: white;
}
.board-row:active { transform: scale(0.98); }
.valid-target:hover { background-color: var(--nyt-off-white); border-color: var(--nyt-gray); }
.forced-move { background-color: var(--nyt-yellow) !important; border-color: var(--nyt-yellow) !important; }
.lost-row    { background-color: var(--error-red) !important; border-color: var(--error-red) !important; opacity: 0.8; }
.has-number  { border-color: var(--nyt-gray); background-color: white; animation: popIn 0.15s ease-in-out; }

@keyframes popIn {
    0%   { transform: scale(0.95); }
    100% { transform: scale(1); }
}
.row-index {
    width: 40px;
    text-align: center;
    font-size: 12px;
    color: var(--nyt-gray);
    font-weight: 500;
}
.forced-move .row-index, .lost-row .row-index { color: rgba(255,255,255,0.8); }
.row-value {
    flex: 1;
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    color: var(--nyt-black);
}
.board-row.won { background-color: var(--nyt-green); border-color: var(--nyt-green); }
.board-row.won .row-value, .board-row.won .row-index { color: white; }

/* --- DASHBOARD --- */
.dashboard {
    width: 100%;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: white;
    /* Removed flex-shrink: 0 */
}
.status-section { text-align: center; }
.status-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--nyt-gray);
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.current-number-display {
    font-size: 36px;
    font-weight: 700;
    color: var(--nyt-black);
    line-height: 1;
}

/* --- BUTTONS --- */
.nyt-btn {
    background-color: var(--nyt-yellow);
    color: white;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    font-size: 14px;
    border: none;
    border-radius: 20px;
    padding: 12px 30px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.nyt-btn:hover { background-color: var(--nyt-yellow) }
.nyt-btn.warning { background-color: var(--nyt-yellow); color: white; }

/* Practice specific buttons */
.practice-btn {
    background-color: var(--nyt-green);
    width: 100%;
    margin-bottom: 10px;
}
.practice-btn:hover { background-color: #4a7c43; }

.practice-exit-btn {
    background-color: var(--nyt-green);
    margin-bottom: 4px;
}
.practice-exit-btn:hover { background-color: #4a7c43; }

.hidden { display: none !important; }

/* --- IN-GAME STATS BAR --- */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}
.stat-item { display: flex; flex-direction: column; align-items: center; }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 10px; text-transform: uppercase; color: var(--nyt-gray); }
.stat-divider { width: 1px; height: 25px; background-color: var(--border-color); }

/* --- GAME OVER / VICTORY MODAL --- */
.overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255,255,255,0.8);
    backdrop-filter: blur(2px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    text-align: center;
    position: relative;
    max-width: 300px;
    width: 90%;
}
.modal-close {
    position: absolute; top: 10px; right: 10px;
    background: none; border: none;
    font-size: 18px; color: var(--nyt-gray); cursor: pointer;
}
.modal h2 { font-family: 'Georgia', serif; margin-top: 0; font-size: 24px; }
.modal-content { font-size: 16px; color: var(--nyt-black); line-height: 1.5; }

/* --- STATS MODAL --- */
.stats-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 150;
}
.stats-modal {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    animation: slideUp 0.25s ease;
}
.stats-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e0e0e0;
    position: relative;
}
.stats-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #000;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.stats-close {
    background: none; border: none;
    cursor: pointer; color: #333;
    font-size: 20px; line-height: 1;
    padding: 2px 4px; margin-left: auto;
}
.stats-body { padding: 20px 24px 24px; }

/* Top stats row */
.stats-top-row {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
}
.stats-top-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.stats-top-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--nyt-black);
    line-height: 1;
}
.stats-top-label {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--nyt-gray);
    text-align: center;
    line-height: 1.3;
}

/* Distribution graph */
.dist-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #333;
    margin-bottom: 10px;
    text-align: center;
}
.dist-bars { display: flex; flex-direction: column; gap: 4px; margin-bottom: 20px; }
.dist-row  { display: flex; align-items: center; gap: 8px; }
.dist-label {
    width: 16px;
    font-size: 12px;
    font-weight: 700;
    color: var(--nyt-black);
    text-align: right;
    flex-shrink: 0;
}
.dist-bar-wrap { flex: 1; }
.dist-bar {
    background: var(--nyt-gray);
    border-radius: 2px;
    height: 20px;
    min-width: 20px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    transition: width 0.4s ease;
    box-sizing: border-box;
}
.dist-bar-fail      { background: var(--error-red); }
.dist-bar-highlight { background: var(--nyt-green); }
.dist-count {
    font-size: 11px;
    font-weight: 700;
    color: white;
}

/* Divider */
.stats-divider { height: 1px; background: #e0e0e0; margin: 16px 0; }

/* Countdown + share row */
.stats-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.countdown-section { text-align: center; flex: 1; }
.countdown-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--nyt-gray);
    margin-bottom: 4px;
}
.countdown-timer {
    font-size: 24px;
    font-weight: 700;
    color: var(--nyt-black);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}
.footer-divider { width: 1px; height: 40px; background: #e0e0e0; flex-shrink: 0; }

/* Modified Share Section */
.share-section {
    flex: 1;
    display: flex;
    flex-direction: column; /* Stack vertically */
    align-items: center;
    gap: 8px; /* Space between buttons */
    justify-content: center;
}

/* View Results Button */
.view-results-btn {
    background: none;
    border: 1px solid var(--nyt-green);
    color: var(--nyt-green);
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    font-size: 12px;
    border-radius: 20px;
    padding: 8px 16px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.15s;
    width: 100%;
    max-width: 140px;
}
.view-results-btn:hover {
    background-color: #f0f8f0;
}

/* Main Share Button */
.share-btn {
    background-color: var(--nyt-green);
    color: white;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    font-size: 12px;
    border: none;
    border-radius: 20px;
    padding: 10px 16px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: background-color 0.15s;
    width: 100%;
    max-width: 140px;
}
.share-btn:hover { background-color: #4a7c43; }


/* --- RESULTS VISUAL MODAL --- */
.results-modal-width {
    max-width: 360px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.results-grid-box {
    background-color: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0 20px;
    white-space: pre; /* Keeps newlines */
    font-family: sans-serif;
    line-height: 1.4;
    font-size: 14px;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
}

/* --- HOW TO PLAY MODAL (Updated) --- */
.htp-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
    z-index: 200;
}
.htp-modal {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    animation: slideUp 0.25s ease;
    margin: auto;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.htp-header {
    display: flex; align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e0e0e0;
    position: relative;
}
.htp-title {
    font-size: 13px; font-weight: 700;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: #000;
    position: absolute; left: 50%; transform: translateX(-50%);
}
.htp-close {
    background: none; border: none; cursor: pointer;
    color: #333; font-size: 20px; line-height: 1;
    padding: 2px 4px; margin-left: auto;
}
.htp-body { padding: 20px 24px 24px; }
.htp-game-title {
    font-size: 28px; font-weight: 900;
    letter-spacing: -0.5px; color: #000;
    font-family: 'Georgia', serif;
    text-align: center; margin-bottom: 4px;
}
.htp-divider  { height: 1px; background: #e0e0e0; margin: 14px 0; }

/* HTP Simple Rules */
.htp-simple-section { margin: 12px 0; }
.htp-rules-simple {  list-style-position: outside; padding-left: 20px; margin: 0; }
.htp-rules-simple li { font-size: 14px; line-height: 1.6; margin-bottom: 8px; color: #111; }

.htp-color-explainer { display: flex; flex-direction: column; gap: 8px; }
.htp-color-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #111; }
.htp-dot { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.htp-dot-green  { background: #538d4e; }
.htp-dot-yellow { background: #b59f3b; }
.htp-dot-red    { background: #c0392b; }

.htp-actions { display: flex; flex-direction: column; align-items: center; margin-top: 20px; gap: 10px; }
.htp-link-btn {
    background: none; border: none;
    color: var(--nyt-gray);
    font-size: 15px;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    font-family: 'Helvetica Neue', Arial, sans-serif;
}
.htp-link-btn:hover { color: var(--nyt-black); }

/* NEW CSS for Contact Link */
.htp-contact-section {
    text-align: center;
    margin-top: 10px;
    padding-bottom: 10px;
}
.htp-contact-link {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 12px;
    color: var(--nyt-gray);
    text-decoration: none;
    cursor: pointer;
}
.htp-contact-link:hover {
    text-decoration: underline;
    color: var(--nyt-black);
}

/* --- LIVES SHAKE --- */
@keyframes livesShake {
    0%   { transform: translateX(0);    color: var(--nyt-black); }
    20%  { transform: translateX(-4px); color: var(--nyt-yellow); }
    40%  { transform: translateX(4px);  color: var(--nyt-yellow); }
    60%  { transform: translateX(-4px); color: var(--nyt-yellow); }
    80%  { transform: translateX(4px);  color: var(--nyt-yellow); }
    100% { transform: translateX(0);    color: var(--nyt-black); }
}
.lives-shake { display: inline-block; animation: livesShake 0.4s ease-in-out; }

/* --- MOBILE --- */
@media (max-width: 600px) {
    .game-container  { padding: 8px 10px 10px; }
    .board-row       { height: 45px; }
    .current-number-display { font-size: 32px; }
    .header-left, .header-right { width: 60px; }
    .stats-footer    { flex-direction: column; }
    .footer-divider  { width: 40px; height: 1px; }
}