/* Hangul Alphabet Speed Reader — dark theme */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-romanization: #8b949e;
        /* Hangul chrome v2 — stronger hanji + dancheong (Colin 2026-09-09) */
    --accent: #8eb0ff;
    --accent-warm: #e85d4c;
    --dancheong-red: #d63b2f;
    --dancheong-blue: #2f5fbf;
    --dancheong-gold: #e0b84a;
    --dancheong-green: #2f8f6b;
    --chrome-ink: #0c1018;
    --chrome-indigo: #152238;
    --btn-green: #238636;
    --btn-green-hover: #2ea043;
    --btn-red: #da3633;
    --btn-red-hover: #f85149;
    --btn-gray: #30363d;
    --btn-gray-hover: #3d444d;
    --border-color: #30363d;
    /* Visible hanji wash + lattice for sidebar + mobile banner only */
    --chrome-motif:
        linear-gradient(
            160deg,
            rgba(28, 42, 68, 0.97) 0%,
            rgba(18, 26, 40, 0.98) 45%,
            rgba(12, 16, 24, 0.99) 100%
        ),
        repeating-linear-gradient(
            90deg,
            transparent 0,
            transparent 14px,
            rgba(232, 93, 76, 0.14) 14px,
            rgba(232, 93, 76, 0.14) 15px
        ),
        repeating-linear-gradient(
            0deg,
            transparent 0,
            transparent 14px,
            rgba(142, 176, 255, 0.12) 14px,
            rgba(142, 176, 255, 0.12) 15px
        ),
        radial-gradient(
            ellipse 120% 80% at 0% 0%,
            rgba(224, 184, 74, 0.1) 0%,
            transparent 55%
        );
    --dancheong-stripe: linear-gradient(
        90deg,
        var(--dancheong-red) 0 14%,
        var(--dancheong-blue) 14% 32%,
        var(--dancheong-gold) 32% 48%,
        var(--dancheong-green) 48% 62%,
        var(--dancheong-red) 62% 76%,
        var(--dancheong-blue) 76% 88%,
        var(--dancheong-gold) 88% 100%
    );
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    padding:
        env(safe-area-inset-top, 0)
        env(safe-area-inset-right, 0)
        env(safe-area-inset-bottom, 0)
        env(safe-area-inset-left, 0);
}

.mobile-bar {
    display: none;
}

.panel-backdrop {
    display: none;
}

.panel-close {
    display: none;
}

.panel-header {
    display: block;
}

.mobile-bar-spacer {
    width: 88px;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

.side-panel {
    width: 280px;
    min-width: 260px;
    background-color: var(--chrome-indigo);
    background-image: var(--chrome-motif);
    background-attachment: local;
    padding: 14px;
    overflow-y: auto;
    border-right: 1px solid rgba(224, 184, 74, 0.35);
    box-shadow:
        inset -3px 0 0 rgba(214, 59, 47, 0.55),
        inset -6px 0 0 rgba(47, 95, 191, 0.4);
    position: relative;
}

.side-panel::before {
    content: "";
    display: block;
    height: 6px;
    margin: -14px -14px 12px;
    background: var(--dancheong-stripe);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.app-title {
    color: var(--accent);
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 4px;
    text-align: center;
}

.app-subtitle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: center;
    margin-bottom: 12px;
}

.panel-section {
    margin-bottom: 24px;
}

.panel-section h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.radio-group,
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-label,
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background-color 0.15s;
}

.radio-label:hover,
.checkbox-label:hover {
    background-color: var(--bg-tertiary);
}

.radio-label input,
.checkbox-label input {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.radio-label span,
.checkbox-label span {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.scrollable {
    max-height: 200px;
    overflow-y: auto;
    padding-right: 8px;
}

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

.scrollable::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.scrollable::-webkit-scrollbar-thumb {
    background: var(--btn-gray);
    border-radius: 3px;
}

.slider-group {
    margin-top: 16px;
}

.slider-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.slider-group input[type="range"],
#speed-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb,
#speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    min-width: 0;
    justify-content: flex-start;
}

.speed-control {
    text-align: center;
    margin-bottom: 16px;
}

#speed-label {
    display: block;
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 8px;
}

#speed-slider {
    width: min(560px, 85%);
    max-width: 100%;
    height: 8px;
    border-radius: 4px;
}

#speed-slider::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
}

.control-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.btn {
    padding: 12px 32px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

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

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

.btn-primary.paused {
    background-color: var(--btn-red);
}

.btn-primary.paused:hover {
    background-color: var(--btn-red-hover);
}

.btn-secondary {
    background-color: var(--btn-gray);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--btn-gray-hover);
}

.btn-success {
    background-color: var(--btn-green);
    color: white;
}

.btn-success:hover {
    background-color: var(--btn-green-hover);
}

.btn-danger {
    background-color: var(--btn-red);
    color: white;
}

.btn-danger:hover {
    background-color: var(--btn-red-hover);
}

