:root {
  color-scheme: dark;
  --bg: #060b10;
  --bg-elevated: #0b131b;
  --panel: rgba(13, 24, 33, 0.94);
  --panel-2: rgba(18, 31, 42, 0.92);
  --line: rgba(154, 208, 224, 0.18);
  --line-strong: rgba(154, 208, 224, 0.34);
  --text: #edf8fb;
  --muted: #8ca5af;
  --accent: #80d8e8;
  --accent-strong: #b3f4ff;
  --danger: #ffaaa6;
  --human: #d6e9ff;
  --alien: #b7ffd6;
  --action: #f4d9a9;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.33);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% -20%, rgba(70, 145, 168, 0.22), transparent 38%),
    linear-gradient(180deg, #071019 0%, #05090d 60%, #020406 100%);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, textarea, input { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible, label:focus-within {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 14px calc(164px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px 13px;
}

.eyebrow, .section-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.62rem, 7vw, 2.2rem); letter-spacing: -0.045em; }
h2 { margin-bottom: 0; font-size: 1.12rem; letter-spacing: -0.02em; }
h3 { margin-bottom: 10px; font-size: 0.92rem; color: var(--accent-strong); }

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.035);
  font-size: 1.35rem;
  cursor: pointer;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.status-strip > div {
  min-width: 0;
  padding: 10px 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(3, 12, 18, 0.66);
}

.status-label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.status-strip strong {
  display: block;
  overflow: hidden;
  font-size: 0.77rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main { display: grid; gap: 12px; }

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(17, 31, 41, 0.92), rgba(8, 16, 23, 0.96));
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 15px 11px;
}

.compact-heading { padding-bottom: 9px; }

.text-button {
  flex: 0 0 auto;
  padding: 7px 3px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 750;
  cursor: pointer;
}

.zone-labels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 0 18px 5px;
  color: rgba(153, 189, 198, 0.5);
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-align: center;
}

.chamber {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-height: 285px;
  margin: 0 10px 12px;
  overflow: hidden;
  border: 1px solid rgba(164, 220, 235, 0.16);
  border-radius: 15px;
  background:
    linear-gradient(90deg, transparent 33.2%, rgba(155, 208, 220, 0.08) 33.4%, transparent 33.7%, transparent 66.2%, rgba(155, 208, 220, 0.08) 66.4%, transparent 66.7%),
    radial-gradient(circle at 50% 54%, rgba(93, 205, 225, 0.10), transparent 38%),
    linear-gradient(180deg, #0b1720 0%, #081118 67%, #0e1b21 68%, #071016 100%);
}

.chamber::after {
  content: "";
  position: absolute;
  inset: auto 0 31% 0;
  height: 1px;
  background: rgba(158, 217, 231, 0.11);
  pointer-events: none;
}

.zone {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 11px;
  padding: 19px 7px 92px;
}

.chamber-object {
  position: relative;
  display: flex;
  width: 74px;
  min-height: 88px;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  padding: 8px 5px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.chamber-object:active { transform: scale(0.96); }
.chamber-object.selected {
  border-color: rgba(179, 244, 255, 0.58);
  background: rgba(126, 221, 239, 0.08);
}

.object-shape {
  position: relative;
  display: grid;
  width: 45px;
  height: 45px;
  place-items: center;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.3));
}

.object-shape.sphere {
  border-radius: 50%;
  box-shadow: inset -8px -8px 13px rgba(0,0,0,0.27), inset 7px 6px 10px rgba(255,255,255,0.26);
}

.object-shape.cube {
  border-radius: 7px;
  box-shadow: inset -7px -7px 12px rgba(0,0,0,0.25), inset 5px 5px 8px rgba(255,255,255,0.20);
}

