/* ==========================================================================
   System Design Simulator (/simulator/) — drag-and-drop architecture canvas.
   The page rebuilds document.body on every view change, so all of its CSS
   lives here rather than in an injected <style> that a re-render would wipe.
   Tokens come from core.css.
   ========================================================================== */

:root {
    --sidebar-w: 240px;

    /* Aliases for the short names the canvas JS inlines into SVG stroke/fill
       attributes (edge colours, verdict colours). Kept as aliases so there is
       still one source of truth in core.css. */
    --green: var(--success);
    --yellow: var(--warning);
    --red: var(--danger);
    --dim: var(--text-dim);
    --muted: var(--text-muted);
}

/* The canvas owns the viewport; panes scroll, the page does not. */
body { height: 100vh; overflow: hidden; }

/* --------------------------------------------------------------------------
   Builder header
   -------------------------------------------------------------------------- */
.bd-hdr {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0 var(--sp-4);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.bd-logo { text-decoration: none; display: inline-flex; align-items: center; gap: 7px; }
.bd-wordmark { font-size: var(--fs-md); font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.bd-wordmark b { color: var(--accent); font-weight: 700; }
.bd-back {
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 5px 10px;
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    text-decoration: none;
    display: inline-block;
    transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.bd-back:hover { color: var(--text); border-color: var(--accent); }
.bd-title { font-weight: 600; }
.bd-actions { margin-left: auto; display: flex; gap: var(--sp-2); }
.bd-actions button {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 14px;
    min-height: 34px;
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    font-weight: 600;
    transition: border-color var(--dur-fast) var(--ease);
}
.bd-actions button:hover { border-color: var(--accent); }
.bd-actions .primary { background: var(--accent-subtle); border-color: var(--accent); color: var(--accent); }
.bd-actions .primary:hover { background: var(--accent-subtle-hover); }
.bd-actions .accent { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.bd-actions .accent:hover { filter: brightness(1.08); }

/* --------------------------------------------------------------------------
   Body: library · canvas · inspector
   -------------------------------------------------------------------------- */
.bd-body { display: flex; height: calc(100vh - var(--header-h)); }

.bd-lib {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: var(--sp-3);
    flex-shrink: 0;
}
.lib-cat { font-size: 0.68rem; color: var(--accent); text-transform: uppercase; font-weight: 700; margin: var(--sp-3) 0 5px; letter-spacing: 0.05em; }
.lib-item { display: flex; align-items: center; gap: var(--sp-2); padding: 7px 9px; border-radius: var(--r-sm); cursor: grab; font-size: var(--fs-sm); transition: background var(--dur-fast) var(--ease); }
.lib-item:hover { background: var(--bg); }
.lib-ic {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px;
    color: var(--accent);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    flex-shrink: 0;
}
.lib-ic svg { width: 15px; height: 15px; }

.bd-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg);
    background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
    background-size: 22px 22px;
}
.bd-brief {
    position: absolute;
    top: var(--sp-3); left: var(--sp-3); right: var(--sp-3);
    z-index: 5;
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 13px var(--sp-4);
    box-shadow: var(--shadow);
}
.brief-prompt { font-size: var(--fs-base); font-weight: 600; line-height: 1.5; margin-bottom: 9px; }
.brief-reqs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.req-pill { font-size: var(--fs-xs); color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-full); padding: 3px 10px; }
.bd-brief .bd-hint { color: var(--text-dim); font-size: var(--fs-xs); border-top: 1px solid var(--border); padding-top: var(--sp-2); }

.bd-edges { position: absolute; inset: 0; z-index: 1; pointer-events: none; width: 100%; height: 100%; }
.bd-canvas { position: absolute; inset: 0; z-index: 2; }

.bd-side { width: 220px; background: var(--surface); border-left: 1px solid var(--border); padding: var(--sp-4); overflow-y: auto; flex-shrink: 0; }
.bd-side h3 { font-size: var(--fs-xs); text-transform: uppercase; color: var(--text-dim); margin: var(--sp-3) 0 6px; letter-spacing: 0.05em; }
.bd-side h3:first-child { margin-top: 0; }
.sp-scale { font-size: var(--fs-lg); font-weight: 700; color: var(--accent); }
.sp-scale span { font-size: var(--fs-xs); color: var(--text-dim); font-weight: 400; }
.sp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.sp-grid div { background: var(--bg); border-radius: var(--r-sm); padding: var(--sp-2); text-align: center; }
.sp-grid b { display: block; font-size: var(--fs-md); color: var(--accent); }
.sp-grid span { font-size: 0.65rem; color: var(--text-dim); }
.sp-bn { margin-top: 10px; font-size: var(--fs-sm); }
.sp-bn ul { list-style: none; margin-top: 6px; }
.sp-bn li {
    background: color-mix(in srgb, var(--danger) 8%, transparent);
    border-left: 3px solid var(--danger);
    padding: 7px;
    border-radius: var(--r-xs);
    margin-bottom: 6px;
    font-size: var(--fs-xs);
}
.sp-bn em { color: var(--text-dim); font-size: var(--fs-xs); }
.sp-ok { margin-top: 10px; background: color-mix(in srgb, var(--success) 10%, transparent); color: var(--success); padding: var(--sp-2); border-radius: var(--r-sm); font-size: var(--fs-sm); }
.sp-tip { color: var(--text-dim); font-size: var(--fs-sm); line-height: 1.55; background: var(--bg); padding: 10px; border-radius: var(--r-sm); }
.sp-kind { font-weight: 700; color: var(--danger); }

/* --------------------------------------------------------------------------
   Nodes
   -------------------------------------------------------------------------- */
.node {
    position: absolute;
    width: 112px;
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    border: 1.5px solid var(--border);
    border-radius: var(--r-md);
    padding: 11px var(--sp-2) 9px;
    display: flex; flex-direction: column; align-items: center;
    gap: 5px;
    cursor: grab;
    user-select: none;
    z-index: 3;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
                transform var(--dur-fast) var(--ease);
}
.node:hover { box-shadow: var(--shadow-accent); transform: translateY(-1px); }
.node:hover .node-x, .node:hover .node-handle { opacity: 1; }
.node.healthy { border-color: var(--success); }
.node.warning { border-color: var(--warning); }
.node.bottleneck { border-color: var(--danger); animation: sim-pulse 1s infinite alternate; }
.node.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes sim-pulse {
    from { box-shadow: 0 0 6px color-mix(in srgb, var(--danger) 30%, transparent); }
    to   { box-shadow: 0 0 20px color-mix(in srgb, var(--danger) 60%, transparent); }
}
.node-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    color: var(--accent-contrast);
    background: var(--accent);
    border-radius: 9px;
}
.node-icon svg { width: 18px; height: 18px; }
.node.healthy .node-icon { background: var(--success); }
.node.warning .node-icon { background: var(--warning); color: #1a1a24; }
.node.bottleneck .node-icon { background: var(--danger); }
.node-label { font-size: var(--fs-xs); color: var(--text); font-weight: 600; text-align: center; line-height: 1.2; }
.node-load { font-size: 0.62rem; color: var(--text-dim); font-weight: 700; }
.node-inst { display: inline-flex; align-items: center; gap: 5px; }
.ni-btn {
    width: 17px; height: 17px;
    line-height: 1;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--r-xs);
    font-size: var(--fs-sm);
    font-weight: 700;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
}
.ni-btn:hover { border-color: var(--accent); color: var(--accent); }
.ni-n { font-size: 0.66rem; font-weight: 800; color: var(--text-muted); min-width: 22px; text-align: center; }
.node-alert { font-size: 0.6rem; color: var(--danger); font-weight: 700; }
.node-handle {
    position: absolute;
    right: -8px; top: 50%;
    transform: translateY(-50%);
    width: 15px; height: 15px;
    font-size: 0;
    cursor: crosshair;
    opacity: 0.6;
    background: var(--accent);
    border: 2px solid var(--surface);
    border-radius: 50%;
    transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.node-handle:hover { transform: translateY(-50%) scale(1.3); }
.node-x {
    position: absolute;
    top: -8px; right: -8px;
    width: 18px; height: 18px;
    background: var(--danger);
    color: #fff;
    border-radius: 50%;
    font-size: var(--fs-sm);
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease);
}

