:root {
  --ink: #0f2338;
  --ink-soft: #3c5064;
  --paper: #f4f6f8;
  --paper-raised: #ffffff;
  --line: #dde3ea;
  --line-soft: #e9edf2;

  --primary: #185fa5;
  --primary-deep: #0f2a44;
  --primary-tint: #eaf2fb;

  --seq: #534ab7;
  --seq-tint: #efeefb;
  --stat: #178a68;
  --stat-tint: #e7f7f1;
  --numth: #b06b12;
  --numth-tint: #fbf1e2;
  --fin: #185fa5;
  --fin-tint: #eaf2fb;

  --error: #a32d2d;
  --error-tint: #fceaea;
  --success: #178a68;

  --brand-blue-a: #1c6fd6;
  --brand-blue-b: #4fb6ee;

  --topbar-h: 64px;

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 22px;

  --shadow-1: 0 1px 2px rgba(15, 35, 56, 0.06), 0 1px 1px rgba(15,35,56,.04);
  --shadow-2: 0 8px 24px rgba(15, 35, 56, 0.10);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
h1, h2, h3, h4, p { margin: 0; }

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--primary-deep);
  color: #fff;
  box-shadow: var(--shadow-1);
}
.back-btn {
  color: #fff;
  background: rgba(255,255,255,0.12);
}
.back-btn:hover { background: rgba(255,255,255,0.2); }
.icon-btn {
  border: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #3a86d6, var(--primary));
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }
.screen-label { font-size: 12.5px; color: rgba(255,255,255,0.68); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }

main {
  flex: 1;
  padding: 16px 16px 100px;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--paper-raised);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px 8px;
  color: var(--ink-soft);
  cursor: pointer;
}
.tab-btn span { font-size: 11.5px; font-weight: 600; }
.tab-btn.active { color: var(--primary); }

.section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 22px 2px 10px;
}
.section-title:first-child { margin-top: 4px; }

.hero {
  background: var(--primary-deep);
  color: #fff;
  border-radius: var(--radius-l);
  padding: 22px 20px;
  margin-bottom: 6px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -30px; top: -40px;
  width: 160px; height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.08), transparent 70%);
}
.hero h1 { font-size: 21px; font-weight: 700; margin-bottom: 6px; }
.hero p { font-size: 13.5px; color: rgba(255,255,255,0.72); line-height: 1.5; max-width: 46ch; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.category-card {
  border: none;
  border-radius: var(--radius-m);
  padding: 14px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 92px;
  transition: transform .12s ease;
}
.category-card:active { transform: scale(0.98); }
.category-card .cat-name { font-weight: 700; font-size: 14px; }
.category-card .cat-count { font-size: 12px; opacity: 0.75; }
.cat-sequences { background: var(--seq-tint); color: var(--seq); }
.cat-statistics { background: var(--stat-tint); color: var(--stat); }
.cat-number_theory { background: var(--numth-tint); color: var(--numth); }
.cat-finance { background: var(--fin-tint); color: var(--fin); }

.topic-list { display: flex; flex-direction: column; gap: 8px; }
.topic-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-m);
  padding: 13px 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  box-shadow: var(--shadow-1);
}
.topic-card:hover { border-color: var(--line); }
.topic-dot { width: 8px; height: 34px; border-radius: 4px; flex-shrink: 0; }
.topic-card .t-name {
  font-weight: 700;
  font-size: 14.5px;
  margin-bottom: 2px;
  color: var(--brand-blue-a); 
}
@supports (background-clip: text) or (-webkit-background-clip: text) {
  .topic-card .t-name {
    background: linear-gradient(120deg, var(--brand-blue-a), var(--brand-blue-b));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }
}
.topic-card .t-desc { font-size: 12.5px; color: var(--ink-soft); line-height: 1.35; }
.topic-card .t-chevron { margin-left: auto; color: var(--line); flex-shrink: 0; }

