:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1b2430;
  --line: #2a3543;
  --text: #edf2f7;
  --muted: #91a0b2;
  --accent: #78d8c2;
  --accent-2: #e8c777;
  --danger: #ef8d8d;
  --blue: #79aee8;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 20% 0%, rgba(120, 216, 194, 0.08), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.login-gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: rgba(7, 10, 14, .86); backdrop-filter: blur(18px);
}
.login-gate[hidden] { display: none; }
.login-card {
  width: min(430px, 100%); padding: 28px;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow);
}
.login-card p:not(.eyebrow) { color: var(--muted); }
.login-card label { display: block; margin: 20px 0 7px; color: var(--muted); font-size: .84rem; }
.login-card input {
  width: 100%; padding: .78rem .86rem; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); color: var(--text); font: inherit;
}
.login-card button { width: 100%; }
#loginStatus { display: block; min-height: 1.2em; margin-top: 10px; color: var(--danger); font-size: .82rem; }

button, select { font: inherit; }

button, select {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0.62rem 0.86rem;
}

button { cursor: pointer; transition: border-color 150ms, transform 150ms, background 150ms; }
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: 0.48; }
button.primary { background: var(--accent); color: #09251f; border-color: var(--accent); font-weight: 600; }

.lab-shell { width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: 30px 0 56px; }
.lab-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.eyebrow, .section-label { color: var(--accent); letter-spacing: 0.15em; font-size: 0.72rem; font-weight: 700; margin: 0 0 5px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: 1.12rem; }
h3 { margin-bottom: 12px; font-size: 0.86rem; color: var(--muted); font-weight: 600; }
.subtitle { color: var(--muted); margin-bottom: 0; }
.identity-block { text-align: right; padding-bottom: 4px; }
.identity-block span { color: var(--muted); display: block; font-family: ui-monospace, monospace; font-size: 0.82rem; }
.identity-block strong { font-size: 1.25rem; }

.status-strip, .control-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--line); background: rgba(21, 27, 35, 0.78); backdrop-filter: blur(12px);
}
.status-strip { border-radius: 12px 12px 0 0; padding: 11px 15px; border-bottom: 0; }
.status-item { color: var(--muted); font-size: 0.78rem; display: inline-flex; align-items: center; gap: 7px; }
.status-item i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); }
.status-item.ok i { background: var(--accent); box-shadow: 0 0 0 4px rgba(120,216,194,.08); }
.status-item.error i { background: var(--danger); }
.control-bar { border-radius: 0 0 12px 12px; padding: 12px 15px; box-shadow: var(--shadow); }
.control-bar label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .82rem; }
#actionStatus { margin-left: auto; color: var(--muted); font-size: .78rem; }
.shadow-notice { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; }
.shadow-notice i { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 4px rgba(121,174,232,.08); }

