:root {
  --bg: #04060d;
  --panel: rgba(8, 14, 28, 0.78);
  --border: rgba(64, 160, 255, 0.25);
  --fg: #c8e3ff;
  --dim: #4d6a8f;
  --accent: #41a6ff;
  --ok: #00ff88;
  --bad: #ff2244;
  --warn: #ff7700;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

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

/* author display rules (flex/grid) otherwise beat the [hidden] attribute */
[hidden] { display: none !important; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
}

#app { position: fixed; inset: 0; }
#app canvas { display: block; }

/* ---------- panels ---------- */
.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 10px 12px;
  box-shadow: 0 0 24px rgba(0, 60, 140, 0.25);
  z-index: 10;
}

.panel-title {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.dim { color: var(--dim); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }

/* ---------- stats ---------- */
.hud-stats { top: 14px; left: 14px; width: 306px; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 14px;
  margin-bottom: 8px;
}
.stat-grid .row { display: flex; justify-content: space-between; }
.stat-grid .k { color: var(--dim); }
.stat-grid .v { color: var(--fg); font-variant-numeric: tabular-nums; }

.chart-label { color: var(--dim); font-size: 10px; margin: 2px 0 8px; }

/* layer activity meter */
#layer-meter { margin: 2px 0 2px; }
.lm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 16px;
  font-size: 10px;
}
.lm-name { width: 104px; white-space: nowrap; }
.lm-track {
  flex: 1;
  height: 6px;
  background: rgba(20, 40, 80, 0.6);
  border-radius: 3px;
  overflow: hidden;
}
.lm-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  box-shadow: 0 0 6px currentColor;
  transition: none;
}
.lm-count {
  width: 22px;
  text-align: right;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
#chart-throughput, #chart-pps, #chart-cwnd {
  width: 100%;
  border: 1px solid rgba(64, 160, 255, 0.12);
  border-radius: 4px;
  background: rgba(0, 8, 20, 0.5);
}

/* ---------- inspector ---------- */
.hud-inspector {
  top: 14px; right: 14px;
  width: 384px;
  max-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
}

#flow-list {
  max-height: 180px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  padding-bottom: 6px;
}
.flow-row {
  display: flex;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 11px;
}
/* role-play: datagram card sits below a shortened inspector, same right column */
.hud-datagram {
  top: calc(48vh + 8px);
  right: 14px;
  bottom: 14px;
  width: 384px;
  overflow-y: auto;
  border-color: rgba(99, 160, 255, 0.5);
  box-shadow: 0 0 28px rgba(40, 120, 255, 0.2);
}
body.roleplay .hud-inspector { max-height: 46vh; }

.flow-row:hover { background: rgba(64, 160, 255, 0.12); }
.flow-row.sel { background: rgba(64, 160, 255, 0.22); outline: 1px solid var(--border); }
.flow-row .proto { width: 34px; font-weight: bold; }
.flow-row .st { margin-left: auto; color: var(--dim); }

#inspector-body { overflow-y: auto; flex: 1; }

.field-table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.field-table td {
  padding: 2px 6px;
  border-bottom: 1px solid rgba(64, 160, 255, 0.08);
  font-size: 11px;
}
.field-table td:first-child { color: var(--dim); width: 42%; }
.field-table tr.hl { background: rgba(255, 200, 0, 0.12); }
.field-table tr[data-hex] { cursor: default; }
.field-table tr[data-hex]:hover { background: rgba(255, 200, 0, 0.12); }

.flagchip {
  display: inline-block;
  padding: 0 5px;
  margin-right: 4px;
  border-radius: 3px;
  font-size: 10px;
  border: 1px solid currentColor;
}

.hexdump {
  font-size: 10.5px;
  line-height: 1.5;
  background: rgba(0, 8, 20, 0.6);
  border: 1px solid rgba(64, 160, 255, 0.12);
  border-radius: 4px;
  padding: 8px;
  margin: 6px 0;
  white-space: pre;
  overflow-x: auto;
}
.hexdump .b { padding: 0 1px; }
.hexdump .b.hl { background: rgba(255, 200, 0, 0.35); color: #fff; border-radius: 2px; }
.hexdump .off { color: var(--dim); }
.hexdump .ascii { color: var(--dim); }

.sec-title {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 10px 0 4px;
  text-transform: uppercase;
}

#ladder {
  width: 100%;
  border: 1px solid rgba(64, 160, 255, 0.12);
  border-radius: 4px;
  background: rgba(0, 8, 20, 0.5);
}

/* ---------- controls ---------- */
.hud-controls {
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  max-width: calc(100vw - 40px);
}

.ctl-group { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }

button {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg);
  background: rgba(20, 40, 80, 0.6);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.12s;
}
button:hover { background: rgba(64, 160, 255, 0.25); border-color: var(--accent); }
button.active { background: var(--accent); color: #021022; }

label { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 11px; }
input[type="range"] { width: 90px; accent-color: var(--accent); }
label span { color: var(--fg); min-width: 34px; font-variant-numeric: tabular-nums; }

.legend { font-size: 10px; gap: 8px; }
.legend .li { display: flex; align-items: center; gap: 4px; color: var(--dim); }
.legend .sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ---------- guide mode ---------- */
.hud-tutor {
  bottom: 118px;
  left: 50%;
  transform: translateX(-50%);
  width: 640px;
  max-width: calc(100vw - 40px);
  border-color: rgba(255, 210, 77, 0.45);
  box-shadow: 0 0 32px rgba(255, 180, 40, 0.18);
  padding: 12px 16px;
}
.hud-tutor.tutor-pop { animation: tutorpop 0.35s ease-out; }
@keyframes tutorpop {
  0% { opacity: 0.2; transform: translateX(-50%) translateY(10px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.tutor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.tutor-chip {
  font-size: 10px;
  letter-spacing: 0.12em;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 1px 7px;
  white-space: nowrap;
}
.tutor-title { font-size: 14px; font-weight: bold; flex: 1; }
.tutor-exit {
  padding: 1px 7px;
  font-size: 11px;
  background: transparent;
  border-color: rgba(255, 210, 77, 0.3);
}

#tutor-body { font-size: 12.5px; line-height: 1.55; color: var(--fg); }
#tutor-body b { color: #ffd24d; }
#tutor-body i { color: var(--accent); font-style: normal; }

.tutor-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 9px;
  font-size: 11px;
  color: var(--dim);
}
.tutor-foot label { font-size: 11px; }
#tutor-continue {
  background: rgba(255, 210, 77, 0.18);
  border-color: rgba(255, 210, 77, 0.5);
  color: #ffd24d;
  animation: contpulse 1.2s infinite;
}
@keyframes contpulse {
  50% { background: rgba(255, 210, 77, 0.38); }
}

/* ---------- ticker ---------- */
#ticker {
  position: fixed;
  bottom: 110px;
  left: 14px;
  width: 360px;
  max-height: 150px;
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
  display: flex;
  flex-direction: column-reverse;
  font-size: 10.5px;
}
#ticker .tk {
  padding: 1px 8px;
  color: var(--dim);
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
  animation: tkfade 6s forwards;
}
@keyframes tkfade {
  0% { opacity: 1; }
  70% { opacity: 0.8; }
  100% { opacity: 0; }
}

/* ---------- role-play: action deck ---------- */
.hud-deck {
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 860px;
  max-width: calc(100vw - 28px);
  display: flex;
  gap: 14px;
  border-color: rgba(99, 160, 255, 0.5);
  box-shadow: 0 0 34px rgba(40, 120, 255, 0.22);
  z-index: 12;
}
.rp-left { flex: 1; min-width: 0; }
.rp-right { width: 232px; border-left: 1px solid var(--border); padding-left: 12px; }

.rp-head { display: flex; align-items: center; margin-bottom: 6px; }
.rp-title { font-size: 14px; font-weight: bold; color: #8ec5ff; flex: 1; }
.rp-x { padding: 1px 7px; background: transparent; }

.rp-feedback {
  font-size: 12px;
  line-height: 1.4;
  min-height: 32px;
  color: var(--fg);
  margin-bottom: 8px;
  padding: 5px 8px;
  background: rgba(20, 40, 80, 0.35);
  border-radius: 5px;
}

.rp-pickrow { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.rp-lbl { width: 46px; flex: none; color: var(--dim); font-size: 10px; padding-top: 6px; letter-spacing: 0.1em; }
.rp-opts { display: flex; flex-wrap: wrap; gap: 5px; }

.rp-chip {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  padding: 4px 8px;
  font-size: 10.5px;
  border: 1px solid var(--border);
}
.rp-chip .rp-sub { font-size: 8px; color: var(--dim); }
.rp-chip.on { background: var(--accent); color: #021022; border-color: var(--accent); }
.rp-what { border-color: var(--c); color: var(--c); }
.rp-what::before {
  content: ''; width: 8px; height: 8px; border-radius: 2px;
  background: var(--c); box-shadow: 0 0 6px var(--c); margin-bottom: 2px;
}
.rp-what.on { background: var(--c); color: #021022; }

.rp-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.rp-dispatch {
  background: rgba(0, 255, 136, 0.16);
  border-color: rgba(0, 255, 136, 0.5);
  color: var(--ok);
  font-weight: bold;
}
.rp-dispatch:disabled { opacity: 0.4; cursor: not-allowed; color: var(--dim); border-color: var(--border); background: rgba(20, 40, 80, 0.4); }
.rp-score { font-size: 10px; margin-left: auto; font-variant-numeric: tabular-nums; }

.rp-checklist-t { font-size: 10px; letter-spacing: 0.12em; color: var(--accent); margin-bottom: 6px; }
.rp-checklist { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; max-height: 188px; overflow-y: auto; }
.rp-step { color: var(--dim); padding: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-step.done { color: var(--ok); }
.rp-step.cur { color: var(--fg); font-weight: bold; }
.rp-auto { color: #9d7bff; }

/* ---------- role-play: overlays (picker + recap) ---------- */
.rp-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 6, 16, 0.55);
  z-index: 40;
}
.rp-modal {
  background: var(--panel);
  border: 1px solid rgba(99, 160, 255, 0.5);
  border-radius: 10px;
  box-shadow: 0 0 44px rgba(40, 120, 255, 0.3);
  padding: 18px 20px;
  width: 560px;
  max-width: calc(100vw - 40px);
}
.rp-modal-wide { width: 640px; }
.rp-group-t { font-size: 10px; letter-spacing: 0.12em; color: var(--accent); margin: 12px 0 6px; }
.rp-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0; }
.rp-card {
  text-align: left;
  padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
  align-items: flex-start;
  border: 1px solid var(--border);
}
.rp-card:hover { border-color: var(--accent); }
.rp-card-t { font-size: 13px; font-weight: bold; color: #8ec5ff; }
.rp-card-b { font-size: 11px; color: var(--dim); line-height: 1.4; white-space: normal; }
.rp-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.rp-grade { font-size: 64px; font-weight: bold; text-align: center; margin: 8px 0; text-shadow: 0 0 24px currentColor; }
.rp-recap-table { width: 100%; margin-bottom: 6px; }

/* ---------- credit ---------- */
#credit {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 6;
  font-size: 10px;
  color: var(--dim);
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
  pointer-events: auto;
}
#credit a { color: var(--accent); text-decoration: none; }
#credit a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(64, 160, 255, 0.3); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }
