/* ===================================================
   Typing Replay Mode - Keystroke replay viewer
   旧プレイヤー(userscript_rtcombat)の配色を踏襲した画面だが、
   親の .player-overlay は --body-bg のテーマ追従面なので、
   判定色（正解 / ミス / ライン完了）は --color-info / --color-danger / --color-success に載せた。
   固定色を残すのは自前で暗面を敷く .typing-replay-summary の中だけ。
   =================================================== */

/* --- Main Container --- */
.typing-replay {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 720px;
    height: 100%;
    margin: 0 auto;
    position: relative;
}

/* --- YouTube Player --- */
.typing-replay-player-wrap {
    flex-shrink: 0;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000; /* design-allow: color-literal */
    border-radius: 8px 8px 0 0;
    overflow: hidden;
}

.typing-replay-player-wrap iframe {
    width: 100%;
    height: 100%;
}

/* --- Controls Bar --- */
.typing-replay-controls {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--player-surface);
    border-bottom: 1px solid var(--player-border);
    user-select: none;
    -webkit-user-select: none;
}

.typing-replay-controls-left {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.typing-replay-controls-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.typing-replay-ctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.typing-replay-ctrl-btn:hover {
    background: var(--player-hover);
    color: var(--text-primary);
}

.typing-replay-play-btn {
    width: 48px;
    height: 48px;
    font-size: 1.4rem;
    background: var(--player-surface);
}

.typing-replay-play-btn:hover {
    background: var(--player-surface-strong);
}

/* --- Speed Button --- */
.typing-replay-speed-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 42px;
}

.typing-replay-speed-btn:hover {
    border-color: rgba(var(--accent-rgb), 0.4);
    color: var(--text-primary);
}

.typing-replay-speed-btn.active {
    background: rgba(var(--accent-rgb), 0.08);
    border-color: rgba(var(--accent-rgb), 0.4);
    color: var(--text-primary); /* ⚠️ accent 文字は操作バー面で 4.26（light-sakana）*/
}

/* ⚠️ lyrics_scroll と同型。地だけ光らせ、文字は本文段に上げる（accent on 20% tint = 3.59） */
.typing-replay-speed-btn.flash {
    background: rgba(var(--accent-rgb), 0.2);
    color: var(--text-primary);
    transform: scale(1.1);
}

/* --- Time Display --- */
.typing-replay-time {
    font-family: "Courier New", monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* --- Typing Link Button --- */
.typing-replay-typing-link {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid rgba(var(--accent-rgb), 0.4);
    border-radius: 20px;
    /* lyrics_scroll と同型。同系 tint を外し、alpha 付きの色も素の accent に戻す */
    background: transparent;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.typing-replay-typing-link i {
    font-size: 0.85rem;
}

.typing-replay-typing-link:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-on-accent);
}

/* --- Progress Bar --- */
.typing-replay-progress {
    flex-shrink: 0;
    height: 4px;
    background: var(--player-surface);
    cursor: pointer;
    position: relative;
    padding: 8px 0;
    margin: -8px 0;
    background-clip: content-box;
    -webkit-touch-callout: none;
}

.typing-replay-progress:hover .typing-replay-progress-fill {
    transform: scaleY(1.5);
}

.typing-replay-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
    transition: width 0.1s linear;
    transform-origin: bottom;
    pointer-events: none;
}

/* === Replay Info Bar: 旧システム準拠 2行×4列グリッド === */
.typing-replay-info {
    flex-shrink: 0;
    border-bottom: 1px solid var(--player-border);
}

.typing-replay-info-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 1rem 0.25rem;
    border-bottom: 1px solid var(--player-surface);
}

.typing-replay-info-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Input Mode Badge */
.typing-replay-info-mode {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    /* .typing-replay-info は面を持たないので地は .player-overlay = --body-bg。
       同系 tint .15 + alpha 付き accent で 3.62 だった → tint を薄め、色は素の accent（4.65） */
    background: rgba(var(--accent-rgb), 0.08);
    color: var(--accent);
    letter-spacing: 0.03em;
}

/* 2行×4列 Stats Grid */
.typing-replay-info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
}

.typing-replay-info-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.25rem 0;
    border-right: 1px solid var(--player-surface);
}

.typing-replay-info-cell:nth-child(4n) {
    border-right: none;
}

/* Row 2 separator */
.typing-replay-info-cell:nth-child(n+5) {
    border-top: 1px solid var(--player-surface);
}

.typing-replay-info-cell-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1;
}

.typing-replay-info-cell-value {
    font-family: "Courier New", monospace;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
}

/* === Typing Zone: ターゲットテキスト＋入力再現＋歌詞 === */
.typing-replay-typing-zone {
    flex: 1;
}

