/* Learn Tab Styles */

#page-learn {
    height: calc(100vh - 58px);
    /* Full height minus the thin global .app-header shell */
    position: relative;
    padding: 0;
    margin: -16px -20px 0 -20px;
    /* Cancel body padding + .app-header margin so learn-header sits flush */
    overflow: hidden;
}

#page-learn.page.active {
    display: flex;
    flex-direction: column;
}

.learn-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--color-bg-dark, #0f172a);
    position: relative;
}

.learn-content {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Header — compact sub-topbar mirroring .replay-topbar (replay.css:150).
   Matchup selector lives inline-left; right side is reserved for action
   pills injected by the guide (archetype toggle, export, etc.). */
.learn-header {
    flex-shrink: 0;
    padding: 0.45rem 0.95rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    background: rgba(8, 12, 24, 0.92);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: 0.85rem;
    z-index: 10;
}

.learn-header-info {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: #aaa;
    min-width: 0;
    flex-wrap: wrap;
}

.learn-header-eyebrow {
    font-family: 'Rajdhani', system-ui, sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #56c2ff;
}

.learn-header-divider {
    color: #444;
    font-size: 1rem;
    line-height: 1;
}

.learn-header-hint {
    color: #777;
    font-size: 0.76rem;
    font-style: italic;
    padding-left: 0.1rem;
}

.learn-header-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

/* Dropdown styled like replay toggle-buttons: compact, matte, cyan focus */
.tree-select {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e6f0ff;
    padding: 0.32rem 1.8rem 0.32rem 0.7rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    min-width: 240px;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2356c2ff' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.55rem center;
    background-repeat: no-repeat;
    background-size: 1.2em 1.2em;
    appearance: none;
    transition: all 0.15s;
}

.tree-select:hover {
    border-color: rgba(86, 194, 255, 0.35);
    color: #fff;
}

.tree-select:focus {
    outline: none;
    border-color: var(--primary-color, #00d4ff);
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.15);
}

.learn-header-select {
    min-width: 260px;
}

/* Learn-header pill button — matches .replay-toggle-btn pattern exactly.
   Guide code can inject <button class="learn-header-btn"> into .learn-header-actions. */
.learn-header-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ccc;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all 0.15s;
}

.learn-header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.learn-header-btn.active,
.learn-header-btn[aria-pressed="true"] {
    background: rgba(0, 212, 255, 0.16);
    border-color: var(--primary-color, #00d4ff);
    color: var(--primary-color, #00d4ff);
}

/* View Controls */
.view-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #1e293b;
    padding: 0.25rem;
    border-radius: 6px;
    border: 1px solid #334155;
}

.btn-icon {
    background: transparent;
    border: none;
    color: #94a3b8;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1.1rem;
}

.btn-icon:hover {
    background-color: #334155;
    color: #f8fafc;
}

.zoom-controls {
    display: flex;
    align-items: center;
    border-left: 1px solid #334155;
    margin-left: 0.25rem;
    padding-left: 0.25rem;
}

#zoom-level {
    font-size: 0.8rem;
    color: #94a3b8;
    min-width: 45px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Visualization Container */
.viz-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    background-image:
        radial-gradient(circle at 1px 1px, #1e293b 1px, transparent 0);
    background-size: 40px 40px;
}

.viz-container:active {
    cursor: grabbing;
}

.learn-opening-hint {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 14;
    max-width: 420px;
    padding: 0.95rem 1rem;
    border-radius: 18px;
    border: 1px solid rgba(96, 165, 250, 0.18);
    background:
        linear-gradient(180deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.82)),
        radial-gradient(circle at top left, rgba(56, 189, 248, 0.16), transparent 58%);
    box-shadow: 0 18px 42px rgba(2, 6, 23, 0.28);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.learn-opening-hint.hidden {
    display: none;
}

.learn-opening-hint-copy {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.learn-opening-hint-eyebrow {
    color: #7dd3fc;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 700;
}

.learn-opening-hint-title {
    color: #f8fafc;
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.35;
}

.learn-opening-hint-text {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.82rem;
    line-height: 1.55;
}

.learn-opening-hint-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 0.85rem;
}

.learn-hint-btn {
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: rgba(15, 23, 42, 0.46);
    color: #dbeafe;
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.learn-hint-btn:hover {
    background: rgba(30, 41, 59, 0.88);
    border-color: rgba(148, 163, 184, 0.4);
    transform: translateY(-1px);
}

.learn-hint-btn.learn-hint-btn-primary {
    background: rgba(37, 99, 235, 0.24);
    border-color: rgba(96, 165, 250, 0.35);
    color: #eff6ff;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    border-top-color: #3b82f6;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Node Detail Panel (Slide-over) */
.detail-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    background-color: rgba(15, 23, 42, 0.98);
    border-left: 1px solid #334155;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
    overflow-y: auto;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
}

.detail-panel.hidden {
    transform: translateX(100%);
}

/* SVG Styles — scoped to the learn tab's tree viz container. Was an
   unscoped `svg { width:100%; height:100% }` that leaked globally and
   blew up every inline-sized SVG on the page (auth modal logos, icon
   chevrons, etc.), overriding their HTML width/height attributes. */
.viz-container svg {
    display: block;
    width: 100%;
    height: 100%;
}

.link {
    fill: none;
    stroke: #475569;
    stroke-width: 2px;
    transition: stroke 0.3s, stroke-width 0.3s;
}

.link.active {
    stroke: #3b82f6;
    stroke-width: 3px;
    filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.5));
}

