/* ═══════════════════════════════════════════════════════════════════════════════
   Session Recap — Desktop post-review overlay
   Visual language adapted from mobile debrief HUD
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Overlay ─────────────────────────────────────────────────────────────────── */

.recap-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: recap-overlay-in 0.3s ease-out;
}

.recap-overlay.recap-exiting {
    animation: recap-overlay-out 0.25s ease-in forwards;
}

@keyframes recap-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes recap-overlay-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ── Container ───────────────────────────────────────────────────────────────── */

.recap-container {
    --recap-accent: #22c55e;
    --recap-accent-glow: rgba(34, 197, 94, 0.3);
    --recap-done-color: #22c55e;
    --recap-done-glow: rgba(34, 197, 94, 0.3);

    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    padding: 2rem 2.5rem;
    box-sizing: border-box;
    background: #0a0a0c;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 20px;
    overflow: hidden;
    color: #fafafa;
    animation: recap-container-in 0.4s ease-out;
}

@keyframes recap-container-in {
    from { opacity: 0; transform: scale(0.95) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Scanline ────────────────────────────────────────────────────────────────── */

.recap-scanline {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    top: 0;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--recap-accent) 30%,
        var(--recap-accent) 70%,
        transparent 100%
    );
    box-shadow: 0 0 20px var(--recap-accent-glow);
    opacity: 0;
    animation: recap-scan 1.5s ease-out 0.2s forwards;
    pointer-events: none;
}

@keyframes recap-scan {
    0% { top: 0%; opacity: 0; }
    10% { opacity: 0.8; }
    90% { opacity: 0.8; }
    100% { top: 100%; opacity: 0; }
}

/* ── Header ──────────────────────────────────────────────────────────────────── */

.recap-header {
    text-align: center;
    margin-bottom: 1.25rem;
    opacity: 0;
    animation: recap-fade-in 0.5s ease-out 0.3s forwards;
}

@keyframes recap-fade-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.recap-mode-name {
    font-size: 0.8125rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-family: ui-monospace, 'SF Mono', Monaco, monospace;
}

/* ── Summary (grade ring + stats) ────────────────────────────────────────────── */

.recap-summary {
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 1.25rem;
    opacity: 0;
    animation: recap-summary-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s forwards;
}

@keyframes recap-summary-in {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* ── Grade ring ──────────────────────────────────────────────────────────────── */

.recap-grade-ring {
    position: relative;
    width: 120px;
    height: 120px;
    min-width: 120px;
    flex-shrink: 0;
}

.recap-grade-ring svg {
    width: 120px;
    height: 120px;
    transform: rotate(-90deg);
    display: block;
    overflow: visible;
}

.recap-ring-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 8;
}

.recap-ring-progress {
    fill: none;
    stroke: var(--recap-accent);
    stroke-width: 8;
    stroke-linecap: round;
    filter: drop-shadow(0 0 8px var(--recap-accent-glow));
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.recap-grade-letter {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 800;
    color: var(--recap-accent);
    text-shadow: 0 0 30px var(--recap-accent-glow);
    font-family: ui-sans-serif, system-ui, sans-serif;
    line-height: 1;
    /* button reset */
    background: transparent;
    border: none;
    padding: 0;
    padding-bottom: var(--emblem-nudge-up, 0.14em);
    padding-left: var(--emblem-nudge-right, 0.05em);
    margin: 0;
    cursor: pointer;
    border-radius: 50%;
    transition: transform 0.15s, filter 0.15s;
}

.recap-grade-letter:hover {
    transform: scale(1.12);
    /* shimmer: gradient clipped to the kanji glyph only */
    background: linear-gradient(
        120deg,
        var(--recap-accent) 0%,
        var(--recap-accent) 30%,
        rgba(255, 255, 255, 0.9) 50%,
        var(--recap-accent) 70%,
        var(--recap-accent) 100%
    );
    background-size: 250% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 0 30px var(--recap-accent-glow));
    animation: recap-shimmer 1.5s ease-in-out forwards;
}

@keyframes recap-shimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.recap-grade-letter:active {
    transform: scale(1.05);
}

.recap-grade-letter:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--recap-accent);
}

.recap-grade-letter:focus:not(:focus-visible) {
    outline: none;
}

/* ── Stats ────────────────────────────────────────────────────────────────────── */

.recap-stats {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
}

.recap-stat {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.recap-stat-label {
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.recap-stat-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: #fafafa;
    font-family: ui-monospace, 'SF Mono', Monaco, monospace;
    font-variant-numeric: tabular-nums;
}

/* ── Debrief message ─────────────────────────────────────────────────────────── */

/* ── Item breakdown ──────────────────────────────────────────────────────────── */

.recap-items {
    flex: 1;
    overflow-y: auto;
    max-height: 35vh;
    margin-bottom: 1.25rem;
    padding-right: 0.5rem;
    opacity: 0;
    animation: recap-items-in 0.5s ease-out 1s forwards;
}

@keyframes recap-items-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Scrollbar — Firefox */
.recap-items {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

/* Scrollbar — WebKit/Blink */
.recap-items::-webkit-scrollbar {
    width: 4px;
}
.recap-items::-webkit-scrollbar-track {
    background: transparent;
}
.recap-items::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
}

/* ── Group headers ───────────────────────────────────────────────────────────── */

.recap-group {
    margin-bottom: 0.75rem;
}

.recap-group:last-child {
    margin-bottom: 0;
}

.recap-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
    user-select: none;
}

.recap-group-header:hover {
    background: rgba(255, 255, 255, 0.02);
}

