/* GatewayTycoon: site management chrome over a full screen canvas.
   Chunky bevels and stamped signage, but a steel control-room palette rather
   than a fairground one, because the thing being run here is a policy edge. */

:root {
  --steel:      #7f93a8;
  --steel-dark: #3d4c5e;
  --frame:      #27323f;
  --panel:      #e6edf3;
  --panel-mid:  #cdd9e3;
  --panel-dark: #adbcc9;
  --ink:        #1b2634;
  --ink-soft:   #445468;
  --gold:       #f2c14e;
  --teal:       #2f9e86;
  --blue:       #2f80c8;
  --red:        #c8412f;
  --amber:      #d3821f;
  --shadow:     rgba(0, 0, 0, 0.35);
  --act1: #3f7fa8;
  --act2: #6d5fa8;
  --act3: #2f8f7c;
  --act4: #a8683f;
  --act5: #8f5f9a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  color: var(--ink);
  background: #2b4f43;
  -webkit-text-size-adjust: 100%;
}

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

/* ---------- shared panel look ---------- */

.btn, .icon, .zoomer button {
  font: inherit;
  font-weight: bold;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 12px;
  background: linear-gradient(var(--panel), var(--panel-mid));
  border: 2px solid var(--frame);
  border-radius: 4px;
  box-shadow: inset 1px 1px 0 #fbfdff, inset -2px -2px 0 var(--panel-dark), 2px 2px 0 var(--shadow);
}
.btn:hover, .icon:hover, .zoomer button:hover { background: linear-gradient(#fbfdff, var(--panel)); }
.btn:active, .icon:active, .zoomer button:active {
  transform: translate(2px, 2px);
  box-shadow: inset 2px 2px 0 var(--panel-dark);
}

/* ---------- topbar ---------- */

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: linear-gradient(#5f7590, #3d4c5e);
  border-bottom: 4px solid var(--frame);
  box-shadow: 0 3px 0 var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.logo {
  width: 26px; height: 26px; flex: none;
  background: #1f2937;
  border: 2px solid var(--frame);
  border-radius: 5px;
  position: relative;
}
.logo::after {
  content: ""; position: absolute; inset: 5px;
  background: var(--teal); border-radius: 2px;
}
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0; font-size: 19px; letter-spacing: 0.5px; line-height: 1.1;
  color: var(--gold); text-shadow: 2px 2px 0 #16202c;
}
.brand-text h1 span { color: #fff; }
.brand-text p {
  margin: 1px 0 0; font-size: 12px; color: #dde8f0;
  text-shadow: 1px 1px 0 #16202c;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-actions { display: flex; gap: 8px; flex: none; }

/* ---------- HUD ---------- */

.hud {
  position: fixed; z-index: 20;
  top: 60px; left: 12px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  max-width: min(620px, calc(100vw - 24px));
}
.hud-item {
  display: flex; align-items: baseline; gap: 6px;
  padding: 4px 10px;
  background: #1b2836;
  border: 2px solid var(--frame);
  border-radius: 4px;
  box-shadow: 2px 2px 0 var(--shadow);
}
.hud-item .k { font-size: 10.5px; letter-spacing: 0.5px; text-transform: uppercase; color: #92aec4; }
.hud-item .v { font-size: 14px; font-weight: bold; color: var(--gold); }
.hud-note {
  padding: 4px 10px; font-size: 12px; font-weight: bold;
  color: #fff; text-shadow: 1px 1px 0 #16202c;
}

/* ---------- the verdict banner ---------- */

/* Deliberately not inside the guide panel: the outcome belongs to the request,
   not to whichever building you happen to be reading about. */
.verdict {
  position: fixed; z-index: 28;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--hud-h, 108px) + 4px);
  display: flex; align-items: baseline; gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 7px 14px;
  font-size: 13px;
  color: #fff;
  border: 2px solid var(--frame); border-radius: 5px;
  box-shadow: 3px 3px 0 var(--shadow);
}
.verdict[hidden] { display: none; }
.verdict b { font-size: 13.5px; letter-spacing: 0.6px; }
.verdict i { font-style: normal; font-size: 11.5px; opacity: 0.85; }
.verdict.good { background: linear-gradient(#2f9e86, #237966); }
.verdict.bad  { background: linear-gradient(#c8412f, #9c3124); }
.verdict.warn { background: linear-gradient(#d3821f, #a66317); }

/* ---------- zoom ---------- */

.zoomer {
  position: fixed; z-index: 20; left: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px;
}
.zoomer button { width: 34px; height: 34px; padding: 0; font-size: 16px; }

/* ---------- the guide panel ---------- */

.guide {
  position: fixed; z-index: 25; top: 60px; right: 12px; bottom: 96px;
  width: 386px; max-width: calc(100vw - 24px);
  overflow-y: auto;
  padding: 14px;
  background: var(--panel);
  border: 3px solid var(--frame);
  border-radius: 5px;
  box-shadow: inset 2px 2px 0 #fbfdff, inset -2px -2px 0 var(--panel-dark), 5px 5px 0 var(--shadow);
}
.guide.hidden { display: none; }

.eyebrow { margin-bottom: 6px; }
.chip {
  display: inline-block; font-size: 11px; font-weight: bold;
  letter-spacing: 0.5px; text-transform: uppercase;
  padding: 3px 10px; border-radius: 11px; color: #fff;
  background: var(--steel-dark);
}
.chip.act1 { background: var(--act1); }
.chip.act2 { background: var(--act2); }
.chip.act3 { background: var(--act3); }
.chip.act4 { background: var(--act4); }
.chip.act5 { background: var(--act5); }

.guide h2 { margin: 2px 0 8px; font-size: 25px; line-height: 1.15; }
.lede {
  margin: 0 0 10px; font-size: 16.5px; font-weight: bold; line-height: 1.45;
  background: #fbfdff; border-left: 5px solid var(--teal); padding: 7px 11px;
}
.body { margin: 0 0 10px; font-size: 14.5px; line-height: 1.62; color: var(--ink-soft); }
.tip {
  margin: 0; font-size: 13.5px; line-height: 1.55;
  background: #fbfdff; border: 2px dashed var(--steel);
  border-radius: 4px; padding: 8px 11px;
}
.tip b { color: var(--teal); }

.dwell { margin: 10px 0 0; }
.dwell .track {
  height: 9px; overflow: hidden;
  background: var(--panel-mid);
  border: 2px solid var(--frame); border-radius: 5px;
}
.dwell i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(var(--gold), #d9a52f);
  transition: width 0.12s linear;
}
.dwell span { display: block; margin-top: 5px; font-size: 11.5px; color: var(--ink-soft); }

.pin-note {
  margin-top: 10px; font-size: 12.5px; font-weight: bold;
  background: #fbfdff; border: 2px solid var(--frame);
  border-radius: 4px; padding: 7px 10px;
}
.link {
  font: inherit; font-size: 12.5px; font-weight: bold;
  color: #1d5f9c; background: none; border: 0; padding: 0;
  cursor: pointer; text-decoration: underline;
}

.sec { margin-top: 18px; border-top: 2px solid var(--panel-dark); padding-top: 12px; }
.sec h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.6px; }
.sec h3 .hint {
  float: right; font-size: 11px; font-weight: normal;
  text-transform: none; letter-spacing: 0; color: var(--ink-soft);
}
.fine { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--ink-soft); }

/* ---------- the request card ---------- */

.req {
  margin: 12px 0 0; padding: 10px 11px;
  background: #1b2836; border: 2px solid var(--frame); border-radius: 5px;
  box-shadow: 2px 2px 0 var(--shadow);
}
.req-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.req-method {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 14px; font-weight: bold; color: #8fd0e8;
}
.req-status {
  font-size: 10.5px; font-weight: bold; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 10px; color: #fff;
}
.req-status.good { background: var(--teal); }
.req-status.bad  { background: var(--red); }
.req-status.warn { background: var(--amber); }
.req-rows { margin: 7px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 9px; }
.req-rows dt {
  font-size: 10px; letter-spacing: 0.5px; text-transform: uppercase; color: #92aec4;
}
.req-rows dd { margin: 0; font-size: 12px; color: #dde8f0; }
.req-note { margin: 8px 0 0; font-size: 12px; line-height: 1.55; color: #b9cbdb; }

/* ---------- chip lists ---------- */

.stop-list { display: flex; flex-wrap: wrap; gap: 5px; }
.stop-chip {
  display: flex; align-items: center; gap: 5px;
  font: inherit; font-size: 11.5px; font-weight: bold;
  padding: 4px 9px 4px 4px; cursor: pointer;
  color: var(--ink);
  background: linear-gradient(#fbfdff, var(--panel-mid));
  border: 2px solid var(--frame); border-radius: 12px;
  box-shadow: 1px 1px 0 var(--shadow);
}
.stop-chip i {
  display: grid; place-items: center;
  width: 17px; height: 17px; flex: none;
  font-style: normal; font-size: 10px; color: #fff;
  background: var(--steel-dark); border-radius: 50%;
}
.stop-chip.act1 i { background: var(--act1); }
.stop-chip.act2 i { background: var(--act2); }
.stop-chip.act3 i { background: var(--act3); }
.stop-chip.act4 i { background: var(--act4); }
.stop-chip.act5 i { background: var(--act5); }
.stop-chip.seen { background: linear-gradient(#e8f4ef, #c7e2d8); }
.stop-chip.on {
  background: linear-gradient(#ffe08a, var(--gold));
  box-shadow: 0 0 0 2px #fbfdff, 1px 1px 0 var(--shadow);
}
.stop-chip:hover { background: linear-gradient(#fff, #eaf3f8); }

.scen-list { display: flex; flex-direction: column; gap: 4px; }
.scen-chip {
  display: flex; align-items: baseline; gap: 8px;
  width: 100%; text-align: left;
  font: inherit; font-size: 12px; cursor: pointer;
  padding: 5px 9px;
  color: var(--ink);
  background: linear-gradient(#fbfdff, var(--panel-mid));
  border: 2px solid var(--frame); border-left-width: 5px; border-radius: 4px;
  box-shadow: 1px 1px 0 var(--shadow);
}
.scen-chip code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11.5px; font-weight: bold;
}
.scen-chip span { margin-left: auto; font-size: 10.5px; color: var(--ink-soft); }
.scen-chip.good { border-left-color: var(--teal); }
.scen-chip.bad  { border-left-color: var(--red); }
.scen-chip.warn { border-left-color: var(--amber); }
.scen-chip.on {
  background: linear-gradient(#ffe08a, var(--gold));
  box-shadow: 0 0 0 2px #fbfdff, 1px 1px 0 var(--shadow);
}
.scen-chip:hover { background: linear-gradient(#fff, #eaf3f8); }
.scen-chip.on:hover { background: linear-gradient(#ffe8a8, var(--gold)); }

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

.dock {
  position: fixed; z-index: 26; left: 12px; right: 12px; bottom: 12px;
  padding: 0 0 8px;
  background: var(--panel);
  border: 3px solid var(--frame);
  border-radius: 5px;
  box-shadow: inset 2px 2px 0 #fbfdff, inset -2px -2px 0 var(--panel-dark), 4px 4px 0 var(--shadow);
  overflow: hidden;
}
.progress { height: 8px; background: var(--panel-mid); border-bottom: 2px solid var(--frame); }
.progress i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(var(--teal), #237966);
  transition: width 0.25s linear;
}
.dock-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 12px 0;
}
.group { display: flex; gap: 6px; align-items: center; }
.icon { width: 38px; height: 34px; padding: 0; font-size: 15px; }

.field { display: flex; flex-direction: column; gap: 3px; min-width: 168px; }
.field span { font-size: 11.5px; font-weight: bold; color: var(--ink-soft); }
.field b { color: var(--ink); }
input[type="range"] { width: 100%; accent-color: var(--teal); }

.toggles { margin-left: auto; gap: 12px; }
.toggle { display: flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: bold; cursor: pointer; }
.toggle input { accent-color: var(--teal); }
.toggle input:disabled { accent-color: var(--panel-dark); }
.toggle input:disabled + span { color: var(--panel-dark); }

/* ---------- narration ---------- */

.btn.sound { padding: 4px 9px; font-size: 12px; }
.btn.sound[hidden] { display: none; }

.audio-note {
  display: flex; align-items: center; gap: 6px;
  margin: 6px 12px 0; padding: 4px 9px;
  font-size: 11.5px; font-weight: bold;
  border-radius: 4px;
}
.audio-note[hidden] { display: none; }
.audio-note::before {
  content: ""; width: 8px; height: 8px; flex: none;
  border-radius: 50%; background: currentColor;
}
.audio-note.on      { color: #1f7a68; background: #dcefe9; }
.audio-note.off     { color: var(--ink-soft); background: var(--panel-mid); }
.audio-note.blocked { color: #8a5a12; background: #f6e6c8; }
/* A live clip gets a pulse, so it is obvious the silence is not a fault. */
.audio-note.live::before { animation: narrating 1.1s ease-in-out infinite; }
@keyframes narrating {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.72); }
}
@media (prefers-reduced-motion: reduce) {
  .audio-note.live::before { animation: none; }
}

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

.tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  max-width: 260px; padding: 7px 10px;
  font-size: 12.5px; line-height: 1.45;
  background: var(--panel);
  border: 2px solid var(--frame); border-radius: 4px;
  box-shadow: 3px 3px 0 var(--shadow);
}
.tooltip b { display: block; font-size: 13.5px; margin-bottom: 2px; }

/* ---------- about ---------- */

.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 20px; background: rgba(14, 24, 20, 0.62);
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  max-width: 680px; max-height: 84vh; overflow-y: auto;
  padding: 22px 26px;
  background: var(--panel);
  border: 3px solid var(--frame); border-radius: 6px;
  box-shadow: inset 2px 2px 0 #fbfdff, 6px 6px 0 var(--shadow);
}
.modal-card h2 { margin: 18px 0 8px; font-size: 20px; }
.modal-card h2:first-of-type { margin-top: 0; }
.modal-card p, .modal-card li { font-size: 14.5px; line-height: 1.62; color: var(--ink-soft); }
.modal-card ul { margin: 0 0 10px; padding-left: 20px; }
.modal-card code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 13px; background: #dbe6ee; padding: 1px 4px; border-radius: 3px;
}
.modal-close {
  position: absolute; top: 10px; right: 12px;
  width: 30px; height: 30px; padding: 0;
  font: inherit; font-size: 18px; font-weight: bold; cursor: pointer;
  background: linear-gradient(var(--panel), var(--panel-mid));
  border: 2px solid var(--frame); border-radius: 4px;
}

/* ---------- the bottom sheet handle (phones only) ---------- */

.sheet-handle { display: none; }
.guide-more { display: block; }

/* ---------- narrow screens ---------- */

/* --dock-h and --hud-h are written by main.js from the measured chrome, so the
   sheet sits exactly on the dock however the controls happen to wrap. */
@media (max-width: 900px) {
  .topbar { padding: 6px 10px; }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 17px; }
  .logo { width: 22px; height: 22px; }
  .btn { padding: 5px 10px; font-size: 13px; }

  .hud { top: var(--hud-top, 48px); left: 8px; gap: 5px; }
  .hud-item { padding: 3px 8px; }
  .hud-item .k { font-size: 9.5px; }
  .hud-item .v { font-size: 12.5px; }
  .hud-note { width: 100%; padding: 2px 4px; font-size: 11px; }

  .verdict { font-size: 12px; padding: 6px 11px; gap: 6px; }
  .verdict b { font-size: 12px; }
  .verdict i { display: none; }

  .zoomer {
    top: calc(var(--hud-h, 108px) + 4px); bottom: auto; transform: none;
    left: 8px; flex-direction: row;
  }
  .zoomer button { width: 32px; height: 32px; }

  /* the guide becomes a sheet pinned above the dock */
  .guide {
    top: auto; left: 8px; right: 8px;
    bottom: var(--dock-h, 82px);
    width: auto; max-height: 38vh;
    padding: 0 12px 12px;
    overscroll-behavior: contain;
  }
  .guide h2 { font-size: 20px; margin-bottom: 6px; }
  .lede { font-size: 14.5px; padding: 6px 9px; margin-bottom: 8px; }
  .body { font-size: 13.5px; }
  .tip { font-size: 12.5px; }

  /* collapsed by default: the head is enough to follow the run */
  .guide-more { display: none; }
  .guide.open { max-height: 62vh; }
  .guide.open .guide-more { display: block; }

  /* a long lede must not grow the collapsed sheet without limit */
  .guide:not(.open) .lede {
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .sheet-handle {
    display: flex; align-items: center; gap: 8px;
    position: sticky; top: 0; z-index: 2;
    width: calc(100% + 24px); margin: 0 -12px 2px;
    padding: 9px 12px;
    font: inherit; font-size: 12.5px; font-weight: bold;
    color: var(--ink-soft); cursor: pointer;
    background: var(--panel);
    border: 0; border-bottom: 2px solid var(--panel-dark);
  }
  .sheet-handle .grip {
    width: 34px; height: 4px; border-radius: 2px;
    background: var(--panel-dark);
  }
  .sheet-handle .sheet-caret { margin-left: auto; font-size: 14px; }
  .guide.open .sheet-handle .sheet-caret { transform: rotate(180deg); }

  .dock { left: 8px; right: 8px; bottom: 8px; }
  .dock-row { gap: 10px; padding: 7px 10px 0; }
  .icon { width: 36px; height: 32px; font-size: 14px; }
  .field { min-width: 0; flex: 1 1 90px; }
  .field span { font-size: 10.5px; }
  .toggles { margin-left: 0; gap: 10px; }
  .toggle { font-size: 12px; }
}

@media (max-width: 430px) {
  .guide { max-height: 34vh; }
  .guide.open { max-height: 58vh; }
  .guide h2 { font-size: 18px; }
  .lede { font-size: 13.5px; }
  .hud-item:nth-child(3) { display: none; }   /* the run number is least useful */
  .toggles { width: 100%; justify-content: space-between; }
}

/* Short and wide, which is any phone held sideways. A bottom sheet would eat the
   whole map, so the guide goes back to being a column down the side. */
@media (max-height: 560px) and (min-width: 620px) {
  .guide {
    top: var(--hud-h, 96px); bottom: var(--dock-h, 76px);
    left: auto; right: 8px; width: 306px; max-height: none;
    padding: 12px;
  }
  .guide.open { max-height: none; }
  .guide-more { display: block; }
  .sheet-handle { display: none; }
  .zoomer {
    top: auto; bottom: calc(var(--dock-h, 76px) + 8px);
    left: 8px; flex-direction: column;
  }
  .guide:not(.open) .lede { display: block; overflow: visible; }
  .verdict { left: 12px; transform: none; }
}
