:root {
  --glass: rgba(16, 22, 30, 0.68);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9eff5;
  --muted: #98a6b4;
  --accent: #f2a541;
  --ok: #7fdc9a;
  --warn: #ff8a70;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #86bfe6;
  color: var(--text);
  font: 13px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.glass {
  position: fixed;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

h3 {
  margin: 2px 2px 8px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

button {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 7px 11px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); }
button:disabled { opacity: 0.38; cursor: not-allowed; }
button.active, button.active:hover {
  background: linear-gradient(180deg, #f7b85e, #e3912c);
  color: #1d1407;
  font-weight: 600;
}
button.danger:hover { background: rgba(255, 107, 91, 0.18); color: #ffb3aa; }

/* ---- top bar ---- */
.topbar {
  top: 12px; left: 12px; right: 12px;
  height: 52px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 17px; margin-right: 4px; white-space: nowrap; }
.brand small { font-weight: 500; color: var(--muted); font-size: 11px; margin-left: 2px; }
.logo { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.group { display: flex; gap: 2px; background: rgba(255, 255, 255, 0.05); padding: 3px; border-radius: 10px; flex: none; }
.group.right { margin-left: auto; }
.topbar { overflow-x: auto; scrollbar-width: none; }
button.go:not(.active) { color: #8ff0a8; font-weight: 600; }
button.go.running { color: #ffd36b; }
button.warnbtn { color: #ffd36b; }
button.caution { font-size: 10.5px; line-height: 1.15; padding: 3px 9px; text-align: center; white-space: nowrap; }
button.caution:not(.active) { color: #ffcf3f; font-weight: 600; border: 1px dashed rgba(255, 207, 63, 0.55); }
button.caution:hover:not(:disabled) { background: rgba(255, 90, 60, 0.22); color: #ffb3a3; }

.toolopts { margin: -6px 0 14px; padding: 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.2); font-size: 12px; }
.toolopts:empty { display: none; }
.toolopts label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; margin-bottom: 6px; }
.toolopts output { font-weight: 600; font-variant-numeric: tabular-nums; }
.toolopts input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 2px 0 0; accent-color: var(--accent); }
.toolopts .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; margin-bottom: 8px; }
.toolopts .seg button { padding: 5px 0; background: rgba(255, 255, 255, 0.05); font-size: 11.5px; }
.toolopts .sub { color: var(--muted); font-size: 10.5px; margin: 0 0 4px; }
.toolopts p { margin: 0; color: var(--muted); line-height: 1.4; }

.sim-status {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%);
  padding: 9px 18px; border-radius: 999px; font-weight: 600; font-size: 13px;
  background: rgba(16, 22, 30, 0.8); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); pointer-events: none; white-space: nowrap;
}
.sim-status.good { color: var(--ok); }
.sim-status.warn { color: #ffc36b; }
.sim-status.bad { color: #fff; background: rgba(200, 40, 30, 0.9); }
.sim-status.info { color: #cfe6ff; }
.boot-error { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px)); padding: 18px 20px; display: grid; gap: 8px; z-index: 20; }
.boot-error[hidden] { display: none; }
.boot-error b { font-size: 15px; color: var(--warn); }
.boot-error span { color: var(--text); font-size: 13px; }

.preset-menu { top: 70px; width: 320px; padding: 6px; z-index: 10; display: grid; gap: 2px; max-height: calc(100vh - 90px); overflow-y: auto; scrollbar-width: thin; }
.preset-menu h4 { margin: 8px 10px 2px; font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.preset-menu[hidden] { display: none; }
.preset-menu button { text-align: left; padding: 8px 10px; }
.preset-menu b { display: block; font-size: 13px; }
.preset-menu span { color: var(--muted); font-size: 11.5px; }
.preset-menu .rand { display: grid; gap: 6px; padding: 4px 6px 6px; }
.preset-menu .rand-styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); }
.preset-menu .rand-styles button { text-align: center; padding: 5px 0; font-size: 11.5px; }
.preset-menu .check { display: flex; align-items: center; gap: 7px; margin: 0 4px; color: var(--muted); font-size: 12px; cursor: pointer; }
.preset-menu .check input { accent-color: var(--accent); margin: 0; }
.preset-menu .rand-go { text-align: center; background: rgba(255, 255, 255, 0.06); }

.budget { margin-top: 10px; }
.budget label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.budget select { font: inherit; font-size: 12px; color: var(--text); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 7px; padding: 3px 6px; }
.budget select option { background: #1b232d; }
.budget .bar { height: 6px; margin-top: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.budget .bar i { display: block; height: 100%; border-radius: 3px; background: var(--ok); }
.budget .bar i.over { background: var(--warn); }
.budget p { margin: 4px 0 0; font-size: 11px; }
.palette.locked { pointer-events: none; }
.palette.locked > * { opacity: 0.4; filter: grayscale(0.6); }

/* ---- palette ---- */
.palette {
  top: 76px; left: 12px;
  width: 232px;
  padding: 12px;
  max-height: calc(100% - 76px - 172px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.chips, .mats { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 14px; }
.chip {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 4px 7px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11.5px;
}
.chip svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.chip em { position: absolute; top: 3px; right: 5px; font-style: normal; font-size: 9px; color: var(--muted); }
.mat { display: flex; align-items: center; gap: 7px; padding: 7px 8px; background: rgba(255, 255, 255, 0.04); text-align: left; font-size: 12px; }
.swatch {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%; flex: none;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.35), inset 0 2px 2px rgba(255, 255, 255, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.conns { margin-bottom: 6px; }
.conns button:disabled { opacity: 0.35; }
.connnote { margin: 0 2px 14px; font-size: 10.5px; line-height: 1.4; color: var(--muted); }
.connnote b { color: var(--text); font-weight: 600; }
.sizes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 14px; }
.size { padding: 6px 0; background: rgba(255, 255, 255, 0.04); font-weight: 600; }

.matinfo { background: rgba(0, 0, 0, 0.2); border-radius: 10px; padding: 10px; font-size: 11.5px; }
.mi-head { display: flex; gap: 9px; align-items: center; }
.mi-head .swatch { width: 22px; height: 22px; }
.mi-head span { display: block; color: var(--muted); font-size: 10.5px; }

dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 9px 0 0; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dd small { color: var(--muted); }

/* ---- site ---- */
.site { left: 12px; bottom: 12px; width: 232px; padding: 12px; }
.site label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; margin-bottom: 8px; }
.site output { font-weight: 600; font-variant-numeric: tabular-nums; }
.site input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 2px 0 0; accent-color: var(--accent); }
.site .check { display: flex; gap: 7px; margin: 2px 0 0; color: var(--muted); font-size: 12px; cursor: pointer; }
.site .check input { accent-color: var(--accent); margin: 0; }

/* ---- right column: stats + analysis ---- */
.col-right {
  position: fixed; top: 76px; right: 12px; bottom: 12px;
  width: 236px;
  display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; scrollbar-width: none;
  pointer-events: none;
}
.col-right > .glass { position: static; flex: none; pointer-events: auto; padding: 12px; }
.stats dl { margin-top: 0; }
.stats p { margin: 9px 0 0; font-size: 11.5px; }
.stats .ok { color: var(--ok); }
.stats .warn { color: var(--warn); }
.stats .muted { color: var(--muted); }

.an-head { display: flex; align-items: center; justify-content: space-between; }
.an-head h3 { margin: 0 2px; }
#analyze { font-weight: 600; }
#analyze:not(.active) { background: rgba(255, 255, 255, 0.08); }
.analysis h3 { margin-top: 14px; }
.legend i {
  display: block; height: 8px; margin-top: 12px; border-radius: 4px;
  background: linear-gradient(90deg, rgb(25, 45, 210), rgb(45, 115, 255) 18%, rgb(228, 232, 236) 50%, rgb(255, 55, 40) 82%, rgb(205, 0, 25));
}
.legend div { display: flex; justify-content: space-between; margin-top: 3px; font-size: 10.5px; color: var(--muted); }
.verdict { margin: 10px 0 2px; padding: 8px 10px; border-radius: 9px; font-weight: 600; background: rgba(255, 255, 255, 0.06); }
.verdict.good { background: rgba(80, 200, 120, 0.16); color: var(--ok); }
.verdict.warn { background: rgba(240, 160, 60, 0.18); color: #ffc36b; }
.verdict.bad { background: rgba(255, 90, 70, 0.18); color: var(--warn); }
dd.good { color: var(--ok); }
dd.bad { color: var(--warn); }
.analysis label:not(.check) { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; margin-bottom: 8px; }
.analysis output { font-weight: 600; font-variant-numeric: tabular-nums; }
.analysis input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 2px 0 0; accent-color: #7fd3ff; }
.analysis .check { display: flex; align-items: center; gap: 7px; margin: 4px 0 8px; font-size: 12px; cursor: pointer; }
.analysis .check input { accent-color: var(--accent); margin: 0; }
.analysis .check output { margin-left: auto; color: var(--muted); }
.seg.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); }
.seg.three button { padding: 6px 0; font-size: 11.5px; }
#posRow[hidden] { display: none; }

.weak-head { display: flex; align-items: center; justify-content: space-between; margin: 14px 2px 6px; }
.weak-head h3 { margin: 0; }
.weak-head button { padding: 5px 9px; font-size: 11px; background: rgba(255, 255, 255, 0.08); }
.weak-src { margin-bottom: 6px; }
.weak-src.seg.mini { display: inline-flex; }
ol.weak { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
ol.weak li { display: grid; grid-template-columns: 20px 1fr auto; gap: 7px; align-items: center; padding: 7px 8px; border-radius: 9px; background: rgba(255, 255, 255, 0.05); font-size: 11.5px; cursor: default; }
ol.weak li:hover { background: rgba(255, 214, 110, 0.14); }
ol.weak .num { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 11px; background: #e18c19; color: #fff; }
ol.weak .num.bad { background: #c81919; }
ol.weak b { font-size: 12px; }
ol.weak small { color: var(--muted); }
ol.weak .fixtext { color: #cfe6ff; }
ol.weak .advice { color: #ffc36b; }
ol.weak button.fix { padding: 5px 8px; font-size: 11px; background: linear-gradient(180deg, #4fb3ff, #2d84d6); color: #fff; font-weight: 600; white-space: nowrap; }
.weak-ok { margin: 10px 0 0; font-size: 11.5px; color: var(--ok); }
.note.warnnote { color: #ffc36b; }
.note { margin: 8px 0 0; font-size: 10.5px; line-height: 1.4; color: var(--muted); }
.send { width: 100%; margin-top: 10px; background: rgba(255, 255, 255, 0.05); }

.traffic label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; margin: 10px 0 0; }
.traffic output { font-weight: 600; font-variant-numeric: tabular-nums; }
.traffic input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 2px 0 0; accent-color: #7fd3ff; }
.traffic label.check { display: flex; gap: 7px; color: var(--muted); font-size: 12px; cursor: pointer; }
.traffic .check input { accent-color: #7fd3ff; margin: 0; }
.traffic .crowds, .traffic .gaps { margin-top: 10px; }
.traffic .gaps[hidden], .traffic .note:empty { display: none; }
.seg.mini { display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); }
.seg.mini button { padding: 4px 10px; font-size: 11.5px; }
button.drive { background: linear-gradient(180deg, #4fb3ff, #2d84d6); color: #fff; font-weight: 600; }
button.drive:hover:not(:disabled) { background: linear-gradient(180deg, #67beff, #3b92e4); }
#trafficResult .verdict { font-size: 12px; }
#trafficResult dl { margin-top: 6px; font-size: 11.5px; }

.ubar { height: 6px; margin: 8px 0 4px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.ubar i { display: block; height: 100%; border-radius: 3px; }
.upct { font-size: 11.5px; color: var(--muted); }
.upct b { display: inline; font-size: 13px; color: var(--text); }

/* ---- overlays ---- */
.hint {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 560px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(16, 22, 30, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #dfe7ee; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
  transition: background 0.2s;
}
.hint.flash { background: rgba(200, 50, 40, 0.92); color: #fff; }
.hint.flash.warn { background: rgba(214, 140, 36, 0.94); }

.tooltip { pointer-events: none; padding: 10px 12px; width: 240px; font-size: 12px; z-index: 5; }
.tooltip b { display: block; font-size: 13px; }
.tooltip span { color: var(--muted); font-size: 11px; }

/* ---- narrow screens ---- */
@media (max-width: 760px) {
  .topbar { left: 8px; right: 8px; top: 8px; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .brand small, .stats, .hint, .matinfo, .analysis .note { display: none; }
  .col-right { top: 150px; left: 8px; right: 8px; bottom: auto; width: auto; max-height: 30vh; }
  .analysis .legend, .analysis dl { display: none; }
  .group.right { margin-left: 0; }
  button { padding: 7px 9px; }
  .site { top: 68px; bottom: auto; left: 8px; right: 8px; width: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; padding: 8px 12px; }
  .site h3, .site .check { display: none; }
  .site label { margin-bottom: 0; }
  .palette { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto; max-height: 34vh; padding: 10px; }
  .chips { grid-template-columns: repeat(4, 1fr); }
  .sim-status { top: 120px; font-size: 12px; }
  .mats { grid-template-columns: repeat(3, 1fr); }
}