.object-shape.red { background: #d9575b; }
.object-shape.blue { background: #4f83d9; }
.object-shape.small-container, .object-shape.large-container {
  border: 3px solid #a0a7a9;
  border-top-width: 2px;
  border-radius: 4px 4px 11px 11px;
  background: linear-gradient(180deg, rgba(212, 221, 222, 0.11), rgba(79, 91, 94, 0.29));
}
.object-shape.small-container { width: 46px; height: 36px; margin-top: 9px; }
.object-shape.large-container { width: 57px; height: 49px; }
.object-shape.small-container::before, .object-shape.large-container::before {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: -5px;
  height: 5px;
  border: 2px solid #afb7b9;
  border-radius: 50%;
  background: #59656a;
}

.contained-count {
  position: absolute;
  right: -8px;
  bottom: -8px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 50%;
  background: #14232b;
  color: var(--text);
  font-size: 0.66rem;
  font-weight: 900;
}

.object-name {
  max-width: 100%;
  color: #d8e9ee;
  font-size: 0.68rem;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.object-location {
  color: var(--muted);
  font-size: 0.55rem;
  text-transform: uppercase;
}

.inside-tray {
  position: absolute;
  right: 8px;
  bottom: 8px;
  left: 8px;
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 7px;
  padding: 8px;
  overflow-x: auto;
  border: 1px dashed rgba(154, 208, 224, 0.18);
  border-radius: 11px;
  background: rgba(2, 9, 13, 0.45);
}

.inside-tray::before {
  content: "CONTAINED";
  flex: 0 0 auto;
  color: rgba(153, 189, 198, 0.46);
  font-size: 0.53rem;
  font-weight: 850;
  letter-spacing: 0.12em;
}

.inside-chip {
  flex: 0 0 auto;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  color: #dbeef1;
  font-size: 0.65rem;
  font-weight: 800;
}

.selection-panel {
  padding: 0 14px 15px;
}

.selection-panel > div:first-child {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 9px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.action-button, .secondary-button, .danger-button, .primary-button {
  min-height: 44px;
  border-radius: 12px;
  font-weight: 780;
  cursor: pointer;
}

.action-button {
  padding: 8px 5px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.035);
  font-size: 0.73rem;
}

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

.transcript {
  min-height: 270px;
  max-height: 390px;
  padding: 0 13px 14px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.transcript-empty {
  display: grid;
  min-height: 230px;
  place-items: center;
  padding: 30px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
  text-align: center;
}

.entry {
  position: relative;
  margin: 8px 0;
  padding: 10px 11px 10px 13px;
  border-left: 3px solid var(--line-strong);
  border-radius: 5px 12px 12px 5px;
  background: rgba(255,255,255,0.028);
}

.entry::before {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.57rem;
  font-weight: 850;
  letter-spacing: 0.11em;
}

.entry.human { border-left-color: rgba(146, 193, 245, 0.62); color: var(--human); }
.entry.human::before { content: "HUMAN UTTERANCE"; }
.entry.alien { border-left-color: rgba(138, 245, 177, 0.64); color: var(--alien); }
.entry.alien::before { content: "ALIEN UTTERANCE"; }
.entry.action { border-left-color: rgba(240, 198, 128, 0.58); color: var(--action); font-style: italic; }
.entry.action::before { content: "VISIBLE ACTION"; }
.entry.system { border-left-color: rgba(166, 171, 177, 0.38); color: #aeb7bb; }
.entry.system::before { content: "CHAMBER RECORD"; }

.entry-text {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.88rem;
  line-height: 1.42;
  white-space: pre-wrap;
}

.entry-time {
  display: block;
  margin-top: 5px;
  color: rgba(168, 188, 194, 0.52);
  font-size: 0.56rem;
  font-style: normal;
}

.composer {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(5, 11, 16, 0.94);
  box-shadow: 0 -13px 38px rgba(0,0,0,0.38);
  backdrop-filter: blur(18px);
}

.composer-label {
  display: block;
  margin: 0 0 5px 2px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.composer-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
textarea {
  width: 100%;
  min-height: 46px;
  max-height: 112px;
  resize: none;
  padding: 12px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: #0b161e;
  color: var(--text);
  line-height: 1.35;
}
textarea::placeholder { color: #6f848c; }

.primary-button {
  padding: 0 16px;
  border: 1px solid rgba(178, 243, 255, 0.58);
  background: linear-gradient(180deg, #91e2ef, #5bb9ca);
  color: #051015;
}

.quick-actions { display: grid; grid-template-columns: 0.7fr 1.45fr 0.85fr; gap: 7px; margin-top: 8px; }
.secondary-button, .danger-button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.035);
  font-size: 0.7rem;
}
.danger-button { border-color: rgba(255,170,166,0.28); color: var(--danger); }

.modal {
  width: min(calc(100% - 24px), 520px);
  max-height: min(82dvh, 720px);
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: #0b151d;
  color: var(--text);
  box-shadow: 0 28px 90px rgba(0,0,0,0.65);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(5px); }
.modal form { padding: 18px; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-description { margin: 10px 0 16px; color: #a6bac2; font-size: 0.83rem; line-height: 1.48; }
.choice-options { display: grid; gap: 8px; }
.choice-option {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.035);
  color: var(--text);
  font-weight: 760;
  text-align: left;
}
.control-section { padding: 15px 0; border-top: 1px solid var(--line); }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-label { display: grid; place-items: center; text-align: center; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row small { margin-top: 3px; color: var(--muted); font-size: 0.7rem; line-height: 1.35; }
.toggle-row input { width: 22px; height: 22px; accent-color: #77d4e5; }
.diagnostics dl { margin: 0; }
.diagnostics dl > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid rgba(154,208,224,0.08); }
.diagnostics dt { color: var(--muted); font-size: 0.75rem; }
.diagnostics dd { margin: 0; font-size: 0.75rem; font-weight: 750; text-align: right; }
.prototype-note { margin: 4px 0 0; padding: 12px; border: 1px solid rgba(244,217,169,0.14); border-radius: 12px; background: rgba(244,217,169,0.05); color: #ddcfb6; font-size: 0.75rem; line-height: 1.45; }

.toast {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: calc(154px + var(--safe-bottom));
  left: 18px;
  max-width: 440px;
  margin: 0 auto;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(13, 25, 33, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 150ms ease, transform 150ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (min-width: 640px) {
  .app-shell { padding-right: 20px; padding-left: 20px; }
  main { grid-template-columns: 1.04fr 0.96fr; align-items: start; }
  .transcript { max-height: 520px; }
  .composer { padding-right: 20px; padding-left: 20px; }
  .chamber { min-height: 350px; }
  .zone { padding-top: 28px; }
}

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