.display-area {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    /* Lock plate to typical filled card (glyph + reading + Got it/Nope) so
       Ready / inter-card clear do not collapse shorter than a live card. */
    min-height: calc(
        32px /* area padding */
        + 20px /* card-display padding */
        + (5rem * 1.15) /* glyph face */
        + 10px + (1.75rem * 1.35) /* reading slot + margin */
        + 10px + (1.15rem * 1.4) /* optional meaning slot */
        + 20px + 2.75rem /* action-buttons margin + row */
    );
    max-height: min(520px, calc(100vh - 160px));
    /* RSVP: lock plate width so cards do not shrink-wrap longer/shorter glyphs */
    width: min(560px, 100%);
    max-width: 100%;
    align-self: center;
    box-sizing: border-box;
}

.stats-panel {
    position: absolute;
    top: 16px;
    right: 20px;
    text-align: right;
}

.remaining-count {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#remaining-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.remaining-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.session-stats {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.card-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 10px 24px;
    /* Reserve glyph + reading even when :empty { display:none } collapses lines */
    min-height: calc(20px + (5rem * 1.15) + 10px + (1.75rem * 1.35) + 10px + (1.15rem * 1.4));
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.hangul-text {
    font-size: 5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "AppleGothic", "Hiragino Sans", "Noto Sans JP", "Noto Sans SC", "PingFang SC", sans-serif;
    line-height: 1.15;
    min-height: 1.15em; /* empty reserve-glyph keeps face height (no line box otherwise) */
}

/* Shared glyph face for Kana pages (.kana-text); match hangul metrics so
   Ready / clear / filled share one plate height across languages. */
.kana-text {
    font-size: 5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.15;
    min-height: 1.15em;
}

.romanization-text {
    font-size: 1.75rem;
    font-weight: 500;
    color: var(--text-romanization);
    margin-top: 10px;
    min-height: 1.35em; /* one line — match line-height so empty≈filled */
    line-height: 1.35;
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

.action-buttons .btn {
    padding: 10px 24px;
    font-size: 0.95rem;
    min-width: 7.5rem;
    flex: 1 1 0;
    max-width: 11rem;
    box-sizing: border-box;
    text-align: center;
}

.keyboard-hints {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-top: 16px;
    padding: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.keyboard-hints span {
    background-color: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 4px;
}

.english-text {
    margin-top: 10px;
    font-size: 1.15rem;
    font-weight: 400;
    color: var(--text-secondary);
    min-height: 1.4em;
    line-height: 1.4;
    opacity: 0.95;
}

/* Tablet and below: side panel becomes a drawer so the glyph stays primary */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        min-height: 100dvh;
    }

    .mobile-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 10px 12px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 30;
    }

    .mobile-title {
        flex: 1;
        text-align: center;
        font-size: 1rem;
        font-weight: 600;
        color: var(--accent);
        margin: 0;
    }

    .settings-toggle {
        min-width: 88px;
        min-height: 44px;
        padding: 8px 12px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--bg-tertiary);
        color: var(--text-primary);
        font-size: 0.95rem;
        font-weight: 600;
        cursor: pointer;
    }

    .settings-toggle[aria-expanded="true"] {
        background: var(--accent);
        color: #0d1117;
        border-color: var(--accent);
    }

    .panel-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 40;
    }

    .panel-backdrop[hidden] {
        display: none;
    }

    .side-panel {
        position: fixed;
        top: 0;
        left: 0;
        width: min(340px, 85vw);
        height: 100dvh;
        max-height: none;
        z-index: 50;
        border-right: 1px solid var(--border-color);
        border-bottom: none;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
    }

    .panel-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 8px;
    }

    .panel-header .app-title {
        text-align: left;
        margin-bottom: 0;
    }

    .panel-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        min-width: 44px;
        min-height: 44px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--bg-tertiary);
        color: var(--text-primary);
        font-size: 1.25rem;
        line-height: 1;
        cursor: pointer;
    }

    .side-panel.open {
        transform: translateX(0);
    }

    .side-panel .app-title,
    .side-panel .app-subtitle {
        text-align: left;
    }

    .main-content {
        padding: 12px;
        flex: 1;
        min-height: 0;
    }

    .display-area {
        max-height: none;
        min-height: min(55dvh, 480px);
        padding: 16px 12px 12px;
    }

    .stats-panel {
        position: static;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 8px;
        text-align: left;
    }

    .remaining-count {
        align-items: flex-start;
    }

    .session-stats {
        margin-top: 0;
        text-align: right;
    }

    .card-display {
        padding: 8px;
    }

    .hangul-text {
        font-size: clamp(3.25rem, 14vw, 5rem);
    }

    .romanization-text {
        font-size: clamp(1.35rem, 5vw, 1.8rem);
        min-height: 1.35em;
    }

    .keyboard-hints {
        display: none;
    }

    .btn {
        min-height: 48px;
        touch-action: manipulation;
    }

    .action-buttons {
        gap: 12px;
        margin-top: 16px;
    }

    .action-buttons .btn {
        flex: 1;
        max-width: none;
        padding: 14px 16px;
    }
}

