:root {
  color-scheme: light;
  --ink: #3a2a1c;
  --muted: #8a7360;
  --cream: #fffaf3;
  --honey: #e7c48a;
  --wood: #c4a574;
  --sage: #7da86a;
  --peach: #f2c1a8;
  --sky: #b7ddf2;
  --line: #eadccb;
  --working: #2a9d8f;
  --waiting: #e0a100;
  --idle: #7da86a;
  --error: #d4574e;
  --sleeping: #7c6bb5;
  font-family: "Sarabun", "Noto Sans Thai", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #fff 0, transparent 28%),
    linear-gradient(180deg, #f7efe4 0%, #e7f3ea 100%);
}
button, input { font: inherit; color: inherit; }
.page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 10px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 6px 0 rgba(196, 165, 116, 0.35);
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.crest { width: 36px; height: 36px; flex: 0 0 auto; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.clock-block { display: flex; align-items: center; gap: 10px; }
.clock { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.date { color: var(--muted); font-size: 12px; }
.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f3f7ea;
  border: 1px solid #d5e4c8;
  font-size: 12px;
  font-weight: 700;
}
.link i { width: 8px; height: 8px; border-radius: 50%; background: var(--waiting); }
.link[data-state="live"] i { background: var(--working); }
.link[data-state="down"] i { background: var(--error); }

.stats { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.chip b { font-variant-numeric: tabular-nums; }
.chip i, .swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.chip.working i, .swatch.working { background: var(--working); }
.chip.waiting i, .swatch.waiting { background: var(--waiting); }
.chip.idle i, .swatch.idle { background: var(--idle); }
.chip.error i, .swatch.error { background: var(--error); }
.chip.sleeping i, .swatch.sleeping { background: var(--sleeping); }
.chip.all i { background: var(--honey); }
.chip.mode { background: #f8e7d8; }

.social-banner, .demo-note {
  margin: 0;
  padding: 6px 10px;
  border-radius: 10px;
  background: #fff6ea;
  border: 1px solid var(--honey);
  font-size: 13px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.stage-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.loading, .load-error {
  padding: 18px 20px;
  background: var(--cream);
  border-radius: 16px;
  border: 1px solid var(--line);
  text-align: center;
}
.viewport {
  position: relative;
  width: min(100%, calc((100dvh - 214px) * 16 / 9));
  max-width: 1180px;
  aspect-ratio: 16 / 9;
  container-type: inline-size;
  border-radius: 22px;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  box-shadow: 0 14px 0 rgba(196, 165, 116, 0.28), 0 24px 40px rgba(90, 60, 30, 0.12);
  background: #d7ecf6;
}
.viewport:active { cursor: grabbing; }
.world {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}
.world img, .viewport img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 1s ease;
}
.wash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: background 1s ease;
}
.glows { position: absolute; inset: 0; pointer-events: none; }
.glows i {
  position: absolute;
  width: 7%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 226, 160, 0.95), transparent 68%);
  transition: opacity 1s ease;
}
body[data-time="morning"] .viewport img { filter: sepia(0.35) saturate(1.12) brightness(1.05); }
body[data-time="morning"] .wash { background: rgba(255, 168, 84, 0.28); }
body[data-time="day"] .wash { background: rgba(255, 255, 255, 0.04); }
body[data-time="evening"] .viewport img { filter: sepia(0.28) saturate(1.15) brightness(0.96); }
body[data-time="evening"] .wash { background: rgba(214, 112, 52, 0.22); }
body[data-time="evening"] .glows i { opacity: 0.55; }
body[data-time="night"] .viewport img { filter: brightness(0.55) saturate(0.8); }
body[data-time="night"] .wash { background: rgba(18, 32, 78, 0.38); }
body[data-time="night"] .glows i { opacity: 1; }

#view3d { position: absolute; inset: 0; }
#view3d canvas { display: block; width: 100% !important; height: 100% !important; }
.viewport.is-3d .world { display: none; }
.viewport:not(.is-3d) .floor-btn { display: none; }
.float-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 180px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 250, 243, 0.94);
  color: #3a2a1c;
  font: 700 11px/1.3 "Sarabun", "Noto Sans Thai", sans-serif;
  box-shadow: 0 1px 0 rgba(58, 42, 28, 0.12);
  pointer-events: none;
  white-space: nowrap;
}
.float-label b, .float-label span { overflow: hidden; text-overflow: ellipsis; }
.float-label span { font-weight: 500; color: #8a7360; max-width: 90px; }
.label-dot { width: 7px; height: 7px; border-radius: 50%; background: #7da86a; flex: 0 0 auto; }
.label-dot.working { background: #2a9d8f; }
.label-dot.waiting { background: #e0a100; }
.label-dot.idle { background: #7da86a; }
.label-dot.error { background: #d4574e; }
.label-dot.sleeping { background: #7c6bb5; }
.mood-mark { font-style: normal; font-weight: 800; }
.mood-mark.ask { color: #e0a100; }
.mood-mark.bang { color: #d4574e; }
.mood-mark.zzz { color: #7c6bb5; }
.zoombar {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 6;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 70%;
}
.zoombar button {
  min-width: 32px;
  height: 32px;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 250, 243, 0.94);
  font-weight: 700;
  cursor: pointer;
}
.zoombar button.floor-btn, #zoom-fit { width: auto; padding: 0 8px; font-size: 12px; }
.bots { position: absolute; inset: 0; }
.bot {
  position: absolute;
  left: 0;
  top: 0;
  width: 7.2cqi;
  max-width: 78px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: center;
}
.bot:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; border-radius: 12px; }
.robot {
  display: block;
  width: 78%;
  margin: 0 auto;
  transform: scaleX(var(--face, 1)) rotate(var(--tilt, 0deg));
  transform-origin: 50% 70%;
  animation: hover 3.2s ease-in-out infinite;
}
.bot[data-moving="1"] .robot { animation: march 0.34s ease-in-out infinite; }
@keyframes hover {
  50% { transform: scaleX(var(--face, 1)) rotate(var(--tilt, 0deg)) translateY(-6%); }
}
@keyframes march {
  0%, 100% { transform: scaleX(var(--face, 1)) rotate(var(--tilt, 0deg)) translateY(0); }
  50% { transform: scaleX(var(--face, 1)) rotate(var(--tilt, 0deg)) translateY(-8%); }
}
.robot-svg { width: 100%; height: auto; display: block; overflow: visible; }
.robot-svg .ear, .robot-svg .ring { fill: var(--accent, #f0a060); }
.robot-svg .ring { opacity: 0.85; }
.robot-svg .eyes { display: none; }
.bot[data-face="happy"] .eyes-happy,
.bot[data-face="focused"] .eyes-focused,
.bot[data-face="curious"] .eyes-curious,
.bot[data-face="sleepy"] .eyes-sleepy,
.bot[data-face="confused"] .eyes-confused,
.bot[data-face="excited"] .eyes-excited { display: block; }
.bot[data-face="happy"] .eyes-happy,
.bot[data-face="focused"] .eyes-focused,
.bot[data-face="curious"] .eyes-curious,
.bot[data-face="excited"] .eyes-excited {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 4.8s infinite;
}
@keyframes blink {
  0%, 90%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.12); }
}
.holo, .qmark { display: none; }
.bot[data-face="focused"] .holo { display: block; }
.bot[data-face="confused"] .qmark { display: block; }
.bot[data-face="confused"] { --tilt: -8deg; }
.bot[data-face="excited"] .arm-l { transform: rotate(-28deg); transform-origin: 22px 62px; }
.bot[data-face="excited"] .arm-r { transform: rotate(28deg); transform-origin: 78px 62px; }
.badge {
  position: absolute;
  right: 0;
  bottom: 1.5em;
  font-size: max(10px, 1.3cqi);
  line-height: 1;
  filter: drop-shadow(0 1px 0 #fff);
}
.name {
  display: block;
  max-width: 11cqi;
  margin: 2px auto 0;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(255, 250, 243, 0.94);
  color: var(--ink);
  font-size: max(9px, 1.25cqi);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 0 rgba(58, 42, 28, 0.08);
}
.star { color: #c9842a; margin-right: 2px; }
.bubble, .bang, .zzz {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -4px);
  max-width: 18cqi;
  padding: 3px 6px;
  border-radius: 10px;
  background: #fffaf3;
  border: 1px solid var(--line);
  font-size: 1.35cqi;
  line-height: 1.3;
  text-align: left;
}
.bang {
  background: #d4574e;
  color: #fff;
  font-weight: 800;
  border: 0;
  min-width: 1.4em;
  text-align: center;
}
.zzz { color: #7c6bb5; font-weight: 700; letter-spacing: 1px; background: transparent; border: 0; }
.bot[data-state="error"] .bubble { bottom: calc(100% + 1.4em); }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(58, 42, 28, 0.28);
  z-index: 20;
}
.panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  width: min(400px, 100%);
  height: 100dvh;
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 30px rgba(58, 42, 28, 0.12);
  padding-bottom: 24px;
}
.panel-handle { display: none; }
.panel-head, .panel-now, .panel-log-wrap { padding: 12px 16px 0; }
.panel-idline, .panel-title-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.kicker { margin: 0; color: var(--muted); font-size: 12px; }
.panel h2 { margin: 4px 0; font-size: 22px; }
.panel h3 { margin: 12px 0 6px; font-size: 13px; color: #8a6230; }
.panel-meta, .when, .think, .stale-note { margin: 0; color: var(--muted); font-size: 13px; }
#panel-task { margin: 0; font-weight: 700; }
#panel-detail { margin: 4px 0 0; }
.btn {
  border: 1px solid var(--wood);
  background: var(--honey);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn.ghost { background: #fff; }
#chat-feed, #panel-log { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
#chat-feed li, .log-item {
  padding: 8px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
}
.log-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.state-chip, .demo-chip {
  padding: 0 6px;
  border-radius: 999px;
  background: #f3f7ea;
  font-size: 11px;
  font-weight: 700;
}
.noscript { margin: 12px; }

@media (max-width: 800px) {
  .page { padding: 8px; }
  .stage-wrap { align-items: start; }
  .topbar { align-items: flex-start; }
  .brand p { display: none; }
  .clock { font-size: 20px; }
  .viewport { width: 100%; border-radius: 14px; }
  .name { font-size: 8px; }
  .badge { font-size: 9px; }
  .bubble, .bang, .zzz { font-size: 8px; max-width: 72px; }
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(78dvh, 720px);
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
  }
  .panel-handle {
    display: block;
    width: 48px;
    height: 5px;
    margin: 8px auto 0;
    background: #e4d3bf;
    border-radius: 99px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .viewport img, .wash, .glows i { transition: none; }
  .robot, .robot-svg .eyes, .arm-l, .arm-r { animation: none !important; }
}
