/**
 * Open Dictation Desktop - V2 Inspired Minimal Dark Mode
 * 
 * Craigslist-inspired aesthetics with beautiful flag cards
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #000;
    color: #ddd;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100dvh;
}

a {
    color: #66b3ff;
    text-decoration: none;
    cursor: pointer;
}

a:hover {
    text-decoration: underline;
}

h1 {
    font-size: 24px;
    font-weight: normal;
    margin-bottom: 8px;
    color: #fff;
}

h2 {
    font-size: 18px;
    font-weight: normal;
    margin: 20px 0 10px 0;
    color: #fff;
}

p {
    margin-bottom: 10px;
    color: #999;
}

/* Header */
header {
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
}

.loading-spinner {
    font-size: 48px;
    animation: spin 1s linear infinite;
}

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

/* Language filter (revealed by JS when the grid is long) */
.language-filter-wrap {
    margin: 20px 0 0;
    position: relative;
    max-width: 420px;
}
.language-filter {
    width: 100%;
    padding: 10px 40px 10px 14px; /* right padding clears the ✕ button */
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    color: #ddd;
    font-size: 16px; /* ≥16px so iOS Safari doesn't zoom the page on focus */
    outline: none;
}
.language-filter:focus { border-color: #66b3ff; }
.language-filter::placeholder { color: #666; }
/* Native ✕ is desktop-WebKit-only and would double up with ours — hide it */
.language-filter::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.language-filter-clear {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 40px; /* full-height 40px column = comfortable thumb target */
    background: none;
    border: none;
    color: #666;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
}
.language-filter-clear:hover, .language-filter-clear:active { color: #ddd; }

/* Sync feedback: a stat line whose numbers just changed lands with a brief
   highlight instead of swapping silently */
@keyframes stat-pulse {
    0%   { color: #4caf7d; }
    60%  { color: #4caf7d; }
    100% { color: inherit; }
}
.stat-line.stat-pulse { animation: stat-pulse 1.6s ease-out; }

/* Flag Grid */
.flag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    margin: 20px 0;
}
/* Region dividers within the one scroll (labels, never navigation) */
.grid-divider {
    grid-column: 1 / -1;
    border-top: 1px solid #1a1a1a;
    margin: 8px 0 4px;
    padding-top: 12px;
    font-size: 11px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: .5px;
}
/* Phones: two columns instead of one — "I just don't like the idea of
   scrolling down a single column" (Adam 2026-07-10). Compact cards.
   iPhone SE (320px) is the floor: a practiced card is ~146px wide there and
   the Practice+Stats button pair exceeded it ("column slightly too wide" —
   Adam, same day) — actions wrap and everything tightens. */
@media (max-width: 520px) {
    .flag-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .flag-card { padding: 12px; }
    .flag { font-size: 26px; margin-bottom: 6px; }
    .flag img.flag-svg { height: 24px; }
    .card-actions { flex-wrap: wrap; gap: 5px; }
    /* STACK the pair: "▶ P…" (ellipsized side-by-side) shipped to Adam's
       13 mini + SE, 2026-07-10 — Practice takes the full row (real thumb
       target), Stats a full row beneath. No truncation is possible. */
    .card-practice-btn { flex: 1 1 100%; }
    .card-stats-btn { flex: 1 1 100%; }
    .card-practice-btn, .card-stats-btn { padding: 6px 8px; font-size: 13px; }
    .stat-line { font-size: 12px; }
    .lang-name { font-size: 15px; }
}

.flag-card {
    background: #111;
    border: 1px solid #333;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
}

.flag-card:hover {
    border-color: #66b3ff;
    background: #1a1a1a;
}

/* ── Language card actions (mirrors desktop renderer) ────────────────────── */
.card-actions {
    display: flex;
    gap: 6px;
    margin-top: auto;   /* pins to bottom of card regardless of content height */
    padding-top: 12px;
    align-items: center;
}

.card-more-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: 1px solid #2a2a2a;
    color: #555;
    border-radius: 4px;
    padding: 2px 7px;
    font-size: 13px;
    cursor: pointer;
    line-height: 1.4;
    letter-spacing: 1px;
}
.card-more-btn:hover { border-color: #555; color: #999; }

.card-practice-btn {
    flex: 1;
    min-width: 0;          /* WebKit: flex items refuse to shrink below content without this */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: transparent;
    color: #4caf50;
    border: 1px solid #2d5a2d;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
}
.card-practice-btn:hover { background: #1a2a1a; border-color: #4caf50; }

.card-stats-btn {
    white-space: nowrap;
    flex-shrink: 0;
    background: transparent;
    color: #888;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}
.card-stats-btn:hover { border-color: #666; color: #bbb; }

.flag {
    font-size: 32px;
    margin-bottom: 8px;
}
/* SVG flags for languages with no emoji flag (Basque, Galician, Esperanto —
   Wikimedia Commons public-domain files, self-hosted). Sized to sit like an
   emoji in the same slot. */
.flag img.flag-svg {
    height: 30px;
    width: auto;
    display: inline-block;
    vertical-align: -4px;
    border-radius: 2px;
}

.lang-name {
    font-size: 16px;
    color: #fff;
    display: block;
    margin-bottom: 8px;
}

.stat-line {
    font-size: 12px;
    color: #999;
    margin: 2px 0;
}

.stat-value {
    color: #ddd;
    font-weight: bold;
}

.success-rate {
    color: #66ff66;
}

.r4r-count {
    color: #ffaa66;
}

.session-chevron {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: #2a2a2a;
    color: #888;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 11px;
    cursor: pointer;
    line-height: 1.4;
}

.session-chevron:hover {
    background: #383838;
    color: #bbb;
    border-color: #666;
}

.session-dropdown {
    position: absolute;
    bottom: 34px;
    right: 8px;
    background: #1e1e1e;
    border: 1px solid #555;
    border-radius: 4px;
    z-index: 100;
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

.session-dropdown button {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: #ccc;
    padding: 8px 12px;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

.session-dropdown button:hover {
    background: #2e2e2e;
    color: #fff;
}

/* Gameplay Screen */
#gameplay-screen {
    max-width: 900px;
    margin: 0 auto;
}

.audio-container {
    text-align: center;
    margin: 30px 0;
}

audio {
    width: 100%;
    max-width: 600px;
    height: 50px;
}

textarea {
    width: 100%;
    max-width: 800px;
    height: 140px;
    min-height: 100px;
    padding: 18px;
    font-size: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: #111;
    color: #fff;
    border: 2px solid #333;
    border-radius: 4px;
    resize: vertical;
    margin: 20px auto;
    display: block;
}

textarea:focus {
    outline: none;
    border-color: #0a84ff;
    background: #0d0d0d;
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
}

/* Buttons */
.button-group {
    text-align: center;
    margin: 20px 0;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

button {
    background: #1a1a1a;
    border: 1px solid #333;
    color: #fff;
    padding: 12px 20px;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

button:hover:not(:disabled) {
    background: #2a2a2a;
    border-color: #66b3ff;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.primary {
    background: #1a4d2e;
    border-color: #2d7a4f;
    font-weight: 500;
    font-size: 18px;
    padding: 16px 28px;
}

button.primary:hover:not(:disabled) {
    background: #2d7a4f;
    border-color: #4caf50;
}

/* Diff View */
.diff-container {
    margin: 20px 0;
    padding: 20px;
    background: #111;
    border: 1px solid #333;
    border-radius: 4px;
}

.diff-label {
    color: #999;
    font-size: 12px;
    margin-bottom: 5px;
}

.diff-text {
    font-size: 18px;
    line-height: 1.8;
    margin-bottom: 15px;
}

.diff-correct {
    background: #1a4d2e;
    padding: 2px 4px;
}

.diff-error {
    background: #4d1a1a;
    padding: 2px 4px;
}

/* Session Info */
.session-info {
    background: #111;
    border: 1px solid #333;
    padding: 15px;
    margin: 20px 0;
    border-radius: 4px;
}

.session-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.stat-box {
    text-align: center;
}

.stat-number {
    font-size: 32px;
    color: #66ff66;
    font-weight: bold;
}

.stat-label {
    color: #999;
    font-size: 12px;
}

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

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

/* Stats View */
#stats-view {
    height: 100vh;
    overflow-y: auto;
}

/* Stats Tab Buttons */
.stats-tab-btn.active {
    border-bottom-color: #0a84ff !important;
    color: #fff !important;
}

/* Mobile */
@media (max-width: 768px) {
    html, body {
        height: 100%;
        /* overflow: hidden removed — was blocking hub scroll on mobile */
    }

    /* Header was a single nowrap flex row with no narrow-viewport handling —
       at real phone widths the tagline wrapped to 5 lines and pushed the
       sign-in buttons past the right edge of the screen. Drop the tagline
       (decorative) and let the action group wrap onto its own row instead. */
    .app-header {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .app-header-tagline {
        display: none;
    }

    .app-header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        width: 100%;
    }

    body {
        padding: 10px;
        padding-top: 54px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    #gameplay-screen main {
        padding-top: 0 !important;
    }

    .audio-container {
        position: sticky;
        top: 0;
        background: #000;
        margin: 0;
        /* top padding respects the notch/status bar — with black-translucent
           the page extends under it and the play button was getting clipped
           behind the clock (observed on iPhone 2026-07-03) */
        padding: max(6px, env(safe-area-inset-top)) 0 6px;
        z-index: 10;
        border-bottom: 1px solid #333;
    }

    /* On phones the fat scrub tap-target pushed the sticky audio controls up
       into the status bar for no thumb benefit (the bar is reachable there) —
       keep the compact 3px bar on mobile; desktop keeps the padded target. */
    #audio-progress-track {
        padding: 0 !important;
    }

    audio {
        height: 40px;
    }

    #practice-title, #review-title {
        display: none;
    }

    textarea {
        height: 130px;
        font-size: 18px;
        margin: 8px auto;
        padding: 12px;
    }

    #diff-display {
        margin-top: 8px !important;
    }

    #translation-section {
        margin-top: 8px !important;
        padding-top: 8px !important;
    }

    #stats-view main {
        padding: 12px !important;
        max-width: 100% !important;
    }

    #stats-view .stats-tab-btn {
        padding: 8px 10px !important;
        font-size: 12px !important;
    }

    .stats-tab-content {
        max-height: calc(100vh - 130px) !important;
    }

    #stats-view table {
        font-size: 12px;
    }
}

/* ── Session override modal (P9: matches desktop) ───────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.session-modal {
    background: #1a1a1a; border: 1px solid #333; border-radius: 8px;
    padding: 24px; min-width: 300px; max-width: 380px; width: 90%;
}
.session-modal h3 { margin: 0 0 18px; font-size: 15px; color: #ccc; font-weight: 600; }
.modal-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px; font-size: 13px; color: #aaa;
}
.modal-row label { flex: 1; }
.modal-row input[type="number"] {
    width: 60px; background: #111; border: 1px solid #444; color: #ddd;
    border-radius: 4px; padding: 4px 6px; font-size: 13px; text-align: right;
}
.modal-row .unit { margin-left: 6px; color: #666; font-size: 12px; }
.modal-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.modal-quick-opts { display: flex; gap: 4px; margin-left: 8px; }
.modal-quick-opts button {
    background: #222; border: 1px solid #444; color: #888;
    border-radius: 3px; padding: 2px 7px; font-size: 11px; cursor: pointer;
}
.modal-quick-opts button:hover { border-color: #66b3ff; color: #66b3ff; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; }
.modal-btn-start {
    background: #1a3a1a; color: #4caf50; border: 1px solid #2d5a2d;
    border-radius: 4px; padding: 7px 20px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.modal-btn-start:hover { background: #1f4a1f; }
.modal-btn-cancel {
    background: #222; color: #666; border: 1px solid #333;
    border-radius: 4px; padding: 7px 16px; font-size: 13px; cursor: pointer;
}
.modal-btn-cancel:hover { color: #aaa; border-color: #555; }

/* Footer */
/* Footer controls wrap as whole units on narrow screens — "hide translation"
   used to break mid-label on mobile (2026-07-09) */
#native-language-section label {
    white-space: nowrap;
    display: inline-block;
}

footer {
    border-top: 1px solid #333;
    padding-top: 15px;
    margin-top: 40px;
    color: #666;
    font-size: 12px;
    text-align: center;
}
