/* TokenTown — dark neon isometric UI */

:root {
  --bg: #05070f;
  --ink: #e8eefc;
  --ink-dim: #9fb0cf;
  --ink-fine: #6d7f9e;
  --panel: rgba(10, 16, 28, 0.82);
  --panel-solid: #0a1120;
  --line: rgba(120, 160, 220, 0.16);
  --line-strong: rgba(120, 160, 220, 0.32);
  --cyan: #3fdcff;
  --magenta: #ff5fd2;
  --amber: #ffc45e;
  --green: #5ef2a0;
  --violet: #9b8cff;
  --coral: #ff7a6b;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --panel-w: 372px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#stage.dragging { cursor: grabbing; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(to bottom, rgba(5,7,15,0.85), rgba(5,7,15,0));
}

.brand { display: flex; gap: 12px; align-items: center; pointer-events: auto; }

.logo {
  width: 30px; height: 30px;
  flex: none;
  border-radius: 7px;
  background:
    linear-gradient(135deg, var(--cyan), var(--magenta) 55%, var(--amber));
  box-shadow: 0 0 22px rgba(63, 220, 255, 0.35);
  position: relative;
}
.logo::after {
  content: "";
  position: absolute; inset: 7px;
  background: #05070f;
  border-radius: 3px;
  transform: rotate(45deg) scale(0.8);
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.02em;
  font-weight: 700;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-dim);
  max-width: 46ch;
}

.top-actions { display: flex; gap: 8px; pointer-events: auto; }

/* ------------------------------------------------------------------ hud */

.hud {
  position: fixed;
  top: 68px;
  left: 18px;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 360px;
  pointer-events: none;
}
.hud-item {
  display: flex;
  gap: 7px;
  align-items: baseline;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 9px;
  backdrop-filter: blur(9px);
}
.hud-k { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-fine); }
.hud-v { font-family: var(--mono); font-size: 12px; color: var(--ink); }
.hud-note {
  flex-basis: 100%;
  font-size: 11px;
  color: var(--amber);
  padding: 2px 2px;
  min-height: 14px;
}

/* ------------------------------------------------------------- inspector */

.inspector {
  position: fixed;
  top: 62px;
  right: 14px;
  bottom: 132px;
  width: var(--panel-w);
  z-index: 5;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transition: transform 0.28s ease, opacity 0.28s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(120,160,220,0.3) transparent;
}
.inspector.hidden { transform: translateX(calc(100% + 22px)); opacity: 0; pointer-events: none; }

/* Bottom-sheet grab handle — mobile only */
.sheet-handle { display: none; }
.inspector::-webkit-scrollbar { width: 8px; }
.inspector::-webkit-scrollbar-thumb { background: rgba(120,160,220,0.25); border-radius: 4px; }

.stage-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px;
  background: linear-gradient(160deg, rgba(63,220,255,0.07), rgba(255,95,210,0.04));
  margin-bottom: 14px;
}
.eyebrow { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; flex-wrap: wrap; }
.chip {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(63, 220, 255, 0.14);
  color: var(--cyan);
  border: 1px solid rgba(63, 220, 255, 0.28);
}
.tag { font-size: 11px; color: var(--ink-dim); }
.stage-card h2 { margin: 0 0 6px; font-size: 16px; letter-spacing: 0.01em; }
.lede { margin: 0 0 8px; font-size: 13px; line-height: 1.45; color: var(--ink); }
.muted { margin: 0; font-size: 12px; line-height: 1.55; color: var(--ink-dim); }

/* the "we are holding here so you can read" indicator */
.dwell { margin-top: 12px; }
.dwell[hidden] { display: none; }
.dwell i {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  width: 100%;
  transition: width 0.12s linear;
}
.dwell span {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink-fine);
}
.dwell span b { color: var(--ink-dim); font-weight: 600; }

.sec { margin-bottom: 16px; }
.sec h3 {
  margin: 0 0 8px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-fine);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.hint { font-family: var(--mono); font-size: 10px; text-transform: none; letter-spacing: 0; color: var(--ink-dim); }
.fine { margin: 6px 0 0; font-size: 10.5px; line-height: 1.5; color: var(--ink-fine); }

/* vector strip */
.vec { display: flex; gap: 2px; align-items: flex-end; height: 58px; }
.vec .cell {
  flex: 1;
  position: relative;
  height: 100%;
  background: rgba(255, 255, 255, 0.035);
  border-radius: 2px;
  overflow: hidden;
}
.vec .cell i {
  position: absolute;
  left: 0; right: 0;
  bottom: 50%;
  display: block;
  transition: height 0.14s ease, background 0.2s ease;
}
.vec .cell.neg i { bottom: auto; top: 50%; }
.vec .mid {
  position: absolute; left: 0; right: 0; top: 50%;
  border-top: 1px dashed rgba(255,255,255,0.14);
}

