/* smartz.chat: Smartz in the browser, in Apple's manner. The system font (SF Pro on Apple devices), line icons drawn
   after SF Symbols, frosted bars, light and dark, and room for a thumb on a phone. Asteria's colours: night, aqua, sea,
   violet and heavy. */

:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --sidebar: rgba(242, 242, 247, 0.82);
  --bar: rgba(255, 255, 255, 0.72);
  --text: #1D1D1F;
  --secondary: #6E6E73;
  --tertiary: #A1A1A6;
  --separator: rgba(60, 60, 67, 0.16);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --accent: #00826B;       /* deep aqua: 4.8:1 on white */
  --on-accent: #FFFFFF;
  --mine: #00826B;
  --theirs: rgba(120, 120, 128, 0.12);
  --danger: #D70015;
  --violet: #5B3FD9;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #05080F;
    --surface: #0D1320;
    --sidebar: rgba(13, 19, 32, 0.82);
    --bar: rgba(5, 8, 15, 0.72);
    --text: #F5F5F7;
    --secondary: #A1A1A6;
    --tertiary: #6E6E73;
    --separator: rgba(84, 84, 88, 0.5);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.36);
    --accent: #00FFD3;      /* pure aqua: 13:1 on night */
    --on-accent: #05080F;
    --mine: #00826B;
    --theirs: rgba(118, 118, 128, 0.2);
    --danger: #FF6961;
    --violet: #B4A3FF;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.47 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 10px; }
[hidden] { display: none !important; }

.sym { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Layout */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--sidebar);
  backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-right: 0.5px solid var(--separator);
  padding: max(12px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; color: var(--text); text-decoration: none; letter-spacing: -0.02em; }
