/* ============================================================
   OS I/O Simulator — Laboratory Instrument Panel
   Precision instrument aesthetic · Cyan-teal accent · 7:3 layout
   ============================================================ */

:root {
    font-size: 15px; /* 全局基准放大 */

    /* ── Backgrounds (light → deeper) ── */
    --bg-deep:       #f3f4f6;
    --bg-panel:      #ffffff;
    --bg-card:       #eef0f3;
    --bg-elevated:   #e5e8ec;
    --bg-hover:      #dbe0e5;

    /* ── Text ── */
    --ink:           #1c1f24;
    --ink-bright:    #0b0d10;
    --ink-muted:     #5b6069;
    --ink-dim:       #8a8f98;

    /* ── Borders ── */
    --border:        #dce0e5;
    --border-light:  #e8ebef;
    --border-active: #c2c7ce;

    /* ── Primary accent: Cyan-Teal ── */
    --phosphor:      #0891b2;
    --phosphor-dim:  #0e7490;
    --phosphor-soft: rgba(8,145,178,0.08);
    --phosphor-glow: rgba(8,145,178,0.20);

    /* ── Secondary accent: Violet ── */
    --cyan:          #7c3aed;
    --cyan-soft:     rgba(124,58,237,0.08);

    /* ── Warning: Amber ── */
    --amber:         #d97706;
    --amber-soft:    rgba(217,119,6,0.10);

    /* ── Error: Red ── */
    --red:           #dc2626;
    --red-soft:      rgba(220,38,38,0.08);
    --red-glow:      rgba(220,38,38,0.22);

    /* ── Info/Read: Indigo ── */
    --cobalt:        #6366f1;
    --cobalt-soft:   rgba(99,102,241,0.10);

    /* ── Typography ── */
    --mono: 'JetBrains Mono', 'Courier New', monospace;
    --sans: 'Noto Sans SC', system-ui, -apple-system, sans-serif;

    /* ── Misc ── */
    --radius: 6px;
    --transition-fast: 0.15s ease;
    --transition-slow: 0.30s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 14px rgba(0,0,0,0.07);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg-deep); }

body {
    background: var(--bg-deep);
    color: var(--ink);
    font-family: var(--sans);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   TOP CONTROL BAR
   ============================================================ */

.top-control-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    height: 72px;
    box-sizing: border-box;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.ctrl-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ctrl-config {
    flex: 1;
    justify-content: center;
    gap: 16px;
}

.field-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--ink-muted);
    background: var(--bg-card);
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
}

.field-inline input[type="range"] {
    width: 100px;
}

.logo {
    font-family: var(--mono); font-weight: 700; font-size: 17px;
    color: var(--phosphor); letter-spacing: 2px;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
    font-family: var(--sans); font-size: 12px; font-weight: 600;
    padding: 6px 14px;
    border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer;
    background: var(--bg-panel);
    color: var(--ink-muted);
    transition: all var(--transition-fast);
    white-space: nowrap;
    letter-spacing: 0.3px;
}
.btn:hover {
    color: var(--ink-bright);
    border-color: var(--border-active);
    background: var(--bg-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--phosphor);
    color: #fff;
    border-color: var(--phosphor);
    font-weight: 700;
}
.btn-primary:hover {
    background: var(--phosphor-dim);
    box-shadow: 0 0 0 4px var(--phosphor-soft);
    color: #fff;
}
.btn-accent {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
    font-weight: 600;
}
.btn-accent:hover {
    background: var(--ink-bright);
    box-shadow: 0 0 0 4px rgba(28,31,36,0.08);
    color: #fff;
}
.btn-warn {
    background: var(--amber);
    color: #fff;
    border-color: var(--amber);
}
.btn-warn:hover {
    background: #b85d04;
    box-shadow: 0 0 0 4px var(--amber-soft);
    color: #fff;
}
.btn:disabled {
    opacity: 0.35;
    pointer-events: none;
    filter: grayscale(0.3);
}

