:root {
  --ink-950: #14141c;
  --ink-900: #1c1c26;
  --ink-800: #24242f;
  --ink-700: #2c2c38;
  --paper-50: #fafaf8;
  --paper-100: #f0efe9;
  --indigo-500: #3452db;
  --indigo-400: #7b8fed;
  --muted: #63636f;
  --line: rgba(26, 26, 46, 0.12);

  --bg: var(--paper-50);
  --surface: #ffffff;
  --surface-2: var(--paper-100);
  --text: #1a1a2e;
  --text-dim: var(--muted);
  --accent: var(--indigo-500);
  --accent-ink: #ffffff;
  --rule: var(--line);
  --danger-bg: #fbe4e4;
  --danger-text: #8a2c2c;

  --font-display: "Instrument Serif", ui-serif, Georgia, serif;
  --font-body: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--ink-950);
    --surface: var(--ink-900);
    --surface-2: var(--ink-800);
    --text: #f2f1ee;
    --text-dim: #9aa0ab;
    --accent: var(--indigo-400);
    --accent-ink: #0e0e14;
    --rule: rgba(242, 241, 238, 0.1);
    --danger-bg: #4a2020;
    --danger-text: #f1c6c6;
  }
}

:root[data-theme="dark"] {
  --bg: var(--ink-950);
  --surface: var(--ink-900);
  --surface-2: var(--ink-800);
  --text: #f2f1ee;
  --text-dim: #9aa0ab;
  --accent: var(--indigo-400);
  --accent-ink: #0e0e14;
  --rule: rgba(242, 241, 238, 0.1);
  --danger-bg: #4a2020;
  --danger-text: #f1c6c6;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: env(safe-area-inset-top, 12px) 16px 12px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

.topbar__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.3rem;
}

.topbar__title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.topbar__back {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 1.2rem;
  padding: 4px 8px;
  margin-left: -8px;
}

.topbar__install {
  margin-left: auto;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 7px 14px 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  clip-path: polygon(0 0, 100% 0, 100% 76%, 94% 100%, 6% 100%, 0 76%);
}

.ios-hint {
  position: relative;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 10px 36px 10px 16px;
  line-height: 1.4;
  border-bottom: 1px solid var(--rule);
}

.ios-hint strong {
  color: var(--text);
}

.ios-hint__close {
  position: absolute;
  right: 8px;
  top: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.96rem;
}

.msg--user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 14px 14px 3px 14px;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--surface);
  border-radius: 14px 14px 14px 3px;
}

.msg--pending {
  opacity: 0.6;
}

.msg--error {
  align-self: flex-start;
  background: var(--danger-bg);
  color: var(--danger-text);
  border-radius: 14px 14px 14px 3px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
}

.composer__input {
  flex: 1;
  resize: none;
  max-height: 140px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 1rem;
  font-family: inherit;
}

.composer__input::placeholder {
  color: var(--text-dim);
}

.composer__input:focus {
  outline: none;
  border-color: var(--accent);
}

.composer__send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.1rem;
  cursor: pointer;
}

.composer__send:disabled {
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: default;
}

.account {
  position: relative;
  margin-left: auto;
  display: flex;
  align-items: center;
}

.topbar__install {
  margin-left: 8px;
}

.account__avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background-color: var(--accent);
  background-size: cover;
  background-position: center;
  color: var(--accent-ink);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.account__panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 30;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 16px 32px -18px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account__name {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text);
  margin: 0;
}

.account__sync {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-dim);
  cursor: pointer;
}

.account__sync input {
  margin-top: 2px;
}

.account__link {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-decoration: underline;
}

.account__logout {
  font-size: 0.82rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.account__login-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
}

.account__consent {
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--text-dim);
  margin: 0;
}

.account__consent a {
  color: var(--accent);
}