.link-cross {
    stroke-dasharray: 6, 4;
    opacity: 0.6;
    stroke: #64748b; /* Slate-500 */
}

.node {
    cursor: pointer;
    transition: filter 0.2s;
}

.node:hover {
    filter: brightness(1.2);
}

.node:focus {
    outline: none;
}

.node:focus .node-rect {
    stroke: #3b82f6;
    stroke-width: 2px;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.6));
}

.node-rect {
    fill: #1e293b;
    stroke: #334155;
    stroke-width: 1.5px;
    transition: fill 0.3s, stroke 0.3s;
}

.node-text {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    fill: #f1f5f9;
    font-size: 13px;
    pointer-events: none;
}

.node-content {
    pointer-events: none;
}

.node-text.title {
    fill: #f8fafc;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
    paint-order: stroke fill;
    stroke: rgba(15, 23, 42, 0.72);
    stroke-width: 3px;
    stroke-linejoin: round;
}

.node-text.title.is-centered {
    font-size: 12px;
}

.node-text.subtitle {
    fill: #cbd5e1;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.node-icon {
    pointer-events: none;
}

.node-icon-badge {
    fill: rgba(15, 23, 42, 0.94);
    stroke: rgba(148, 163, 184, 0.35);
    stroke-width: 1.2px;
    filter: drop-shadow(0 4px 10px rgba(2, 6, 23, 0.38));
}

.node-icon-badge.is-upgrade {
    stroke: rgba(52, 211, 153, 0.55);
}

.node-timing-pill {
    fill: rgba(15, 23, 42, 0.9);
    stroke: rgba(148, 163, 184, 0.22);
    stroke-width: 1px;
}

.node-timing-pill.type-decision {
    fill: rgba(69, 36, 10, 0.92);
    stroke: rgba(251, 191, 36, 0.34);
}

.node-timing-pill.type-timing_checkpoint,
.node-timing-pill.type-information_state {
    fill: rgba(49, 20, 88, 0.92);
    stroke: rgba(167, 139, 250, 0.34);
}

.node-timing-pill.type-composition_check {
    fill: rgba(8, 64, 78, 0.92);
    stroke: rgba(34, 211, 238, 0.34);
}

.node-timing-pill.type-milestone {
    fill: rgba(8, 77, 52, 0.92);
    stroke: rgba(52, 211, 153, 0.32);
}

/* ========================================
   Node Types - All 7 types with distinct styles
   ======================================== */

