:root {
  --purple: #5a2ea6;
  --purple-deep: #3d1d78;
  --purple-soft: #efe7fb;
  --ink: #1f1b2d;
  --muted: #6e6980;
  --line: #ebe6f3;
  --panel: #ffffff;
  --page: #2a1850;
  --bubble-ai: #f2f0f7;
  --bubble-user: #e6f0ff;
  --green: #2fbf5b;
  --red: #ec3b3b;
  --shadow: 0 12px 30px rgba(30, 10, 70, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eeeaf7; --muted: #a39eb5; --line: #2f2a3d; --panel: #1b1826; --page: #120b24;
    --bubble-ai: #272336; --bubble-user: #1f3151; --purple-soft: #2c2143;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--page); color: var(--ink); font-family: "IBM Plex Sans Thai", system-ui, sans-serif; }
button { font: inherit; cursor: pointer; border: 0; }

.app { display: flex; height: 100vh; height: 100dvh; }

/* ------------------------------------------------------------------ office scene */
.office { flex: 1; min-width: 0; display: grid; place-items: center; padding: 12px; overflow: hidden; position: relative; }
/* fill the letterbox with a soft, blurred copy of the office */
.office::before { content: ""; position: absolute; inset: -40px; background: url(assets/office.webp) center / cover;
  filter: blur(28px) saturate(1.1) brightness(.55); }
.scene {
  position: relative; z-index: 1;
  width: min(100%, calc((100dvh - 24px) * 1586 / 992));
  aspect-ratio: 1586 / 992;
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
  container-type: inline-size;           /* 1cqw = 1% of the scene width */
  font-family: "Mitr", "IBM Plex Sans Thai", sans-serif;
}
.bg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; }

.glow {
  position: absolute; border-radius: 1cqw; pointer-events: none; opacity: 0;
  box-shadow: 0 0 0 .25cqw #ffd84d, 0 0 2.2cqw .6cqw rgba(255, 216, 77, .75);
  transition: left .5s, top .5s, width .5s, height .5s, opacity .3s;
}
.glow.on { opacity: 1; animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 .25cqw #ffd84d, 0 0 1cqw .2cqw rgba(255, 216, 77, .4); } }

/* sky outside the big window follows Bangkok time: day / dusk / night / dawn */
.sky { position: absolute; left: 22.7%; top: 4.4%; width: 38.9%; height: 22.4%; pointer-events: none;
  transition: background 2s, opacity 2s; opacity: 0; }
.sky[data-phase="dusk"] { opacity: 1; background: linear-gradient(180deg, rgba(235,90,70,.75), rgba(255,160,90,.55));
  mix-blend-mode: multiply; }
.sky[data-phase="dawn"] { opacity: 1; background: linear-gradient(180deg, rgba(240,150,190,.6), rgba(255,215,150,.45));
  mix-blend-mode: multiply; }
.sky[data-phase="night"] { opacity: 1; background: linear-gradient(180deg, rgba(10,14,60,.82), rgba(40,30,90,.62));
  mix-blend-mode: multiply; }
.sky .stars { position: absolute; inset: 0; opacity: 0; transition: opacity 2s;
  background-image:
    radial-gradient(.25cqw .25cqw at 12% 18%, #fff 60%, transparent 70%),
    radial-gradient(.2cqw .2cqw at 33% 9%, #fff 60%, transparent 70%),
    radial-gradient(.3cqw .3cqw at 58% 22%, #fff 60%, transparent 70%),
    radial-gradient(.2cqw .2cqw at 76% 12%, #fff 60%, transparent 70%),
    radial-gradient(.25cqw .25cqw at 90% 30%, #fff 60%, transparent 70%),
    radial-gradient(.2cqw .2cqw at 22% 38%, #fff 60%, transparent 70%);
  animation: twinkle 2.6s ease-in-out infinite; }
.sky[data-phase="night"] .stars { opacity: 1; mix-blend-mode: screen; }
@keyframes twinkle { 50% { filter: brightness(.55); } }

.clock {
  position: absolute; right: 2.2%; top: 1.4%; min-width: 13%; text-align: center;
  background: rgba(40, 18, 88, .92); color: #fff; border: .25cqw solid #8e6ad6; border-radius: 1cqw;
  padding: .35cqw 1cqw .45cqw; box-shadow: 0 .5cqw 0 rgba(0,0,0,.25);
}
.clock-date { font-size: .95cqw; opacity: .9; }
.clock-time { font-size: 2cqw; line-height: 1.1; font-weight: 600; letter-spacing: .15cqw; font-variant-numeric: tabular-nums;
  color: #ffe27a; text-shadow: 0 .2cqw 0 #6b3fb8; }

.path { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.path path { fill: none; stroke: #fff; stroke-width: 5; stroke-dasharray: 14 12; stroke-linecap: round;
  opacity: 0; transition: opacity .3s; animation: dash 1s linear infinite; }
.path path.on { opacity: .85; }
@keyframes dash { to { stroke-dashoffset: -26; } }

.mission {
  position: absolute; left: 2.4%; top: 3%; width: 20%;
  background: rgba(40, 18, 88, .92); color: #fff; border: .25cqw solid #8e6ad6;
  border-radius: 1cqw; padding: 1cqw 1.2cqw; font-size: 1.15cqw; box-shadow: 0 .5cqw 0 rgba(0,0,0,.25);
}
.mission-head { display: flex; justify-content: space-between; align-items: center; font-weight: 500; margin-bottom: .6cqw; }
.hearts i { display: inline-block; width: 1.1cqw; height: 1cqw; margin-left: .25cqw; background: #6b4f9e;
  clip-path: path("M5 9 L0.6 4.6 A2.6 2.6 0 0 1 5 1.3 A2.6 2.6 0 0 1 9.4 4.6 Z"); transform: scale(1.1); }
.hearts i.on { background: #ff5fb0; }
.mission ul { list-style: none; margin: 0; padding: 0; }
.mission li { display: flex; align-items: center; gap: .7cqw; padding: .25cqw 0; opacity: .85; }
.mission li::before { content: ""; width: 1.2cqw; height: 1.2cqw; border: .2cqw solid #fff; border-radius: .2cqw; flex: none; }
.mission li.done { opacity: 1; }
.mission li.done::before { background: #fff; box-shadow: inset 0 0 0 .2cqw rgba(40,18,88,.92);
  background-image: linear-gradient(#35d17a, #35d17a); background-clip: content-box; padding: .15cqw; }

.sabai { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 712; } /* z = feet line, see critters */
.sabai.walking { transition: left var(--walk, 1s) linear, top var(--walk, 1s) linear; }
.sprite { width: 100%; height: 100%; background-repeat: no-repeat; }
.bubble {
  position: absolute; left: 56%; bottom: 84%;   /* beside her head, clear of the station signs */
  width: max-content; max-width: 15cqw; background: #fff; color: #231a3a; border: .22cqw solid #2d1e4f;
  border-radius: 1cqw; padding: .7cqw 1cqw; font-size: 1.15cqw; line-height: 1.45;
  box-shadow: 0 .35cqw 0 rgba(0,0,0,.2); opacity: 0; transition: opacity .25s;
}
.bubble.on { opacity: 1; }
.bubble::after { content: ""; position: absolute; left: 1.2cqw; top: 100%; border: .8cqw solid transparent;
  border-top-color: #2d1e4f; border-bottom: 0; border-left: 0; }

.xp {
  position: absolute; left: 50%; bottom: 2.5%; transform: translateX(-50%); width: 30%;
  background: rgba(40, 18, 88, .92); color: #fff; border: .25cqw solid #8e6ad6; border-radius: 1cqw;
  padding: .8cqw 1.2cqw; font-size: 1cqw; box-shadow: 0 .5cqw 0 rgba(0,0,0,.25);
}
.xp-row { display: flex; align-items: center; gap: 1cqw; margin-top: .5cqw; }
.xp-bar { flex: 1; height: 1.5cqw; background: #251244; border: .2cqw solid #b9a4e6; border-radius: .4cqw; overflow: hidden; }
.xp-bar i { display: block; height: 100%; width: 0; transition: width .6s;
  background: repeating-linear-gradient(90deg, #43d66b 0 1.6cqw, #2fae52 1.6cqw 1.8cqw); }
.xp-level { font-weight: 500; }

/* ------------------------------------------------------------------ call panel */
.panel {
  width: 420px; flex: none; display: flex; flex-direction: column; background: var(--panel);
  border-left: 1px solid var(--line);
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 20px 6px; }
.panel-head h1 { margin: 0; font-size: 19px; font-weight: 600; }
.head-right { text-align: right; }
.live { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #b9b4c6; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(47, 191, 91, .2); }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; margin-top: 2px; min-height: 20px; }

.profile { text-align: center; padding: 4px 16px 10px; border-bottom: 1px solid var(--line); }
.avatar { width: 104px; height: 104px; margin: 0 auto 8px; border-radius: 50%; padding: 4px; position: relative;
  background: linear-gradient(135deg, #b48cf2, #6e3cc9); }
.avatar img { width: 100%; height: 100%; border-radius: 50%; display: block; image-rendering: pixelated; background: #efe6fd; }
.avatar::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid #9b6ce8; opacity: 0; }
.avatar.speaking::after { opacity: .8; animation: ring 1.1s ease-in-out infinite; }
@keyframes ring { 50% { transform: scale(1.07); opacity: .3; } }
.name { font-weight: 600; font-size: 18px; }
.role { color: var(--muted); font-size: 13px; }
.tool { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; padding: 4px 12px; border-radius: 999px;
  background: var(--purple-soft); color: var(--purple); font-size: 13px; visibility: hidden; }
@media (prefers-color-scheme: dark) { .tool { color: #c8aef5; } }
.tool.on { visibility: visible; }
.spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.meter { height: 3px; width: 120px; margin: 8px auto 0; background: var(--line); border-radius: 2px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--purple); transition: width .08s linear; }

.log { flex: 1; overflow-y: auto; padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; color: var(--muted); line-height: 1.7; }
.row { display: flex; align-items: flex-end; gap: 8px; }
.row.user { flex-direction: row-reverse; }
.row time { color: var(--muted); font-size: 11px; flex: none; padding-bottom: 6px; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 14px; line-height: 1.55; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.row.assistant .msg { background: var(--bubble-ai); border-bottom-left-radius: 4px; }
.row.user .msg { background: var(--bubble-user); border-bottom-right-radius: 4px; }
.msg.cut::after { content: " …"; color: var(--muted); }
.sys { align-self: center; color: var(--muted); font-size: 11.5px; }

form.type { display: none; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--line); }
form.type.show { display: flex; }
form.type input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; }
form.type button { padding: 0 16px; border-radius: 12px; background: var(--purple); color: #fff; }

.controls { display: flex; justify-content: center; gap: 22px; padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); }
.ctl { display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; color: var(--ink); }
.ctl .ico { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; font-size: 24px;
  background: var(--purple-soft); transition: transform .1s, background .2s; }
.ctl .lbl { font-size: 13px; font-weight: 500; }
.ctl:active .ico { transform: scale(.94); }
.ctl:disabled { opacity: .4; cursor: default; }
.ctl.on .ico { background: var(--red); color: #fff; }
.ctl.main .ico { width: 72px; height: 72px; background: var(--green); color: #fff; font-size: 28px; }
.ctl.main.hang .ico { background: var(--red); }
.ctl.main.hang .ico > span { display: inline-block; transform: rotate(135deg); }

/* ------------------------------------------------------------------ mobile: talk panel only */
@media (max-width: 900px) {
  .office { display: none; }
  .panel { width: 100%; border-left: 0; }
}

/* ---- ambient life (critters.js): office cat + plane past the window ---- */
.mission, .clock, .xp { z-index: 2000; }
.critter { position: absolute; left: 0; top: 0; cursor: pointer; }
.critter-sprite { width: 100%; height: 100%; background-repeat: no-repeat; image-rendering: pixelated; }
.critter-bubble { position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -.3cqw) scale(.6);
  white-space: nowrap; background: #fff; color: #3b2470; border: .18cqw solid #8e6ad6; border-radius: .8cqw;
  padding: .2cqw .6cqw; font-size: .95cqw; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.critter-bubble.on { opacity: 1; transform: translate(-50%, -.3cqw) scale(1); }
.flyzone { position: absolute; overflow: hidden; pointer-events: none; }
.flyzone .plane { position: absolute; left: -30%; opacity: 0; image-rendering: pixelated; }
.flyzone .plane.on { opacity: 1; }
.flyzone .mullions { position: absolute; inset: 0; width: 100%; height: 100%; }