/* Animated request flow along the wires */
.bd-edges path.flow { stroke-dasharray: 7 6; animation: sim-flow 0.6s linear infinite; }
.bd-edges path.flow-bad { animation-duration: 0.28s; }
@keyframes sim-flow { to { stroke-dashoffset: -13; } }

/* --------------------------------------------------------------------------
   Status + metrics overlays
   -------------------------------------------------------------------------- */
.bd-status {
    position: absolute;
    bottom: var(--sp-3); left: var(--sp-3);
    z-index: 6;
    font-size: var(--fs-xs);
    color: var(--text-dim);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 6px var(--sp-3);
    max-width: calc(100% - 28px);
}
.bd-status b { color: var(--text); }

.bd-metrics {
    position: absolute;
    bottom: var(--sp-3); left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    display: flex;
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}
.mx { padding: 9px 18px; text-align: center; border-right: 1px solid var(--border); }
.mx:last-child { border-right: none; }
.mx-v { display: block; font-size: var(--fs-md); font-weight: 800; color: var(--success); }
.mx-v.bad { color: var(--danger); }
.mx-l { font-size: 0.62rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

/* --------------------------------------------------------------------------
   Evaluation report
   -------------------------------------------------------------------------- */
.report-ov { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: var(--sp-5); }
.report {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-6);
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}
.report-close { position: absolute; top: var(--sp-3); right: var(--sp-4); color: var(--text-dim); font-size: 1.5rem; line-height: 1; }
.report-close:hover { color: var(--text); }
.report-score { text-align: center; margin-bottom: var(--sp-4); }
.rs-pct { display: block; font-size: 2.6rem; font-weight: 800; line-height: 1; }
.rs-verdict { display: block; font-size: var(--fs-md); font-weight: 700; margin-top: 4px; }
.rs-sub { display: block; font-size: var(--fs-sm); color: var(--text-dim); margin-top: 2px; }
.rep-sim { text-align: center; font-size: var(--fs-sm); color: var(--text-dim); background: var(--bg); padding: var(--sp-2); border-radius: var(--r-sm); margin-bottom: var(--sp-4); }
.report h4 { font-size: var(--fs-base); margin: var(--sp-4) 0 var(--sp-2); }
.rep-rubric { list-style: none; }
.rep-rubric li { padding: 7px 10px; border-radius: var(--r-sm); margin-bottom: 5px; font-size: var(--fs-sm); }
.rep-rubric li.ok { background: color-mix(in srgb, var(--success) 10%, transparent); color: var(--success); }
.rep-rubric li.no { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }
.rep-ref { margin-top: 18px; padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.ref-stack { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ref-chip { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-full); padding: 3px 11px; font-size: var(--fs-xs); }
.rep-ref p { color: var(--text-dim); font-size: var(--fs-sm); line-height: 1.6; margin-bottom: var(--sp-3); }
/* Block-level so the "read the design" and "draw it" next-steps stack instead of
   colliding on one line. */
.ref-link { display: block; color: var(--accent); text-decoration: none; font-weight: 600; font-size: var(--fs-sm); }
.ref-link + .ref-link { margin-top: 6px; }
.ref-link:hover { text-decoration: underline; }
.rep-retry {
    width: 100%;
    margin-top: 18px;
    background: var(--accent);
    color: var(--accent-contrast);
    padding: 11px;
    border-radius: var(--r-md);
    font-weight: 700;
    font-size: var(--fs-base);
}
.rep-modes { list-style: none; }
.rep-modes li {
    background: color-mix(in srgb, var(--danger) 8%, transparent);
    border-left: 3px solid var(--danger);
    padding: 9px 11px;
    border-radius: var(--r-xs);
    margin-bottom: 7px;
    font-size: var(--fs-sm);
    line-height: 1.55;
}
.rep-modes b { color: var(--danger); }
.rep-modes em { color: var(--text-dim); }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.toast {
    position: fixed;
    bottom: var(--sp-6); left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--danger);
    color: var(--text);
    padding: var(--sp-3) var(--sp-5);
    border-radius: var(--r-md);
    z-index: 200;
    font-size: var(--fs-sm);
    box-shadow: var(--shadow-lg);
}