/* ============================================================
   SELECT / INPUT / RANGE
   ============================================================ */

.sel, .inp {
    font-family: var(--sans); font-size: 12px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
    color: var(--ink);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}
.sel:focus, .inp:focus {
    border-color: var(--phosphor);
    box-shadow: 0 0 0 3px var(--phosphor-soft);
}
.sel.full, .inp.full { width: 100%; }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--phosphor);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

select.sel {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a8f98'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

/* ============================================================
   TOGGLE
   ============================================================ */

.toggle { display:inline-flex; align-items:center; gap:8px; cursor:pointer; }
.toggle input { display:none; }
.toggle-track {
    width:36px; height:20px; border-radius:10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    position:relative; transition: all var(--transition-fast);
}
.toggle input:checked + .toggle-track {
    background: var(--phosphor);
    border-color: var(--phosphor-dim);
}
.toggle-thumb {
    width:14px; height:14px; border-radius:50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    position:absolute; top:2px; left:2px;
    transition: all var(--transition-fast);
}
.toggle input:checked + .toggle-track .toggle-thumb {
    transform: translateX(16px);
}
.toggle-label {
    font-family: var(--sans); font-size: 11px; color: var(--ink-muted);
}

/* ============================================================
   CONNECTION STATUS
   ============================================================ */

.conn-status {
    font-family: var(--sans); font-size: 11px; font-weight: 600;
    padding: 6px 14px;
    border-radius: var(--radius);
    text-align: center;
    letter-spacing: 0.5px;
    transition: all var(--transition-slow);
}
.conn-status.connected {
    background: var(--phosphor-soft);
    color: var(--phosphor-dim);
    border: 1px solid var(--phosphor);
    animation: status-pulse 2s ease-in-out infinite;
}
.conn-status.disconnected {
    background: var(--bg-card);
    color: var(--ink-dim);
    border: 1px solid var(--border-light);
}
.conn-status.error {
    background: var(--red-soft);
    color: var(--red);
    border: 1px solid var(--red);
    animation: error-flicker 0.5s ease-in-out 3;
}
@keyframes status-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--phosphor-soft); }
    50% { box-shadow: 0 0 0 4px var(--phosphor-soft); }
}
@keyframes error-flicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ============================================================
   VISUALIZATION PANEL (grid dots ported from old .panel-topology)
   ============================================================ */

.panel-visual::before {
    content: '';
    position: absolute; inset: 0; pointer-events: none; z-index: 0;
    background-image: radial-gradient(circle, rgba(139,144,153,0.08) 1.5px, transparent 1.5px);
    background-size: 24px 24px;
}

.topo-svg {
    position: absolute; inset: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 1;
}

/* ============================================================
   SVG CONNECTORS
   ============================================================ */