.dashboard { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(330px, .75fr); gap: 16px; margin-top: 16px; }
.panel { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.panel-heading > span { color: var(--muted); font-size: .76rem; }
.shadow-panel { grid-column: 1 / -1; min-height: 0; }
.shadow-rule { color: var(--muted); margin: -4px 0 14px; font-size: .82rem; }
.experience-list { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.experience-list li { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--muted); font-size: .78rem; }
.experience-list code { color: var(--accent); font-size: .7rem; }
.world-panel { min-height: 470px; }
.state-panel { min-height: 470px; }
.decision-panel { grid-column: 1; }
.memory-panel { grid-column: 2; grid-row: 2 / span 2; }
.teacher-panel { grid-column: 1; }

.now-action { text-align: right; }
.now-action span, .goal-line span, .learning-box span { display: block; color: var(--muted); font-size: .73rem; }
.now-action strong { color: var(--accent-2); }

.room {
  position: relative; height: 350px; overflow: hidden; border-radius: 11px;
  border: 1px solid #344252;
  background-color: #111821;
  background-image:
    linear-gradient(rgba(104, 132, 158, .12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 132, 158, .12) 1px, transparent 1px);
  background-size: 10% 14.2857%;
}
.room::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 -80px 100px rgba(0,0,0,.18); pointer-events: none; }
.room-light { position: absolute; width: 260px; height: 260px; right: -80px; top: -110px; border-radius: 50%; background: rgba(232,199,119,.07); filter: blur(8px); }
.object { position: absolute; transform: translate(-50%, -50%); display: grid; place-items: center; gap: 3px; color: var(--muted); font-size: .7rem; z-index: 1; }
.object-shape { width: 30px; height: 25px; border: 1px solid #68849e; background: rgba(121,174,232,.12); border-radius: 7px; }
.object[data-name="cushion"] .object-shape { width: 45px; height: 19px; border-radius: 50%; background: rgba(232,199,119,.12); border-color: #8b794f; }
.object[data-name="window"] .object-shape { height: 45px; background: linear-gradient(135deg, rgba(121,174,232,.2), rgba(120,216,194,.06)); }
.creature {
  position: absolute; width: 42px; height: 42px; border-radius: 48% 52% 45% 55%;
  transform: translate(-50%, -50%); background: var(--accent); z-index: 4;
  box-shadow: 0 9px 24px rgba(120,216,194,.22); transition: left 260ms ease, top 260ms ease, transform 180ms;
}
.creature::before { content: ""; position: absolute; width: 13px; height: 9px; left: 1px; top: -2px; background: var(--accent); border-radius: 80% 10%; transform: rotate(-25deg); }
.eye { position: absolute; width: 4px; height: 6px; border-radius: 50%; background: #09251f; top: 15px; }
.eye.left { left: 12px; } .eye.right { right: 12px; }
.mouth { position: absolute; width: 8px; height: 4px; left: 17px; top: 26px; border-bottom: 1.5px solid #09251f; border-radius: 50%; }
.creature[data-action="rest"] { transform: translate(-50%, -50%) scaleY(.76) rotate(-4deg); }
.creature[data-action="explore"] { box-shadow: 0 9px 30px rgba(120,216,194,.36); }
.user-marker { position: absolute; transform: translate(-50%, -50%); width: 48px; height: 48px; border: 1px dashed var(--accent-2); border-radius: 50%; display: grid; place-items: center; color: var(--accent-2); z-index: 2; }
.user-marker[hidden] { display: none; }
.user-marker span { font-size: .78rem; }
.goal-line { display: flex; align-items: baseline; gap: 9px; margin-top: 13px; }
.goal-line strong { margin-right: auto; }

.honesty-tag { max-width: 145px; text-align: right; }
.metric-group + .metric-group { margin-top: 22px; }
.metric { margin-bottom: 13px; }
.metric-top { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: .78rem; }
.metric-top span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.meter { height: 7px; overflow: hidden; border-radius: 20px; background: #0d1218; }
.meter-fill { height: 100%; border-radius: inherit; background: var(--accent); transition: width 260ms ease; }
.emotions-group .meter-fill { background: var(--blue); }
.learning-box { margin-top: 22px; padding: 13px; border-left: 2px solid var(--accent-2); background: rgba(232,199,119,.045); }
.learning-box strong { display: block; margin: 4px 0; font-family: ui-monospace, monospace; }
.learning-box small { color: var(--muted); }

.causal-trace { display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.trace-node { position: relative; flex: 1 1 150px; min-width: 130px; padding: 11px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--line); }
.trace-node:not(:last-child)::after { content: "→"; position: absolute; right: -13px; top: 50%; color: var(--muted); z-index: 2; }
.trace-node span { color: var(--muted); display: block; font-size: .68rem; text-transform: uppercase; margin-bottom: 3px; }
.trace-node strong { font-size: .8rem; }
.candidate-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .78rem; }
th { color: var(--muted); font-weight: 500; text-align: left; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.selected td { color: var(--accent); background: rgba(120,216,194,.035); }
code { color: var(--muted); font-size: .7rem; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }

.event-list { list-style: none; padding: 0; margin: 0; max-height: 650px; overflow-y: auto; }
.event-list li { border-left: 1px solid var(--line); margin-left: 6px; padding: 0 0 16px 17px; position: relative; }
.event-list li::before { content: ""; position: absolute; left: -4px; top: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.event-list li:last-child::before { background: var(--accent); }
.event-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .67rem; }
.event-title { margin: 4px 0; font-size: .8rem; }
.event-detail { color: var(--muted); font-size: .72rem; line-height: 1.45; }

.teacher-rule { color: var(--muted); font-size: .78rem; }
.teacher-review { min-height: 76px; white-space: pre-wrap; border-left: 2px solid var(--blue); padding: 12px 14px; background: rgba(121,174,232,.05); color: #cbd8e7; line-height: 1.65; font-size: .82rem; }

@media (max-width: 930px) {
  .dashboard { grid-template-columns: 1fr; }
  .decision-panel, .memory-panel, .teacher-panel { grid-column: 1; grid-row: auto; }
  .memory-panel { max-height: none; }
}

@media (max-width: 620px) {
  .lab-shell { width: min(100% - 18px, 1440px); padding-top: 18px; }
  .lab-header { align-items: flex-start; }
  .identity-block { text-align: left; }
  .lab-header, .panel-heading { flex-direction: column; }
  .identity-block, .now-action { text-align: left; }
  #actionStatus { width: 100%; margin-left: 0; }
  .room { height: 300px; }
  .panel { padding: 14px; }
  .trace-node:not(:last-child)::after { display: none; }
}

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