:root {
  --bg: #f6f8f4;
  --surface: #ffffff;
  --ink: #15201a;
  --muted: #66716b;
  --line: #e3e8e2;
  --zeno: #45ad68;
  --luna: #e0669f;
  --accent: var(--zeno);
  --accent-soft: #e3f3e8;
  --hot: #e5484d;
  color-scheme: light;
}
body[data-char="luna"] { --accent: var(--luna); --accent-soft: #fbe6f0; }
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1411; --surface: #18201b; --ink: #e8efe9; --muted: #93a098; --line: #26302a; --accent-soft: #1d3326; color-scheme: dark; }
  body[data-char="luna"] { --accent-soft: #3a1d2b; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

/* one screen, no scrolling */
.app {
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 20px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 16px;
  overflow: hidden;
}

.top { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 800; font-size: 1.25rem; letter-spacing: -0.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c9a227; }
.conn.on .dot { background: var(--zeno); }
.conn.off .dot { background: var(--hot); }

/* character switch: cat icon + name */
.cat { width: 40px; height: 40px; flex: none; }
.zeno .cat { color: var(--zeno); }
.luna .cat { color: var(--luna); }
.chars { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.char {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 68px; padding: 10px 12px;
  background: var(--surface); color: inherit; font: inherit; font-size: 1.15rem; font-weight: 800;
  border: 2px solid var(--line); border-radius: 18px; cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
}
.char:active { transform: scale(0.97); }
.char.zeno[aria-pressed="true"] { border-color: var(--zeno); background: #e3f3e8; }
.char.luna[aria-pressed="true"] { border-color: var(--luna); background: #fbe6f0; }
@media (prefers-color-scheme: dark) {
  .char.zeno[aria-pressed="true"] { background: #1d3326; }
  .char.luna[aria-pressed="true"] { background: #3a1d2b; }
}

/* big talk button */
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; min-height: 0; }
.status { margin: 0; font-weight: 700; font-size: 1.05rem; text-align: center; min-height: 1.4em; }
.talk {
  --size: min(66vw, 42dvh, 290px);
  --level: 0;
  position: relative;
  width: var(--size); height: var(--size); border-radius: 50%;
  border: 0; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  background: var(--accent); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 18px 40px -14px var(--accent);
  transition: transform 0.12s, background 0.2s;
}
.talk .mic { width: 32%; height: 32%; }
.talk-label { font-weight: 800; font-size: clamp(1rem, 4.6vw, 1.2rem); padding: 0 14%; text-align: center; line-height: 1.2; }
.talk .ring {
  position: absolute; inset: -12px; border-radius: 50%; pointer-events: none;
  border: 4px solid var(--accent); opacity: 0.25;
  transform: scale(calc(1 + var(--level) * 0.2));
  transition: transform 0.08s linear, opacity 0.2s;
}
.talk.idle { background: var(--surface); color: var(--accent); border: 3px dashed var(--accent); box-shadow: none; }
.talk.connecting { opacity: 0.75; }
.talk.connecting .ring { animation: spin 1.2s linear infinite; border-style: dashed; opacity: 0.5; }
.talk.held { background: var(--hot); transform: scale(0.96); box-shadow: 0 10px 30px -10px var(--hot); }
.talk.held .ring { border-color: var(--hot); opacity: 0.6; }
@keyframes spin { to { transform: rotate(360deg); } }

.caption {
  margin: 0; max-width: 100%; min-height: 2.8em;
  color: var(--muted); text-align: center; font-size: 0.95rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.micinfo { font-size: 0.75rem; color: var(--muted); }
.end {
  min-height: 52px; padding: 0 26px; border-radius: 999px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  font: inherit; font-weight: 700; cursor: pointer;
}

/* dialog */
dialog { border: 0; border-radius: 24px; padding: 0; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 16, 12, 0.55); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; font-size: 1.3rem; }
#sFields { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
dialog input { font: inherit; font-size: 1.05rem; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.primary { min-height: 56px; border: 0; border-radius: 16px; background: var(--accent); color: #fff; font: inherit; font-size: 1.1rem; font-weight: 800; cursor: pointer; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 0.9rem; text-decoration: underline; cursor: pointer; padding: 6px; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0; }
.fine { color: var(--muted); font-size: 0.75rem; margin: 0; text-align: center; }
.err { color: var(--hot); font-size: 0.85rem; min-height: 1.1em; margin: 0; }

/* full-screen notices */
.blocked { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 10; }
.blocked-card { text-align: center; max-width: 340px; }
.blocked-card .cat.big { width: 72px; height: 72px; color: var(--zeno); margin-bottom: 8px; }
.blocked-card h3 { font-size: 1.35rem; margin: 0 0 8px; }
.blocked-card p { color: var(--muted); margin: 0; }
.scan-btn { width: 100%; margin-top: 24px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.scan-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.blocked-card .err { margin-top: 10px; }

/* in-page QR scanner */
.scanner { position: fixed; inset: 0; z-index: 30; background: #000; display: flex; align-items: center; justify-content: center; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: relative; width: min(70vw, 300px); aspect-ratio: 1; border-radius: 24px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55); outline: 3px solid #fff; }
.scan-hint { position: absolute; left: 16px; right: 16px; top: calc(24px + env(safe-area-inset-top)); margin: 0; text-align: center; color: #fff; font-weight: 700; }
.scan-close { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(32px + env(safe-area-inset-bottom)); min-height: 52px; min-width: 160px; border: 0; border-radius: 999px; background: #fff; color: #15201a; font: inherit; font-size: 1.05rem; font-weight: 800; cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem;
  max-width: calc(100vw - 32px); text-align: center; z-index: 20;
}

@media (max-height: 600px) {
  .char { min-height: 54px; font-size: 1rem; }
  .cat { width: 32px; height: 32px; }
  .app { gap: 10px; }
}