.form-card {
  background: var(--paper-raised);
  border-radius: var(--radius-m);
  padding: 18px;
  box-shadow: var(--shadow-1);
  border: 1px solid var(--line-soft);
}
.form-hint {
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--primary-tint);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 650;
  margin-bottom: 5px;
  color: var(--ink);
}
.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  font-size: 15px;
  font-family: var(--font-mono);
  background: var(--paper);
  color: var(--ink);
}
.field input::placeholder { color: #9aa7b3; font-family: var(--font-ui); }
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--paper-raised);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.dataset-box textarea {
  width: 100%;
  min-height: 90px;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  font-family: var(--font-mono);
  font-size: 14.5px;
  resize: vertical;
  background: var(--paper);
  color: var(--ink);
}
.dataset-box textarea:focus { outline: none; border-color: var(--primary); background: var(--paper-raised); }

.freq-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.freq-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); text-align: left; padding: 4px 4px; }
.freq-table td { padding: 3px 4px; }
.freq-table input {
  padding: 8px;
  font-size: 13.5px;
  font-family: var(--font-mono);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  width: 100%;
}
.freq-table input:focus { outline: none; border-color: var(--primary); background: var(--paper-raised); }
.freq-row-del { background: none; border: none; color: var(--error); cursor: pointer; font-size: 18px; padding: 4px 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-s);
  padding: 13px 18px;
  font-size: 14.5px;
  font-weight: 650;
  cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #14507f; }
.btn-secondary { background: var(--paper); color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost { background: none; color: var(--primary); padding: 8px 4px; width: auto; }
.btn-row { display: flex; gap: 10px; margin-top: 4px; }
.btn-row .btn { flex: 1; }
.btn-sm { padding: 8px 12px; font-size: 13px; width: auto; }

.result-card {
  background: var(--paper-raised);
  border-radius: var(--radius-m);
  padding: 20px;
  margin-top: 16px;
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-2);
}
.result-answer-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); font-weight: 700; }
.result-answer {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 700;
  color: var(--primary-deep);
  margin: 4px 0 4px;
  line-height: 1.35;
  word-break: break-word;
  white-space: pre-line;
}
.result-error {
  background: var(--error-tint);
  color: var(--error);
  border-radius: var(--radius-s);
  padding: 14px;
  font-size: 14px;
  line-height: 1.5;
}

.ledger { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 14px; }
.ledger-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ledger-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); font-weight: 700; }
.ledger-step {
  padding: 8px 0;
  border-left: 2px solid var(--line-soft);
  padding-left: 14px;
  margin-left: 4px;
  position: relative;
}
.ledger-step::before {
  content: "";
  position: absolute;
  left: -5px; top: 14px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--line);
}
.ledger-step.has-result::before { background: var(--primary); }
.step-num { display: none; }
.step-title { font-size: 12.5px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.step-expr {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  white-space: pre-wrap;
  line-height: 1.55;
  overflow-x: auto;
}
.step-result {
  margin-top: 6px;
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-tint);
  padding: 4px 9px;
  border-radius: 7px;
}

.history-save-note {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.inline-icon { display: inline-flex; color: var(--success); flex-shrink: 0; }

.history-item {
  background: var(--paper-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-m);
  padding: 13px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-1);
}
.history-item .h-topic { font-size: 11.5px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .03em; }
.history-item .h-answer { font-family: var(--font-mono); font-size: 14px; margin: 3px 0; white-space: pre-line; }
.history-item .h-time { font-size: 11.5px; color: var(--ink-soft); }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
}
.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

.learn-block { margin-bottom: 20px; }
.learn-block h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--primary); margin-bottom: 8px; font-weight: 700; }
.learn-block p, .learn-block li { font-size: 14.5px; line-height: 1.65; color: var(--ink); }
.formula-chip {
  background: var(--primary-tint);
  border-radius: var(--radius-s);
  padding: 10px 13px;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 13.5px;
}
.formula-chip .f-label { font-family: var(--font-ui); font-size: 11.5px; color: var(--ink-soft); display: block; margin-bottom: 2px; }
.worked-example {
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: var(--radius-m);
  padding: 14px;
}
.worked-example ol { margin: 8px 0 0; padding-left: 20px; }
.worked-example li { font-family: var(--font-mono); font-size: 13px; margin-bottom: 4px; }
.tips-list { padding-left: 20px; margin: 0; }
.tips-list li { margin-bottom: 8px; }
.did-you-know {
  background: var(--numth-tint);
  color: var(--numth);
  border-radius: var(--radius-m);
  padding: 14px;
  font-size: 13.5px;
  line-height: 1.55;
}