.recap-group-chevron {
    font-size: 0.625rem;
    color: rgba(255, 255, 255, 0.3);
    transition: transform 0.2s ease;
    line-height: 1;
}

.recap-group-header.recap-group-collapsed .recap-group-chevron {
    transform: rotate(-90deg);
}

.recap-group-body.recap-group-collapsed {
    display: none;
}

.recap-group-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.recap-group-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.6);
}

.recap-group-count {
    font-size: 0.625rem;
    color: rgba(255, 255, 255, 0.3);
    font-family: ui-monospace, 'SF Mono', Monaco, monospace;
    margin-left: auto;
}

/* ── Item rows ───────────────────────────────────────────────────────────────── */

.recap-item-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.recap-item-row:hover,
.recap-item-row:focus-within {
    background: rgba(255, 255, 255, 0.03);
}

.recap-item-row[data-quality="0"] { border-left-color: #ef4444; }
.recap-item-row[data-quality="1"] { border-left-color: #f97316; }
.recap-item-row[data-quality="2"] { border-left-color: #22c55e; }
.recap-item-row[data-quality="3"] { border-left-color: #3b82f6; }

/* ── Checkbox ────────────────────────────────────────────────────────────────── */

.recap-checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    min-width: 16px;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.15s;
    flex-shrink: 0;
}

.recap-checkbox:checked {
    background: var(--recap-accent);
    border-color: var(--recap-accent);
}

.recap-checkbox:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 9px;
    border: solid #0a0a0c;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.recap-checkbox:hover {
    border-color: rgba(255, 255, 255, 0.4);
}

.recap-checkbox:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--recap-accent);
}

.recap-checkbox:focus:not(:focus-visible) {
    outline: none;
}

/* ── Item text ───────────────────────────────────────────────────────────────── */

.recap-item-display {
    font-size: 1rem;
    font-weight: 600;
    color: #fafafa;
    flex-shrink: 0;
}

.recap-item-meaning {
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.45);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* ── Item info button ────────────────────────────────────────────────────────── */

.recap-item-info-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    min-width: 24px;
    margin-left: auto;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: rgba(255, 255, 255, 0.25);
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s;
    flex-shrink: 0;
}

.recap-item-row:hover .recap-item-info-btn,
.recap-item-info-btn:focus-visible {
    opacity: 1;
    color: rgba(255, 255, 255, 0.55);
}

.recap-item-info-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.85);
}

.recap-item-info-btn:active {
    transform: scale(0.92);
}

.recap-item-info-btn:focus:not(:focus-visible) {
    outline: none;
}

.recap-item-info-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--recap-accent);
}

/* ── Action buttons ──────────────────────────────────────────────────────────── */

.recap-actions {
    display: flex;
    gap: 0.75rem;
    opacity: 0;
    animation: recap-actions-in 0.5s ease-out 1.2s forwards;
}

@keyframes recap-actions-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.recap-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    font-family: inherit;
}

.recap-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.recap-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.recap-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.recap-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--recap-accent);
}

.recap-btn:focus:not(:focus-visible) {
    outline: none;
}

/* Redo button — secondary outlined */
.recap-btn-retry:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.7);
}

.recap-btn-retry:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.9);
}

/* Done button — primary filled CTA */
.recap-btn-done {
    background: var(--recap-done-color);
    border-color: var(--recap-done-color);
    color: #0a0a0c;
    font-weight: 700;
    box-shadow: 0 0 20px var(--recap-done-glow);
}

.recap-btn-done:hover:not(:disabled) {
    background: var(--recap-done-color);
    border-color: var(--recap-done-color);
    filter: brightness(1.1);
    box-shadow: 0 0 28px var(--recap-done-glow);
}

.recap-kbd {
    font-family: ui-monospace, 'SF Mono', Monaco, monospace;
    font-size: 0.5625rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.2);
    color: inherit;
    opacity: 0.6;
    margin-left: 0.4em;
    vertical-align: baseline;
}

/* ── Grade color variations ──────────────────────────────────────────────────── */

.recap-container[data-grade="S"] {
    --recap-accent: #fbbf24;
    --recap-accent-glow: rgba(251, 191, 36, 0.3);
    --recap-done-color: #fbbf24;
    --recap-done-glow: rgba(251, 191, 36, 0.3);
}

.recap-container[data-grade="A"] {
    --recap-accent: #22c55e;
    --recap-accent-glow: rgba(34, 197, 94, 0.3);
    --emblem-nudge-right: 0em;
}

.recap-container[data-grade="B"] {
    --recap-accent: #3b82f6;
    --recap-accent-glow: rgba(59, 130, 246, 0.3);
}

.recap-container[data-grade="C"] {
    --recap-accent: #a855f7;
    --recap-accent-glow: rgba(168, 85, 247, 0.3);
}

.recap-container[data-grade="D"] {
    --recap-accent: #f97316;
    --recap-accent-glow: rgba(249, 115, 22, 0.3);
}

.recap-container[data-grade="F"] {
    --recap-accent: #ef4444;
    --recap-accent-glow: rgba(239, 68, 68, 0.3);
    --emblem-nudge-right: 0.03em;
}

/* ── Reduced motion ────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .recap-overlay,
    .recap-overlay.recap-exiting,
    .recap-container,
    .recap-header,
    .recap-summary,
    .recap-items,
    .recap-actions,
    .recap-scanline,
    .recap-btn:active:not(:disabled) {
        animation: none !important;
        transition: none !important;
        transform: none !important;
        opacity: 1 !important;
    }

    .recap-ring-progress {
        transition: none !important;
    }
}
