/* ===================================================
   Typing Replay Mode - Keystroke replay viewer
   旧プレイヤー(userscript_rtcombat)の配色を踏襲
   正解=#0099CC  ミス=#FF3554  ライン完了=#1eff52
   Theme-aware: uses CSS variables for UI chrome
   =================================================== */

/* --- 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;
    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(--accent);
}

.typing-replay-speed-btn.flash {
    background: rgba(var(--accent-rgb), 0.2);
    color: var(--accent);
    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;
    background: rgba(var(--accent-rgb), 0.1);
    color: rgba(var(--accent-rgb), 0.9);
    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: rgba(var(--accent-rgb), 0.2);
    border-color: rgba(var(--accent-rgb), 0.6);
    color: var(--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, #e84898);
    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;
    background: rgba(var(--accent-rgb), 0.15);
    color: rgba(var(--accent-rgb), 0.9);
    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;
}

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

/* 次の入力文字: 太字＋下線（ソロプレイ準拠） */
.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 #1eff52; background: rgba(30, 255, 82, 0.08); }
    100% { box-shadow: inset 3px 0 0 transparent; background: transparent; }
}

/* Character coloring: 旧システム配色 */
.replay-char-correct {
    color: #0099CC;
}

.replay-char-miss {
    color: #FF3554;
    text-decoration: underline wavy #FF3554;
}

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

/* === 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: #0099CC;
}

.typing-replay-score-current.score-down {
    color: #FF3554;
}

/* Combo highlight */
.typing-replay-info-cell-value.combo-active {
    color: #0099CC;
    text-shadow: 0 0 8px rgba(0, 153, 204, 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;
}

.typing-replay-summary-mode {
    font-size: 0.75rem;
    color: rgba(var(--accent-rgb), 0.8);
    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;
    color: rgba(255, 255, 255, 0.45);
}

.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: rgba(var(--accent-rgb), 1);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.typing-replay-summary-typing-btn:hover {
    background: rgba(var(--accent-rgb), 0.25);
    border-color: rgba(var(--accent-rgb), 0.7);
}

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

@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: #f0a030;
}

.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);
    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;
    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 {
        width: 34px;
        height: 34px;
        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;
    }
}
