:root {
  --bg: #1b1a24;
  --floor: #2a2838;
  --card: #24232f;
  --line: #3a3850;
  --text: #ece9f5;
  --muted: #a39fba;
  --accent: #f2b14a;
  --ok: #6fd08c;
  --warn: #f2b14a;
  --bad: #f2706a;
  --desk: #6b4a32;
  --desk-top: #8a6242;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif; }
body { padding: 0 16px 32px; max-width: 1180px; margin: 0 auto; }
.hidden { display: none !important; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 0; flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: 1px; font-size: 18px; }
.logo { color: var(--accent); }
/* sits under the header: all instructions and approvals go through Telegram */
.notice { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.meta { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: #3d6b4b; }
.pill.warn { color: var(--warn); border-color: #6b5a2d; }
.pill.bad { color: var(--bad); border-color: #6b3d3d; }

main { display: flex; flex-direction: column; gap: 14px; }
.stage { min-width: 0; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card h2 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; letter-spacing: .5px; }
.office { position: relative; overflow: hidden; background: #3b3550; padding-bottom: 22px; }
#office-bg { position: absolute; top: 0; left: 0; image-rendering: pixelated; z-index: 0; pointer-events: none; }
.office > :not(#office-bg) { position: relative; z-index: 1; }
.office h2 { display: inline-block; background: #00000066; color: #e8e4f5; padding: 3px 10px; border-radius: 6px; }
.office .name, .office .title, .office .engine { text-shadow: 0 1px 2px #000, 0 0 4px #000; }
.office .station:not(.prop) .name { background: #1f1a2acc; padding: 1px 8px; border-radius: 6px; }
.office .title, .office .engine { color: #d6d1e8; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* --- office --- */
.desks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px 10px; }
.boss-row { grid-template-columns: minmax(170px, 240px); justify-content: center; margin-bottom: 18px; }
.station { position: relative; display: flex; flex-direction: column; align-items: center; padding-top: 58px; min-width: 0; text-align: center; }
.bubble {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  max-width: 150px; width: max-content; padding: 5px 8px; border-radius: 8px;
  background: #fffdf6; color: #24232f; font-size: 11.5px; line-height: 1.35;
  box-shadow: 0 2px 0 #00000040; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -6px; border: 6px solid transparent; border-top-color: #fffdf6; border-bottom: 0; transform: translateX(-50%); }
.bubble:empty { display: none; }
.bubble.chatter { opacity: .8; font-style: italic; border: 1px dashed #8a8799; }
.bubble.chatter::before { content: "💭 "; font-style: normal; }
.sprite-wrap { position: relative; width: 150px; height: 146px; }
.sprite-wrap.boss { width: 128px; }
.sprite-wrap .sprite { position: absolute; left: 0; top: 0; }
.deskfx { position: absolute; left: -4px; top: 64px; width: 152px; height: 80px; image-rendering: pixelated; pointer-events: none; z-index: 2; }
.sprite-wrap.boss .deskfx { left: -48px; width: 224px; }
.station .badge { z-index: 3; }
.station.prop { justify-content: flex-start; }
.propfx { width: 152px; height: 144px; image-rendering: pixelated; display: block; }
.smoke { z-index: 3; }
.sprite { width: 128px; height: 128px; image-rendering: pixelated; display: block; }
.name { margin-top: 6px; font-weight: 700; font-size: 13px; }
.title { font-size: 11px; color: var(--muted); }
.engine { font-size: 10px; color: var(--muted); opacity: .75; overflow-wrap: anywhere; }

.badge { position: absolute; top: 2px; right: -6px; font-weight: 900; font-size: 18px; }
.station.working .sprite { animation: peck .34s steps(1, end) infinite; }
@keyframes peck { 0% { transform: translateY(0); } 50% { transform: translateY(4px) rotate(2deg); } }
.sprite { transform-origin: 50% 100%; animation: breathe 3s steps(1, end) infinite; }
.station.idle .sprite { filter: saturate(.8) brightness(.92); }
.station.trouble .sprite, .station.needs .sprite { animation: hop 1s ease-in-out infinite; }
.station.idle .badge::after { content: "z z"; color: var(--muted); font-size: 11px; animation: float 2.4s ease-in-out infinite; display: inline-block; }
.station.needs .badge::after { content: "?"; color: var(--warn); }
.station.trouble .badge::after { content: "!"; color: var(--bad); }
.station.working .badge::after { content: "⌨"; color: #9cc8ff; font-size: 13px; }

@keyframes type { 0% { transform: translateY(0); } 100% { transform: translateY(-2px); } }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.012, 1.03); } }
.smoke { position: absolute; width: 8px; height: 8px; background: #d9d6e2; opacity: 0; pointer-events: none; image-rendering: pixelated; box-shadow: 4px -4px 0 #c9c5d4, -2px -6px 0 #e4e1ec; animation: smoke 2.6s linear forwards; }
@keyframes smoke { 0% { opacity: .85; transform: translate(0, 0) scale(.6); } 60% { opacity: .5; } 100% { opacity: 0; transform: translate(var(--drift, 6px), -46px) scale(1.6); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }
@keyframes float { 0%, 100% { transform: translateY(0); opacity: .6; } 50% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sprite, .badge::after { animation: none !important; } }

/* --- lists --- */
.list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.list li { padding: 7px 0; border-bottom: 1px solid #ffffff10; font-size: 13px; overflow-wrap: anywhere; }
.list li:last-child { border-bottom: 0; }
.list .when { color: var(--muted); font-size: 11px; margin-right: 6px; }
.list .who { font-weight: 700; margin-right: 4px; }
.log li { font-size: 12.5px; }

/* --- usage --- */
.gauge { margin-bottom: 12px; }
.gauge .label { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; margin-bottom: 4px; }
.gauge .label span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.gauge.reset .label span:last-child { color: var(--muted); }
.bar { height: 10px; background: #17161f; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, #8b78e6, #b4befe); }
.bar.hot > span { background: linear-gradient(90deg, #e16c45, #f2b14a); }

/* ===== wide screens: office on the left (auto-fit to the window), sidebar on the right ===== */
@media (min-width: 1100px) {
  html, body { height: 100%; overflow: hidden; }
  body { max-width: none; margin: 0; padding: 0 16px 12px; display: flex; flex-direction: column; }
  .top { padding: 10px 0 6px; flex: none; }
  .notice { flex: none; }
  main { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; }
  .stage { position: relative; overflow: hidden; min-height: 0; border-radius: var(--radius); }
  .stage .office { position: absolute; left: 0; top: 0; width: 1040px; transform-origin: 0 0; }
  .side { overflow-y: auto; min-height: 0; padding-right: 4px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
  .side .list { max-height: 180px; }
  .office .desks { gap: 8px 10px; }
  .office .boss-row { margin-bottom: 8px; }
  .office .name { font-size: 15px; }
  .office .title { font-size: 12.5px; }
  .office .engine { font-size: 11.5px; opacity: .9; }
  .boss-row.wide { width: calc(100% * 5 / 6); margin-left: auto; margin-right: auto; }
}

/* ===== below 1100px: single column, office first ===== */
@media (max-width: 1099.98px) {
  .side { display: contents; }
}

/* ===== phone: whole office on the first screen (4 columns, small birds, one-line bubbles) ===== */
@media (max-width: 720px) {
  body { padding-left: 12px; padding-right: 12px; }
  .office { padding: 8px 4px 10px; }
  .office h2 { font-size: 12px; margin: 0 0 0 4px; padding: 2px 8px; }
  .boss-row { margin-bottom: calc(4px + var(--phone-ex, 0px)); }
  .desks { gap: calc(4px + var(--phone-ex, 0px)) 2px; }
  .station { padding-top: 36px; }
  .sprite-wrap, .propfx { zoom: var(--phone-zoom, .5); }
  .bubble { width: 100%; max-width: 100%; max-height: 60px; box-sizing: border-box; font-size: 9px; line-height: 1.25; padding: 2px 5px; border-radius: 6px; display: block; z-index: 4; white-space: normal; overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; word-break: keep-all; overflow-wrap: anywhere; }
  .bubble::after { border-width: 5px; bottom: -5px; }
  .station.idle .bubble:not(.chatter) { display: none; }
  .name { font-size: 11.5px; margin-top: 0; padding: 0 5px; }
  .office .station:not(.prop) .name { padding: 0 5px; }
  .title, .engine { display: none; }
  .badge { right: 2px; top: 22px; font-size: 14px; }
}

/* --- staff info card (tap / hover) --- */
.station:not(.prop) { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#info-card { position: fixed; z-index: 15; left: 0; top: 0; width: min(300px, calc(100vw - 16px)); box-sizing: border-box; padding: 12px 16px; border-radius: 12px; background: #1b1a24e6; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border: 1px solid #ffffff26; color: var(--text); font-size: 14px; line-height: 1.4; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .15s ease; text-align: left; overflow-wrap: anywhere; }
#info-card.show { opacity: 1; visibility: visible; }
#info-card > div + div { margin-top: 4px; }
#info-card .ic-name { font-size: 16px; font-weight: 800; }
#info-card .ic-title, #info-card .ic-engine { color: var(--muted); font-size: 13px; }
#info-card .ic-state { font-weight: 700; margin-top: 8px; }
#info-card .ic-state.working { color: #9cc8ff; }
#info-card .ic-state.needs { color: var(--warn); }
#info-card .ic-state.trouble { color: var(--bad); }
#info-card .ic-state.idle { color: var(--muted); }
#info-card .ic-light { color: var(--warn); font-size: 13px; }
#info-card .ic-duties { margin-top: 8px; }
#info-card .ic-persona { color: var(--muted); font-size: 13px; font-style: italic; }
@media (prefers-reduced-motion: reduce) { #info-card { transition: none; } }
