/* Network Lab. Dark, cool, packet colors carry meaning. */
:root {
  --bg: #0e1418; --panel: #151d23; --panel2: #1b252d; --line: #283640; --text: #e4ecf1; --dim: #9db0bc; --faint: #7d93a3;
  --acc: #34d399; --acc2: #60a5fa; --ok: #4ade80; --err: #f87171; --warn: #fbbf24;
  --arp: #fbbf24; --echo: #60a5fa; --reply: #4ade80; --error: #f87171;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --r: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, kbd { font-family: var(--mono); font-size: .88em; background: #20303a; border-radius: 5px; padding: .08em .35em; color: #b6f0d8; }
a { color: var(--acc2); }
.dim { color: var(--dim); }
.ok { color: var(--ok); } .err { color: var(--err); } .warn { color: var(--warn); }
[hidden] { display: none !important; }

/* ---------- header */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: #0b1014; flex-wrap: wrap; }
.logo { font: 800 22px/1 var(--mono); text-decoration: none; letter-spacing: -.5px; }
.lg-a { color: var(--acc); } .lg-b { color: var(--text); margin-left: 1px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-b { background: none; border: 1px solid transparent; border-radius: 8px; padding: 5px 10px; color: var(--dim); }
.nav-b:hover, .nav-b:focus-visible, .nav-b.on { color: var(--text); border-color: var(--line); background: var(--panel); }
.top-r { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.progress { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--acc); white-space: nowrap; }

/* ---------- layout: side | stage | log */
.app { flex: 1; display: grid; gap: 12px; padding: 12px; grid-template-columns: minmax(300px, 370px) minmax(0, 1fr) minmax(250px, 320px); grid-template-areas: "side stage log"; min-height: 0; }
.side { grid-area: side; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side > * { flex: none; }
.stage { grid-area: stage; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.log-card { grid-area: log; display: flex; flex-direction: column; min-width: 0; }
@media (min-width: 1181px) {
  body { height: 100vh; }
  .app { overflow: hidden; }
  .side { overflow: auto; }
  .log-card { min-height: 0; }
}
@media (max-width: 1180px) {
  .app { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); grid-template-areas: "stage stage" "side log"; }
  .log-card { max-height: 640px; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "side" "stage" "log"; padding: 8px; gap: 8px; }
  .side { display: contents; }
  .mission, .sandbox-card { order: 1; }
  .stage { order: 2; }
  .panel { order: 3; }
  .log-card { order: 4; max-height: 480px; }
  .app { display: flex; flex-direction: column; }
  .top { padding: 8px; gap: 8px; }
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }

/* ---------- mission */
.mission, .sandbox-card { padding: 14px 16px; }
.m-head { display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--acc); font-weight: 700; }
.m-head span:last-child { color: var(--faint); }
.m-title { font-size: 20px; margin: 4px 0 6px; line-height: 1.25; }
.m-story p, .m-story ul { margin: 0 0 8px; color: #d3dde3; }
.m-story ul { padding-left: 20px; }
.goals { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.goals li { display: flex; gap: 9px; align-items: flex-start; padding: 7px 10px; border-radius: 9px; background: var(--panel2); border: 1px solid transparent; transition: background .3s, border-color .3s; font-size: 14px; }
.goals li::before { content: ""; flex: none; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--faint); transition: all .25s; }
.goals li.done { background: #12291f; border-color: #1f5139; }
.goals li.done::before { border-color: var(--ok); background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l3 3 5-6' stroke='%230e1418' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center/100% no-repeat; }
.goals li.broken { background: #2b1719; border-color: #5c2a2e; }
.goals li.broken::before { border-color: var(--err); }
.goals li.pop { animation: pop .5s; }
@keyframes pop { 40% { transform: scale(1.03); } }
.m-hints { display: grid; gap: 6px; }
.hint { background: #1a2a33; border-left: 3px solid var(--acc2); padding: 6px 10px; border-radius: 6px; font-size: 14px; }
.sol { background: #1a2a33; border-left: 3px solid var(--acc); padding: 8px 10px 8px 28px; border-radius: 6px; font-size: 14px; margin: 0; }
.m-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.note-banner { background: #1a2a33; border-left: 3px solid var(--warn); padding: 8px 10px; border-radius: 6px; margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- buttons and fields */
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 12px; font-size: 14px; }
.btn:hover, .btn:focus-visible { border-color: var(--acc2); }
.btn.ghost { background: none; color: var(--dim); }
.btn.primary { background: var(--acc); color: #04140d; border-color: var(--acc); font-weight: 700; }
.btn.small { padding: 1px 8px; font-size: 12px; }
.btn.danger:hover { border-color: var(--err); color: var(--err); }
.btn:disabled { opacity: .4; cursor: default; }
input[type=text], input:not([type]), select, textarea { background: #0d1418; border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; min-width: 0; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--acc2); outline-offset: 1px; }
input.bad { border-color: var(--err); }
.mono, input.mono { font-family: var(--mono); font-size: 13px; }

/* ---------- stage */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.tool { background: none; border: 0; padding: 6px 12px; color: var(--dim); font-size: 14px; }
.tool + .tool { border-left: 1px solid var(--line); }
.tool.on { background: #1d3a30; color: var(--text); }
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.pal { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px dashed #3a4c58; border-radius: 9px; padding: 4px 10px 4px 6px; font-size: 13px; color: var(--dim); touch-action: none; user-select: none; }
.pal svg { width: 26px; height: 22px; }
.pal.on { border-style: solid; border-color: var(--acc); color: var(--text); }
.canvas-wrap { position: relative; flex: 1; min-height: 340px; background: radial-gradient(circle at 1px 1px, #1d2a32 1px, transparent 1.4px) 0 0/24px 24px, #10181d; }
.canvas { display: block; width: 100%; height: 100%; min-height: 340px; touch-action: none; user-select: none; -webkit-user-select: none; }
@media (max-width: 1180px) { .canvas-wrap, .canvas { min-height: 0; } .canvas { aspect-ratio: 1000 / 620; height: auto; } }
@media (max-width: 760px) { .canvas { aspect-ratio: 4 / 3; } }
.toast { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: #2b1719; border: 1px solid #5c2a2e; color: #ffd4d4; padding: 6px 12px; border-radius: 8px; font-size: 14px; max-width: 90%; text-align: center; }
.toast.info { background: #13283a; border-color: #2a4d6b; color: #d6eaff; }
.legend { position: absolute; right: 10px; bottom: 8px; display: flex; gap: 10px; font-size: 12px; color: var(--faint); pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.pk { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.pk.arp { background: var(--arp); } .pk.echo { background: var(--echo); } .pk.reply { background: var(--reply); } .pk.error { background: var(--error); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); }
.ctl { min-width: 70px; }
.speed { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); font-size: 14px; }
.status { margin-left: auto; color: var(--faint); font: 12px var(--mono); }

/* svg */
.link line.wire { stroke: #4b6272; stroke-width: 3; }
.link line.hit { stroke: transparent; stroke-width: 18; }
.link.hot line.wire { stroke: var(--acc2); stroke-width: 4; }
.mode-delete .link:hover line.wire { stroke: var(--err); }
.port { font: calc(11px * var(--k, 1)) var(--mono); fill: #8fa6b4; paint-order: stroke; stroke: #10181d; stroke-width: 4px; stroke-linejoin: round; }
.port.ip { fill: #b6f0d8; }
.dev { cursor: pointer; }
.dev .body { fill: #1d2b34; stroke: #6f8a9b; stroke-width: 2; }
.dev .ink { fill: none; stroke: #b9cad4; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dev .fillink { fill: #b9cad4; }
.dev.t-router .body { stroke: var(--acc); } .dev.t-router .ink { stroke: #a7f3d0; }
.dev.t-switch .body { stroke: var(--acc2); } .dev.t-switch .ink { stroke: #bfdbfe; }
.dev.t-cloud .body { stroke: #a78bfa; } .dev.t-server .body { stroke: #94a3b8; }
.dev .ring { fill: none; stroke: transparent; stroke-width: 3; }
.dev.sel .ring { stroke: var(--acc); }
.dev.pick .ring { stroke: var(--warn); stroke-dasharray: 6 4; }
.mode-delete .dev:hover .ring { stroke: var(--err); }
.dev:hover .body { filter: brightness(1.25); }
.dev .name { font: 600 13px system-ui, sans-serif; fill: var(--text); text-anchor: middle; paint-order: stroke; stroke: #10181d; stroke-width: 4px; }
.dev .addr { font: 11px var(--mono); fill: #b6f0d8; text-anchor: middle; paint-order: stroke; stroke: #10181d; stroke-width: 4px; }
.dev .addr.none { fill: var(--faint); }
.dev .flash { fill: none; stroke-width: 3; opacity: 0; }
.dev .flash.on { animation: flash .7s; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
.packet circle { stroke: #0e1418; stroke-width: 2; }
.packet text { font: 700 10px var(--mono); fill: #0e1418; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.packet.arp circle { fill: var(--arp); } .packet.echo circle { fill: var(--echo); } .packet.reply circle { fill: var(--reply); } .packet.error circle { fill: var(--error); }
.packet.focus circle { stroke: #fff; stroke-width: 3; }
.drag-ghost { opacity: .55; pointer-events: none; }
.rubber { stroke: var(--warn); stroke-width: 2; stroke-dasharray: 6 5; pointer-events: none; }
.empty-hint { fill: var(--faint); font-size: 18px; text-anchor: middle; }

/* ---------- side panel */
.panel { padding: 12px 14px; min-height: 120px; }
.panel h2 { font-size: 16px; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); margin: 14px 0 6px; }
.panel .kind { font-size: 12px; color: var(--faint); font-weight: 400; }
.form { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; }
.form label { color: var(--dim); font-size: 14px; }
.calc { font: 12px var(--mono); color: var(--dim); margin-top: 6px; }
.msg { font-size: 13px; margin: 6px 0 0; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.row input { flex: 1 1 120px; }
.tbl { width: 100%; border-collapse: collapse; font: 12px var(--mono); }
.tbl th { text-align: left; color: var(--faint); font-weight: 400; padding: 2px 6px 2px 0; border-bottom: 1px solid var(--line); }
.tbl td { padding: 3px 6px 3px 0; border-bottom: 1px solid #1d2830; vertical-align: middle; }
.tbl input { width: 100%; padding: 3px 6px; font: 12px var(--mono); }
.tbl .x { background: none; border: 0; color: var(--faint); padding: 0 4px; }
.tbl .x:hover { color: var(--err); }
.empty { color: var(--faint); font-size: 13px; }
.results { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 4px; font: 12px/1.4 var(--mono); }
.results li { padding: 4px 8px; border-radius: 6px; background: var(--panel2); overflow-wrap: anywhere; }
.results li.good { border-left: 3px solid var(--ok); } .results li.bad { border-left: 3px solid var(--err); } .results li.wait { border-left: 3px solid var(--faint); }
.results ol { margin: 2px 0 0; padding-left: 22px; }
.hdr { margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.hdr h4 { margin: 0; padding: 4px 8px; font-size: 13px; background: var(--panel2); display: flex; justify-content: space-between; }
.hdr h4 small { color: var(--faint); font-weight: 400; }
.hdr dl { margin: 0; padding: 6px 8px; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font: 12px var(--mono); }
.hdr dt { color: var(--faint); } .hdr dd { margin: 0; overflow-wrap: anywhere; }
.hdr.arp h4 { border-left: 4px solid var(--arp); } .hdr.ip h4 { border-left: 4px solid var(--echo); } .hdr.icmp h4 { border-left: 4px solid var(--reply); } .hdr.eth h4 { border-left: 4px solid var(--faint); }

/* ---------- log */
.c-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.c-head h2 { font-size: 14px; margin: 0; margin-right: auto; }
.mini { font-size: 12px; color: var(--dim); display: inline-flex; gap: 4px; align-items: center; }
.log { list-style: none; margin: 0; padding: 6px; overflow: auto; flex: 1; min-height: 160px; font: 12px/1.35 var(--mono); }
.log li { padding: 3px 6px; border-radius: 6px; display: grid; grid-template-columns: 2.4em 1fr; gap: 6px; }
.log li .s { color: var(--faint); text-align: right; }
.log li.frame { cursor: pointer; }
.log li.frame:hover, .log li.frame:focus-visible { background: var(--panel2); outline: none; }
.log li.frame.sel { background: #1d3a30; }
.log li .who { color: var(--dim); }
.log li .what { display: block; }
.log li.frame.arp .what { color: var(--arp); } .log li.frame.echo .what { color: var(--echo); } .log li.frame.reply .what { color: var(--reply); } .log li.frame.error .what { color: var(--error); }
.log li.note .what { color: var(--faint); }
.log li.note.good .what { color: var(--ok); } .log li.note.bad .what { color: var(--err); } .log li.note.cmd .what { color: var(--text); }
.log.hide-notes li.note:not(.good):not(.bad):not(.cmd) { display: none; }
.log li.empty { display: block; padding: 10px; font-family: system-ui, sans-serif; }

/* ---------- dialog */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 18px 22px; width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
.dlg::backdrop { background: #0008; }
.dlg-x { position: absolute; right: 10px; top: 8px; }
.dlg-x button { background: none; border: 0; font-size: 24px; color: var(--dim); }
.dlg h2 { margin: 0 0 8px; }
.track { margin: 14px 0 6px; }
.track h3 { margin: 0; font-size: 14px; color: var(--acc); }
.track p { margin: 0 0 6px; color: var(--dim); font-size: 14px; }
.mlist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.mlist button { width: 100%; text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; display: flex; gap: 10px; align-items: center; }
.mlist button:hover { border-color: var(--acc2); }
.mlist .chk { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--faint); flex: none; }
.mlist .done .chk { background: var(--ok); border-color: var(--ok); }
.mlist .cur { border-color: var(--acc); }
.cheat table { border-collapse: collapse; font: 13px var(--mono); width: 100%; }
.cheat th, .cheat td { text-align: left; padding: 3px 10px 3px 0; border-bottom: 1px solid var(--line); }
.cheat th { color: var(--faint); font-weight: 400; }
.cheat .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 24px; }
.cheat ul { padding-left: 20px; margin: 4px 0; }
.share-url { width: 100%; font: 12px var(--mono); }
.share textarea { width: 100%; min-height: 60px; resize: vertical; }
.done-box .after p { color: #d3dde3; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