/* === Target Text: ソロプレイ準拠 3分割表示 === */
.typing-replay-target-text {
    min-height: 1.6em;
    padding: 0.5rem 1rem 0.25rem;
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    line-height: 1.6;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
}

.typing-replay-target-text:empty {
    display: none;
}

/* design-allow-start: color-literal */
/* リプレイ画面は旧プレイヤー (userscript_rtcombat) のダーク前提固定配色を踏襲。テーマ非依存の機能識別色 (typed=青/miss=赤/clear=緑) と暗背景 + 半透明白文字のレイアウト */

/* 入力済み文字: 旧システム correct-word-color #0099CC */
.target-typed {
    color: var(--color-info);
}

/* 次の入力文字: 太字＋下線（ソロプレイ準拠） */
.target-next {
    color: var(--text-primary);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
    position: relative;
}

/* 残りの文字: 半透明（旧 word-color） */
.target-remaining {
    color: var(--text-muted);
}

/* === Input Replay Area === */
.typing-replay-input-area {
    min-height: 2.5rem;
    max-height: 5rem;
    padding: 0.375rem 1rem 0.5rem;
    font-family: "Courier New", monospace;
    font-size: 1.1rem;
    line-height: 1.6;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    transition: opacity 0.15s ease;
}

/* Line fade transition (G5) */
.typing-replay-input-area.line-fade {
    opacity: 0.3;
}

/* Miss flash effect (G4) */
.typing-replay-input-area.miss-flash {
    background: rgba(212, 131, 106, 0.08);
}

/* Line complete flash (GD-2: 旧システム #1eff52 緑) */
.typing-replay-typing-zone.line-complete-flash {
    animation: lineCompleteFlash 0.4s ease-out;
}

@keyframes lineCompleteFlash {
    0% { box-shadow: inset 3px 0 0 var(--color-success); background: rgba(var(--color-success-rgb), 0.08); }
    100% { box-shadow: inset 3px 0 0 transparent; background: transparent; }
}

/* Character coloring: 旧システム配色 */
.replay-char-correct {
    color: var(--color-info);
}

.replay-char-miss {
    color: var(--color-danger);
    text-decoration: underline wavy var(--color-danger);
}

/* ライン完了文字 (将来の拡張用) */
.replay-char-complete {
    color: var(--color-success);
}