/* Action: Rectangle, Blue */
.node.type-action .node-rect,
.node.type-action .node-shape {
    stroke: #3b82f6;
    fill: rgba(59, 130, 246, 0.1);
}

/* Decision: Diamond, Amber */
.node.type-decision .node-shape {
    stroke: #f59e0b;
    fill: rgba(245, 158, 11, 0.15);
}

/* Milestone: Star, Emerald */
.node.type-milestone .node-shape {
    stroke: #10b981;
    fill: rgba(16, 185, 129, 0.15);
}

/* Timing Checkpoint: Diamond, Violet */
.node.type-timing_checkpoint .node-shape {
    stroke: #8b5cf6;
    fill: rgba(139, 92, 246, 0.15);
}

/* Composition Check: Diamond, Cyan */
.node.type-composition_check .node-shape {
    stroke: #06b6d4;
    fill: rgba(6, 182, 212, 0.15);
}

/* Information State: Hexagon, Violet */
.node.type-information_state .node-shape {
    stroke: #8b5cf6;
    fill: rgba(139, 92, 246, 0.15);
}

/* Harassment: Hexagon, Red */
.node.type-harassment .node-shape {
    stroke: #ef4444;
    fill: rgba(239, 68, 68, 0.15);
}

/* Active node styling */
.node.active .node-rect,
.node.active .node-shape {
    fill: rgba(59, 130, 246, 0.25);
    stroke-width: 2.5px;
}

.node.active .node-text.title {
    fill: #ffffff;
}

.node.active .node-timing-pill {
    stroke-width: 1.6px;
}

/* ========================================
   Node Importance Visual Hierarchy
   ======================================== */

.node.importance-critical .node-rect,
.node.importance-critical .node-shape {
    stroke-width: 3px;
    filter: drop-shadow(0 0 6px currentColor);
}

.node.importance-optional {
    opacity: 0.7;
}

.node.importance-optional .node-rect,
.node.importance-optional .node-shape {
    stroke-width: 1px;
    stroke-dasharray: 4, 2;
}

/* Exemplar nodes: orange dashed border for top-replay examples */
.node.exemplar .node-rect,
.node.exemplar .node-shape {
    stroke: #f97316;
    stroke-dasharray: 6, 3;
    opacity: 0.75;
}

/* ========================================
   Cross-link Toggle
   ======================================== */

.link-cross.hidden {
    display: none;
}

.btn-icon.active {
    background-color: #3b82f6;
    color: #fff;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 300px;
    color: #94a3b8;
    text-align: center;
    padding: 2rem;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 1.1rem;
    max-width: 400px;
    line-height: 1.6;
}

/* ========================================
   Focus Styles for All Node Shapes
   WCAG 2.4.7 Focus Visible (Level AA)
   ======================================== */

.node:focus .node-diamond,
.node:focus .node-hex {
    stroke: #3b82f6;
    stroke-width: 2px;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.6));
}

/* Skip Navigation Link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #3b82f6;
    color: #fff;
    padding: 0.5rem 1rem;
    z-index: 100;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 6px 0;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* ========================================
   Color Contrast Fixes
   WCAG 1.4.3 Contrast Minimum (4.5:1)
   ======================================== */

/* Original #64748b (~3.5:1) upgraded to #94a3b8 (~4.8:1) */
.link-cross {
    stroke-dasharray: 6, 4;
    opacity: 0.8;
    stroke: #94a3b8;
}

/* Improved contrast for secondary text */
#zoom-level {
    font-size: 0.8rem;
    color: #cbd5e1; /* Upgraded from #94a3b8 for better contrast */
    min-width: 45px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ========================================
   Node Legend Component
   ======================================== */

.learn-legend {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background-color: rgba(15, 23, 42, 0.95);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    z-index: 15;
    min-width: 180px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.learn-legend.collapsed {
    padding: 0.5rem;
    min-width: auto;
}

.learn-legend.collapsed .legend-items {
    display: none;
}

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    color: #f1f5f9;
    font-size: 0.85rem;
    font-weight: 600;
}

