:root {
  color-scheme: dark;
  --night: #070b18;
  --ink: #ece6da;
  --muted: #9aa3b5;
  --line: #2a3142;
  --panel: #10141f;
  --panel-2: #171c2a;
  --facade: #262c3a;
  --frame: #0e1219;
  --glass: #141a27;
  --warm: #ffcf73;
  --warm-deep: #f0973a;
  --red: #ff7a7a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--night);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

h1,
h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
}

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

.brand h1 {
  font-size: 22px;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.mark {
  width: 34px;
  height: 34px;
  color: var(--warm);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.occupancy {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- buttons and fields ---------- */

.button {
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}

.button.primary {
  background: var(--warm);
  color: #2a1a05;
}

.button.primary:hover {
  background: #ffdb94;
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.button.ghost:hover {
  border-color: var(--muted);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.field {
  display: grid;
  gap: 6px;
  margin: 18px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus,
.button:focus-visible,
.unit:focus-visible {
  outline: 2px solid var(--warm);
  outline-offset: 2px;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr);
  gap: 22px;
  padding: 0 28px;
  align-items: stretch;
}

/* ---------- scene ---------- */

.scene {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-height: 600px;
  padding: 70px 24px 0;
  overflow: hidden;
  border-radius: 22px;
  background: linear-gradient(180deg, #060a17 0%, #101a36 55%, #1c2950 100%);
}

.sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sky::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 8% 12%, #fff, transparent),
    radial-gradient(1px 1px at 18% 30%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 27% 8%, #fff, transparent),
    radial-gradient(1px 1px at 36% 22%, #fff, transparent),
    radial-gradient(1px 1px at 47% 6%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 58% 16%, #fff, transparent),
    radial-gradient(1px 1px at 66% 34%, #fff, transparent),
    radial-gradient(1px 1px at 74% 9%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 88% 26%, #fff, transparent),
    radial-gradient(1px 1px at 94% 6%, #fff, transparent),
    radial-gradient(1px 1px at 4% 40%, #fff, transparent),
    radial-gradient(1px 1px at 52% 38%, #fff, transparent);
  opacity: 0.7;
  animation: twinkle 6s ease-in-out infinite alternate;
}

.moon {
  position: absolute;
  top: 24px;
  right: 5%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 34%, #fffbea, #ebe2bf 60%, #cfc49c);
  box-shadow: 0 0 46px 12px rgba(255, 244, 205, 0.16);
}

.skyline {
  position: absolute;
  bottom: 34px;
  background: #0c1328;
  background-image: repeating-linear-gradient(0deg, transparent 0 14px, rgba(255, 214, 140, 0.05) 14px 18px);
}

.skyline.s1 { left: 0; width: 18%; height: 46%; }
.skyline.s2 { left: 14%; width: 12%; height: 30%; }
.skyline.s3 { right: 0; width: 22%; height: 38%; }

/* ---------- building ---------- */

.building {
  position: relative;
  z-index: 1;
  width: min(540px, 100%);
  padding: 0 24px;
  border: 1px solid #39415a;
  border-bottom: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 26px),
    linear-gradient(180deg, #2d3446, var(--facade));
  box-shadow: 0 -20px 80px rgba(0, 0, 0, 0.45);
}

.roof {
  display: flex;
  justify-content: center;
  margin: 0 -25px 22px;
  padding: 12px 0;
  border-bottom: 3px solid #1a1f2b;
  background: #1c212e;
}

.sign {
  color: var(--warm);
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.32em;
  text-shadow: 0 0 8px rgba(255, 190, 100, 0.8), 0 0 22px rgba(255, 150, 60, 0.45);
}

.floors {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 26px 24px;
}

.unit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

.window {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 5px solid var(--frame);
  border-radius: 3px;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px #3b4457;
  transition: box-shadow 1s ease, transform 0.2s ease;
}

.unit:hover .window {
  transform: translateY(-2px);
}

.glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 22%, #fff1c9 0%, var(--warm) 38%, var(--warm-deep) 100%);
  opacity: 0;
  transition: opacity 1.4s ease;
}

.interior {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1s ease;
}

.lamp {
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 20%;
  background: rgba(0, 0, 0, 0.55);
}

.lamp::after {
  content: "";
  position: absolute;
  top: 100%;
  left: -11px;
  width: 24px;
  height: 10px;
  clip-path: polygon(25% 0, 75% 0, 100% 100%, 0 100%);
  background: #3a2a1a;
}

.desk {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 14%;
  height: 8%;
  border-radius: 2px;
  background: #4a3424;
}

.monitor {
  position: absolute;
  left: 54%;
  bottom: 22%;
  width: 24%;
  height: 26%;
  border: 2px solid #0e1118;
  border-radius: 2px;
  background: #1d2433;
  transition: background 0.6s, box-shadow 0.6s;
}

.resident {
  position: absolute;
  left: 24%;
  bottom: 22%;
  width: 22%;
  height: 44%;
}

.resident .head {
  display: block;
  width: 46%;
  aspect-ratio: 1;
  margin: 0 auto 6%;
  border-radius: 50%;
  background: #21160e;
}

.resident .body {
  display: block;
  width: 100%;
  height: 52%;
  border-radius: 45% 45% 4px 4px;
  background: #21160e;
}

.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 16%;
  opacity: 0;
  background: repeating-linear-gradient(90deg, #7a4a3c 0 4px, #6a3e33 4px 8px);
  transition: opacity 0.8s;
}

.curtain.left { left: 0; }
.curtain.right { right: 0; }

.mullion {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent calc(50% - 2px), var(--frame) calc(50% - 2px) calc(50% + 2px), transparent calc(50% + 2px)),
    linear-gradient(115deg, transparent 38%, rgba(255, 255, 255, 0.07) 44%, transparent 54%);
  pointer-events: none;
}

.plate {
  max-width: 100%;
  overflow: hidden;
  padding: 2px 9px;
  border-radius: 2px;
  background: #b8975e;
  color: #2a1e0e;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.unit.vacant .plate {
  background: #3a4152;
  color: #aab2c3;
}

/* occupied, lights dimmed */
.unit.idle .glow,
.unit.moving-in .glow {
  opacity: 0.22;
}

.unit:not(.vacant) .interior {
  opacity: 0.55;
}

.unit:not(.vacant) .curtain {
  opacity: 0.9;
}

/* agent at work: lights on */
.unit.working .glow {
  opacity: 1;
}

.unit.working .interior {
  opacity: 1;
}

.unit.working .window {
  box-shadow:
    inset 0 0 0 1px #ffd99a,
    0 0 26px 6px rgba(255, 190, 100, 0.55),
    0 0 90px 24px rgba(255, 160, 70, 0.22);
}

.unit.working::after {
  content: "";
  position: absolute;
  top: 55%;
  left: -14%;
  right: -14%;
  height: 80%;
  background: radial-gradient(ellipse at top, rgba(255, 190, 100, 0.26), transparent 70%);
  pointer-events: none;
}

.unit.working .resident {
  animation: typing 0.7s ease-in-out infinite alternate;
}

.unit.working .monitor {
  background: #d6ecff;
  box-shadow: 0 0 12px 2px rgba(160, 210, 255, 0.8);
  animation: screen 1.8s ease-in-out infinite;
}

.unit.working .lamp::after {
  background: #ffe7b0;
  box-shadow: 0 6px 18px 4px rgba(255, 220, 150, 0.9);
}

/* waiting for a free desk */
.unit.queued .glow {
  animation: flicker 1.6s linear infinite;
}

/* something went wrong */
.unit.failed .glow {
  background: radial-gradient(circle at 50% 30%, #ffc1c1, #e05656);
  opacity: 0.75;
}

.unit.failed .window {
  animation: alarm 0.7s ease-in-out 3;
}

/* moving in */
.unit.moving-in .glow {
  animation: switch-on 2.2s ease-out forwards;
}

.unit.moving-in .resident {
  animation: walk-in 1.8s ease-out;
}

.unit.selected .window {
  outline: 2px solid var(--warm);
  outline-offset: 5px;
}

.unit.selected .plate {
  box-shadow: 0 0 0 2px var(--warm);
}

/* ---------- lobby and street ---------- */

.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 30px -25px 0;
  padding-top: 14px;
  border-top: 4px solid #1a1f2b;
  background: #20252f;
}

.lobby-sign {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.door {
  display: flex;
  gap: 3px;
  width: 74px;
  height: 64px;
  padding: 4px 4px 0;
  background: var(--frame);
  transition: box-shadow 0.8s;
}

.door span {
  flex: 1;
  background: linear-gradient(180deg, #2b3b55, #1a2436);
  transition: background 0.8s;
}

.building.arrival .door {
  box-shadow: 0 0 34px 10px rgba(255, 200, 120, 0.45);
}

.building.arrival .door span {
  background: linear-gradient(180deg, #ffe6b5, #f2b25c);
}

.street {
  position: relative;
  width: calc(100% + 48px);
  margin: 0 -24px;
  height: 34px;
  background: linear-gradient(180deg, #151a27, #0b0e16);
}

.lamp-post {
  position: absolute;
  bottom: 34px;
  left: 12%;
  width: 4px;
  height: 120px;
  background: #0b0e16;
}

.lamp-post::after {
  content: "";
  position: absolute;
  top: -8px;
  left: -8px;
  width: 20px;
  height: 10px;
  border-radius: 10px 10px 2px 2px;
  background: #ffe3a6;
  box-shadow: 0 10px 40px 14px rgba(255, 210, 140, 0.25);
}

/* ---------- panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 600px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
}

.panel > section {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.panel > section[hidden] {
  display: none;
}

.panel h2 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--warm);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.lead {
  margin: 14px 0 22px;
  color: var(--muted);
}

#panelIntro .button {
  align-self: flex-start;
}

.perks {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.perks strong {
  display: block;
  color: var(--ink);
}

.note {
  min-height: 1.5em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#moveIn {
  align-self: flex-start;
}

.room-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.chip {
  flex: none;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.chip.working {
  border-color: var(--warm);
  background: rgba(255, 207, 115, 0.14);
  color: var(--warm);
}

.chip.queued {
  border-color: #c9a24a;
  color: #e0c071;
}

.chip.failed {
  border-color: var(--red);
  color: var(--red);
}

.meter {
  margin: 18px 0 14px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.meter-bar {
  height: 6px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--panel-2);
}

.meter-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--warm-deep), var(--warm));
  transition: width 0.6s ease;
}

.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  max-height: 46vh;
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
}

.msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user {
  align-self: flex-end;
  background: var(--warm);
  color: #2a1a05;
}

.msg.agent {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: #1f2534;
}

.msg pre,
.msg code {
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.msg pre {
  margin: 8px 0;
  padding: 10px 12px;
  overflow-x: auto;
  border-radius: 8px;
  background: #0b0e16;
  white-space: pre;
}

.msg code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #0b0e16;
}

.msg.system,
.msg.empty {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.msg.error {
  align-self: flex-start;
  border: 1px solid rgba(255, 122, 122, 0.5);
  color: var(--red);
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.suggestion {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.suggestion:hover {
  border-color: var(--warm);
  color: var(--ink);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.composer textarea {
  resize: vertical;
}

/* ---------- legend and dialog ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  padding: 18px 28px 28px;
  color: var(--muted);
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 16px;
  height: 12px;
  border: 2px solid var(--frame);
  border-radius: 2px;
  background: var(--glass);
}

.swatch.idle { background: #5d4a2e; }
.swatch.working { background: var(--warm); box-shadow: 0 0 10px rgba(255, 190, 100, 0.7); }
.swatch.queued { background: #8a6a2a; animation: flicker 1.6s linear infinite; }

.key-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--ink);
}

.key-dialog::backdrop {
  background: rgba(3, 5, 12, 0.7);
  backdrop-filter: blur(3px);
}

.key-dialog p {
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* ---------- animations ---------- */

@keyframes typing {
  from { transform: translateY(0); }
  to { transform: translateY(-3px); }
}

@keyframes screen {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

@keyframes flicker {
  0%, 100% { opacity: 0.18; }
  8% { opacity: 0.6; }
  11% { opacity: 0.2; }
  40% { opacity: 0.55; }
  62% { opacity: 0.25; }
}

@keyframes switch-on {
  0% { opacity: 0; }
  10% { opacity: 0.9; }
  14% { opacity: 0.05; }
  24% { opacity: 1; }
  30% { opacity: 0.3; }
  45% { opacity: 1; }
  100% { opacity: 0.22; }
}

@keyframes walk-in {
  from { transform: translateX(170%); }
  to { transform: translateX(0); }
}

@keyframes alarm {
  0%, 100% { box-shadow: inset 0 0 0 1px #3b4457; }
  50% { box-shadow: inset 0 0 0 1px var(--red), 0 0 30px 6px rgba(255, 80, 80, 0.55); }
}

@keyframes twinkle {
  from { opacity: 0.45; }
  to { opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- small screens ---------- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 0 16px;
  }

  .topbar,
  .legend {
    padding-left: 16px;
    padding-right: 16px;
  }

  .scene,
  .panel {
    min-height: 0;
  }

  .scene {
    padding-top: 56px;
  }

  .building {
    padding: 0 14px;
  }

  .roof,
  .lobby {
    margin-left: -15px;
    margin-right: -15px;
  }

  .floors {
    gap: 18px 12px;
  }

  .occupancy {
    display: none;
  }
}
