:root {
  color-scheme: dark;
  --bg: #121710;
  --panel: #1a2118;
  --raised: #243026;
  --line: #314033;
  --fg: #e7e4db;
  --muted: #9aa192;
  --amber: #e0a106;
  --alarm: #ff4a3d;
  --ok: #3dde6e;
  --ink: #10120e;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
code { font-family: "IBM Plex Mono", ui-monospace, monospace; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.kicker { margin: 0; letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.68rem; color: var(--amber); }
h1 { margin: 0; font-size: 1.15rem; }
.top { display: flex; flex-wrap: nowrap; gap: 0.5rem 0.75rem; align-items: center; padding: 0.45rem 0.75rem; border-bottom: 1px solid var(--line); }
.name input, .field, .select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 0.6rem; min-height: 2.5rem; padding: 0.35rem 0.7rem;
}
.top-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 0.35rem; margin-left: auto; }
.top .btn, .top .select, .top .name input { min-height: 2.15rem; padding: 0.2rem 0.65rem; }
#who { width: auto; white-space: nowrap; color: var(--muted); font-size: 0.8rem; padding: 0 0.15rem; }
[hidden] { display: none !important; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 2.5rem; padding: 0.35rem 0.8rem; border-radius: 0.7rem; border: 1px solid var(--line);
  background: var(--raised); cursor: pointer;
}
.btn.primary { background: var(--amber); color: var(--ink); border-color: transparent; font-weight: 600; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.top, .status { flex: none; }
.status { min-height: 1.2rem; margin: 0; padding: 0.25rem 1rem; color: var(--muted); font-size: 0.85rem; }
main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr) 17rem;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}
.rail { min-height: 0; overflow: auto; padding: 0.9rem; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 0.75rem; }
#inspector { border-right: 0; border-left: 1px solid var(--line); }
.stage-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  container-type: size;
  overflow: hidden;
}
.stage {
  position: relative;
  z-index: 1;
  flex: none;
  height: min(calc(100cqh - 3.4rem), calc(100cqw * 600 / 1024));
  width: auto;
  max-width: 100%;
  aspect-ratio: 1024 / 600;
  margin: 0;
  background: #0c0e0b;
  overflow: visible;
  border: 1px solid var(--line);
  touch-action: none;
  container-type: inline-size;
}
.stage img.bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(to right, rgba(143, 153, 124, 0.18) 1px, transparent 1px), linear-gradient(to bottom, rgba(143, 153, 124, 0.18) 1px, transparent 1px);
}
.mark { position: absolute; }
.mark.selected { outline: 2px solid var(--amber); outline-offset: 2px; }
.hit { position: absolute; inset: 0; border: 0; background: transparent; padding: 0; cursor: grab; }
.hit img, .line-body { width: 100%; height: 100%; display: block; pointer-events: none; }
body.sim-run .mark[data-flash="1"] .hit,
body.sim-run .loss.unacked span {
  animation: zone-flash 0.55s steps(1, end) infinite;
}
@keyframes zone-flash {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.15; }
}
.users-page { min-height: 100%; overflow: auto; padding: 1.25rem; }
.users-wrap { width: min(100%, 42rem); margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.users-card { display: flex; flex-direction: column; gap: 0.7rem; padding: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; }
.users-card h2 { margin: 0; font-size: 1rem; }
.user-table { width: 100%; border-collapse: collapse; }
.user-table th, .user-table td { text-align: left; padding: 0.4rem 0.25rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.user-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.user-actions .field { min-height: 2.15rem; width: 9rem; }
.login-page { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; overflow: auto; }
.login-card { width: min(100%, 26rem); display: flex; flex-direction: column; gap: 0.7rem; padding: 1.2rem; background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.7rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.25rem; color: var(--muted); }
.inbox-row { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; width: 100%; }
.btn.alarm { background: #6e221c; color: #ffd2cc; border-color: #ff4a3d; }
.btn.clear { background: #145c32; color: #e5fff0; border-color: #3dde6e; }
.btn.ack { background: #3a2a12; border-color: var(--amber); color: var(--amber); }
.corner-ack {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: 16%;
  height: 17%;
  border: 0;
  background: transparent;
  color: rgba(231, 228, 219, 0.75);
  font: 600 0.72rem "IBM Plex Sans", sans-serif;
  letter-spacing: 0.12em;
  text-align: right;
  padding: 0 0.45rem 0.35rem 0;
  cursor: pointer;
}
.mark[data-state="red"] .hit { filter: drop-shadow(0 0 8px rgba(255, 74, 61, 0.55)); }
.line-body { border-radius: 999px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35); }
.line-body[data-state="green"] { background: linear-gradient(#e5fff0, #3dde6e 34%, #063318); }
.line-body[data-state="red"] { background: linear-gradient(#ffd2cc, #ff4a3d 34%, #4a0c0c); }
.handle, .rot {
  position: absolute; width: 0.9rem; height: 0.9rem; border-radius: 999px; border: 2px solid var(--ink); background: var(--fg); cursor: nwse-resize;
}
.handle { right: -0.35rem; bottom: -0.35rem; }
.rot { left: 50%; top: -1.15rem; transform: translateX(-50%); cursor: grab; background: var(--amber); }
.rot::after { content: ""; position: absolute; top: 100%; left: 50%; width: 2px; height: 0.45rem; background: var(--amber); transform: translateX(-50%); }
.mark-label { position: absolute; pointer-events: none; }
.mark-label.pos-bottom { top: calc(100% + 2px); left: 50%; transform: translateX(-50%); }
.mark-label.pos-top { bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%); }
.mark-label.pos-left { right: calc(100% + 2px); top: 50%; transform: translateY(-50%); }
.mark-label.pos-right { left: calc(100% + 2px); top: 50%; transform: translateY(-50%); }
.mark-label-text { display: inline-block; font-family: "IBM Plex Sans", sans-serif; line-height: 1.15; white-space: nowrap; padding: 0.08em 0.28em; border-radius: 0.15em; }
.mark-label.flip .mark-label-text { transform: rotate(180deg); }
.loss {
  position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
}
.loss span { background: rgba(0,0,0,0.8); color: #ff6b60; font-size: 1.6rem; font-weight: 650; padding: 0.4rem 0.9rem; }
.hint { flex: none; margin: 0; width: min(100%, 64rem); color: var(--muted); font-size: 0.85rem; }
.slot { display: flex; flex-direction: column; gap: 0.3rem; }
.slot label.drop {
  min-height: 4.5rem; display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 0.8rem; cursor: pointer; background: var(--bg); overflow: hidden;
}
.slot img { max-height: 4.5rem; max-width: 100%; object-fit: contain; }
.row { display: flex; gap: 0.4rem; }
.row > * { flex: 1; }
.mark-btn { display: flex; gap: 0.5rem; align-items: center; text-align: left; border: 0; background: transparent; min-height: 2.6rem; border-radius: 0.6rem; padding: 0.2rem 0.35rem; cursor: pointer; }
.mark-btn[aria-pressed="true"] { background: var(--raised); box-shadow: inset 3px 0 0 var(--amber); }
.swatch { width: 1.6rem; height: 1.6rem; object-fit: contain; }
.fields { display: flex; flex-direction: column; gap: 0.55rem; }
.fields label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
.fields input, .fields select { width: 100%; }
.link {
  position: relative;
  z-index: 30;
  flex: none;
  background: var(--bg);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.45);
  padding: 0.6rem 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.link-bar, .presets { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.log { margin: 0; max-height: 4.5rem; overflow: auto; font-family: "IBM Plex Mono", monospace; font-size: 0.75rem; color: var(--muted); white-space: pre-wrap; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 0.7rem; overflow: hidden; }
.seg button { flex: 1; border: 0; background: transparent; min-height: 2.3rem; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--amber); }

@media (max-width: 960px) {
  html, body { height: auto; overflow: auto; }
  body { min-height: 100vh; overflow: visible; }
  main { display: flex; flex-direction: column; overflow: visible; }
  .stage-wrap { height: auto; overflow: visible; container-type: normal; }
  .stage { width: 100%; height: auto; aspect-ratio: 1024 / 600; }
  .rail { border: 0; border-top: 1px solid var(--line); max-height: 22rem; }
  .link { position: sticky; bottom: 0; }
}
