/* Iris - iOS-inspired chat. Light default, dark via prefers-color-scheme. */
:root {
  color-scheme: light dark;
  --accent: #007aff;
  --accent-grad: linear-gradient(180deg, #0a84ff 0%, #007aff 100%);
  --bg: #ffffff;
  --bar: rgba(255, 255, 255, 0.72);
  --bar-border: rgba(60, 60, 67, 0.14);
  --bubble-in: #e9e9eb;
  --bubble-in-fg: #000000;
  --bubble-out-fg: #ffffff;
  --fg: #000000;
  --muted: #8e8e93;
  --field: #ffffff;
  --field-border: rgba(60, 60, 67, 0.2);
  --card: #ffffff;
  --group: #ffffff;
  --separator: rgba(60, 60, 67, 0.12);
  --sheet: #f2f2f7;
  --reminder-bg: #fff0cf;
  --reminder-fg: #6b4e00;
  --danger: #ff3b30;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bar: rgba(22, 22, 24, 0.72);
    --bar-border: rgba(84, 84, 88, 0.5);
    --bubble-in: #262629;
    --bubble-in-fg: #ffffff;
    --fg: #ffffff;
    --muted: #98989f;
    --field: #1c1c1e;
    --field-border: rgba(84, 84, 88, 0.5);
    --card: #1c1c1e;
    --group: #1c1c1e;
    --separator: rgba(84, 84, 88, 0.55);
    --sheet: #1c1c1e;
    --reminder-bg: #3a2f0c;
    --reminder-fg: #ffd780;
  }
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* --- header --- */
header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--bar-border);
}
.header-id { display: flex; align-items: center; justify-content: center; gap: 8px; }
.header-id h1 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.02em; }
.header-spacer { width: 44px; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  flex: none;
}
.avatar svg { width: 17px; height: 17px; }
.avatar-lg { width: 64px; height: 64px; margin-bottom: 6px; }
.avatar-lg svg { width: 34px; height: 34px; }

/* --- chat --- */
main {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 12px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg {
  position: relative;
  width: fit-content;
  max-width: 78%;
  min-width: 0;
  padding: 8px 13px;
  border-radius: 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: pop 0.22s ease;
}
.msg + .msg { margin-top: 1px; }
.msg.user + .msg.assistant,
.msg.assistant + .msg.user,
.msg.reminder { margin-top: 9px; }

.msg.user {
  align-self: flex-end;
  background: var(--accent-grad);
  color: var(--bubble-out-fg);
  border-bottom-right-radius: 6px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bubble-in);
  color: var(--bubble-in-fg);
  border-bottom-left-radius: 6px;
}
.msg.reminder {
  align-self: flex-start;
  background: var(--reminder-bg);
  color: var(--reminder-fg);
  border-bottom-left-radius: 6px;
}
.msg img { max-width: 100%; border-radius: 14px; display: block; margin-bottom: 6px; }
.msg audio { width: 240px; max-width: 100%; height: 38px; display: block; margin-top: 8px; }

/* --- email confirm card --- */
.card {
  align-self: flex-start;
  max-width: 82%;
  margin-top: 9px;
  background: var(--card);
  border: 0.5px solid var(--separator);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
  animation: pop 0.22s ease;
}
.card b { font-weight: 600; }
.card .actions { display: flex; gap: 8px; margin-top: 12px; }
.card .actions button {
  flex: 1;
  padding: 9px;
  border: 0;
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
}
.card .ok { background: var(--accent); color: #fff; }
.card .no { background: transparent; color: var(--accent); }

/* --- composer --- */
footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--bar-border);
}
footer textarea {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 140px;
  border: 0.5px solid var(--field-border);
  border-radius: 19px;
  padding: 8px 14px;
  background: var(--field);
  color: var(--fg);
  font-family: inherit;
  font-size: 17px;
  line-height: 1.3;
}
footer textarea::placeholder { color: var(--muted); }
footer textarea:focus { outline: none; border-color: var(--field-border); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.icon-btn svg { width: 25px; height: 25px; }
.icon-btn:active { transform: scale(0.9); }
#btn-settings { color: var(--muted); }
#btn-mic.rec { color: var(--danger); }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.send-btn svg { width: 22px; height: 22px; }
.send-btn:active { transform: scale(0.9); }

/* --- settings sheet --- */
dialog {
  margin: 0 auto;
  position: fixed;
  inset: auto 0 max(env(safe-area-inset-bottom), 0px) 0;
  width: min(100%, 500px);
  max-height: 88vh;
  border: 0;
  padding: 0;
  background: transparent;
  overflow: visible;
}
dialog::backdrop { background: rgb(0 0 0 / 40%); backdrop-filter: blur(2px); }
.sheet {
  background: var(--sheet);
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  max-height: 88vh;
  overflow-y: auto;
  animation: slideup 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.grabber {
  display: block;
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--muted);
  opacity: 0.4;
  margin: 6px auto 10px;
}
.sheet h2 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; margin: 2px 2px 14px; }
.group-label {
  font-size: 0.78rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 18px 14px 6px;
}
.group {
  background: var(--group);
  border-radius: 12px;
  overflow: hidden;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  font-size: 1.0625rem;
}
.row + .row { border-top: 0.5px solid var(--separator); }
.row input[type="radio"] { accent-color: var(--accent); width: 20px; height: 20px; }
.muted { color: var(--muted); }

.btn-primary {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 1.0625rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { filter: brightness(0.92); }
.btn-plain {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  border: 0;
  border-radius: 14px;
  background: var(--group);
  color: var(--accent);
  font-family: inherit;
  font-size: 1.0625rem;
  font-weight: 600;
  cursor: pointer;
}
#install-text { margin: 0 14px; font-size: 0.95rem; }

/* --- gate --- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-card { text-align: center; color: var(--muted); max-width: 320px; }
.gate-card p { margin-top: 4px; line-height: 1.5; }

.hidden { display: none !important; }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes slideup {
  from { transform: translateY(100%); }
  to { transform: none; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .msg, .card, .sheet { animation: none; }
  .icon-btn, .send-btn { transition: none; }
}