.chat-fab {
  position: fixed;
  right: 18px;
  bottom: 86px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-2);
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
  z-index: 25;
  touch-action: none;
}
.chat-fab:active { cursor: grabbing; }
.chat-fab:hover { background: #14507f; }

.toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%);
  background: var(--primary-deep);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-2);
  z-index: 40;
  animation: toastIn .18s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(6px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.formula-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
.formula-picker-btn {
  border: 1.5px solid var(--line);
  background: var(--paper);
  border-radius: var(--radius-s);
  padding: 10px;
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
  text-align: center;
}
.formula-picker-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

@media (min-width: 760px) {
  .tabbar {
    position: sticky;
    top: var(--topbar-h);
    bottom: auto;
    flex-direction: column;
    width: 220px;
    height: calc(100vh - var(--topbar-h));
    border-top: none;
    border-right: 1px solid var(--line);
    padding: 18px 10px;
    gap: 4px;
    z-index: 15;
    overflow-y: auto;
  }
  .tab-btn { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 11px 12px; border-radius: var(--radius-s); }
  .tab-btn span { font-size: 13.5px; }
  .tab-btn.active { background: var(--primary-tint); }
  #app { flex-direction: row; }
  .topbar { position: sticky; min-height: var(--topbar-h); z-index: 30; }
  .app-body { display: flex; flex: 1; }
  main { padding-bottom: 40px; }
  .category-grid { grid-template-columns: repeat(4, 1fr); }
  .chat-fab { right: 28px; bottom: 28px; }
  .field-row.two-col-desktop { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 760px) {
  #app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / 3; }
  .tabbar { grid-row: 2; grid-column: 1; }
  main { grid-row: 2; grid-column: 2; }
}

:root[data-theme="dark"] {
  --ink: #eaf0f6;
  --ink-soft: #9fb0c0;
  --paper: #0d1a26;
  --paper-raised: #142433;
  --line: #22394c;
  --line-soft: #1a2e40;

  --primary: #5b9fe0;
  --primary-deep: #081521;
  --primary-tint: #16324a;

  --seq: #a79df0;
  --seq-tint: #241f3d;
  --stat: #4fd8ab;
  --stat-tint: #0f2a22;
  --numth: #eab06a;
  --numth-tint: #33260f;
  --fin: #5b9fe0;
  --fin-tint: #16324a;

  --error: #f08585;
  --error-tint: #3a1a1a;
  --success: #4fd8ab;

  --shadow-1: 0 1px 2px rgba(0,0,0,0.35);
  --shadow-2: 0 8px 26px rgba(0,0,0,0.5);
}
:root[data-theme="dark"] .brand-mark { background: linear-gradient(135deg, #4a80c0, var(--primary)); }
:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select,
:root[data-theme="dark"] .dataset-box textarea { color: var(--ink); }
:root[data-theme="dark"] .field input::placeholder { color: #5e7488; }

body, .topbar, .tabbar, .form-card, .result-card, .history-item, .topic-card {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

.theme-toggle-btn {
  color: #fff;
  background: rgba(255,255,255,0.12);
  position: relative;
  overflow: hidden;
}
.theme-toggle-btn:hover { background: rgba(255,255,255,0.2); }
.theme-toggle-btn .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle-btn .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle-btn .icon-sun { display: block; }

.settings-group { margin-bottom: 22px; }
.settings-list {
  background: var(--paper-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-m);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.settings-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  background: none;
  border-left: none; border-right: none; border-top: none;
  width: 100%;
  text-align: left;
  font-size: 14.5px;
  color: var(--ink);
}
.settings-item:last-child { border-bottom: none; }
.settings-item .s-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--primary-tint);
  color: var(--primary);
}
.settings-item .s-label { flex: 1; font-weight: 600; }
.settings-item .s-sub { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }
.settings-item .t-chevron { color: var(--line); }

.toggle-switch {
  width: 46px; height: 27px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-switch.on { background: var(--primary); }
.toggle-switch.on::after { transform: translateX(19px); }

.app-meta { text-align: center; color: var(--ink-soft); font-size: 12.5px; margin-top: 24px; line-height: 1.7; }
.app-meta a { color: var(--primary); text-decoration: none; font-weight: 600; }

.coffee-banner {
  background: linear-gradient(135deg, #ffdd57, #ffb84d);
  color: #3a2a05;
  border-radius: var(--radius-m);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
  margin-bottom: 22px;
}
.coffee-banner .s-title { font-weight: 700; font-size: 14.5px; }
.coffee-banner .s-sub { font-size: 12.5px; opacity: 0.8; }

.legal-text { font-size: 13.5px; line-height: 1.7; color: var(--ink); }
.legal-text h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--primary); margin: 18px 0 8px; }
.legal-text h3:first-child { margin-top: 0; }
.legal-text p { margin-bottom: 10px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2.5px solid var(--primary);
  outline-offset: 2px;
}

.chat-panel {
  position: fixed;
  right: 0; bottom: 0; left: 0;
  top: 12%;
  background: var(--paper);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  box-shadow: var(--shadow-2);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .22s ease;
  border: 1px solid var(--line-soft);
}
.chat-panel.open { transform: translateY(0); }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--primary-deep);
  color: #fff;
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  flex-shrink: 0;
}
.chat-header-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14.5px; }
.chat-header-dot { width: 8px; height: 8px; border-radius: 50%; background: #4fd8ab; box-shadow: 0 0 0 3px rgba(79,216,171,0.25); }
.chat-header-actions { display: flex; gap: 6px; }
.chat-header-btn { color: #fff; background: rgba(255,255,255,0.12); width: 32px; height: 32px; }
.chat-header-btn:hover { background: rgba(255,255,255,0.22); }
.chat-header-btn.on { background: #4fd8ab; color: var(--primary-deep); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-row { display: flex; align-items: flex-end; gap: 6px; max-width: 88%; }
.chat-row-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-row-assistant { align-self: flex-start; }
.chat-bubble {
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble-user { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble-assistant { background: var(--paper-raised); color: var(--ink); border: 1px solid var(--line-soft); border-bottom-left-radius: 4px; }
.chat-bubble-error { background: var(--error-tint); color: var(--error); border-color: var(--error); }
.chat-bubble-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: 100%;
  height: auto;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 6px;
  object-fit: cover;
}
.chat-bubble-file-note {
  font-size: 12.5px;
  opacity: 0.85;
  margin-bottom: 4px;
  word-break: break-word;
}
.chat-error-icon { display: inline-flex; margin-right: 6px; position: relative; top: 2px; }
.chat-play-btn { background: none; border: none; cursor: pointer; font-size: 13px; opacity: 0.6; flex-shrink: 0; padding: 4px; }
.chat-play-btn:hover { opacity: 1; }

.chat-typing { display: flex; gap: 4px; padding: 13px 14px; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-soft); animation: chatTypingBlink 1.1s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatTypingBlink { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

.chat-attach-preview { padding: 0 16px; }
.chat-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-tint);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--primary);
  margin-bottom: 8px;
}
.chat-attach-chip img { width: 22px; height: 22px; border-radius: 5px; object-fit: cover; }
.chat-attach-chip button { background: none; border: none; color: var(--primary); font-size: 16px; cursor: pointer; line-height: 1; padding: 0 2px; }

.chat-input-bar {
  border-top: 1px solid var(--line-soft);
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--paper-raised);
  flex-shrink: 0;
}
.chat-input-row { display: flex; align-items: flex-end; gap: 6px; }
.chat-tool-btn { color: var(--ink-soft); background: var(--paper); flex-shrink: 0; }
.chat-tool-btn:hover { color: var(--primary); }
.chat-tool-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.chat-tool-btn.recording { color: #fff; background: var(--error); animation: chatPulse 1s infinite; }
@keyframes chatPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(163,45,45,0.4); } 50% { box-shadow: 0 0 0 6px rgba(163,45,45,0); } }

.chat-textarea {
  flex: 1;
  resize: none;
  max-height: 100px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 9px 14px;
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.4;
}
.chat-textarea:focus { outline: none; border-color: var(--primary); }

.chat-send-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send-btn:hover { background: #14507f; }
.chat-send-btn:disabled { background: var(--line); color: var(--ink-soft); cursor: not-allowed; }

.chat-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 0;
  font-size: 11px;
  color: var(--ink-soft);
}
.chat-char-count.over { color: var(--error); font-weight: 700; }

@media (min-width: 760px) {
  .chat-panel {
    left: auto;
    right: 28px;
    bottom: 28px;
    top: auto;
    width: 380px;
    height: 620px;
    max-height: 78vh;
    border-radius: 22px;
    transform: translateY(20px) scale(0.97);
    opacity: 0;
    transition: transform .18s ease, opacity .18s ease;
    pointer-events: none;
  }
  .chat-panel.open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }
  .chat-header { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
}

.attach-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 15, 22, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.attach-preview-content {
  background: var(--paper-raised);
  border-radius: var(--radius-l);
  max-width: min(520px, 100%);
  max-height: 85vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-2);
}
.attach-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}
.attach-preview-title { font-weight: 700; font-size: 13.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-preview-close { color: var(--ink-soft); background: var(--paper); flex-shrink: 0; }
.attach-preview-close:hover { color: var(--error); }
.attach-preview-body { overflow: auto; padding: 0; }
.attach-preview-body img { display: block; width: 100%; height: auto; max-height: 70vh; object-fit: contain; background: var(--paper); }
.attach-preview-text {
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
}

.chat-attach-chip .chat-attach-tap { cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.chat-attach-chip .chat-attach-tap:hover { text-decoration: underline; }

.tts-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--primary);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
.tts-btn:hover { border-color: var(--primary); }
.tts-btn.tts-reading { background: var(--primary); color: #fff; border-color: var(--primary); }
.tts-icon { font-size: 13px; }
.tts-word { border-radius: 3px; }
.tts-word.tts-highlight { background: var(--primary-tint); color: var(--primary-deep); box-shadow: 0 0 0 2px var(--primary-tint); }
:root[data-theme="dark"] .tts-word.tts-highlight { color: #fff; }

.learn-block-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.learn-block-header h3 { margin-bottom: 0; }

.tos-gate-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  background: rgba(8, 15, 22, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.tos-gate-content {
  background: var(--paper-raised);
  border-radius: var(--radius-l);
  max-width: min(440px, 100%);
  max-height: 88vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-2);
}
.tos-gate-body { padding: 16px; overflow: auto; }
.tos-gate-body > p { font-size: 13.5px; color: var(--ink); margin-bottom: 10px; }
.tos-gate-list { margin: 0 0 14px; padding-left: 20px; }
.tos-gate-list li { font-size: 13px; color: var(--ink-soft); line-height: 1.55; margin-bottom: 6px; }
.tos-gate-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  padding: 10px;
  background: var(--paper);
  border-radius: var(--radius-s);
  margin-bottom: 14px;
}
.tos-gate-checkbox-row input { margin-top: 2px; flex-shrink: 0; width: 16px; height: 16px; }
.tos-gate-checkbox-row a { color: var(--primary); font-weight: 650; }
.tos-gate-google-btn {
  display: flex;
  justify-content: center;
  min-height: 44px;
  opacity: 0.35;
  pointer-events: none;
  filter: grayscale(0.6);
  transition: opacity .15s ease;
}
.tos-gate-google-btn.enabled { opacity: 1; pointer-events: auto; filter: none; }

.account-modal-body { padding: 18px; }
.account-profile { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.account-profile img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.account-name { font-weight: 700; font-size: 15px; color: var(--ink); }
.account-email { font-size: 12.5px; color: var(--ink-soft); }
.account-stats { font-size: 13px; color: var(--ink-soft); background: var(--paper); border-radius: var(--radius-s); padding: 10px 12px; margin-bottom: 16px; }
.s-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.pwa-banner {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 460px;
  z-index: 90;
  background: var(--paper-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-2);
  padding: 12px 12px 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.pwa-banner-icon { color: var(--primary); flex-shrink: 0; display: flex; }
.pwa-banner-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.pwa-banner-text strong { font-size: 13.5px; color: var(--ink); }
.pwa-banner-text span { font-size: 12px; color: var(--ink-soft); }
.pwa-banner-close { color: var(--ink-soft); background: var(--paper); flex-shrink: 0; width: 30px; height: 30px; }
.pwa-banner-never {
  position: absolute;
  left: 14px;
  bottom: -20px;
  background: none;
  border: none;
  font-size: 11px;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 0;
}
@media (min-width: 760px) {
  .pwa-banner { left: auto; right: 28px; bottom: 28px; transform: none; }
  .pwa-banner-never { left: 14px; }
}
