:root {
  color-scheme: light;
  --paper: #efeae2;
  --ink: #1c1917;
  --muted: #6b645c;
  --line: #e4ddd4;
  --user: #1c1917;
  --agent: #f3f0ea;
  --accent: #3f5c4d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 "Segoe UI", sans-serif;
}

body {
  min-height: 100%;
  padding: 20px;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  max-width: 1280px;
  height: calc(100vh - 40px);
  margin: 0 auto;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 16px 50px rgba(40, 32, 22, 0.08);
  overflow: hidden;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px;
  min-width: 0;
  min-height: 0;
}

#stage {
  position: relative;
  width: min(100%, calc((100vh - 150px) * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 150px);
  margin-inline: auto;
  flex: 0 0 auto;
  background: #f6f4f1;
  border-radius: 14px;
  overflow: hidden;
  cursor: crosshair;
  outline: none;
}

#stage:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
}

#screen {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  background: #f6f4f1;
}

#screen[src] {
  display: block;
}

#stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
}

#stage-empty[hidden] {
  display: none;
}

#cursor {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
  transform: translate(-1px, -1px);
}

#cursor[hidden] {
  display: none;
}

#cursor svg {
  width: 16px;
  height: 16px;
  fill: #111;
  filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.8));
}

#cursor span {
  margin-top: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
}

.hint {
  margin: 10px 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.talk {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  min-height: 0;
}

.who {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 18px 18px 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #f2d2b6, #c47a4a 55%, #8d4b2a);
}

.who strong { display: block; }

#status {
  color: var(--muted);
  font-size: 14px;
}

#log {
  flex: 1;
  overflow: auto;
  padding: 8px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 95%;
  padding: 10px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
}

.bubble.agent {
  align-self: flex-start;
  background: var(--agent);
}

.bubble.you {
  align-self: flex-end;
  background: var(--user);
  color: #fff;
}

.bubble.pending { opacity: 0.7; }

#composer {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

#text {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: #efeae2;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.end {
  background: #1c1917;
  color: #fff;
}

#gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(28, 25, 23, 0.28);
}

#gate[hidden] {
  display: none;
}

.gate-card {
  width: min(440px, calc(100% - 32px));
  padding: 28px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 16px 50px rgba(40, 32, 22, 0.16);
}

.gate-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.gate-card p { color: var(--muted); }

#start {
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
}

.error {
  color: #9b2c2c;
  min-height: 1.2em;
}

@media (max-width: 900px) {
  body { padding: 0; }
  .shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
    border-radius: 0;
  }
  .shell { height: auto; min-height: 100vh; }
  .talk { min-height: 420px; border-left: 0; border-top: 1px solid var(--line); }
  #stage {
    width: min(100%, calc(52vh * 16 / 9));
    max-height: 52vh;
  }
}
