:root {
  --bg: #0e1116;
  --panel: #171c25;
  --panel-2: #1f2734;
  --text: #eef2f7;
  --muted: #9aa7b8;
  --accent: #ff7a2f;
  --accent-2: #ffb347;
  --user: #2b6cff;
  --ok: #3ecf8e;
  --danger: #ff5470;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overscroll-behavior: none;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--panel), transparent);
  position: sticky;
  top: 0;
  z-index: 5;
}

header .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
header .brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent);
}
header .sub { font-size: 12px; color: var(--muted); font-weight: 500; }

.iconbtn {
  background: var(--panel-2); border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px;
  cursor: pointer; display: grid; place-items: center;
}
.iconbtn:active { transform: scale(0.94); }

/* ---- chat ---- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 82%;
  padding: 12px 15px;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

.msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid #232c3a;
  border-bottom-left-radius: 4px;
}
.msg.user {
  align-self: flex-end;
  background: var(--user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 92%;
}

.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* ---- controls ---- */
footer {
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, var(--panel), transparent);
}

.status {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 8px;
}
.status.live { color: var(--accent-2); }

.mic-wrap { display: flex; justify-content: center; align-items: center; gap: 14px; }

.mic {
  width: 84px; height: 84px; border-radius: 50%;
  border: none; cursor: pointer; color: #fff; font-size: 34px;
  background: radial-gradient(circle at 30% 30%, var(--accent-2), var(--accent));
  box-shadow: 0 8px 24px rgba(255, 122, 47, .35);
  display: grid; place-items: center;
  transition: transform .1s ease;
}
.mic:active { transform: scale(0.95); }
.mic.listening {
  animation: pulse 1.4s infinite;
  background: radial-gradient(circle at 30% 30%, #ff9a62, var(--danger));
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 84, 112, .5); }
  70% { box-shadow: 0 0 0 22px rgba(255, 84, 112, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 84, 112, 0); }
}
.mic:disabled { opacity: .5; }

.handsfree {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 12px; color: var(--muted); font-size: 13px; cursor: pointer;
  user-select: none;
}
.handsfree input { width: 18px; height: 18px; accent-color: var(--accent); }

.textrow {
  display: flex; gap: 8px; margin-top: 12px;
}
.textrow input {
  flex: 1; background: var(--panel-2); border: 1px solid #2a3444;
  color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 16px;
}
.textrow input:focus { outline: none; border-color: var(--accent); }
.textrow button {
  background: var(--panel-2); border: 1px solid #2a3444; color: var(--text);
  border-radius: 12px; padding: 0 16px; font-size: 16px; cursor: pointer;
}

/* ---- forms (login / setup) ---- */
.center {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.card {
  width: 100%; max-width: 460px; background: var(--panel);
  border: 1px solid #232c3a; border-radius: 20px; padding: 26px;
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card p.lead { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.card h2 { font-size: 15px; margin: 22px 0 10px; color: var(--accent-2); }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid #2a3444;
  color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 16px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.btn {
  width: 100%; margin-top: 22px; padding: 14px; border: none; border-radius: 12px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #1a1205; font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn:active { transform: scale(0.99); }
.btn.secondary {
  background: var(--panel-2); color: var(--text); border: 1px solid #2a3444;
  font-weight: 600;
}

/* House rules list */
.rule-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.rule-input {
  flex: 1; resize: none; overflow: hidden; min-height: 46px; line-height: 1.45;
}
.rule-del {
  flex: 0 0 auto; width: 42px; height: 46px; border-radius: 12px;
  border: 1px solid #3a2530; background: #2a1a22; color: var(--danger);
  font-size: 16px; cursor: pointer;
}
.rule-del:active { transform: scale(0.94); }
.rule-add { display: flex; gap: 8px; margin-top: 4px; }
.rule-add input { flex: 1; }
.rule-add button {
  flex: 0 0 auto; padding: 0 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid #2a3444; background: var(--panel-2); color: var(--text); font-size: 15px;
}
.rule-add button:active { transform: scale(0.97); }
.mem-text {
  flex: 1; background: var(--panel-2); border: 1px solid #2a3444; border-radius: 12px;
  padding: 12px 14px; line-height: 1.45; font-size: 15px;
}

.error { color: var(--danger); font-size: 14px; margin-top: 12px; min-height: 18px; }
.divider { height: 1px; background: #232c3a; margin: 20px 0; }
details summary { cursor: pointer; color: var(--accent-2); font-size: 14px; margin-top: 6px; }
a { color: var(--accent-2); }