/* === Lyric Display (ソロプレイ準拠: 現在行 + 次行) === */
.typing-replay-lyric {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 0.75rem 0 0.25rem;
    padding: 0 1rem;
    font-weight: 500;
    min-height: 1.6em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.typing-replay-next-lyric {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 0 1rem;
    min-height: 1.6em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Replay Score Animation === */
.typing-replay-score-current {
    font-family: "Courier New", monospace;
    font-weight: 700;
}

.typing-replay-score-current.score-up {
    color: var(--color-info);
}

.typing-replay-score-current.score-down {
    color: var(--color-danger);
}

/* Combo highlight */
.typing-replay-info-cell-value.combo-active {
    color: var(--color-info);
    text-shadow: 0 0 8px rgba(var(--color-info-rgb), 0.4);
}

/* === End Summary Overlay (G3) === */
.typing-replay-summary {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.4s ease;
}

.typing-replay-summary-inner {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
}

.typing-replay-summary-title {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
}

.typing-replay-summary-player {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 0.25rem;
}

/* ⚠️ summary は rgba(0,0,0,.85) の暗面。light テーマの --accent（濃色）をそのまま置くと
   1.26 まで沈むので、.battle-play-page と同じく light 5 テーマだけ明度を上げた accent に差し替える。
   さらに alpha .8 を掛けると暗面に沈むので alpha は外す。
   ⚠️ 2026-08-20: 旧値（L 43〜64%）は**監査が面を二重に暗くしていた**ときに選んだもので、
   実際の面では .typing-replay-summary-typing-btn（自前で accent 15% の地を敷く）が 3.58〜3.67 だった。
   色相・彩度は据え置きで明度だけ +10pt 上げて 4.76 以上に（計画書 182 Phase 6）。 */
[data-theme="light-classic"] .typing-replay-summary { --accent: #ea8b8b; --accent-rgb: 234,139,139; }
[data-theme="light-slate"] .typing-replay-summary { --accent: #88a8d6; --accent-rgb: 136,168,214; }
[data-theme="light-sakana"] .typing-replay-summary { --accent: #db958a; --accent-rgb: 219,149,138; }
[data-theme="light-botanical"] .typing-replay-summary { --accent: #53ba6a; --accent-rgb: 83,186,106; }
[data-theme="light-shell"] .typing-replay-summary { --accent: #94a8c3; --accent-rgb: 148,168,195; }
/* ⚠️ accent を借り物に差し替えたら --text-on-accent も対で差し替える。light の #fff を
   明度を上げた accent の上に置くと 3.38 まで落ちる（計画書 182 Phase 3-4）。#1a1a1a なら 5.05 */
[data-theme="light-classic"] .typing-replay-summary,
[data-theme="light-slate"] .typing-replay-summary,
[data-theme="light-sakana"] .typing-replay-summary,
[data-theme="light-botanical"] .typing-replay-summary,
[data-theme="light-shell"] .typing-replay-summary { --text-on-accent: #1a1a1a; }

.typing-replay-summary-mode {
    font-size: 0.75rem;
    color: var(--accent);
    margin-bottom: 1rem;
}

.typing-replay-summary-score {
    font-family: "Courier New", monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: #0099CC;
    margin-bottom: 1.5rem;
}

.typing-replay-summary-score small {
    font-size: 0.5em;
    color: rgba(255, 255, 255, 0.5);
}

.typing-replay-summary-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.typing-replay-summary-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.typing-replay-summary-stat-value {
    font-family: "Courier New", monospace;
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
}

.typing-replay-summary-stat-label {
    font-size: 0.65rem;
    /* alpha .45 では 4.44 で AA を割る（暗面に白を薄く重ねる形は alpha がそのまま効く） */
    color: rgba(255, 255, 255, 0.6);
}

.typing-replay-summary-typing-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: 1px solid rgba(var(--accent-rgb), 0.5);
    border-radius: 24px;
    background: rgba(var(--accent-rgb), 0.15);
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.typing-replay-summary-typing-btn:hover {
    background: var(--accent);
    color: var(--text-on-accent);
    border-color: var(--accent);
}

.typing-replay-summary-replay-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.75rem;
}

.typing-replay-summary-replay-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}
/* design-allow-end: color-literal */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- 動画エラー表示 --- */
.typing-replay-video-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    text-align: center;
}

.typing-replay-video-error i {
    font-size: 2rem;
    color: var(--color-warning);
}

.typing-replay-video-error p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* --- Loading / Error Overlay --- */
.typing-replay-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7); /* design-allow: color-literal */
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* --- Loading State --- */
.typing-replay-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
}

.typing-replay-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--player-spinner-track);
    border-top-color: #0099CC; /* design-allow: color-literal */ /* リプレイ系の機能識別色 */
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Empty State --- */
.typing-replay-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* --- Screen Reader Only --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* === Responsive === */
@media (max-width: 640px) {
    .typing-replay {
        max-width: 100%;
    }

    .typing-replay-player-wrap {
        border-radius: 0;
    }

    .typing-replay-controls {
        padding: 0.25rem 0.5rem;
    }

    .typing-replay-ctrl-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 0.95rem;
    }

    .typing-replay-play-btn {
        width: 40px;
        height: 40px;
        font-size: 1.15rem;
    }

    .typing-replay-info-header {
        padding: 0.25rem 0.75rem 0.2rem;
    }

    .typing-replay-info-name {
        font-size: 0.75rem;
    }

    .typing-replay-info-mode {
        font-size: 0.6rem;
    }

    .typing-replay-info-cell {
        padding: 0.2rem 0;
    }

    .typing-replay-info-cell-label {
        font-size: 0.5rem;
    }

    .typing-replay-info-cell-value {
        font-size: 0.7rem;
    }

    .typing-replay-target-text {
        font-size: 1.1rem;
        padding: 0.375rem 0.75rem 0.2rem;
        min-height: 1.2rem;
    }

    .typing-replay-input-area {
        font-size: 0.95rem;
        min-height: 2rem;
        max-height: 3.5rem;
        padding: 0.25rem 0.75rem 0.375rem;
    }

    .typing-replay-lyric {
        font-size: 0.9rem;
        margin: 0.5rem 0 0.2rem;
        padding: 0 0.75rem;
    }

    .typing-replay-next-lyric {
        font-size: 0.75rem;
        padding: 0 0.75rem;
    }

    .typing-replay-speed-btn {
        font-size: 0.7rem;
        min-width: 38px;
        padding: 0.2rem 0.4rem;
    }

    .typing-replay-time {
        font-size: 0.6rem;
    }

    .typing-replay-typing-link {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
        gap: 0.25rem;
    }

    .typing-replay-typing-link span {
        display: none;
    }

    /* Summary responsive */
    .typing-replay-summary-score {
        font-size: 1.8rem;
    }

    .typing-replay-summary-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .typing-replay-summary-stat-value {
        font-size: 1.1rem;
    }

    .typing-replay-summary-typing-btn {
        font-size: 0.8rem;
        padding: 0.6rem 1.2rem;
    }
}