.connector {
    stroke: var(--border-active);
    stroke-width: 1.5;
    transition: stroke 0.35s, filter 0.35s;
}
.connector.active {
    stroke: var(--phosphor);
    filter: url(#glow-active);
    stroke-width: 2;
}
.connector.loopback {
    stroke-dasharray: 6 3;
    opacity: 0;
    transition: opacity 0.4s, stroke 0.4s;
}
.connector.loopback.active {
    opacity: 1;
    stroke: var(--cyan);
    animation: dash-march 0.6s linear infinite;
}
.connector.return-path {
    stroke: var(--cobalt);
    stroke-width: 1.8;
    stroke-dasharray: 5 4;
    opacity: 0;
    transition: opacity 0.5s, stroke 0.5s;
}
.connector.return-path.active {
    opacity: 1;
    animation: dash-march-up 0.5s linear infinite;
}
@keyframes dash-march { to { stroke-dashoffset: -18; } }
@keyframes dash-march-up { to { stroke-dashoffset: -18; } }

.conn-label {
    font-family: var(--mono); font-size: 9px;
    color: var(--ink-dim);
    text-align: center; line-height: 24px;
    letter-spacing: 1px;
}

/* ============================================================
   LAYER CARDS (merged — single definition, no duplicates)
   ============================================================ */

.layer-card {
    position: absolute;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    z-index: 10;
    cursor: pointer;
    transition: all 0.35s cubic-bezier(0.4,0,0.2,1);
    transform: translateX(-50%);
    box-shadow: var(--shadow-sm);
}
.layer-card:hover {
    border-color: var(--phosphor);
    box-shadow: 0 0 12px var(--phosphor-soft), var(--shadow-md);
    transform: translateX(-50%) scale(1.02);
}
.layer-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--phosphor-soft), transparent);
    opacity: 0.8;
}
.layer-card.active {
    border-color: var(--phosphor);
    box-shadow:
        0 0 20px var(--phosphor-glow),
        0 4px 16px rgba(0,0,0,0.06);
    transform: translateX(-50%) scale(1.03);
    z-index: 20;
    animation: card-glow 2s ease-in-out infinite;
}
.layer-card.error {
    border-color: var(--red);
    box-shadow:
        0 0 24px var(--red-glow),
        inset 0 0 20px rgba(220,38,38,0.04);
    animation: err-shake 0.5s ease-in-out;
}
@keyframes card-glow {
    0%, 100% { box-shadow: 0 0 16px var(--phosphor-glow), 0 4px 12px rgba(0,0,0,0.04); }
    50% { box-shadow: 0 0 28px var(--phosphor-glow), 0 6px 20px rgba(0,0,0,0.08); }
}
@keyframes err-shake {
    0%,100% { transform:translateX(-50%); }
    20%,60% { transform:translateX(calc(-50% - 5px)); }
    40%,80% { transform:translateX(calc(-50% + 5px)); }
}

.layer-tag {
    font-family: var(--mono); font-size: 9px; font-weight: 600;
    color: var(--phosphor-dim);
    background: var(--phosphor-soft);
    padding: 2px 7px; border-radius: var(--radius);
    margin-right: 6px;
    letter-spacing: 1px;
}
.layer-name {
    font-family: var(--sans); font-weight: 700; font-size: 12px;
    color: var(--ink-bright);
    letter-spacing: 0.5px;
}
.layer-sub {
    font-family: var(--sans); font-size: 10px;
    color: var(--ink-muted);
    margin-top: 5px; display: block;
}

/* HW / INT bottom-row cards: override absolute positioning */
.layer-card.hw-card,
.layer-card.int-card {
    width: 290px;
    position: relative;
    transform: none;
    left: auto; right: auto; top: auto;
}
.layer-card.hw-card.active,
.layer-card.int-card.active {
    transform: scale(1.05);
    z-index: 30;
}

/* HW + INT row — synced to 500px (matches HTML inline) */
.hw-int-row {
    position: absolute; top: 500px; left: 0; right: 0; height: auto;
    display: flex; justify-content: center; align-items: flex-start; gap: 20px;
}

/* ============================================================
   BUFFER BOXES
   ============================================================ */

.buffers-row { display:flex; gap:6px; margin-top:8px; }
.kbuf {
    flex:1; padding:8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    font-family: var(--mono); font-size: 9px; text-align: center;
    transition: all 0.4s ease;
    position: relative;
}
.kbuf-label {
    display:block; font-weight: 700; margin-bottom: 3px;
    color: var(--ink-muted);
    letter-spacing: 0.5px;
}
.kbuf-data {
    display:block; color: var(--ink-dim);
    max-height: 14px; overflow: hidden;
    word-break: break-all;
}
.kbuf.write {
    background: var(--phosphor-soft);
    border-color: var(--phosphor);
    box-shadow: 0 0 10px var(--phosphor-glow);
    color: var(--phosphor-dim);
}
.kbuf.read {
    background: var(--cobalt-soft);
    border-color: var(--cobalt);
    box-shadow: 0 0 10px rgba(99,102,241,0.20);
    color: var(--cobalt);
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */

.pbar-wrap {
    width:100%; height:4px;
    background: var(--bg-card);
    border-radius: 2px;
    margin-top:8px; overflow:hidden;
    border: 1px solid var(--border-light);
}
.pbar-fill {
    height:100%; width:0%;
    background: linear-gradient(90deg, var(--phosphor-dim), var(--phosphor));
    border-radius: 2px;
    transition: width 0.5s ease;
}
.chunk-stat {
    font-family: var(--mono); font-size: 9px;
    color: var(--ink-dim);
    margin-top: 2px; display: block;
}

/* ============================================================
   REGISTERS
   ============================================================ */

.regs { margin-top:6px; }
.regs code {
    display:block; font-size: 9px;
    color: var(--ink-muted);
    font-family: var(--mono);
    padding: 2px 0;
}

/* ============================================================
   RIGHT INFO PANELS
   ============================================================ */

.panel-info {
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    padding: 12px; overflow-y: auto;
    display:flex; flex-direction:column; gap:8px;
}
.info-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    position: relative;
}
.info-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
    opacity: 0.6;
}
.info-card h3 {
    font-family: var(--sans); font-size: 11px; font-weight: 700;
    margin-bottom: 8px;
    color: var(--ink-bright);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Accordion header / body */
.accordion-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    padding: 2px 0;
    transition: color var(--transition-fast);
}
.accordion-header:hover { color: var(--phosphor); }
.accordion-arrow {
    font-size: 10px; color: var(--ink-dim);
    transition: transform 0.2s ease;
}
.accordion-body { display: none; padding-top: 6px; }
.accordion.open .accordion-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.accordion.open .accordion-arrow { transform: rotate(180deg); }

.info-card code {
    display:block; font-size: 12px;
    color: var(--ink-muted);
    font-family: var(--mono);
    margin-bottom: 3px;
}

.ubuf-scroll {
    max-height:100px; overflow-y:auto;
    font-family: var(--mono); font-size: 11px;
    color: var(--ink);
    word-break: break-all;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    margin-bottom: 6px;
    line-height: 1.6;
}

.log-scroll {
    max-height:200px; overflow-y:auto;
    font-family: var(--mono); font-size: 11px;
    color: var(--ink-muted);
}
.log-scroll div {
    padding: 2px 0;
    border-bottom: 1px solid var(--border-light);
    transition: color 0.2s;
}
.log-scroll div:first-child {
    color: var(--phosphor-dim);
    font-weight: 600;
}

/* ============================================================
   BADGES
   ============================================================ */

.badge {
    display:inline-block; padding: 2px 10px;
    border-radius: var(--radius);
    font-size: 10px; font-weight: 700;
    letter-spacing: 0.5px;
    font-family: var(--sans);
}
.badge-running {
    background: var(--phosphor-soft);
    color: var(--phosphor-dim);
    border: 1px solid var(--phosphor);
}
.badge-blocked {
    background: var(--amber-soft);
    color: var(--amber);
    border: 1px solid var(--amber);
}
.badge-ready {
    background: var(--cyan-soft);
    color: var(--cyan);
    border: 1px solid var(--cyan);
}

#err-msg.error {
    color: var(--red);
    font-weight: 700;
}

/* ============================================================
   PARTICLE CANVAS
   ============================================================ */

#particle-canvas {
    position: absolute; inset: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 20;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1100px) {
    .main-grid { grid-template-columns: 1fr !important; }
    .topo-anchor { width: 360px; height: 600px; }
    .layer-card { max-width: 280px; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar {
    width: 6px; height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-card);
}
::-webkit-scrollbar-thumb {
    background: var(--border-active);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--ink-dim);
}

::selection {
    background: var(--phosphor-soft);
    color: var(--phosphor-dim);
}
