@font-face {
  font-family: "Press Start 2P";
  src: url("../fonts/PressStart2P-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --ink: #2a1c12;
  --paper: #f6e4c4;
  --paper-deep: #edd3a4;
  --wood: #8a4e2a;
  --wood-dark: #4e2a16;
  --gold: #f0c14a;
  --work: #2f8f55;
  --idle: #e0922f;
  --sleep: #7a6ea8;
  color: var(--ink);
  background: #140e0a;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  line-height: 1.7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 0%, #3a2416 0, transparent 36%),
    linear-gradient(#24170f, #100c09);
}

button, input { font: inherit; color: inherit; }

.cabinet {
  width: min(1120px, calc(100% - 28px));
  margin: 18px auto 28px;
  background: var(--paper);
  border: 4px solid var(--ink);
  box-shadow:
    0 0 0 4px var(--wood),
    0 0 0 8px var(--ink),
    10px 14px 0 #0c0806;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  padding: 14px 16px 8px;
  background: #f3d7ae;
  border-bottom: 4px solid var(--ink);
}

.eyebrow {
  margin: 0 0 6px;
  color: #8a4e2a;
  font-size: 8px;
}

h1, h2, p { margin: 0; }

h1 { font-size: 16px; line-height: 1.5; }

.meters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 520px;
}

.meter {
  border: 3px solid var(--ink);
  background: #fff6e4;
  padding: 5px 7px 4px;
  font-size: 8px;
  white-space: nowrap;
}

.meter.working { background: #d9f3df; }
.meter.idle { background: #ffe6c2; }
.meter.offline { background: #e6e0f4; }
.meter.demo { background: var(--gold); }
.meter.day { background: #fffaf0; }

.sub {
  padding: 8px 16px 10px;
  background: var(--paper);
  color: #5c3d24;
  font-size: 8px;
}

.stage {
  position: relative;
  width: calc(100% - 20px);
  margin: 0 10px 10px;
  aspect-ratio: 384 / 240;
  container-type: inline-size;
  background: #c9843c;
  border: 4px solid var(--ink);
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

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

.plate, .bubble, .popup, .zzz {
  font-family: "Press Start 2P", monospace;
  font-size: calc(100cqi / 50);
  line-height: 1.35;
}

.plate {
  position: absolute;
  transform: translate(-50%, -10%);
  pointer-events: auto;
  cursor: pointer;
  background: #f6e6c5;
  border: 2px solid var(--ink);
  padding: 2px 4px 3px;
  white-space: nowrap;
}

.plate.working { box-shadow: 0 0 0 2px var(--work); }
.plate.idle { box-shadow: 0 0 0 2px var(--idle); }
.plate.offline { box-shadow: 0 0 0 2px var(--sleep); }
.plate.selected { background: var(--gold); }

.plate:focus-visible, button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.bubble {
  position: absolute;
  transform: translate(-50%, -115%);
  max-width: calc(100cqi * 0.26);
  background: #fffaf0;
  border: 3px solid var(--ink);
  padding: 4px 6px 5px;
  font-size: max(8px, calc(100cqi / 68));
  z-index: 2;
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 8px;
  height: 8px;
  background: #fffaf0;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: translateX(-50%) rotate(45deg);
}

.zzz {
  position: absolute;
  transform: translate(-50%, -100%);
  color: #f4efff;
  -webkit-text-stroke: 3px #3a2d55;
  paint-order: stroke fill;
  z-index: 2;
}

.popup {
  position: absolute;
  transform: translate(-50%, 0);
  color: #fff8dc;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  animation: float-up 1.1s ease-out forwards;
  z-index: 3;
}

@keyframes float-up {
  to { transform: translate(-50%, -28px); opacity: 0; }
}

.banner {
  margin: 0 10px 10px;
  padding: 8px;
  background: #ffd2c8;
  border: 3px solid var(--ink);
  font-size: 8px;
}

.log {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 14px 12px;
  background: #1d140f;
  color: #f6e2b5;
  border-top: 4px solid var(--ink);
}

.log h2 {
  margin-top: 4px;
  color: var(--gold);
  font-size: 10px;
}

.log ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
}

.log li { color: #c8ad86; font-size: 8px; }
.log li.latest { color: #fff4d4; }
.log li.flash { animation: flash 0.8s steps(2, end); }
.log em {
  color: #1d140f;
  background: var(--gold);
  font-style: normal;
  padding: 1px 4px 2px;
  margin-right: 6px;
}

@keyframes flash {
  50% { background: #5c3d18; }
}

dialog {
  width: min(560px, calc(100vw - 24px));
  padding: 0;
  border: 4px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 8px 10px 0 #1a120c;
}

dialog::backdrop { background: rgba(20, 12, 8, 0.55); }

.card-top {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 12px;
  padding: 12px;
  background:
    linear-gradient(#f0d2a6, #f0d2a6) 0 0 / 96px 100% no-repeat,
    #f3d7ae;
  border-bottom: 4px solid var(--ink);
}

#portrait {
  width: 96px;
  height: 112px;
  image-rendering: pixelated;
  background: #e2a45e;
  border: 3px solid var(--ink);
}

.card-id { min-width: 0; }
#card-name { font-size: 14px; line-height: 1.45; margin: 0 0 8px; }
#card-duty { font-size: 8px; color: #5c3d24; }
.live-flag {
  display: inline-block;
  margin-top: 8px;
  background: var(--gold);
  border: 2px solid var(--ink);
  padding: 3px 5px;
  font-size: 8px;
}

#card-close {
  width: 36px;
  height: 32px;
  background: #ffd2c8;
  border: 3px solid var(--ink);
  cursor: pointer;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin: 0;
  padding: 12px;
}

.facts div {
  border: 3px solid var(--ink);
  background: #fff6e4;
  padding: 6px 8px;
}

.facts dt { font-size: 8px; color: #8a4e2a; }
.facts dd { margin: 4px 0 0; font-size: 8px; }

#card-status[data-status="working"] { color: var(--work); }
#card-status[data-status="idle"] { color: #a86412; }
#card-status[data-status="offline"] { color: #5c5388; }

.xp-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 0 12px 14px;
  font-size: 8px;
}

.xp {
  height: 16px;
  background: #3a2415;
  border: 3px solid var(--ink);
  padding: 2px;
}

#card-xp-bar {
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(90deg, #f0c14a 0 8px, #c9842a 8px 10px);
}

@media (max-width: 720px) {
  h1 { font-size: 12px; }
  .top { flex-direction: column; align-items: flex-start; }
  .meters { justify-content: flex-start; }
  .log { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .card-top { grid-template-columns: 72px 1fr auto; }
  #portrait { width: 72px; height: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  .popup, .log li.flash { animation: none; }
}
