/* ========================================================================
   AXiVRS Lab — The Motherboard
   マザーボード型テストベンチUI
   ======================================================================== */

/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --lab-base:       #0a0e1a;
    --lab-surface:    #0f1424;
    --lab-chip:       #1a1f2e;
    --lab-chip-hover: #252b3b;
    --lab-trace:      #00f0ff;
    --lab-trace-alt:  #00ff88;
    --lab-accent:     #ff6b35;
    --lab-text:       #e0e6ed;
    --lab-text-dim:   #6b7a90;
    --lab-danger:     #f0524e;
    --lab-warning:    #f59e0b;
    --lab-trace-rgb:  0, 240, 255;
    --lab-alt-rgb:    0, 255, 136;
    --lab-accent-rgb: 255, 107, 53;
}

html { font-size: 14px; }

body {
    background: var(--lab-base);
    color: var(--lab-text);
    font-family: 'Rajdhani', 'Segoe UI', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ── PCB Background ─────────────────────────────────────── */
.pcb-bg {
    position: fixed; inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

/* Circuit grid pattern */
.pcb-grid {
    position: absolute; inset: 0;
    background-image:
        linear-gradient(rgba(0,240,255,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,240,255,0.03) 1px, transparent 1px);
    background-size: 40px 40px;
}

/* Animated trace lines */
.pcb-trace {
    position: absolute;
    background: linear-gradient(90deg, transparent, rgba(var(--lab-trace-rgb), 0.15), transparent);
    height: 1px;
    animation: traceFlow 8s linear infinite;
}
.pcb-trace:nth-child(2) {
    width: 100%; top: 25%;
    animation-delay: -2s;
    animation-duration: 12s;
}
.pcb-trace:nth-child(3) {
    width: 80%; top: 50%; left: 10%;
    animation-delay: -4s;
    animation-duration: 10s;
}
.pcb-trace:nth-child(4) {
    width: 60%; top: 75%; left: 20%;
    animation-delay: -6s;
    animation-duration: 14s;
}

/* Vertical traces */
.pcb-trace-v {
    position: absolute;
    background: linear-gradient(180deg, transparent, rgba(var(--lab-alt-rgb), 0.1), transparent);
    width: 1px;
    animation: traceFlowV 10s linear infinite;
}
.pcb-trace-v:nth-child(5) { height: 100%; left: 20%; animation-delay: -3s; }
.pcb-trace-v:nth-child(6) { height: 80%; left: 50%; top: 10%; animation-delay: -5s; animation-duration: 12s; }
.pcb-trace-v:nth-child(7) { height: 70%; left: 80%; top: 15%; animation-delay: -7s; animation-duration: 8s; }

@keyframes traceFlow {
    0%   { opacity: 0; transform: translateX(-100%); }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { opacity: 0; transform: translateX(100%); }
}
@keyframes traceFlowV {
    0%   { opacity: 0; transform: translateY(-100%); }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(100%); }
}

/* Vignette */
.pcb-vignette {
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at center, transparent 40%, var(--lab-base) 100%);
}

/* ── Scan Line (boot animation) ─────────────────────────── */
.scan-line {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--lab-trace) 50%, transparent 100%);
    box-shadow: 0 0 20px rgba(var(--lab-trace-rgb), 0.5);
    z-index: 100;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
.scan-line.active {
    animation: scanDown 1.5s ease-out forwards;
}
@keyframes scanDown {
    0%   { transform: translateY(-10px); opacity: 1; }
    100% { transform: translateY(100vh); opacity: 0; }
}

/* ── Layout ──────────────────────────────────────────────── */
.lab-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px 60px;
}

/* ── Header (HUD Style) ─────────────────────────────────── */
.lab-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 24px;
    border-bottom: 1px solid rgba(var(--lab-trace-rgb), 0.1);
    margin-bottom: 32px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.lab-logo {
    width: 48px; height: 48px;
    border: 2px solid var(--lab-trace);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--lab-trace-rgb), 0.05);
    position: relative;
    overflow: hidden;
}
.lab-logo::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(var(--lab-trace-rgb), 0.1), transparent);
}
.lab-logo-icon {
    font-family: 'Orbitron', monospace;
    font-size: 18px;
    font-weight: 800;
    color: var(--lab-trace);
    position: relative;
    z-index: 1;
}

