/**
 * Mobile-First Responsive Design
 * Base styles for mobile, with desktop enhancements
 */

/* Box sizing reset - critical for mobile */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Reset for full-screen mobile experience.
 * body is the viewport-height flex column so that the arcade topbar
 * (when present) and the game shell share the screen without overflow.
 * 100dvh handles iOS Safari's resizable URL bar; 100vh is the fallback.
 */
html, body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100%;
    overscroll-behavior: none;
}
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Prevent popup scroll when open */
body.popup-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Main game container — fills whatever space is left after the arcade
 * topbar (if any) on mobile. body is the 100dvh flex column; .game-shell
 * takes flex: 1 and uses min-height: 0 so its internal scroll regions
 * can shrink to fit. */
.game-shell {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
    margin: 0;
    max-width: none;
    background: var(--bg-default);
    position: relative;
}

/* Header - minimal on mobile */
.game-shell header {
    flex-shrink: 0;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-default);
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: var(--space-2);
}

.game-shell header h1 {
    font-size: var(--type-h4);
    margin: 0;
    text-align: center;
}

.header-left {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.header-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-600);
    color: white;
    border: none;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-icon-btn--secondary {
    background: var(--zinc-200, #e5e7eb);
    color: var(--text-default);
    font-size: 14px;
}

.header-score {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1;
}

.header-score__label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-subtle);
    margin-bottom: 2px;
}

.header-score__value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-600);
    transition: color 0.2s ease;
    font-variant-numeric: tabular-nums;
}

.header-score__value.updating {
    color: var(--amber-400, #d97706);
}

.header-btn {
    padding: var(--space-2) var(--space-3);
    background: var(--primary-600);
    color: white;
    border: none;
    border-radius: var(--radius-m);
    font-size: var(--type-small);
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
}

/* Main game area - use all available space */
.game-prompt {
    flex: 1;
    display: flex;
    overflow: hidden;
    padding: 0;
}

/* Guess card - full height */
.guess-card {
    width: 100%;
    max-width: none;
    height: 100%;
    min-height: 0; /* Important for flexbox */
    border: none;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Game content area - scrollable */
.guess-card-header {
    flex-shrink: 0;
    padding: var(--space-2);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-default);
}

/* Letter slots - Wordle-style boxes for the word pattern */
.letter-slots {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    padding: var(--space-2) 0;
    margin-bottom: var(--space-2);
}

.letter-slot {
    width: 38px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-default);
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-600);
    background: var(--bg-default);
    text-transform: uppercase;
    transition: transform 0.15s ease, border-color 0.2s ease;
}

.letter-slot.revealed {
    border-color: var(--primary-600);
    background: var(--zinc-50);
}

.letter-slot.unknown {
    color: transparent;
}

.letter-slot.solved {
    background: var(--primary-600);
    border-color: var(--primary-600);
    color: white;
    transform: scale(1.05);
}

/* Compact primary definition */
.primary-definition-compact {
    font-size: var(--font-size-sm);
    color: var(--text-subtle);
    line-height: 1.3;
    flex: 1;
    text-align: center;
    padding: 0 var(--space-2);
}

/* Inline clue rail - always-visible clue affordances */
.clue-rail {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-3);
    border-bottom: 1px dashed var(--border-default);
}

.clue-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    background: var(--bg-default);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
}

.clue-chip:hover:not(:disabled) {
    border-color: var(--primary-600);
    transform: translateY(-1px);
}

.clue-chip:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.clue-chip .clue-chip__cost {
    color: var(--text-subtle);
    font-size: 11px;
}

.clue-chip[data-used="true"] {
    opacity: 0.4;
    text-decoration: line-through;
}

/* Mobile optimizations for header */
@media (max-width: 480px) {
    .letter-slot {
        width: 30px;
        height: 36px;
        font-size: 1.15rem;
    }

    .primary-definition-compact {
        font-size: 0.875rem;
        line-height: 1.2;
    }

    .guess-card-header {
        padding: var(--space-1) var(--space-2);
    }

    .clue-chip {
        font-size: 12px;
        padding: 5px 8px;
    }
}

.guess-card-scroll {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
    -webkit-overflow-scrolling: touch;
}

/* Action area - always visible at bottom */
.action-area {
    flex-shrink: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-default);
    padding: var(--space-3);
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
}

/* Message area */
.action-area .message-area {
    min-height: 24px;
    margin-bottom: var(--space-2);
    text-align: center;
    font-size: var(--type-small);
}

/* Input field - larger and more prominent */
#guess-input {
    width: 100%;
    max-width: 100%;
    padding: var(--space-4);
    font-size: 18px; /* Prevents zoom on iOS */
    text-align: center;
    border: 2px solid var(--border-default);
    border-radius: var(--radius-m);
    margin-bottom: var(--space-3);
    background: var(--bg-default);
    -webkit-appearance: none; /* Remove iOS styling */
    box-sizing: border-box;
}

#guess-input:focus {
    border-color: var(--primary-600);
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 109, 111, 0.2);
}