.brand img { border-radius: 8px; }
.search { display: flex; align-items: center; gap: 6px; background: var(--fill); border-radius: 11px; padding: 6px 10px; margin: 0 4px 10px; color: var(--secondary); }
.search .sym { width: 18px; height: 18px; }
.search input { border: 0; background: none; outline: none; width: 100%; font-size: 16px; color: var(--text); }
.threads { flex: 1; overflow-y: auto; min-height: 0; padding: 0 2px; }
.thread {
  display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 12px;
  padding: 9px 10px; margin-bottom: 2px; color: var(--text);
}
.thread:hover { background: var(--fill); }
.thread[aria-current="true"] { background: var(--fill-strong); }
.thread b { display: block; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread span { display: block; font-size: 13px; color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.threads .empty { color: var(--secondary); font-size: 14px; padding: 10px; }
.account { border-top: 0.5px solid var(--separator); padding: 10px 6px 2px; display: grid; gap: 8px; }
.account .who { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.account .who .sym { color: var(--secondary); }
.account .row { display: flex; gap: 8px; flex-wrap: wrap; }
.account .small { font-size: 13px; color: var(--secondary); margin: 0; }
.pill { border: 0; border-radius: 999px; padding: 7px 14px; background: var(--fill); font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text); }
.pill.accent { background: var(--accent); color: var(--on-accent); }
.pill .sym { width: 18px; height: 18px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.title { font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { font-size: 13px; color: var(--secondary); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.meter .bar { width: 46px; height: 5px; border-radius: 3px; background: var(--fill-strong); overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.icon-button { border: 0; background: none; width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--accent); }
.icon-button:hover { background: var(--fill); }
.icon-button.light { color: #fff; background: rgba(255, 255, 255, 0.12); }
.round-button { border: 0; width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--accent); color: var(--on-accent); flex: none; }
.round-button .sym { width: 20px; height: 20px; stroke-width: 2.2; }
.round-button:disabled { opacity: 0.35; cursor: default; }
.only-narrow { display: none; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 44px; min-width: 250px; padding: 6px; z-index: 10;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); border: 0.5px solid var(--separator);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 9px 10px; border-radius: 9px; text-align: left; font-size: 15px; }
.menu button:hover { background: var(--fill); }
.menu button .sym { width: 19px; height: 19px; color: var(--secondary); }
.menu button[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); font-weight: 700; }
.menu button.danger, .menu button.danger .sym { color: var(--danger); }
.menu button:disabled { opacity: 0.4; cursor: default; }
.menu hr { border: 0; border-top: 0.5px solid var(--separator); margin: 6px 4px; }

/* The conversation */
.conversation { flex: 1; overflow-y: auto; min-height: 0; padding: 18px 16px 8px; scroll-behavior: smooth; }
.welcome { max-width: 680px; margin: 7vh auto 0; text-align: center; }
.welcome img { border-radius: 16px; box-shadow: var(--shadow); }
.welcome h2 { font-size: 34px; letter-spacing: -0.03em; margin: 16px 0 6px; }
.welcome p { color: var(--secondary); margin: 0 auto 20px; max-width: 460px; }
.suggestions { display: grid; gap: 8px; max-width: 460px; margin: 0 auto; }
.suggestions button { border: 0; background: var(--fill); border-radius: 14px; padding: 12px 16px; text-align: left; font-size: 16px; }
.suggestions button:hover { background: var(--fill-strong); }
.messages { max-width: 760px; margin: 0 auto; display: grid; gap: 14px; }
.message { display: grid; gap: 6px; }
.message.mine { justify-items: end; }
.message .bubble { max-width: min(560px, 86%); padding: 10px 15px; border-radius: var(--radius); background: var(--mine); color: #fff; white-space: pre-wrap; word-wrap: break-word; }
.message.theirs .bubble { max-width: 100%; background: none; color: var(--text); padding: 0 2px; white-space: normal; }
.message.theirs .bubble.working::after { content: "●"; color: var(--accent); animation: pulse 1s infinite; margin-left: 2px; }
@keyframes pulse { 50% { opacity: 0.25; } }
.message .actions { display: flex; align-items: center; gap: 2px; color: var(--secondary); font-size: 13px; }
.message .actions button { border: 0; background: none; color: var(--secondary); width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center; }
.message .actions button:hover { background: var(--fill); color: var(--text); }
.message .actions .sym { width: 18px; height: 18px; }
.message .actions .cost { margin-left: 6px; font-variant-numeric: tabular-nums; }
.message .actions button.playing { color: var(--accent); }
.message .edit { border: 0; background: none; color: var(--secondary); font-size: 13px; display: inline-flex; gap: 4px; align-items: center; padding: 2px 6px; border-radius: 6px; }
.message .edit .sym { width: 15px; height: 15px; }
.error-line { color: var(--secondary); font-size: 14px; text-align: center; }

/* Markdown in replies */
.bubble p { margin: 0 0 0.7em; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child, .bubble pre:last-child { margin-bottom: 0; }
.bubble h3, .bubble h4 { font-size: 1.05em; margin: 1em 0 0.4em; }
.bubble ul, .bubble ol { margin: 0 0 0.7em; padding-left: 1.4em; }
.bubble li { margin: 0.2em 0; }
.bubble code { font: 0.88em var(--mono); background: var(--fill); padding: 0.1em 0.35em; border-radius: 6px; }
.bubble pre { background: var(--fill); padding: 12px 14px; border-radius: 12px; overflow-x: auto; margin: 0 0 0.7em; }
.bubble pre code { background: none; padding: 0; font-size: 0.86em; line-height: 1.5; }
.bubble blockquote { margin: 0 0 0.7em; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--secondary); }
.bubble a { word-break: break-word; }

/* Notices and the composer */
.notice { max-width: 760px; margin: 0 auto 6px; padding: 8px 16px; font-size: 14px; color: var(--secondary); text-align: center; }
.notice button { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 0 2px; }
.composer {
  display: flex; align-items: flex-end; gap: 6px; max-width: 792px; width: 100%; margin: 0 auto;
  padding: 8px 16px max(12px, env(safe-area-inset-bottom));
}
.field { flex: 1; min-width: 0; background: var(--surface); border: 0.5px solid var(--separator); border-radius: 22px; padding: 9px 16px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04); }
.field textarea { width: 100%; border: 0; outline: none; background: none; resize: none; max-height: 200px; line-height: 1.4; display: block; font-size: 17px; }
.dictation { display: flex; align-items: center; gap: 10px; min-height: 24px; color: var(--secondary); }
.level { display: inline-flex; gap: 3px; align-items: center; height: 22px; }
.level i { width: 3px; height: 5px; border-radius: 2px; background: var(--accent); transition: height 0.08s; }
.composer .icon-button { margin-bottom: 2px; }
.composer .round-button { margin-bottom: 3px; }

/* Sign-in sheet */
.sheet { border: 0; border-radius: 22px; padding: 0; width: min(400px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.35); backdrop-filter: blur(4px); }
.sheet form { display: grid; gap: 10px; padding: 28px 24px 22px; text-align: center; }
.sheet img { justify-self: center; border-radius: 13px; }
.sheet h2 { margin: 6px 0 0; font-size: 24px; letter-spacing: -0.02em; }
.sheet p { margin: 0; color: var(--secondary); font-size: 15px; }
.sheet input { border: 0; background: var(--fill); border-radius: 12px; padding: 12px 14px; font-size: 17px; outline: none; }
.sheet input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); }
.sheet .primary { border: 0; border-radius: 13px; padding: 13px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 17px; }
.sheet .primary:disabled { opacity: 0.5; }
.sheet .plain { border: 0; background: none; color: var(--accent); font-size: 16px; padding: 6px; }
.sheet .error { color: var(--danger); min-height: 1em; }
.sheet .small { font-size: 13px; }

/* Talking (audio mode) */
.talk {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: max(20px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
  background: linear-gradient(#070A14, #120D29); color: #fff; color-scheme: dark;
}
.talk-top { width: 100%; max-width: 720px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: rgba(255, 255, 255, 0.6); }
.orb { --scale: 1; border: 0; background: none; width: min(64vw, 260px); aspect-ratio: 1; padding: 0; margin-top: 8vh; position: relative; }
.orb span {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from var(--turn, 0deg), #40E0F2, #8C6BFF, #5233C7, #40E0F2);
  box-shadow: 0 0 80px rgba(140, 107, 255, 0.45), inset 0 0 40px rgba(255, 255, 255, 0.25);
  transform: scale(var(--scale)); transition: transform 0.12s ease-out;
}
.orb span::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.45), transparent 55%); }
.talk.thinking .orb span { animation: spin 3s linear infinite; }
.talk.speaking .orb span { animation: breathe 0.9s ease-in-out infinite alternate; }
@keyframes spin { to { transform: rotate(360deg) scale(var(--scale)); } }
@keyframes breathe { from { transform: scale(0.94); } to { transform: scale(1.04); } }
.talk-status { font-size: 24px; font-weight: 600; margin: 24px 0 6px; }
.talk-words { color: rgba(255, 255, 255, 0.7); text-align: center; max-width: 560px; min-height: 3em; margin: 0; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.talk-buttons { display: flex; gap: 48px; margin-top: auto; padding-top: 24px; }
.talk-buttons .round-button { width: 64px; height: 64px; }
.talk-buttons .round-button .sym { width: 28px; height: 28px; stroke-width: 1.8; }
.round-button.light { background: rgba(255, 255, 255, 0.12); color: #fff; }
.round-button.end { background: #FF3B30; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .talk .orb span { animation: none !important; transition: none; }
  .conversation { scroll-behavior: auto; }
}

/* Phones and narrow windows: the chats slide over */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-narrow { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 30; transform: translateX(-105%); transition: transform 0.25s ease; box-shadow: var(--shadow); }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open::after { content: ""; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.3); }
  .meter .label { display: none; }
  .welcome { margin-top: 3vh; }
  .welcome h2 { font-size: 28px; }
}

.noscript { padding: 24px; text-align: center; }
