:root {
  --bg: #0b1220;
  --panel: rgba(14, 22, 36, 0.86);
  --border: rgba(140, 180, 230, 0.18);
  --text: #dbe7f5;
  --muted: #8ea3bd;
  --accent: #4fb3ff;
  --accent-soft: rgba(79, 179, 255, 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#gl, #overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}
#overlay { touch-action: none; cursor: crosshair; }

#panel {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 270px;
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  user-select: none;
}
#panel.collapsed .panel-body { display: none; }

#panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
#panel h1 { margin: 0; font-size: 15px; letter-spacing: 0.02em; }
#collapse {
  width: 26px; height: 26px; padding: 0;
  font-size: 16px; line-height: 1;
}

.panel-body { overflow-y: auto; padding: 4px 12px 10px; }

section { padding: 8px 0; border-bottom: 1px solid var(--border); }
section:last-of-type { border-bottom: none; }
h2 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.tools { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }

button {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
  font: inherit;
  cursor: pointer;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button.active { background: var(--accent-soft); border-color: var(--accent); color: #fff; }
a.button {
  display: inline-block;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
  text-decoration: none;
}
a.button:hover { background: rgba(255, 255, 255, 0.12); }
button:disabled { opacity: 0.4; cursor: default; }
button:disabled:hover { background: rgba(255, 255, 255, 0.06); }

.subtools { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 6px; padding: 6px; border-radius: 8px; background: rgba(255, 255, 255, 0.03); }
.subtools button { padding: 3px 6px; font-size: 12px; }
.hint { margin: 0 0 6px; color: var(--muted); font-size: 11px; }

.row {
  display: grid;
  grid-template-columns: 1fr 96px 38px;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  color: var(--text);
}
.row select { grid-column: 2 / 4; }
.row.check { display: flex; gap: 6px; }
.row output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

input[type="range"] { width: 100%; accent-color: var(--accent); }
select {
  background: #142033;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 4px;
  font: inherit;
}

kbd {
  font: 10px ui-monospace, monospace;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
}

footer {
  display: flex;
  justify-content: space-between;
  padding-top: 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#info {
  padding-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

#error {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  white-space: pre-wrap;
  font: 13px/1.5 ui-monospace, monospace;
  color: #ffb4b4;
}
#error[hidden] { display: none; }

@media (max-width: 600px) {
  #panel { width: calc(100vw - 24px); max-height: 50vh; }
}

/* ---------------------------------------------------------------- performance dashboard */

#dash {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: 280px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 12px;
  user-select: none;
}
#dash header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
#dash h2 { margin: 0; }
#dash .dash-toggle { width: 22px; height: 22px; padding: 0; line-height: 1; }
#dash.collapsed .dash-body { display: none; }
#dash .dash-body { padding: 8px 10px 10px; }
#dash .spark { width: 100%; height: 40px; display: block; margin-bottom: 6px; }
.dash-grid {
  display: grid;
  grid-template-columns: auto 1fr 48px;
  align-items: center;
  gap: 3px 8px;
}
.dash-grid span { color: var(--muted); }
.dash-grid b { font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-grid i { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.dash-grid u { display: block; height: 100%; width: 0; background: #46d483; transition: width 0.3s; }
.dash-grid u.warm { background: #f2c14e; }
.dash-grid u.hot { background: #ef6b5b; }
#dash h3 {
  margin: 10px 0 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
#dash .row { grid-template-columns: 1fr 110px 40px; }
.dash-note { margin: 6px 0 0; color: var(--muted); font-size: 10.5px; line-height: 1.35; }

@media (max-width: 600px) {
  #dash { width: calc(100vw - 24px); bottom: auto; top: calc(50vh + 24px); }
}

/* ---------------------------------------------------------------- world: bars, toolbar, dialogs */

body.world #topbar {
  position: fixed;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  z-index: 5;
}
#topbar .brand { font-weight: 600; margin-right: 6px; white-space: nowrap; }
#topbar .tb-spacer { flex: 1; }
#topbar select { padding: 5px 6px; }

body.world #toolbar {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 24px);
}
#toolbar .tb-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  overflow-x: auto;
}
#toolbar .tb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 62px;
  padding: 6px 6px 4px;
  border-radius: 10px;
}
#toolbar .tb b { font-size: 22px; line-height: 1.1; font-weight: normal; }
#toolbar .tb span { font-size: 11px; color: var(--muted); }
#toolbar .tb.active span { color: #fff; }
#toolbar .tb-sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 4px; }
#toolbar .tb-size { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
#toolbar .tb-size input { width: 90px; }
#toolbar .tb-pop {
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
}
#toolbar .tb-pop button { padding: 5px 9px; }

body.world #panel.drawer {
  top: 66px;
  right: 10px;
  max-height: calc(100vh - 170px);
}
body.world #dash { top: 66px; left: 10px; bottom: auto; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.modal-box {
  width: min(520px, calc(100vw - 32px));
  padding: 12px 14px 14px;
  background: #121b2b;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.modal-box header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-box h2 { margin: 0; font-size: 14px; color: var(--text); text-transform: none; letter-spacing: 0; }
.modal-box textarea {
  width: 100%;
  margin-top: 8px;
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  font: 11px ui-monospace, monospace;
  resize: vertical;
}

#toast {
  position: fixed;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  z-index: 11;
  padding: 8px 14px;
  background: rgba(20, 30, 46, 0.95);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (max-width: 700px) {
  #topbar .brand { display: none; }
  #toolbar .tb { min-width: 48px; }
  #toolbar .tb span { display: none; }
}

/* ---------------------------------------------------------------- world: challenges & damage */

#hud {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  width: min(460px, calc(100vw - 24px));
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid rgba(255, 210, 90, 0.5);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
#hud .hud-title { font-weight: 600; font-size: 14px; }
#hud .hud-goal { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
#hud .hud-status { font-variant-numeric: tabular-nums; }
#hud .hud-bar { height: 6px; margin: 6px 0; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
#hud .hud-bar u { display: block; height: 100%; width: 0; background: #f2c14e; transition: width 0.3s; }
#hud .hud-budget { font-size: 12px; color: #f2c14e; margin-bottom: 4px; }
#hud .tools { margin: 4px 0 0; }

#damage {
  position: fixed;
  top: 66px;
  right: 10px;
  z-index: 5;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
body.world #panel.drawer:not([hidden]) ~ #damage { right: 290px; }

#challengeList { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; }
#challengeList .challenge { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; text-align: left; }
#challengeList .challenge b { font-size: 13px; }
#challengeList .challenge span { color: var(--muted); font-size: 12px; }
#challengeList .challenge i { font-style: normal; color: #f2c14e; font-size: 12px; }
#result .res-title { font-size: 18px; margin-bottom: 4px; }

/* ---------------------------------------------------------------- world: tour */

#tour {
  position: fixed;
  z-index: 12;
  width: min(320px, calc(100vw - 24px));
  padding: 12px 14px;
  background: #13213a;
  border: 1px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
#tour .tour-title { display: block; font-size: 14px; margin-bottom: 4px; }
#tour .tour-text { margin: 0 0 10px; color: var(--text); }
#tour .tools { justify-content: space-between; align-items: center; margin: 0; }
#tour .tour-step { color: var(--muted); font-size: 12px; }
.tour-focus { outline: 3px solid #f2c14e !important; outline-offset: 3px; border-radius: 10px; position: relative; z-index: 13; }
