:root {
  --primary: #1d4ed8;
  --primary-light: #eff6ff;
  --indigo: #4f46e5;
  --teal: #0f766e;
  --success: #059669;
  --warning: #b45309;
  --danger: #dc2626;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --card-bg: #fff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; background: #f8fafc; color: var(--text-primary); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
ul { list-style: none; }

/* NAV */
.top-nav { background: rgba(255,255,255,0.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); padding: 0 20px; position: sticky; top: 0; z-index: 300; }
.top-nav-inner { height: 52px; max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.nav-back { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); padding: 6px 12px; border: 1px solid var(--border); border-radius: 20px; white-space: nowrap; transition: all 0.15s; }
.nav-back:hover { color: var(--primary); border-color: var(--primary); }
.nav-title { font-size: 0.9rem; font-weight: 800; color: var(--text-primary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* HERO */
.tool-hero { background: linear-gradient(135deg, #1e1b4b 0%, #4338ca 50%, #0f766e 100%); color: #fff; padding: 28px 20px 24px; text-align: center; }
.tool-hero h1 { font-size: 1.4rem; font-weight: 900; margin-bottom: 6px; }
.tool-hero p { font-size: 0.83rem; opacity: 0.9; line-height: 1.65; }
.hero-chips { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.hero-chip { background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 20px; padding: 4px 11px; font-size: 0.72rem; font-weight: 600; }

/* SCENARIO TABS */
.sc-tabs-wrap { background: var(--card-bg); border-bottom: 1px solid var(--border); }
.sc-tabs { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; max-width: 1100px; margin: 0 auto; }
.sc-tabs::-webkit-scrollbar { display: none; }
.sc-tab { flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 14px; border: none; border-bottom: 3px solid transparent; background: none; cursor: pointer; transition: all 0.15s; color: var(--text-muted); font-weight: 700; min-width: 80px; }
.sc-tab:hover { color: var(--text-secondary); background: #f8fafc; }
.sc-tab.active { color: var(--indigo); border-bottom-color: var(--indigo); background: #f8fafc; }
.sc-tab-icon { font-size: 1.3rem; line-height: 1; }
.sc-tab-name { font-size: 0.68rem; white-space: nowrap; }
.sc-desc { max-width: 1100px; margin: 0 auto; padding: 8px 16px; font-size: 0.78rem; color: var(--text-secondary); border-top: 1px solid var(--border); background: #f8fafc; line-height: 1.6; }

/* VIZ OUTER WRAP */
.viz-wrap-outer { max-width: 1100px; margin: 0 auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 14px; }

/* VIZ LAYOUT */
.viz-layout { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 860px) { .viz-layout { grid-template-columns: 3fr 2fr; } }

/* VISUALIZER PANEL */
.viz-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.viz-panel-header { padding: 10px 16px; background: #f8fafc; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.viz-panel-title { font-size: 0.85rem; font-weight: 800; color: var(--text-primary); }
.step-counter { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); flex-shrink: 0; }

/* SVG AREA */
.svg-container { position: relative; width: 100%; background: #f8fafc; overflow: hidden; }
#vizSvg { display: block; width: 100%; height: auto; }
#htmlVizArea { width: 100%; padding: 12px; overflow-x: auto; }

/* STEP DOTS */
.step-dots { display: flex; gap: 6px; justify-content: center; padding: 10px; flex-wrap: wrap; }
.step-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); cursor: pointer; transition: all 0.2s; border: 2px solid transparent; }
.step-dot.done { background: #c7d2fe; }
.step-dot.active { background: var(--indigo); transform: scale(1.35); border-color: rgba(79,70,229,0.2); }
.step-dot:hover:not(.active) { background: #94a3b8; }

/* STEP CONTROLS */
.step-controls { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); background: #f8fafc; flex-wrap: wrap; }
.ctrl-btn { font-size: 0.8rem; font-weight: 700; padding: 8px 16px; border-radius: 8px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-secondary); cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.ctrl-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.ctrl-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ctrl-btn.primary { background: var(--indigo); color: #fff; border-color: var(--indigo); }
.ctrl-btn.primary:hover:not(:disabled) { background: #3730a3; }
.ctrl-btn.reset { font-size: 0.75rem; margin-left: auto; }

/* STEP DESC */
.step-desc-card { padding: 14px 16px; border-top: 1px solid var(--border); }
.step-desc-title { font-size: 0.88rem; font-weight: 800; color: var(--text-primary); margin-bottom: 6px; }
.step-desc { font-size: 0.82rem; line-height: 1.8; color: var(--text-secondary); }

/* INFO PANEL */
.info-panel { display: flex; flex-direction: column; gap: 10px; }
.info-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.info-card.warn { background: #fffbeb; border-color: #fde68a; }
.info-card.exam { background: var(--primary-light); border-color: #bfdbfe; }
.info-card-label { font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.info-card-text { font-size: 0.82rem; line-height: 1.75; color: var(--text-secondary); }
#examList { padding-left: 0; display: flex; flex-direction: column; gap: 6px; }
#examList li { font-size: 0.8rem; line-height: 1.6; color: var(--text-secondary); padding-left: 14px; position: relative; }
#examList li::before { content: '•'; position: absolute; left: 0; color: var(--indigo); font-weight: 900; }

/* SECTION CARDS (fault sim, diagnosis) */
.section-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.section-card-header { padding: 12px 18px; font-size: 0.9rem; font-weight: 900; background: #f8fafc; border-bottom: 1px solid var(--border); }

/* FAULT SIMULATION */
.fault-sim-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 16px; }
@media (max-width: 600px) { .fault-sim-layout { grid-template-columns: 1fr; } }
.fault-col {}
.fault-select-label { font-size: 0.78rem; font-weight: 800; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.fault-radio-group { display: flex; flex-direction: column; gap: 6px; }
.radio-item { font-size: 0.82rem; color: var(--text-primary); display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 5px 8px; border-radius: 6px; transition: background 0.1s; }
.radio-item:hover { background: #f1f5f9; }
.radio-item input { accent-color: var(--indigo); cursor: pointer; }
.radio-item.disabled { opacity: 0.3; pointer-events: none; text-decoration: line-through; }
.btn-simulate { display: block; margin: 0 16px 16px; padding: 12px 24px; background: var(--indigo); color: #fff; font-size: 0.88rem; font-weight: 800; border: none; border-radius: var(--radius-sm); cursor: pointer; transition: background 0.15s; }
.btn-simulate:hover { background: #3730a3; }

/* FAULT RESULT */
.fault-result { margin: 0 16px 16px; border-radius: var(--radius-sm); overflow: hidden; }
.fault-result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; background: #f8fafc; border-radius: var(--radius-sm); }
@media (max-width: 600px) { .fault-result-grid { grid-template-columns: 1fr; } }
.fault-result-item { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.fault-result-item.full-width { grid-column: 1 / -1; }
.fault-result-label { font-size: 0.7rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.fault-result-value { font-size: 0.82rem; line-height: 1.6; color: var(--text-primary); font-weight: 600; }
.fault-result-value.ok { color: var(--success); }
.fault-result-value.warn { color: var(--warning); }
.fault-result-value.ng { color: var(--danger); }
.fault-result-exam { background: var(--primary-light); border-left: 3px solid var(--primary); padding: 10px 12px; font-size: 0.8rem; line-height: 1.7; color: var(--text-secondary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* DIAGNOSIS */
.diag-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
@media (max-width: 600px) { .diag-grid { grid-template-columns: 1fr; } }
.diag-item { display: flex; flex-direction: column; gap: 5px; }
.diag-label { font-size: 0.78rem; font-weight: 700; color: var(--text-secondary); }
.diag-select { padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 0.82rem; background: var(--card-bg); color: var(--text-primary); 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='%2394a3b8'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.diag-select:focus { outline: none; border-color: var(--primary); }

/* RAID COMPARE TABLE */
.raid-compare-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.raid-compare-table th { background: #f1f5f9; padding: 8px 10px; text-align: center; font-weight: 800; color: var(--text-secondary); border: 1px solid var(--border); }
.raid-compare-table td { padding: 8px 10px; border: 1px solid var(--border); text-align: center; color: var(--text-primary); }
.raid-compare-table .good { color: var(--success); font-weight: 700; }
.raid-compare-table .bad { color: var(--danger); font-weight: 700; }
.raid-compare-table .mid { color: var(--warning); font-weight: 700; }
.raid-compare-table .raid-name { font-weight: 900; font-size: 0.85rem; }

/* SVG COMMON STYLES */
.node-label { font-size: 10px; fill: #1e293b; font-weight: 700; text-anchor: middle; pointer-events: none; }
.node-sublabel { font-size: 8px; fill: #64748b; text-anchor: middle; pointer-events: none; }
.arrow-label { font-size: 8.5px; fill: #64748b; text-anchor: middle; pointer-events: none; }
.timeline-label { font-size: 9px; fill: #475569; text-anchor: middle; font-weight: 700; pointer-events: none; }
.dim-label { font-size: 10px; fill: #94a3b8; text-anchor: middle; pointer-events: none; }

/* Data block color classes (used in SVG) */
.blk-a { fill: #3b82f6; }
.blk-b { fill: #10b981; }
.blk-c { fill: #f59e0b; }
.blk-d { fill: #8b5cf6; }
.blk-e { fill: #ef4444; }
.blk-p { fill: #6b7280; }
.blk-log { fill: #14b8a6; }
.blk-fail { fill: #fee2e2; stroke: #ef4444; stroke-width: 1.5; }

/* Animation: data flowing */
@keyframes flow-anim {
  0% { stroke-dashoffset: 20; }
  100% { stroke-dashoffset: 0; }
}
.flow-arrow { stroke-dasharray: 6, 3; animation: flow-anim 0.6s linear infinite; }

/* Animation: pulse glow */
@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 2px currentColor); }
  50% { filter: drop-shadow(0 0 8px currentColor); }
}
.glow-node { animation: pulse-glow 1.5s ease-in-out infinite; }

/* Animation: failure blink */
@keyframes fail-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.fail-blink { animation: fail-blink 0.7s ease-in-out infinite; }

/* TOAST */
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px); background: #1e293b; color: #fff; padding: 10px 20px; border-radius: 20px; font-size: 0.82rem; font-weight: 600; opacity: 0; transition: all 0.25s; z-index: 999; white-space: nowrap; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Page bottom padding */
body { padding-bottom: 60px; }