/* --------------------------------------------------------------------------
   Onboarding tour (first run + "? Help")
   -------------------------------------------------------------------------- */
.onb-back {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(3px);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    padding: var(--sp-5);
    animation: onb-fade var(--dur) var(--ease);
}
@keyframes onb-fade { from { opacity: 0; } to { opacity: 1; } }
.onb-card {
    position: relative;
    max-width: 430px;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-6) var(--sp-5) var(--sp-5);
    box-shadow: var(--shadow-lg);
}
.onb-h { font-size: var(--fs-lg); font-weight: 800; color: var(--text); margin-bottom: 10px; letter-spacing: -0.02em; }
.onb-b { font-size: var(--fs-base); line-height: 1.7; color: var(--text-muted); }
.onb-b b { color: var(--text); }
.onb-tip { color: var(--text-dim); font-size: var(--fs-sm); }
.onb-skip { position: absolute; top: var(--sp-3); right: var(--sp-3); color: var(--text-dim); font-size: 1.35rem; line-height: 1; }
.onb-skip:hover { color: var(--text); }
.onb-foot { display: flex; align-items: center; justify-content: space-between; margin-top: var(--sp-5); gap: var(--sp-3); }
.onb-dots { display: flex; gap: 6px; }
.onb-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.onb-dot.on { background: var(--accent); }
.onb-btns { display: flex; gap: var(--sp-2); }
.onb-btns button {
    font-size: var(--fs-sm);
    font-weight: 600;
    border-radius: var(--r-sm);
    padding: 0.5rem 1rem;
    min-height: 38px;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.onb-btns .onb-next { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.onb-btns .onb-next:hover { filter: brightness(1.08); }
.onb-btns .onb-prev:hover, .onb-btns .onb-skip2:hover { color: var(--text); border-color: var(--accent); }

/* --------------------------------------------------------------------------
   Responsive — the canvas needs room, so panes shrink before they drop
   -------------------------------------------------------------------------- */
@media (max-width: 860px) {
    .bd-lib { width: 132px; }
    .bd-side { width: 150px; }
    .bd-title { display: none; }
    .bd-actions button { padding: 6px 9px; font-size: var(--fs-xs); }
}
@media (max-width: 600px) {
    .bd-hdr { flex-wrap: wrap; height: auto; padding: 7px 10px; gap: 7px; }
    .bd-actions { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
    .bd-body { height: calc(100vh - 92px); }
    .bd-lib { width: 120px; padding: 9px; }
    .lib-item { font-size: var(--fs-xs); padding: 6px 7px; }
    .bd-side { display: none; }
    .bd-brief { padding: 10px var(--sp-3); left: 10px; right: 10px; top: 10px; }
    .brief-prompt { font-size: var(--fs-sm); margin-bottom: 7px; }
    .bd-metrics { flex-wrap: wrap; left: 10px; right: 10px; transform: none; bottom: 10px; }
    .bd-metrics .mx { flex: 1; min-width: 70px; padding: 7px var(--sp-2); }
    .bd-status { display: none; }
    .node { width: 96px; }
}

/* --------------------------------------------------------------------------
   Desktop-only notice (shown instead of the canvas on touch/small screens)
   -------------------------------------------------------------------------- */
.sim-notice { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-6); text-align: center; }
.sim-notice-inner { max-width: 400px; }
.sim-notice-icon { font-size: 2.6rem; margin-bottom: var(--sp-3); }
.sim-notice h1 { font-size: var(--fs-xl); font-weight: 800; margin: 0 0 10px; letter-spacing: -0.02em; }
.sim-notice p { color: var(--text-muted); line-height: 1.65; margin: 0 0 var(--sp-5); }
.sim-notice a {
    display: inline-block;
    background: var(--accent);
    color: var(--accent-contrast);
    text-decoration: none;
    font-weight: 600;
    padding: 0.65rem 1.25rem;
    border-radius: var(--r-md);
    font-size: var(--fs-base);
}
.sim-notice a:hover { box-shadow: var(--shadow-accent); }

/* --------------------------------------------------------------------------
   Challenge picker (shown at /simulator/ with no ?c= slug)
   -------------------------------------------------------------------------- */
.pk-wrap { min-height: 100vh; display: flex; flex-direction: column; }
.pk-hdr {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.pk-logo { text-decoration: none; font-weight: 700; font-size: var(--fs-md); color: var(--text); letter-spacing: -0.02em; }
.pk-logo b { color: var(--accent); }
.pk-nav { margin-left: auto; display: flex; gap: var(--sp-4); }
.pk-nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: var(--fs-sm);
    font-weight: 500;
    transition: color var(--dur-fast) var(--ease);
}
.pk-nav a:hover { color: var(--text); }

.pk-main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: var(--sp-6) var(--sp-5) var(--sp-7); }
.pk-main h1 { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -0.025em; margin: 0 0 var(--sp-3); }
.pk-lede { color: var(--text-muted); line-height: 1.7; max-width: 62ch; margin: 0 0 var(--sp-6); }

.pk-group { margin-bottom: var(--sp-6); }
.pk-group h2 {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    font-weight: 700;
    margin: 0 0 var(--sp-3);
}
.pk-group h2 span { color: var(--text-dim); font-weight: 600; }
.pk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: var(--sp-3); }

.pk-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    text-decoration: none;
    transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.pk-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.pk-card-title { font-weight: 650; color: var(--text); font-size: var(--fs-base); }
.pk-card-prompt { color: var(--text-muted); font-size: var(--fs-sm); line-height: 1.55; }
.pk-card-meta { margin-top: auto; padding-top: var(--sp-2); color: var(--text-dim); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }

@media (max-width: 600px) {
    .pk-main { padding: var(--sp-5) var(--sp-4) var(--sp-6); }
    .pk-grid { grid-template-columns: 1fr; }
}