.title-block h1 {
    font-family: 'Orbitron', monospace;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--lab-text);
    line-height: 1;
}
.title-block .subtitle {
    font-size: 11px;
    letter-spacing: 4px;
    color: var(--lab-trace);
    text-transform: uppercase;
    margin-top: 4px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* HUD status readout */
.hud-readout {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 8px 16px;
    background: rgba(var(--lab-trace-rgb), 0.03);
    border: 1px solid rgba(var(--lab-trace-rgb), 0.08);
    border-radius: 6px;
}
.hud-item {
    display: flex;
    align-items: center;
    gap: 6px;
}
.hud-label {
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--lab-text-dim);
    text-transform: uppercase;
}
.hud-value {
    font-family: 'Orbitron', monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--lab-trace);
}
.hud-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--lab-trace-alt);
    box-shadow: 0 0 6px rgba(var(--lab-alt-rgb), 0.5);
    animation: dotPulse 2s ease-in-out infinite;
}
@keyframes dotPulse {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1; }
}

/* User info */
.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}
.user-info:hover { background: rgba(var(--lab-trace-rgb), 0.05); }
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: 1px solid rgba(var(--lab-trace-rgb), 0.2);
    object-fit: cover;
}
.user-avatar-fallback {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: 1px solid rgba(var(--lab-trace-rgb), 0.2);
    background: var(--lab-chip);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: var(--lab-trace);
}
.user-name {
    font-size: 13px;
    color: var(--lab-text-dim);
}

/* ── Section Header ──────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
}
.section-title .icon {
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    color: var(--lab-trace);
}
.section-title h2 {
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 3px;
    color: var(--lab-text-dim);
}
.section-title .count {
    font-family: 'Orbitron', monospace;
    font-size: 12px;
    color: var(--lab-trace);
    padding: 2px 8px;
    background: rgba(var(--lab-trace-rgb), 0.08);
    border: 1px solid rgba(var(--lab-trace-rgb), 0.15);
    border-radius: 4px;
}

.btn-rescan {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(var(--lab-trace-rgb), 0.06);
    border: 1px solid rgba(var(--lab-trace-rgb), 0.15);
    border-radius: 6px;
    color: var(--lab-trace);
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-rescan:hover {
    background: rgba(var(--lab-trace-rgb), 0.12);
    border-color: rgba(var(--lab-trace-rgb), 0.3);
}
.btn-rescan.scanning .rescan-icon {
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.rescan-icon { display: inline-block; }

/* ── Motherboard Grid ────────────────────────────────────── */
.motherboard {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    position: relative;
}

/* Bus line connecting chips */
.motherboard::before {
    content: '';
    position: absolute;
    bottom: -16px; left: 5%; right: 5%;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(var(--lab-trace-rgb), 0.08) 10%,
        rgba(var(--lab-trace-rgb), 0.15) 50%,
        rgba(var(--lab-trace-rgb), 0.08) 90%,
        transparent 100%
    );
}

/* ── Chip Card (CPU Module) ──────────────────────────────── */
.chip {
    position: relative;
    background: var(--lab-chip);
    border: 1px solid rgba(var(--lab-trace-rgb), 0.1);
    border-radius: 10px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    overflow: hidden;
}

/* Pin connectors (top & bottom) */
.chip::before,
.chip::after {
    content: '';
    position: absolute;
    left: 20%; right: 20%;
    height: 3px;
    background: repeating-linear-gradient(
        90deg,
        rgba(var(--lab-trace-rgb), 0.2) 0px,
        rgba(var(--lab-trace-rgb), 0.2) 4px,
        transparent 4px,
        transparent 10px
    );
}
.chip::before { top: 0; border-radius: 0 0 2px 2px; }
.chip::after  { bottom: 0; border-radius: 2px 2px 0 0; }

/* Side pins (left & right) */
.chip-pins-left,
.chip-pins-right {
    position: absolute;
    top: 20%; bottom: 20%;
    width: 3px;
    background: repeating-linear-gradient(
        180deg,
        rgba(var(--lab-trace-rgb), 0.2) 0px,
        rgba(var(--lab-trace-rgb), 0.2) 4px,
        transparent 4px,
        transparent 10px
    );
}
.chip-pins-left  { left: 0; border-radius: 0 2px 2px 0; }
.chip-pins-right { right: 0; border-radius: 2px 0 0 2px; }