.learn-legend.collapsed .legend-header {
    margin-bottom: 0;
}

.legend-toggle {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 0.9rem;
    line-height: 1;
}

.legend-toggle:hover {
    color: #f1f5f9;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: #cbd5e1;
}

.legend-shape {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.legend-shape svg {
    width: 18px;
    height: 18px;
}

/* ========================================
   Keyboard Shortcuts Help Overlay
   ======================================== */

.shortcuts-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.shortcuts-overlay.visible {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

.shortcuts-panel {
    background-color: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.shortcuts-panel h3 {
    color: #f8fafc;
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.shortcuts-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.25rem;
}

.shortcuts-close:hover {
    color: #f1f5f9;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1rem;
}

.shortcut-key {
    background-color: #334155;
    color: #f1f5f9;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
    text-align: center;
    min-width: 60px;
}

.shortcut-desc {
    color: #cbd5e1;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
}

/* ========================================
   Reduced Motion Support
   WCAG 2.3.3 Animation from Interactions
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .btn-icon,
    .link,
    .node,
    .node-rect,
    .loading-overlay,
    .detail-panel,
    .shortcuts-overlay {
        transition: none !important;
    }

    .spinner {
        animation: none;
        border-top-color: #3b82f6;
        border-right-color: #3b82f6;
    }

    /* Disable zoom/pan transitions */
    svg {
        transition: none !important;
    }

    /* Disable edge scrolling animation */
    .viz-container {
        scroll-behavior: auto;
    }
}

/* ========================================
   Responsive Styles - Mobile Support
   ======================================== */

/* Tablet breakpoint */
@media (max-width: 1024px) {
    .learn-header {
        padding: 0 1rem;
        flex-wrap: wrap;
        height: auto;
        min-height: 60px;
        gap: 0.5rem;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .tree-select {
        min-width: 250px;
    }

    .detail-panel {
        width: 350px;
    }
}

/* Mobile breakpoint */
@media (max-width: 768px) {
    #page-learn {
        height: calc(100vh - 58px);
    }

    .learn-header {
        flex-direction: column;
        align-items: stretch;
        padding: 0.6rem 0.75rem;
        gap: 0.55rem;
    }

    .learn-header-info {
        justify-content: flex-start;
    }

    .learn-header-select,
    .tree-select {
        min-width: 0;
        width: 100%;
    }

    .learn-header-hint {
        display: none;
    }

    .learn-controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .tree-select {
        min-width: 100%;
        width: 100%;
        padding: 0.6rem 2rem 0.6rem 0.8rem;
        font-size: 1rem;
    }

    .view-controls {
        justify-content: center;
        width: 100%;
    }

    /* Touch-friendly button sizes (44x44px minimum) */
    .btn-icon {
        width: 44px;
        height: 44px;
        font-size: 1.25rem;
    }

    /* Full-width detail panel overlay on mobile */
    .detail-panel {
        width: 100%;
        left: 0;
        top: 0;
        bottom: 0;
        border-left: none;
        border-radius: 0;
        transform: translateY(100%);
    }

    .detail-panel.hidden {
        transform: translateY(100%);
    }

    .detail-panel:not(.hidden) {
        transform: translateY(0);
    }

    /* Legend repositioned for mobile */
    .learn-legend {
        bottom: auto;
        top: 0.5rem;
        left: 0.5rem;
        right: auto;
        max-width: calc(100% - 1rem);
    }

    .learn-opening-hint {
        top: 0.75rem;
        left: 0.75rem;
        right: 0.75rem;
        max-width: none;
    }

    .learn-legend.collapsed {
        max-width: auto;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .learn-header h2 {
        font-size: 1rem;
    }

    .shortcuts-panel {
        padding: 1rem;
        margin: 0.5rem;
    }

    .shortcuts-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .shortcut-key {
        display: inline-block;
        margin-right: 0.5rem;
    }
}

/* ========================================
   Screen Reader Announcer (hidden visually)
   ======================================== */

.sr-announcer {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
