:root {
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.35);
  --ink: #d9f6ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: transparent;
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  user-select: none;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

#scanlines {
  position: fixed; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(180, 240, 255, 0.025) 0 1px, transparent 1px 3px);
  z-index: 10;
  opacity: 0.6;
}

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(40px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, rgba(3, 10, 16, 0.6), transparent);
  -webkit-app-region: drag;
  z-index: 20;
}

#brand {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; letter-spacing: 0.14em;
  color: rgba(125, 211, 252, 0.85);
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #475569;
  box-shadow: 0 0 6px rgba(71, 85, 105, 0.6);
  transition: background 0.2s, box-shadow 0.2s;
}
.dot.listen { background: #34d399; box-shadow: 0 0 9px rgba(52, 211, 153, 0.9); animation: pulse 1.1s infinite; }
.dot.think { background: #fbbf24; box-shadow: 0 0 9px rgba(251, 191, 36, 0.9); animation: pulse 0.7s infinite; }
.dot.speak { background: var(--cyan); box-shadow: 0 0 10px rgba(34, 211, 238, 0.95); animation: pulse 0.45s infinite; }
.dot.warn { background: #f87171; box-shadow: 0 0 9px rgba(248, 113, 113, 0.9); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#winbtns { display: flex; gap: 4px; }
#winbtns button {
  -webkit-app-region: no-drag;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: rgba(125, 211, 252, 0.75);
  font-size: 11px;
  cursor: pointer;
}
#winbtns button:hover {
  border-color: var(--cyan-soft);
  color: #cffafe;
  background: rgba(8, 47, 73, 0.35);
}
.browser #winbtns { display: none; }

/* ---------- chat / controls ---------- */
#ui {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  z-index: 20;
}

#feed {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 36vh;
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 211, 238, 0.3) transparent;
}
#feed::-webkit-scrollbar { width: 4px; }
#feed::-webkit-scrollbar-thumb { background: rgba(34, 211, 238, 0.3); border-radius: 2px; }

.msg {
  max-width: 92%;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: rgba(8, 47, 73, 0.7);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: #bae6fd;
}
.msg.ai {
  align-self: flex-start;
  background: rgba(2, 10, 18, 0.66);
  border: 1px solid rgba(34, 211, 238, 0.22);
  color: #e0f2fe;
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.08);
}
.msg.error {
  align-self: flex-start;
  background: rgba(50, 10, 10, 0.55);
  border: 1px solid rgba(248, 113, 113, 0.5);
  color: #fecaca;
}
.msg.tip {
  align-self: flex-start;
  font-size: 12px;
  color: #94a3b8;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  background: transparent;
}

#inputRow { display: flex; align-items: center; gap: 6px; }

#btnMic, #btnSend {
  position: relative;
  width: 34px; height: 34px; flex: 0 0 34px;
  display: grid; place-items: center;
  background: rgba(3, 12, 20, 0.72);
  border: 1px solid rgba(34, 211, 238, 0.3);
  border-radius: 50%;
  color: #7dd3fc;
  cursor: pointer;
}
#btnMic:hover, #btnSend:hover {
  border-color: rgba(34, 211, 238, 0.65);
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.25);
}
#btnMic.muted { color: #64748b; border-color: rgba(100, 116, 139, 0.4); }
#btnMic.muted::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 22px; height: 1px;
  background: #f87171;
  transform: translate(-50%, -50%) rotate(-45deg);
}

#textInput {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  background: rgba(3, 12, 20, 0.72);
  border: 1px solid rgba(34, 211, 238, 0.25);
  border-radius: 9px;
  color: var(--ink);
  font-size: 16px;
  outline: none;
}
#textInput::placeholder { color: rgba(148, 163, 184, 0.6); }
#textInput:focus {
  border-color: rgba(34, 211, 238, 0.6);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.18);
}

#hint {
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: rgba(125, 211, 252, 0.5);
}

/* ---------- start overlay ---------- */
#overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 38%, rgba(8, 47, 73, 0.35), rgba(2, 8, 14, 0.82) 70%);
  z-index: 50;
  transition: opacity 0.35s ease;
}
#overlay.hidden { opacity: 0; pointer-events: none; }

.panel {
  max-width: 300px;
  padding: 26px 22px 20px;
  text-align: center;
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 14px;
  background: rgba(3, 12, 20, 0.72);
  box-shadow: 0 0 40px rgba(34, 211, 238, 0.12), inset 0 0 30px rgba(34, 211, 238, 0.05);
}
.panel h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.3em;
  color: #a5f3fc;
}
.panel h1 span {
  display: block;
  margin-top: 7px;
  font-size: 9px;
  letter-spacing: 0.5em;
  color: rgba(125, 211, 252, 0.55);
}
.panel p { margin: 12px 0 0; font-size: 12px; color: #94a3b8; }
.panel .tiny { font-size: 10.5px; color: rgba(148, 163, 184, 0.65); margin-top: 12px; }

#btnStart, #btnLogin {
  margin: 18px auto 0;
  padding: 10px 36px;
  font-size: 14px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: #cffafe;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.16), rgba(59, 130, 246, 0.16));
  border: 1px solid rgba(103, 232, 249, 0.5);
  border-radius: 9px;
  cursor: pointer;
}
#btnStart:hover, #btnLogin:hover {
  box-shadow: 0 0 22px rgba(34, 211, 238, 0.35);
  border-color: rgba(103, 232, 249, 0.85);
}
#btnLogin:disabled { opacity: 0.5; cursor: wait; }

#loginInput {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(3, 12, 20, 0.8);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 9px;
  color: var(--ink);
  font-size: 16px;
  text-align: center;
  letter-spacing: 0.15em;
  outline: none;
}
#loginInput:focus {
  border-color: rgba(34, 211, 238, 0.75);
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.2);
}

.panel[hidden] { display: none; }
.panel .error { min-height: 14px; color: #fca5a5; }

/* ---------- mobile / standalone ---------- */
.browser {
  background: radial-gradient(ellipse at 50% 28%, #071523 0%, #030a12 55%, #01050a 100%);
}

@media (max-width: 520px) {
  #feed { max-height: 30vh; }
  .panel { max-width: 84vw; }
}

/* ---------- toast ---------- */
#toast {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%) translateY(-4px);
  padding: 6px 12px;
  font-size: 12px;
  color: #a5f3fc;
  background: rgba(3, 12, 20, 0.85);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