/* Internal circuit pattern */
.chip-circuit {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
    background:
        linear-gradient(90deg, transparent 49.5%, rgba(var(--lab-trace-rgb), 0.04) 49.5%, rgba(var(--lab-trace-rgb), 0.04) 50.5%, transparent 50.5%),
        linear-gradient(0deg, transparent 49.5%, rgba(var(--lab-trace-rgb), 0.04) 49.5%, rgba(var(--lab-trace-rgb), 0.04) 50.5%, transparent 50.5%);
    background-size: 20px 20px;
}

.chip:hover {
    border-color: rgba(var(--lab-trace-rgb), 0.3);
    background: var(--lab-chip-hover);
    transform: translateY(-2px);
    box-shadow:
        0 8px 32px rgba(0,0,0,0.3),
        0 0 20px rgba(var(--lab-trace-rgb), 0.05),
        inset 0 1px 0 rgba(var(--lab-trace-rgb), 0.1);
}
.chip:hover .chip-circuit { opacity: 1; }
.chip:hover .chip-pins-left,
.chip:hover .chip-pins-right {
    background: repeating-linear-gradient(
        180deg,
        rgba(var(--lab-trace-rgb), 0.4) 0px,
        rgba(var(--lab-trace-rgb), 0.4) 4px,
        transparent 4px,
        transparent 10px
    );
}

/* Chip header */
.chip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    position: relative;
    z-index: 1;
}

.chip-label-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chip-color-dot {
    width: 10px; height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.chip-name {
    font-family: 'Orbitron', monospace;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--lab-text);
}

/* Status LED */
.chip-status {
    display: flex;
    align-items: center;
    gap: 6px;
}
.status-led {
    width: 8px; height: 8px;
    border-radius: 50%;
    position: relative;
}
.status-led::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    opacity: 0.3;
}

.status-led.online {
    background: var(--lab-trace-alt);
    box-shadow: 0 0 8px rgba(var(--lab-alt-rgb), 0.6);
}
.status-led.online::after { background: var(--lab-trace-alt); }

.status-led.testing {
    background: var(--lab-warning);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
    animation: ledBlink 2s ease-in-out infinite;
}
.status-led.testing::after { background: var(--lab-warning); }

.status-led.unregistered {
    background: var(--lab-trace);
    box-shadow: 0 0 8px rgba(var(--lab-trace-rgb), 0.5);
    animation: ledBlink 1.5s ease-in-out infinite;
}
.status-led.unregistered::after { background: var(--lab-trace); }

.status-led.fault {
    background: var(--lab-danger);
    box-shadow: 0 0 8px rgba(240, 82, 78, 0.6);
    animation: ledBlink 0.8s ease-in-out infinite;
}
.status-led.fault::after { background: var(--lab-danger); }

@keyframes ledBlink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.3; }
}

.status-text {
    font-family: 'Orbitron', monospace;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.status-text.online       { color: var(--lab-trace-alt); }
.status-text.testing      { color: var(--lab-warning); }
.status-text.unregistered { color: var(--lab-trace); }
.status-text.fault        { color: var(--lab-danger); }

/* Chip body — silkscreen style info */
.chip-body {
    position: relative;
    z-index: 1;
}

.chip-desc {
    font-size: 12px;
    color: var(--lab-text-dim);
    line-height: 1.5;
    margin-bottom: 14px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 36px;
}

/* Chip footer — metadata printed on PCB */
.chip-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid rgba(var(--lab-trace-rgb), 0.06);
}

.chip-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}
.chip-meta-label {
    font-size: 9px;
    letter-spacing: 1.5px;
    color: rgba(var(--lab-trace-rgb), 0.4);
    text-transform: uppercase;
    font-family: 'Orbitron', monospace;
}
.chip-meta-value {
    font-family: 'Orbitron', monospace;
    font-size: 11px;
    font-weight: 500;
    color: var(--lab-text-dim);
}