/* bar lists */
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar {
  display: grid;
  grid-template-columns: 84px 1fr 46px;
  gap: 8px;
  align-items: center;
  font-size: 11px;
}
.bar .lbl {
  font-family: var(--mono);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar .track {
  height: 9px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
}
.bar .fill { height: 100%; border-radius: 3px; transition: width 0.18s ease; }
.bar .val { font-family: var(--mono); font-size: 10px; color: var(--ink-dim); text-align: right; }
.bar.cut { opacity: 0.36; }
.bar.chosen .lbl { color: var(--green); font-weight: 700; }

/* token stream */
.tokens { display: flex; flex-wrap: wrap; gap: 3px; max-height: 108px; overflow-y: auto; }
.tok {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(120, 160, 220, 0.12);
  color: var(--ink-dim);
  border: 1px solid transparent;
  white-space: pre;
}
.tok.gen { background: rgba(94, 242, 160, 0.13); color: var(--green); }
.tok.focus { border-color: var(--cyan); color: var(--ink); box-shadow: 0 0 12px rgba(63,220,255,0.3); }

.output {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 46px;
  color: var(--green);
  word-break: break-word;
}
.output .prompt-part { color: var(--ink-dim); }
.output .caret {
  display: inline-block;
  width: 7px;
  background: var(--green);
  animation: blink 1s steps(1) infinite;
  color: transparent;
}
@keyframes blink { 50% { opacity: 0; } }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips button {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  cursor: pointer;
  font-family: var(--sans);
}
.chips button:hover { background: rgba(63, 220, 255, 0.14); color: var(--ink); border-color: var(--line-strong); }
.chips button.on { background: rgba(63, 220, 255, 0.2); color: var(--cyan); border-color: rgba(63,220,255,0.45); }

/* ------------------------------------------------------------------ dock */

.dock {
  position: fixed;
  left: 14px; right: 14px; bottom: 12px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 11px 13px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.dock-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.dock-prompt { align-items: center; }

/* On desktop the settings flow straight into the control row; on mobile they
   collapse behind the ⚙ button so the dock stays two short rows. */
.dock-tune { display: contents; }
#btn-tune { display: none; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 110px; }
.field > span {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-fine);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.field > span b { font-family: var(--mono); color: var(--ink); font-weight: 500; letter-spacing: 0; text-transform: none; }
.field.grow { flex: 1 1 260px; }

input[type="text"] {
  width: 100%;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input[type="text"]:focus { border-color: rgba(63, 220, 255, 0.5); box-shadow: 0 0 0 3px rgba(63,220,255,0.1); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.13);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--cyan);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(63, 220, 255, 0.6);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--cyan);
  cursor: pointer;
}

button {
  font-family: var(--sans);
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 12px;
  padding: 8px 12px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--line-strong); }
button:active { transform: translateY(1px); }

button.primary {
  background: linear-gradient(135deg, rgba(63,220,255,0.9), rgba(155,140,255,0.9));
  color: #04121c;
  font-weight: 700;
  border-color: transparent;
  padding: 9px 20px;
}
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: rgba(10,16,28,0.7); backdrop-filter: blur(8px); }

.group { display: flex; gap: 6px; align-items: center; }
button.icon {
  width: 38px; height: 34px;
  padding: 0;
  font-size: 13px;
  display: grid;
  place-items: center;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-dim);
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--cyan); width: 14px; height: 14px; }

/* --------------------------------------------------------------- tooltip */