/* Guess history — chip row showing previously-tried words. */
.guess-history {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: var(--space-2);
    min-height: 0;
    max-height: 64px;          /* Two rows max, then scroll. */
    overflow-y: auto;
    align-content: flex-start;
}
.guess-history:empty {
    display: none;
}
.guess-chip {
    display: inline-block;
    padding: 3px 8px;
    background: var(--zinc-100, #f1f5f9);
    color: var(--text-subtle);
    border: 1px solid var(--border-default);
    border-radius: 999px;
    font-size: 12px;
    line-height: 1.4;
    text-decoration: line-through;
    text-decoration-color: rgba(0,0,0,0.4);
    white-space: nowrap;
}
[data-theme="dark"] .guess-chip {
    background: var(--zinc-100);
    color: var(--text-subtle);
}

/* Action buttons - improved grid layout */
.action-buttons {
    display: grid;
    grid-template-columns: 1.6fr 1fr 1.1fr;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.action-btn {
    white-space: nowrap;
}

.action-btn {
    padding: var(--space-3);
    min-height: 48px;
    border: none;
    border-radius: var(--radius-m);
    font-size: var(--type-body);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-default);
    color: var(--text-default);
    border: 1px solid var(--border-default);
    touch-action: manipulation; /* Prevent double-tap zoom */
    -webkit-tap-highlight-color: transparent;
}

.action-btn.primary {
    background: var(--primary-600);
    color: white;
    border: none;
}

.action-btn:active {
    transform: scale(0.98);
}

/* Floating Help Button */
.help-floating {
    position: fixed;
    top: 16px; /* Fixed distance from viewport top */
    right: 16px; /* Fixed distance from viewport right */
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--primary-600);
    color: white;
    border: none;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    z-index: 999; /* Lower z-index to stay below modals */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
}

.help-floating:hover {
    background-color: var(--primary-700);
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.help-floating:active {
    transform: scale(0.95);
}

/* Hide help button when help modal is open */
.help-floating.modal-open-hidden,
body.modal-open .help-floating {
    display: none !important;
}

/* Popup Overlays */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-4);
}

.popup-content {
    background: var(--bg-card);
    border-radius: var(--radius-l);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.popup-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.popup-header h2 {
    margin: 0;
    font-size: var(--type-h4);
}

.popup-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-subtle);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-m);
}

/* Clue Grid */
.clue-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: var(--space-3);
    padding: var(--space-4);
    overflow-y: auto;
}

