/* Kana Speed Reader — lean hosted cut (dark + washi/sakura chrome) */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-romaji: #8b949e;
    --accent: #f0a8c0;
    --accent-ink: #8eb4ff;
    --btn-green: #238636;
    --btn-green-hover: #2ea043;
    --btn-red: #da3633;
    --btn-red-hover: #f85149;
    --btn-gray: #30363d;
    --btn-gray-hover: #3d444d;
    --border-color: #30363d;
}

* {
    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: 300px;
    min-width: 280px;
    background-color: #121820;
    background-image:
        linear-gradient(180deg, rgba(18, 24, 32, 0.72) 0%, rgba(13, 17, 23, 0.88) 100%),
        url("art/kana-sidebar-washi.png");
    background-size: cover;
    background-position: center;
    background-attachment: local;
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid rgba(240, 168, 192, 0.22);
    box-shadow: inset -2px 0 0 rgba(188, 50, 66, 0.35);
    position: relative;
}

.app-title {
    color: var(--accent);
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 4px;
    text-align: center;
    text-shadow: 0 0 20px rgba(240, 168, 192, 0.28);
}

.app-subtitle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: center;
    margin-bottom: 24px;
    letter-spacing: 0.03em;
}

.side-panel .app-title {
    position: relative;
    padding-bottom: 10px;
    margin-bottom: 8px;
}

.side-panel .app-title::after {
    content: "";
    display: block;
    height: 3px;
    margin-top: 10px;
    border-radius: 2px;
    background: linear-gradient(
        90deg,
        rgba(188, 50, 66, 0.85) 0%,
        rgba(240, 168, 192, 0.75) 45%,
        rgba(142, 180, 255, 0.35) 100%
    );
}

.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;
    border-left: 3px solid rgba(240, 168, 192, 0.55);
    padding-left: 8px;
}

.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"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

.slider-group input[type="range"]::-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: 20px;
    min-width: 0;
}

.top-chrome {
    display: block;
    position: relative;
    height: 72px;
    margin: -20px -20px 16px;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
    background-color: #10151c;
    background-image:
        linear-gradient(180deg, rgba(13, 17, 23, 0.15) 0%, rgba(13, 17, 23, 0.55) 100%),
        url("art/kana-top-sakura.png");
    background-size: cover;
    background-position: center;
    border-bottom: 1px solid rgba(240, 168, 192, 0.2);
    flex-shrink: 0;
}

.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: 300px;
    max-width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

#speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

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

.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: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    min-height: 300px;
    max-height: calc(100vh - 200px);
}

.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 20px;
    min-height: 0;
}

.kana-text {
    font-size: 5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
    line-height: 1.1;
}

.romaji-text {
    font-size: 2rem;
    color: var(--text-romaji);
    margin-top: 4px;
    min-height: 2rem;
}

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

.action-buttons .btn {
    padding: 10px 24px;
    font-size: 0.95rem;
}

.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;
}

/* Glyph stage stays clean — no wallpaper behind big kana */
.display-area,
.card-display,
.kana-text {
    background-image: none !important;
}

@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;
        padding-top: 14px;
        background-color: #121820;
        background-image:
            linear-gradient(180deg, rgba(18, 24, 32, 0.78) 0%, rgba(13, 17, 23, 0.92) 100%),
            url("art/kana-sidebar-washi.png");
        background-size: cover;
        background-position: center;
        border-bottom: 1px solid rgba(240, 168, 192, 0.22);
        position: sticky;
        top: 0;
        z-index: 30;
        overflow: hidden;
    }

    .mobile-bar::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        height: 4px;
        background: linear-gradient(
            90deg,
            rgba(188, 50, 66, 0.9) 0%,
            rgba(240, 168, 192, 0.8) 45%,
            rgba(142, 180, 255, 0.4) 100%
        );
    }

    .mobile-title {
        flex: 1;
        text-align: center;
        font-size: 1rem;
        font-weight: 600;
        color: var(--accent);
        margin: 0;
        text-shadow: 0 0 14px rgba(240, 168, 192, 0.35);
    }

    .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 rgba(240, 168, 192, 0.22);
        border-bottom: none;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
    }

    .side-panel.open {
        transform: translateX(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 .app-title,
    .side-panel .app-subtitle {
        text-align: left;
    }

    .top-chrome {
        margin: -12px -12px 12px;
        height: 56px;
        border-radius: 0 0 10px 10px;
    }

    .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;
    }

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

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

    .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%;
    }

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

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .main-content {
        padding: 8px;
    }

    .top-chrome {
        height: 40px;
        margin: -8px -8px 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 {
        min-height: auto;
        max-height: none;
        padding: 8px;
    }

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

    .card-display {
        flex: 1;
        min-height: 0;
        padding: 4px;
    }

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

    .romaji-text {
        font-size: 1.1rem;
        min-height: 1.3rem;
        margin-top: 4px;
    }

    .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;
    }
}