.tooltip {
  position: fixed;
  z-index: 8;
  pointer-events: none;
  background: rgba(8, 13, 24, 0.94);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 11.5px;
  max-width: 230px;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.tooltip b { display: block; font-size: 12px; margin-bottom: 2px; }

/* ----------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 5, 11, 0.78);
  backdrop-filter: blur(6px);
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  max-width: 620px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 26px 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.7);
}
.modal-card h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--cyan);
  margin: 22px 0 8px;
}
.modal-card h2:first-of-type { margin-top: 0; }
.modal-card p, .modal-card li { font-size: 13px; line-height: 1.65; color: var(--ink-dim); margin: 0 0 10px; }
.modal-card strong { color: var(--ink); }
.modal-card em { color: var(--amber); font-style: normal; }
.modal-card ul { margin: 0; padding-left: 18px; }
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  border-radius: 8px;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1180px) {
  :root { --panel-w: 320px; }
  .brand-text p { display: none; }
}

/* ---------------------------------------------------------------- mobile */
/* Below 900px the inspector stops being a floating pane over the city and
   becomes a bottom sheet that sits *under* the canvas viewport: collapsed to a
   headline peek by default, expandable to read the full district write-up.
   --dock-h and --sheet-h are measured live in main.js. */

@media (max-width: 900px) {
  :root { --dock-h: 118px; }

  .topbar { padding: 10px 12px; }
  .brand-text h1 { font-size: 15px; }
  .top-actions { gap: 6px; }
  .top-actions button { padding: 7px 9px; font-size: 11px; }

  .hud {
    top: 52px;
    left: 12px;
    right: 12px;
    max-width: none;
    gap: 4px;
  }
  .hud-item { padding: 3px 7px; border-radius: 6px; }
  .hud-k { font-size: 8.5px; letter-spacing: 0.06em; }
  .hud-v { font-size: 10.5px; }
  .hud-note { font-size: 10px; line-height: 1.3; }

  /* --- the sheet --- */
  .inspector {
    top: auto;
    left: 0;
    right: 0;
    bottom: var(--dock-h);
    width: auto;
    max-height: 64vh;
    padding: 0 14px 14px;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.55);
    transition: max-height 0.3s ease, transform 0.28s ease, opacity 0.28s ease;
  }
  /* 100% is only the sheet's own height — it also has to clear the dock it
     sits above, or a strip of it stays parked on screen. */
  .inspector.hidden {
    transform: translateY(calc(100% + var(--dock-h, 118px) + 24px));
  }

  /* collapsed: just the stage headline, so the city stays visible */
  .inspector:not(.open) {
    max-height: var(--peek-h, 176px);
    overflow: hidden;
  }
  .inspector:not(.open) #stage-body,
  .inspector:not(.open) .sec { display: none; }

  .sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    position: sticky;
    top: 0;
    z-index: 2;
    width: 100%;
    padding: 9px 0 7px;
    margin: 0 0 2px;
    border: none;
    border-radius: 0;
    background: linear-gradient(to bottom, var(--panel-solid) 72%, rgba(10, 17, 32, 0));
    color: var(--ink-fine);
  }
  .sheet-handle:hover { background: linear-gradient(to bottom, var(--panel-solid) 72%, rgba(10, 17, 32, 0)); }
  .grip {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: rgba(150, 180, 230, 0.4);
  }
  .sheet-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
  }
  .sheet-label::after { content: " ▲"; font-size: 8px; }
  .inspector.open .sheet-label::after { content: " ▼"; }

  .stage-card { margin-bottom: 12px; padding: 10px; }
  .stage-card h2 { font-size: 15px; }
  .tokens { max-height: 84px; }

  /* --- the dock --- */
  .dock {
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-radius: 14px 14px 0 0;
    gap: 8px;
  }
  .dock-row { gap: 8px; align-items: center; }
  .field.grow { flex: 1 1 120px; min-width: 0; }
  .dock-prompt .field > span { display: none; }
  input[type="text"] { padding: 9px 10px; font-size: 16px; }  /* 16px stops iOS zoom-on-focus */
  button.primary { padding: 10px 16px; }

  #btn-tune { display: grid; }
  #btn-tune[aria-expanded="true"] {
    background: rgba(63, 220, 255, 0.18);
    border-color: rgba(63, 220, 255, 0.45);
  }
  .dock-tune {
    display: none;
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 10px 12px;
    order: 10;
    padding-top: 2px;
  }
  .dock.tune-open .dock-tune { display: flex; }
  .field.slider { min-width: 0; flex: 1 1 122px; }
  .group.toggles { flex: 1 1 100%; justify-content: flex-start; gap: 14px; }

  .modal { padding: 14px; }
  .modal-card { padding: 20px 18px; max-height: 84vh; }
  .tooltip { display: none; }
}

/* Short phones (and landscape) cannot spare 176px for a peek. */
@media (max-width: 900px) and (max-height: 700px) {
  .inspector:not(.open) { --peek-h: 138px; }
  .inspector:not(.open) .dwell span { display: none; }
  .inspector { max-height: 72vh; }
  .hud-note { font-size: 9.5px; }
  .stage-card { padding: 9px; }
}

@media (max-width: 380px) {
  .brand-text h1 { font-size: 14px; }
  .top-actions button { padding: 6px 8px; }
  .field.slider { flex: 1 1 100%; }
}