@media (max-width: 600px) {
    .side-panel {
        width: 100vw;
        border-right: none;
    }

    .control-buttons {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .btn {
        width: 100%;
        max-width: none;
    }

    .speed-control {
        margin-bottom: 12px;
    }

    #speed-slider {
        width: 100%;
    }

    .hangul-text {
        font-size: clamp(2.75rem, 18vw, 4rem);
    }

    .english-text {
        font-size: 1.05rem;
    }
}

/* Landscape phones: keep glyph large, keep answer buttons on screen */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .main-content {
        padding: 8px;
    }

    .speed-control {
        margin-bottom: 6px;
    }

    .control-buttons {
        flex-direction: row;
        gap: 8px;
        margin-bottom: 8px;
    }

    .control-buttons .btn {
        width: auto;
        flex: 1;
        min-height: 40px;
        padding: 8px 12px;
    }

    .display-area {
        /* Keep a floor in landscape so clear/Ready still match filled height */
        min-height: calc(
            16px
            + 8px
            + (2.25rem * 1.15)
            + 4px + (1.1rem * 1.35)
            + 6px + 2.5rem
        );
        max-height: none;
        padding: 8px;
        display: flex;
        flex-direction: column;
    }

    .stats-panel {
        margin-bottom: 4px;
    }

    .card-display {
        flex: 1;
        min-height: calc(8px + (2.25rem * 1.15) + 4px + (1.1rem * 1.35));
        padding: 4px;
    }

    .hangul-text {
        font-size: clamp(2.25rem, 16vh, 3.5rem);
    }

    .romanization-text {
        font-size: 1.1rem;
        min-height: 1.35em;
        margin-top: 4px;
    }

    .english-text {
        margin-top: 4px;
        font-size: 0.95rem;
        min-height: 1.1em;
    }

    .action-buttons {
        position: sticky;
        bottom: 0;
        margin-top: 6px;
        padding-top: 6px;
        background: var(--bg-secondary);
        z-index: 5;
    }

    .action-buttons .btn {
        min-height: 40px;
        padding: 8px 12px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .keyboard-hints {
        display: none;
    }

    .radio-label,
    .checkbox-label {
        min-height: 44px;
    }
}


/* ==========================================================================
   Cultural chrome v2 — Hangul (Sakura + Douglas, 2026-09-09)
   Stronger hanji + dancheong on sidebar + mobile banner only.
   Do NOT put motifs behind .display-area / .hangul-text / .card-display.
   ========================================================================== */

.app-title {
    color: #dce6ff;
    text-shadow:
        0 0 18px rgba(142, 176, 255, 0.35),
        0 1px 0 rgba(0, 0, 0, 0.4);
}

.app-subtitle {
    letter-spacing: 0.03em;
    color: rgba(201, 209, 217, 0.78);
}

.panel-header {
    position: relative;
    padding-bottom: 12px;
    margin-bottom: 6px;
}

.panel-header::after {
    content: "";
    display: block;
    height: 4px;
    margin-top: 12px;
    border-radius: 2px;
    background: var(--dancheong-stripe);
    opacity: 0.95;
    box-shadow: 0 0 10px rgba(224, 184, 74, 0.25);
}

.panel-section h2 {
    color: #e8eefc;
    border-left: 3px solid var(--dancheong-gold);
    padding-left: 8px;
}

@media (max-width: 900px) {
    .mobile-bar {
        background-color: var(--chrome-indigo);
        background-image: var(--chrome-motif);
        border-bottom: none;
        box-shadow: none;
        position: sticky;
        padding-top: 14px;
        overflow: hidden;
    }

    .mobile-bar::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        height: 5px;
        background: var(--dancheong-stripe);
    }

    .mobile-title {
        color: #dce6ff;
        text-shadow: 0 0 14px rgba(142, 176, 255, 0.35);
    }

    .action-buttons {
        background: linear-gradient(
            180deg,
            rgba(22, 27, 34, 0.94) 0%,
            rgba(22, 27, 34, 0.99) 100%
        );
    }
}

/* Glyph stage stays flat and high-contrast — no cultural texture here */
.display-area,
.card-display,
.hangul-text {
    background-image: none !important;
}


/* —— Desktop whitespace tighten 2026-09-25 —— */
@media (min-width: 901px) {
  .side-panel {
    width: 280px;
    min-width: 260px;
    padding: 14px;
  }
  .side-panel::before {
    margin: -14px -14px 12px;
  }
  .main-content {
    padding: 12px 16px 16px;
  }
  .display-area {
    flex: 0 1 auto;
    min-height: 240px;
    max-height: min(560px, calc(100vh - 140px));
    padding: 16px;
    width: min(560px, 100%);
    max-width: 100%;
    align-self: center;
    box-sizing: border-box;
  }
  .control-buttons {
    margin-bottom: 12px;
    gap: 12px;
  }
  .app-subtitle {
    margin-bottom: 12px;
  }
}