/* Chip silkscreen corner marker */
.chip-corner {
    position: absolute;
    top: 8px; right: 8px;
    width: 12px; height: 12px;
    border-top: 1px solid rgba(var(--lab-trace-rgb), 0.15);
    border-right: 1px solid rgba(var(--lab-trace-rgb), 0.15);
    border-radius: 0 4px 0 0;
    z-index: 1;
}

/* Chip boot animation */
.chip.booting {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
}
.chip.booted {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Empty Slot ──────────────────────────────────────────── */
.empty-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    grid-column: 1 / -1;
    padding: 60px 20px;
    text-align: center;
}

.empty-slot-icon {
    width: 80px; height: 80px;
    border: 2px dashed rgba(var(--lab-trace-rgb), 0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}
.empty-slot-icon svg {
    width: 32px; height: 32px;
    stroke: rgba(var(--lab-trace-rgb), 0.3);
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.empty-slot h3 {
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 3px;
    color: var(--lab-text-dim);
    margin-bottom: 8px;
}
.empty-slot p {
    font-size: 13px;
    color: rgba(var(--lab-trace-rgb), 0.4);
    max-width: 400px;
    line-height: 1.6;
}

/* ── Loading State ───────────────────────────────────────── */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    grid-column: 1 / -1;
}
.loading-spinner {
    width: 40px; height: 40px;
    border: 2px solid rgba(var(--lab-trace-rgb), 0.1);
    border-top-color: var(--lab-trace);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}
.loading-text {
    font-family: 'Orbitron', monospace;
    font-size: 11px;
    letter-spacing: 3px;
    color: var(--lab-text-dim);
}

/* ── Login Overlay ───────────────────────────────────────── */
.login-overlay {
    position: fixed; inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 14, 26, 0.95);
    backdrop-filter: blur(8px);
}
.login-container {
    text-align: center;
    padding: 40px;
}
.login-logo {
    width: 80px; height: 80px;
    border: 2px solid var(--lab-trace);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--lab-trace-rgb), 0.05);
    margin: 0 auto 24px;
    font-family: 'Orbitron', monospace;
    font-size: 28px;
    font-weight: 800;
    color: var(--lab-trace);
    position: relative;
    overflow: hidden;
}
.login-logo::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(var(--lab-trace-rgb), 0.15), transparent);
}
.login-title {
    font-family: 'Orbitron', monospace;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--lab-text);
    margin-bottom: 8px;
}
.login-subtitle {
    font-size: 13px;
    letter-spacing: 4px;
    color: var(--lab-trace);
    text-transform: uppercase;
    margin-bottom: 32px;
}
.login-btn-area {
    display: flex;
    justify-content: center;
}

/* ── Footer ──────────────────────────────────────────────── */
.lab-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 0;
    margin-top: 48px;
    border-top: 1px solid rgba(var(--lab-trace-rgb), 0.06);
}
.footer-version {
    font-family: 'Orbitron', monospace;
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--lab-text-dim);
}
.footer-status {
    display: flex;
    align-items: center;
    gap: 6px;
}
.footer-status .conn-dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--lab-trace-alt);
    box-shadow: 0 0 4px rgba(var(--lab-alt-rgb), 0.5);
}
.footer-status .conn-text {
    font-family: 'Orbitron', monospace;
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--lab-text-dim);
}

/* ── Toast ────────────────────────────────────────────────── */
.lab-toast {
    position: fixed;
    bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 10px 20px;
    background: var(--lab-chip);
    border: 1px solid rgba(var(--lab-trace-rgb), 0.2);
    border-radius: 8px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    color: var(--lab-text);
    z-index: 200;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.lab-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .lab-container { padding: 16px; }
    .lab-header { flex-direction: column; gap: 16px; align-items: flex-start; }
    .header-right { width: 100%; justify-content: space-between; }
    .hud-readout { flex-wrap: wrap; gap: 12px; }
    .motherboard { grid-template-columns: 1fr; gap: 16px; }
    .title-block h1 { font-size: 18px; }
}

@media (max-width: 480px) {
    .hud-readout { display: none; }
    .chip-meta { flex-wrap: wrap; gap: 8px; }
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--lab-base); }
::-webkit-scrollbar-thumb {
    background: rgba(var(--lab-trace-rgb), 0.15);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--lab-trace-rgb), 0.3);
}

/* ── Reduced Motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