.clue-card-popup {
    background: var(--bg-default);
    border: 2px solid var(--border-default);
    border-radius: var(--radius-m);
    padding: var(--space-3);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clue-card-popup:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.clue-card-popup:not(:disabled):active {
    transform: translateY(0);
}

.clue-card-popup.used {
    opacity: 0.5;
    cursor: not-allowed;
}

.clue-icon {
    font-size: 24px;
    margin-bottom: var(--space-1);
}

.clue-name {
    font-size: var(--type-small);
    font-weight: 500;
    margin-bottom: var(--space-1);
}

.clue-cost {
    font-size: var(--type-caption);
    color: var(--text-subtle);
}

/* Base disabled clue card styling (applies to both light and dark themes) */
.clue-card.disabled,
.clue-card:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.clue-card.disabled .clue-card-title,
.clue-card:disabled .clue-card-title {
    color: var(--text-subtle);
}

.clue-card.disabled .clue-card-icon,
.clue-card:disabled .clue-card-icon {
    color: var(--text-subtle);
}

.clue-card.disabled .clue-card-cost,
.clue-card:disabled .clue-card-cost {
    color: var(--text-subtle);
}

/* Score/Stats Display */
.score-stats-container {
    padding: var(--space-4);
    overflow-y: auto;
}

.score-display {
    background: var(--bg-default);
    border-radius: var(--radius-m);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.score-section {
    text-align: center;
    margin-bottom: var(--space-3);
}

.score-label {
    display: block;
    font-size: var(--type-small);
    color: var(--text-subtle);
    margin-bottom: var(--space-1);
}

.score-number {
    font-size: var(--type-h2);
    font-weight: bold;
    color: var(--primary-600);
}

.score-details {
    display: grid;
    gap: var(--space-2);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    font-size: var(--type-small);
}

.stats-display h3 {
    margin: 0 0 var(--space-3) 0;
    font-size: var(--type-h4);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
}

.stat-item {
    text-align: center;
    padding: var(--space-2);
    background: var(--bg-default);
    border-radius: var(--radius-m);
}

.stat-value {
    font-size: var(--type-h3);
    font-weight: bold;
    color: var(--primary-600);
}

.stat-label {
    font-size: var(--type-caption);
    color: var(--text-subtle);
}

/* Options Menu */
.options-menu {
    position: fixed;
    bottom: 100px;
    right: var(--space-3);
    background: var(--bg-card);
    border-radius: var(--radius-m);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    z-index: 900;
}

.option-item {
    display: block;
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    border-bottom: 1px solid var(--border-default);
}

.option-item:last-child {
    border-bottom: none;
}

.option-item:hover {
    background: var(--bg-default);
}

/* Hide desktop-only elements */
.game-sidebar,
.game-actions,
.secondary-buttons,
.tab-navigation {
    display: none !important;
}

/* Desktop Enhancements */
@media (min-width: 768px) {
    .game-shell {
        padding: var(--space-4);
        /* Don't force a fixed height — body's flex column already gives
         * .game-shell the remaining viewport space after the topbar. */
    }
    
    .game-shell header h1 {
        font-size: var(--type-h2);
    }
    
    .game-prompt {
        padding: var(--space-4);
    }
    
    .guess-card {
        max-width: 680px;
        margin: 0 auto;
        border: 2px solid var(--border-default);
        border-radius: var(--radius-l);
        box-shadow: 0 4px 16px var(--shadow-default);
    }
    
    .action-buttons {
        grid-template-columns: 1.6fr 1fr 1.1fr;
        max-width: 600px;
        margin: 0 auto var(--space-3) auto;
    }
    
    #guess-input {
        max-width: 600px;
        margin: 0 auto var(--space-3) auto;
    }
}

/* Larger desktop screens */
@media (min-width: 1024px) {
    .popup-content {
        max-width: 600px;
    }
    
    .clue-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
}

/* Hard-mode badge in the header */
.hard-mode-badge {
    display: inline-block;
    margin-left: var(--space-2);
    padding: 2px 8px;
    background: var(--amber-400, #d97706);
    color: white;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    letter-spacing: 0.05em;
    vertical-align: middle;
}

/* Hard-mode + difficulty controls inside help modal */
.hard-mode-toggle {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    cursor: pointer;
}
.hard-mode-toggle input { margin-top: 4px; }
.difficulty-select {
    padding: var(--space-2);
    border-radius: var(--radius-m);
    border: 1px solid var(--border-default);
    font-size: 14px;
    background: var(--bg-default);
    width: 100%;
    max-width: 320px;
}
.help-subsection .hint {
    margin-top: var(--space-1);
    font-size: 12px;
    color: var(--text-subtle);
}

/* Daily archive popup */
.archive-popup-content {
    max-width: 500px;
}

.archive-list {
    padding: var(--space-3);
    max-height: 60vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.archive-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3);
    background: var(--bg-default);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-m);
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.archive-item:hover {
    border-color: var(--primary-600);
}

.archive-item__date {
    font-weight: 600;
}

.archive-item__day {
    color: var(--text-subtle);
    font-size: 13px;
}

.archive-item--today {
    border-color: var(--primary-600);
    background: var(--zinc-50);
}

.archive-item--today .archive-item__date::before {
    content: '★ ';
    color: var(--primary-600);
}

/* Score/Stats Popup Tabbed Interface */
.score-popup-content {
    max-width: 500px;
    width: 90%;
}

/* Tab navigation */
.popup-tabs {
    display: flex;
    border-bottom: 2px solid var(--zinc-200);
    margin-bottom: var(--space-4);
}

.popup-tab {
    flex: 1;
    padding: var(--space-3);
    background: none;
    border: none;
    font-size: var(--font-size-base);
    color: var(--zinc-600);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.popup-tab:hover {
    color: var(--zinc-900);
}

.popup-tab.active {
    color: var(--primary-600);
    font-weight: 600;
}

.popup-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-600);
}

/* Tab content */
.popup-tab-content {
    min-height: 300px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* Current game tab styles */
.score-display {
    text-align: center;
}

.score-section {
    margin-bottom: var(--space-4);
}

.score-label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--zinc-500);
    margin-bottom: var(--space-1);
}

.score-number {
    font-size: var(--font-size-5xl);
    font-weight: bold;
    color: var(--primary-600);
}

.score-details {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    background: var(--zinc-50);
    padding: var(--space-3);
    border-radius: var(--radius-md);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-sm);
}

/* Statistics tab styles */
.stats-grid-full {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

@media (min-width: 768px) {
    .stats-grid-full {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-item {
    background: var(--zinc-50);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    text-align: center;
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: bold;
    color: var(--zinc-900);
}

.stat-label {
    font-size: var(--font-size-xs);
    color: var(--zinc-600);
    margin-top: var(--space-1);
}


/* Share section */
.share-section {
    margin-top: var(--space-4);
    text-align: center;
}

.share-button {
    padding: var(--space-3) var(--space-4);
    background: var(--primary-600);
    color: white;
    border: none;
    border-radius: var(--radius-m);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.share-button:hover {
    background: var(--primary-700);
}

.share-button.copied {
    background: var(--green-600, #16a34a);
}

.share-preview {
    margin: var(--space-3) auto 0;
    padding: var(--space-3);
    background: var(--zinc-50);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-family: 'Courier New', monospace;
    font-size: 13px;
    text-align: left;
    white-space: pre-wrap;
    max-width: 320px;
}

/* Stats actions */
.stats-actions {
    margin-top: var(--space-4);
    text-align: center;
}

.secondary-button {
    padding: var(--space-2) var(--space-4);
    background: var(--zinc-200);
    color: var(--zinc-700);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.secondary-button:hover {
    background: var(--zinc-300);
}