:root {
  --bg: #efeeea;
  --paper: #fffefb;
  --ink: #23221f;
  --muted: #77736a;
  --line: #dfdcd3;
  --wall: #34322e;
  --concrete: #e6e4de;
  --green: #2fa457;
  --orange: #e8552d;
  --cyan: #8ad8e6;
  --blue: #1f3f9a;
  --wood: #dcbb8b;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 "Inter", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* --- header --- */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 16px 28px 12px; }
.title { min-width: 0; }
h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -0.01em; }
.brief { margin: 4px 0 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag {
  display: inline-block; margin-right: 6px; padding: 1px 8px;
  background: var(--cyan); border-radius: 4px; color: var(--ink);
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
}
.phases { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; flex-shrink: 0; }
.phases li {
  padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); background: var(--paper); white-space: nowrap;
}
.phases li.done { color: var(--ink); border-color: #bdb9ae; }
.phases li.now { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }

/* --- layout --- */
main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 18px;
  padding: 0 28px 20px;
}
.stage-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 10px; }
.stage {
  position: relative; flex: 1; min-height: 0;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
/* The SVG letterboxes itself via its viewBox; app.js maps figure positions to pixels. */
#floor { display: block; width: 100%; height: 100%; }

/* --- floor plan --- */
.shell { fill: var(--concrete); stroke: var(--wall); stroke-width: 6; stroke-linejoin: round; }
.wall { fill: none; stroke: var(--wall); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.room-label { font-size: 12px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; fill: var(--ink); opacity: 0.5; }
.room-label.light { fill: #fff; opacity: 0.85; }
.f-white { fill: #fff; stroke: #cfcabd; stroke-width: 1.4; }
.f-wood { fill: var(--wood); stroke: #b99a6b; stroke-width: 1.4; }
.f-grey { fill: #d8d5cc; stroke: #bdb9ae; stroke-width: 1.2; }
.f-dark { fill: #262422; stroke: #111; stroke-width: 1.2; }
.f-green { fill: none; stroke: var(--green); stroke-width: 3; }
.f-screen { fill: #c5d2ee; stroke: #9eb0d8; stroke-width: 1.2; }
.plant { fill: #7fb98a; stroke: #5d9a69; stroke-width: 1.4; }
.stool { fill: var(--orange); stroke: #c2401c; stroke-width: 1.2; }
.glass { stroke: var(--cyan); stroke-width: 5; stroke-dasharray: 10 6; }
#library { cursor: pointer; }
#library .door { transition: transform 0.6s ease; }
#library.open .door { transform: translateX(-66px); }
#library .pull { transition: transform 0.3s ease; }
#library.open .pull { transform: translateY(9px); }
.secret { font-size: 10.5px; font-weight: 600; fill: #fff; }

.agent { transition: opacity 0.35s; }
.agent.away { opacity: 0; }
.agent .shadow { fill: rgba(0, 0, 0, 0.13); }
.agent .body { stroke: #fff; stroke-width: 2.2; }
.agent.simulated .body { stroke: var(--ink); stroke-width: 1.6; stroke-dasharray: 3.5 3; }
.agent .head { fill: #f4dcc6; stroke: #fff; stroke-width: 1.6; }
.agent .eye { fill: var(--ink); }
.agent .wheel { fill: #34322e; }
.agent .cane { stroke: #6b5a45; stroke-width: 2.4; stroke-linecap: round; }
.agent .ring { fill: none; stroke-width: 3; opacity: 0; transition: opacity 0.25s; }
.agent.speaking .ring { opacity: 0.6; }
.agent.listening .ring { opacity: 0.35; stroke-dasharray: 4 5; }
.agent.thinking .dots { opacity: 1; }
.agent .dots { opacity: 0; transition: opacity 0.2s; }
.agent .dots circle { fill: var(--ink); animation: blink 1.1s infinite; }
.agent .dots circle:nth-child(2) { animation-delay: 0.18s; }
.agent .dots circle:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.2; } 30% { opacity: 1; } }
.agent .label-bg { fill: #fff; stroke: var(--line); }
.agent .label { font-size: 10.5px; font-weight: 650; fill: var(--ink); text-anchor: middle; }

/* --- speech bubble --- */
.bubble {
  position: absolute; z-index: 2;
  width: max-content; max-width: min(310px, 44%);
  padding: 9px 13px 10px;
  background: #fff; border: 1.5px solid var(--ink); border-radius: 14px;
  box-shadow: 0 6px 18px rgba(40, 35, 25, 0.14);
  font-size: 14px; line-height: 1.38;
  animation: pop 0.18s ease-out;
}
.bubble[hidden] { display: none; }
.bubble-who { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; margin-bottom: 3px; }
@keyframes pop { from { opacity: 0; scale: 0.94; } to { opacity: 1; scale: 1; } }

/* --- intro: pick a case or write a brief --- */
.intro {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(239, 238, 234, 0.82); backdrop-filter: blur(3px);
}
.intro[hidden] { display: none; }
.intro-box {
  width: min(640px, 100%); max-height: 100%; overflow-y: auto; padding: 26px 30px 22px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(40, 35, 25, 0.18);
}
.kicker { font-size: 11.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.intro h2 { margin: 4px 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.intro-lead { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.cases { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.case {
  text-align: left; padding: 13px 15px; background: #fff;
  border: 1.5px solid var(--line); border-radius: 12px; transition: border-color 0.15s, translate 0.15s;
}
.case:hover:not(:disabled) { border-color: var(--ink); translate: 0 -1px; }
.case:disabled { opacity: 0.5; cursor: not-allowed; }
.case small { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--green); }
.case b { display: block; margin: 2px 0 4px; font-size: 15px; }
.case span { font-size: 13px; color: var(--muted); }
.code { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.code[hidden] { display: none; }
.code label { font-size: 13px; font-weight: 600; }
.code input { flex: 1; max-width: 220px; padding: 7px 11px; background: #fff; border: 1.5px solid var(--line); border-radius: 10px; font: inherit; }
.code input:focus { outline: none; border-color: var(--ink); }
.own { margin-top: 16px; }
.own label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 600; }
.own-row { display: flex; gap: 8px; align-items: stretch; }
.own textarea { flex: 1; resize: none; padding: 9px 11px; background: #fff; border: 1.5px solid var(--line); border-radius: 10px; font-size: 14px; }
.own textarea:focus { outline: none; border-color: var(--ink); }
.own textarea:disabled { opacity: 0.5; }
.intro-note { margin: 12px 0 2px; font-size: 12.5px; color: var(--muted); }
.intro-note.error { color: #b3391a; }
.link { padding: 0; background: none; border: 0; font-size: 13px; text-decoration: underline; color: var(--ink); }

/* --- controls --- */
.controls { display: flex; align-items: center; gap: 10px; }
.controls button { padding: 7px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 99px; }
.controls button:hover { border-color: var(--muted); }
.primary { min-width: 84px; padding: 7px 16px; background: var(--ink) !important; border: 1px solid var(--ink) !important; border-radius: 99px; color: #fff !important; font-weight: 600; }
.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.speeds { display: flex; padding: 2px; background: var(--paper); border: 1px solid var(--line); border-radius: 99px; }
.speeds button { padding: 5px 10px; border: 0; background: none; font-size: 13px; color: var(--muted); }
.speeds button.on { background: var(--ink); color: #fff; }
.status { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.legend i { width: 13px; height: 13px; border-radius: 50%; border: 1.5px dashed var(--ink); background: #b9aecd; }

/* --- transcript --- */
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2, .concept h3 { margin: 0; font-size: 11.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.panel h2 { padding: 15px 18px 10px; border-bottom: 1px solid var(--line); }
#transcript { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 4px 18px 18px; list-style: none; }
#transcript li { padding: 8px 0 8px 12px; border-left: 3px solid var(--c, var(--line)); margin-top: 10px; animation: pop 0.2s ease-out; }
#transcript li.empty { border: 0; padding-left: 0; color: var(--muted); }
#transcript li.phase {
  margin-top: 18px; padding: 0; border: 0;
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}
#transcript .who { font-size: 12px; font-weight: 700; color: var(--c); }
#transcript .meta { font-size: 11.5px; color: var(--muted); font-weight: 400; }
#transcript .msg { margin-top: 2px; font-size: 14px; }
#transcript li.now { background: linear-gradient(90deg, color-mix(in srgb, var(--c) 10%, transparent), transparent); }

/* --- final concept card --- */
.concept {
  position: absolute; inset: 12px; z-index: 5; overflow-y: auto;
  padding: 24px 30px 26px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 18px 50px rgba(40, 35, 25, 0.22);
  animation: rise 0.45s ease-out;
}
.concept[hidden] { display: none; }
@keyframes rise { from { opacity: 0; translate: 0 14px; } to { opacity: 1; translate: 0 0; } }
.concept .close { position: absolute; top: 16px; right: 18px; padding: 5px 12px; background: none; border: 1px solid var(--line); border-radius: 99px; font-size: 13px; }
.concept h2 { margin: 4px 0 2px; font-size: 20px; letter-spacing: -0.01em; max-width: 85%; }
.concept .sub { margin: 4px 0 0; max-width: 80%; color: var(--muted); }
.pill { display: inline-block; margin: 10px 6px 0 0; padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: #dff0e2; color: #256b38; }
.pill.open { background: #f8e4d6; color: #a2431f; }
.pill.sim { background: #e9e4f1; color: #55477a; }
.concept h3 { margin: 22px 0 8px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.card { padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: 10px; font-size: 13.5px; }
.card b { display: block; margin-bottom: 3px; font-size: 14px; }
.card q { display: block; margin-top: 7px; padding-left: 9px; border-left: 2px solid var(--green); color: var(--muted); font-style: italic; }
.card .small { margin-top: 6px; font-size: 12px; color: var(--muted); }
.card ul, .card ol { margin: 6px 0 0; padding-left: 18px; }
.card .row { margin-top: 8px; }
.card .row span { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.card.wide { grid-column: 1 / -1; }
.hmw { padding: 14px 16px; background: var(--cyan); border-radius: 10px; font-size: 16px; font-weight: 600; }
.journey { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.journey .n { font-size: 11px; font-weight: 700; color: var(--orange); }
.journey .pain { margin-top: 6px; font-size: 12px; color: #a2431f; }
.ok { color: #256b38; font-weight: 700; }
.no { color: #a2431f; font-weight: 700; }
.plan { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.plan td { padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.plan td:first-child { white-space: nowrap; font-weight: 650; }
.plan td:last-child { color: var(--muted); }
.concept footer { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

@media (max-width: 1100px) { .phases { display: none; } .legend { display: none; } }
@media (max-width: 900px) {
  body { height: auto; }
  main { grid-template-columns: 1fr; }
  .stage { aspect-ratio: 4 / 3; flex: none; }
  .panel { max-height: 60vh; }
  .journey { grid-auto-flow: row; }
  .cases { grid-template-columns: 1fr; }
}
