/* VITALSTUDY — fully fluid layout, adapts to any screen */
/* Chakra Petch (UI labels) + DM Sans (body text)        */

:root {
  --bg:        #050709;
  --bg-2:      #090d12;
  --surface:   #0e1520;
  --surface-2: #141c28;
  --border:    rgba(0,240,140,0.10);
  --border-hi: rgba(0,240,140,0.32);
  --green:     #00F08C;
  --green-dim: rgba(0,240,140,0.22);
  --teal:      #00D4E8;
  --red:       #FF3B5C;
  --text:      #C8DCE8;
  --text-dim:  #586878;
  --text-hi:   #EDF5FF;
  --ui:        'Chakra Petch', monospace;
  --body:      'DM Sans', sans-serif;
  --nav-h:     62px;
  --nav-w:     88px;   /* desktop sidebar width */
  --header-h:  80px;
}

*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  height: 100%;
  height: 100svh;            /* mobile: real visible height (URL bar aware) */
  height: 100dvh;            /* dynamic viewport height where supported */
  min-height: -webkit-fill-available;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;   /* don't let mobile resize our text */
  overscroll-behavior: none;        /* no rubber-band / pull-to-refresh bounce */
  touch-action: manipulation;       /* kill 300ms tap delay + double-tap zoom */
}

/* Ambient glow */
body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 60% 35% at 50% -5%, rgba(0,240,140,0.055) 0%, transparent 65%),
    radial-gradient(ellipse 40% 25% at 90% 110%, rgba(0,212,232,0.04) 0%, transparent 55%);
}
body::after {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ── APP SHELL ──────────────────────────────────
   Mobile-first: column layout (header / content / bottom-nav)
   Desktop: CSS grid with sidebar nav
*/

#app {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── HEADER ─────────────────────────────────── */

.app-header {
  height: calc(var(--header-h) + env(safe-area-inset-top, 0));
  padding-top: env(safe-area-inset-top, 0);   /* clear the notch in app/standalone mode */
  flex-shrink: 0;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.header-content {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px 6px;
}

.header-left  { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.logo-mark {
  width: 30px; height: 30px; flex-shrink: 0;
  background: var(--green); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--ui); font-size: 20px; font-weight: 700;
  border-radius: 7px; box-shadow: 0 0 16px var(--green-dim);
}
.header-titles { display: flex; flex-direction: column; gap: 1px; }
.app-name { font-family: var(--ui); font-size: 17px; font-weight: 700; color: var(--text-hi); letter-spacing: .07em; }
.app-sub  { font-family: var(--ui); font-size: 8.5px; color: var(--text-dim); letter-spacing: .14em; }

.header-right { display: flex; align-items: center; gap: 6px; }
.status-dot   { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.status-dot.active { background: var(--green); box-shadow: 0 0 8px var(--green); animation: blink 2.5s ease-in-out infinite; }
.status-text  { font-family: var(--ui); font-size: 9.5px; color: var(--green); letter-spacing: .12em; }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

.ecg-container { height: 26px; overflow: hidden; }
.ecg-svg { width: 100%; height: 100%; }
.ecg-path {
  fill: none; stroke: var(--green); stroke-width: 1.4; opacity: .4;
  stroke-dasharray: 1800; stroke-dashoffset: 1800;
  animation: drawEcg 3.5s linear infinite;
}
@keyframes drawEcg { 0%{stroke-dashoffset:1800;opacity:0}8%{opacity:.4}88%{opacity:.4}100%{stroke-dashoffset:0;opacity:0} }

/* ── MAIN CONTENT ───────────────────────────── */

#main-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;   /* each tab owns its own scroll */
  position: relative;
}

/* Scrollable wrapper for the chapter picker */
.scroll-view {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── BOTTOM NAV (mobile) ────────────────────── */

.bottom-nav {
  height: var(--nav-h);
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3,1fr);
  background: rgba(9,13,18,.96);
  border-top: 1px solid var(--border);
  z-index: 20;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding-bottom: env(safe-area-inset-bottom,0);
}

.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); transition: color .18s, transform .12s;
  position: relative; padding: 0;
}
.nav-btn svg { width: 20px; height: 20px; }
.nav-btn span { font-family: var(--ui); font-size: 8px; letter-spacing: .12em; font-weight: 600; }
.nav-btn.active { color: var(--green); }
.nav-btn.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 2px; background: var(--green);
  border-radius: 0 0 3px 3px; box-shadow: 0 0 10px var(--green);
}
.nav-btn:active { transform: scale(.90); }

/* ── CHAPTER PICKER ─────────────────────────── */

.chapter-badge { font-family: var(--ui); font-size: 9.5px; font-weight: 700; letter-spacing: .06em; color: var(--bg); background: var(--green); padding: 3px 7px; border-radius: 4px; flex-shrink: 0; }
.chapter-count { font-family: var(--ui); font-size: 9px; color: var(--text-dim); letter-spacing: .06em; flex-shrink: 0; }

.study-intro { padding: 14px 14px 4px; }
.study-intro h2 { font-family: var(--ui); font-size: 9.5px; color: var(--text-dim); letter-spacing: .14em; margin-bottom: 4px; }
.study-intro p { font-size: 13px; color: var(--text); line-height: 1.5; }

.picker-grid { display: flex; flex-direction: column; gap: 12px; padding: 12px 14px; }

.picker-row { display: flex; align-items: stretch; gap: 8px; }
.picker-row .picker-card { flex: 1; }
.picker-del {
  flex-shrink: 0; width: 48px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text-dim); font-size: 18px; cursor: pointer;
  transition: all .15s;
}
.picker-del:hover, .picker-del:active { color: var(--red); border-color: rgba(255,59,92,.4); background: rgba(255,59,92,.07); }

.picker-card {
  display: flex; align-items: center; gap: 14px; padding: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; text-align: left;
  transition: border-color .2s, box-shadow .2s, transform .12s;
}
.picker-card:hover  { border-color: var(--border-hi); box-shadow: 0 0 20px rgba(0,240,140,.05); }
.picker-card:active { transform: scale(.98); }

.picker-thumb {
  width: 112px; aspect-ratio: 4/3; object-fit: cover; flex-shrink: 0;
  border-radius: 8px; background: #000; border: 1px solid var(--border);
}
.picker-meta  { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.picker-title { font-family: var(--ui); font-size: 13px; font-weight: 600; color: var(--text-hi); letter-spacing: .015em; line-height: 1.3; }
.picker-thumb-blank { display: flex; align-items: center; justify-content: center; font-size: 34px; }
.badge-upload { background: var(--teal); }
.picker-add { border-style: dashed; }
.picker-add .picker-thumb-blank { color: var(--green); }

/* Inline upload status toast */
.upload-status {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 14px); transform: translateX(-50%);
  z-index: 50; max-width: 90%;
  display: flex; align-items: center; gap: 9px;
  padding: 12px 16px; background: var(--surface-2); border: 1px solid var(--border-hi);
  border-radius: 12px; color: var(--text-hi); font-size: 13px; line-height: 1.4;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.upload-status[hidden] { display: none; }   /* beats .upload-status{display:flex} so it can actually hide */
.upload-spin { width: 15px; height: 15px; flex-shrink: 0; border: 2px solid var(--border); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@media (min-width: 1100px) { .upload-status { bottom: 20px; left: calc(50% + var(--nav-w)/2); } }

/* Podcast audio player in a chat bubble */
.bubble-podcast { display: block; width: 100%; margin-top: 10px; }

/* ── SLIDESHOW ──────────────────────────────── */

.slideshow { height: 100%; display: flex; flex-direction: column; }

.slideshow-topbar {
  flex-shrink: 0; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.ss-back {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; color: var(--green); font-family: var(--ui); font-size: 10px;
  letter-spacing: .08em; cursor: pointer; flex-shrink: 0; transition: background .15s;
}
.ss-back:active { background: rgba(0,240,140,.1); }
.ss-chapter {
  flex: 1; font-family: var(--ui); font-size: 11px; font-weight: 600;
  color: var(--text-hi); letter-spacing: .05em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ss-counter { font-family: var(--ui); font-size: 11px; color: var(--green); letter-spacing: .08em; flex-shrink: 0; }

.slideshow-stage {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 10px; background: #000;
}
.ss-img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; border-radius: 4px; }

/* Text/audio uploads have no slide image — show their words instead */
.ss-textpage {
  width: 100%; max-width: 680px; max-height: 100%; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 18px;
}
.ss-textpage-head { font-family: var(--ui); font-size: 14px; font-weight: 700; color: var(--green); letter-spacing: .04em; margin-bottom: 12px; }
.ss-textpage-body { font-size: 15px; line-height: 1.7; color: var(--text); }

.ss-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 5;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(9,13,18,.72); border: 1px solid var(--border-hi);
  color: var(--green); font-size: 26px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding-bottom: 3px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: background .15s, opacity .15s;
}
.ss-prev { left: 10px; }
.ss-next { right: 10px; }
.ss-arrow:active   { background: rgba(0,240,140,.18); }
.ss-arrow:disabled { opacity: .22; cursor: default; }

.slideshow-controls {
  flex-shrink: 0; display: flex; flex-direction: column; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom,0));
  background: var(--bg-2); border-top: 1px solid var(--border);
}

.ss-scrubber {
  width: 100%; appearance: none; -webkit-appearance: none;
  height: 4px; border-radius: 2px; background: var(--surface-2);
  outline: none; cursor: pointer;
}
.ss-scrubber::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 10px var(--green-dim); cursor: pointer;
}
.ss-scrubber::-moz-range-thumb {
  width: 18px; height: 18px; border: none; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 10px var(--green-dim); cursor: pointer;
}

.ss-ask {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 14px;
  background: rgba(0,240,140,.07); border: 1px solid var(--border-hi);
  border-radius: 10px; color: var(--green); font-family: var(--ui); font-size: 11px;
  letter-spacing: .09em; cursor: pointer; transition: background .18s;
}
.ss-ask:active { background: rgba(0,240,140,.14); }

/* ── HOME — start page ──────────────────────── */

.home-view { padding: 18px 16px 28px; max-width: 1000px; margin: 0 auto; }
.home-hero h1 { font-family: var(--ui); font-size: 24px; font-weight: 700; color: var(--text-hi); letter-spacing: .04em; }
.home-hero p  { color: var(--text-dim); font-size: 14px; margin-top: 5px; line-height: 1.5; }

.home-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 18px; }
@media (min-width: 600px)  { .home-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .home-grid { grid-template-columns: repeat(3, 1fr); } }

.home-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 7px;
  padding: 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .12s;
}
.home-card:hover  { border-color: var(--border-hi); box-shadow: 0 0 20px rgba(0,240,140,.05); }
.home-card:active { transform: scale(.98); }
.hc-icon  { font-size: 26px; line-height: 1; }
.hc-title { font-family: var(--ui); font-size: 13px; font-weight: 700; color: var(--green); letter-spacing: .08em; }
.hc-desc  { font-size: 13px; color: var(--text); line-height: 1.5; }

.home-tip {
  margin-top: 18px; padding: 14px 16px;
  background: rgba(0,212,232,.05); border: 1px solid rgba(0,212,232,.2); border-radius: 12px;
  font-size: 13px; color: var(--text); line-height: 1.65;
}
.home-tip strong { color: var(--teal); }
.home-tip em { color: var(--text-hi); font-style: normal; }

.home-section-label { font-family: var(--ui); font-size: 9px; color: var(--text-dim); letter-spacing: .16em; margin: 22px 0 10px; }
.home-grid + .home-section-label { margin-top: 24px; }
.hero-card { border-color: var(--border-hi); background: rgba(0,240,140,.05); }
.hero-card .hc-title { color: var(--green); }

.home-help-link {
  display: block; width: 100%; margin-top: 14px; padding: 13px;
  background: var(--surface); border: 1px solid var(--border-hi); border-radius: 12px;
  color: var(--teal); font-family: var(--ui); font-size: 12px; letter-spacing: .06em; cursor: pointer;
}
.home-help-link:active { background: rgba(0,212,232,.08); }

/* ── HELP page ──────────────────────────────── */
.help-view { padding: 18px 16px 28px; max-width: 760px; margin: 0 auto; }
.help-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 9px; overflow: hidden;
}
.help-item summary {
  list-style: none; cursor: pointer; padding: 14px 16px;
  font-size: 14.5px; font-weight: 500; color: var(--text-hi); line-height: 1.4;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.help-item summary::-webkit-details-marker { display: none; }
.help-item summary::after { content: '＋'; color: var(--green); font-size: 18px; flex-shrink: 0; }
.help-item[open] summary::after { content: '－'; }
.help-item[open] summary { border-bottom: 1px solid var(--border); }
.help-a { padding: 12px 16px 15px; font-size: 14px; color: var(--text); line-height: 1.6; }
.help-a b { color: var(--text-hi); }
.help-contact {
  margin-top: 22px; padding: 15px 16px;
  background: rgba(0,240,140,.06); border: 1px solid var(--border-hi); border-radius: 12px;
  font-size: 14px; color: var(--text); line-height: 1.55;
}
.help-contact b { color: var(--green); }

/* ── LOGIN — full-screen, keyboard-safe, native-feeling ── */

.login-view {
  height: 100%;
  overflow-y: auto;                 /* scrolls (doesn't zoom/jump) when keyboard opens */
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column;
  padding: max(14vh, 64px) 24px calc(40px + env(safe-area-inset-bottom, 0));
  gap: 30px;
}

.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; animation: fadeIn .3s ease-out; }
.login-logo {
  width: 68px; height: 68px;
  background: var(--green); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--ui); font-size: 44px; font-weight: 700; line-height: 1;
  border-radius: 18px; box-shadow: 0 0 34px var(--green-dim);
}
.login-brand h1 { font-family: var(--ui); font-size: 26px; font-weight: 700; color: var(--text-hi); letter-spacing: .1em; }
.login-tag { font-family: var(--ui); font-size: 10px; color: var(--text-dim); letter-spacing: .18em; }

.login-form {
  width: 100%; max-width: 420px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
  animation: fadeIn .3s ease-out .05s both;
}
.login-field { display: flex; flex-direction: column; gap: 7px; }
.login-field > span { font-family: var(--ui); font-size: 9.5px; color: var(--text-dim); letter-spacing: .16em; padding-left: 2px; }
.login-input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 16px; min-height: 54px;
  color: var(--text-hi); font-family: var(--body); font-size: 16px;  /* 16px = no mobile focus-zoom */
  outline: none; transition: border-color .18s, box-shadow .18s; -webkit-appearance: none;
}
.login-input:focus { border-color: var(--border-hi); box-shadow: 0 0 0 3px rgba(0,240,140,.10); }
.login-input::placeholder { color: var(--text-dim); }
.login-error { font-size: 13.5px; color: var(--red); text-align: center; margin: -2px 0 2px; }
.login-btn {
  width: 100%; min-height: 56px; padding: 16px; margin-top: 4px;
  background: var(--green); border: none; border-radius: 14px;
  font-family: var(--ui); font-size: 14px; font-weight: 700; letter-spacing: .12em;
  color: var(--bg); cursor: pointer; transition: opacity .15s, transform .12s;
  box-shadow: 0 0 24px var(--green-dim);
}
.login-btn:active { transform: scale(.98); }
.login-btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
.login-hint { text-align: center; font-size: 13px; color: var(--text-dim); margin-top: 2px; }

/* Roomier brand on taller / bigger screens */
@media (min-height: 720px) { .login-view { padding-top: 16vh; gap: 38px; } }

.logout-btn {
  margin-left: 8px; padding: 5px 9px;
  background: none; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-dim); font-family: var(--ui); font-size: 8.5px; letter-spacing: .1em;
  cursor: pointer; transition: all .15s;
}
.logout-btn:hover { color: var(--red); border-color: rgba(255,59,92,.35); }

.gear-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; flex-shrink: 0;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-dim); cursor: pointer; transition: all .15s;
}
.gear-btn svg { width: 17px; height: 17px; }
.gear-btn:hover, .gear-btn:active { color: var(--green); border-color: var(--border-hi); }

/* ── SETTINGS ───────────────────────────────── */
.settings-view { padding: 18px 16px 28px; max-width: 460px; margin: 0 auto; }
.settings-form { display: flex; flex-direction: column; gap: 14px; }
.settings-banner { padding: 12px 14px; border-radius: 10px; font-size: 13.5px; line-height: 1.5; margin-bottom: 4px; }
.settings-banner.ok  { background: rgba(0,240,140,.08); border: 1px solid var(--border-hi); color: var(--green); }
.settings-banner.err { background: rgba(255,59,92,.08); border: 1px solid rgba(255,59,92,.3); color: var(--red); }

/* ── CHAT ───────────────────────────────────── */

.chat-view { height: 100%; display: flex; flex-direction: column; overflow: hidden; position: relative; }

/* Top bar: recent chats + new chat */
.chat-topbar {
  flex-shrink: 0; display: flex; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.topbar-btn {
  padding: 6px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-family: var(--ui); font-size: 10px;
  letter-spacing: .08em; cursor: pointer; transition: all .15s;
}
.topbar-btn:hover, .topbar-btn:active { background: rgba(0,240,140,.08); border-color: var(--border-hi); color: var(--green); }

/* Recent-chats slide-out drawer */
.drawer-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); z-index: 30; animation: fadeIn .15s ease-out; }
.chat-drawer {
  position: absolute; top: 0; left: 0; bottom: 0; width: min(78%, 320px);
  background: var(--bg-2); border-right: 1px solid var(--border); z-index: 31;
  display: flex; flex-direction: column; gap: 10px; padding: 12px;
  animation: drawerIn .18s ease-out;
}
@keyframes drawerIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.drawer-new {
  flex-shrink: 0; padding: 12px; background: rgba(0,240,140,.08);
  border: 1px solid var(--border-hi); border-radius: 10px; color: var(--green);
  font-family: var(--ui); font-size: 11px; letter-spacing: .08em; cursor: pointer;
  transition: background .15s;
}
.drawer-new:active { background: rgba(0,240,140,.16); }
.drawer-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.drawer-item {
  display: flex; align-items: center; gap: 6px; padding: 10px 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; transition: border-color .15s;
}
.drawer-item:hover, .drawer-item.active { border-color: var(--border-hi); }
.drawer-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.drawer-item-title { font-size: 12.5px; color: var(--text-hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-item-time { font-family: var(--ui); font-size: 8.5px; color: var(--text-dim); letter-spacing: .1em; }
.drawer-del { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 13px; padding: 4px; flex-shrink: 0; }
.drawer-del:hover { color: var(--red); }
.drawer-empty { font-family: var(--ui); font-size: 10px; color: var(--text-dim); letter-spacing: .1em; text-align: center; padding: 20px 0; }

.chat-messages {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
}

.chat-welcome { text-align: center; padding: 50px 24px; max-width: 480px; margin: 0 auto; }
.chat-welcome .icon { font-size: 40px; display: block; margin-bottom: 14px; }
.chat-welcome h3 { font-family: var(--ui); font-size: 13px; color: var(--text-hi); letter-spacing: .06em; margin-bottom: 8px; }
.chat-welcome p { font-size: 14px; color: var(--text-dim); line-height: 1.65; }
.chat-welcome p strong { color: var(--green); font-weight: 600; }

/* Suggestion chips on the welcome screen */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.chip {
  padding: 8px 13px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; font-family: var(--ui); font-size: 10px; color: var(--text);
  letter-spacing: .05em; cursor: pointer; transition: all .15s;
}
.chip:hover, .chip:active { background: rgba(0,240,140,.1); border-color: var(--border-hi); color: var(--green); }

/* Tappable quiz answer buttons under the latest AI question */
.answer-row {
  display: flex; flex-direction: column; gap: 8px;
  align-self: flex-start; width: min(100%, 480px);
  animation: fadeIn .18s ease-out;
}
.answer-btn {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; background: var(--surface-2);
  border: 1px solid var(--border-hi); border-radius: 10px;
  color: var(--text); font-family: var(--body); font-size: 13.5px; line-height: 1.45;
  cursor: pointer; text-align: left; transition: all .15s;
}
.answer-btn:hover  { background: rgba(0,240,140,.08); }
.answer-btn:active { transform: scale(.98); background: rgba(0,240,140,.14); }
.answer-letter {
  font-family: var(--ui); font-size: 11px; font-weight: 700;
  color: var(--green); flex-shrink: 0; margin-top: 1px; width: 14px;
}

/* Read-aloud button inside AI bubbles */
.speak-btn {
  display: block; margin-top: 8px; padding: 4px 11px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
  font-size: 13px; line-height: 1.3; cursor: pointer; opacity: .75; transition: all .15s;
}
.speak-btn:active  { transform: scale(.93); }
.speak-btn.playing { opacity: 1; border-color: var(--border-hi); background: rgba(0,240,140,.1); animation: blink 1.2s ease-in-out infinite; }

.bubble { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; animation: fadeIn .18s ease-out; }
.bubble.user { align-self: flex-end; background: rgba(0,240,140,.13); border: 1px solid rgba(0,240,140,.28); color: var(--text-hi); border-bottom-right-radius: 4px; }
.bubble.ai   { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
.bubble-label { font-family: var(--ui); font-size: 8.5px; letter-spacing: .12em; display: block; margin-bottom: 4px; }
.bubble.user .bubble-label { color: var(--green); }
.bubble.ai   .bubble-label { color: var(--teal); }

/* Audiobook lesson bubble — teal accent, reads itself aloud */
.bubble.audiobook { border-color: rgba(0,212,232,.35); background: rgba(0,212,232,.05); }
.bubble.audiobook .bubble-label { color: var(--teal); }

/* Video lesson bubble — wide, with an inline player */
.bubble.has-video { max-width: min(92%, 560px); width: 100%; border-color: rgba(0,212,232,.35); }
.bubble.has-video .bubble-label { color: var(--teal); }
.bubble-video {
  display: block; width: 100%; margin-top: 10px;
  border-radius: 10px; background: #000; border: 1px solid var(--border);
}

.bubble.thinking { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; padding: 12px 16px; }
.thinking-dots { display: flex; gap: 5px; }
.thinking-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); animation: bounce 1.2s ease-in-out infinite; }
.thinking-dots span:nth-child(2){animation-delay:.18s}
.thinking-dots span:nth-child(3){animation-delay:.36s}
@keyframes bounce { 0%,100%{transform:translateY(0);opacity:.4}50%{transform:translateY(-5px);opacity:1} }

.tool-indicator { display: flex; align-items: center; gap: 6px; color: var(--teal); }
.tool-indicator svg { flex-shrink: 0; animation: spin .9s linear infinite; }

.chat-input-row {
  flex-shrink: 0;
  padding: 10px 16px 14px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; background: rgba(9,13,18,.95);
}

.chat-input-inner {
  flex: 1; display: flex; gap: 8px; max-width: 860px; margin: 0 auto; width: 100%;
}

.chat-input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 10px 16px;
  color: var(--text-hi); font-family: var(--body); font-size: 16px;  /* 16px = no iOS zoom-on-focus */
  outline: none; transition: border-color .18s; -webkit-appearance: none; min-width: 0;
}
.chat-input:focus { border-color: var(--border-hi); }
.chat-input::placeholder { color: var(--text-dim); }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .18s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:active { transform: scale(.90); }
.icon-btn.send { background: var(--green); border-color: var(--green); color: var(--bg); }
.icon-btn.recording { background: var(--red); border-color: var(--red); color: #fff; animation: blink .8s infinite; }

/* ── UTILITY ────────────────────────────────── */
.loading-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 14px; }
.spinner { width: 34px; height: 34px; border: 2px solid var(--border); border-top-color: var(--green); border-radius: 50%; animation: spin .75s linear infinite; }
.loading-state p { font-family: var(--ui); font-size: 10px; color: var(--text-dim); letter-spacing: .12em; }
.empty-state { text-align: center; padding: 50px 20px; }
.empty-state p { font-family: var(--ui); font-size: 11px; color: var(--text-dim); letter-spacing: .1em; margin-bottom: 6px; }

@keyframes fadeIn { from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)} }
@keyframes spin   { to{transform:rotate(360deg)} }

::-webkit-scrollbar       { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 2px; }

/* ══════════════════════════════════════════════
   RESPONSIVE — no preset sizes, scales to screen
   ══════════════════════════════════════════════ */

/* ── Tablet (600px+) ── */
@media (min-width: 600px) {
  .bubble { max-width: 70%; font-size: 14.5px; }
  .study-intro { padding: 16px 20px 4px; }

  /* Chapter cards side-by-side */
  .picker-grid { display: grid; grid-template-columns: 1fr 1fr; padding: 12px 20px; }
}

/* ── Desktop (900px+) — sidebar nav ── */
@media (min-width: 1100px) {
  #app {
    display: grid;
    grid-template-areas:
      "nav header"
      "nav content";
    grid-template-columns: var(--nav-w) 1fr;
    grid-template-rows: var(--header-h) 1fr;
  }

  .app-header   { grid-area: header; }
  #main-content { grid-area: content; }

  .bottom-nav {
    grid-area: nav;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: var(--nav-w);
    border-top: none;
    border-right: 1px solid var(--border);
    background: var(--bg-2);
    padding: 24px 0 0;
    gap: 0;
    /* reset mobile grid */
    grid-template-columns: unset;
  }

  .nav-btn {
    height: 76px;
    width: 100%;
    border-radius: 0;
    flex-direction: column;
    gap: 5px;
    padding: 0 8px;
  }

  .nav-btn.active::before {
    top: 50%; left: 0;
    transform: translateY(-50%);
    width: 3px; height: 32px;
    border-radius: 0 3px 3px 0;
    box-shadow: 2px 0 10px var(--green);
  }

  .bubble { max-width: 60%; font-size: 15px; }

  .chat-messages { padding: 20px 24px; }
  .chat-input-row { padding: 12px 24px 16px; }

  .study-intro { padding: 18px 24px 6px; max-width: 1100px; margin: 0 auto; }
  .picker-grid { max-width: 1100px; margin: 0 auto; padding: 12px 24px; }

  /* Bigger touch targets / arrows on desktop */
  .ss-arrow { width: 52px; height: 52px; font-size: 30px; }
  .ss-prev  { left: 18px; }
  .ss-next  { right: 18px; }
  .slideshow-controls { padding-left: 24px; padding-right: 24px; }
}

/* ── Large desktop (1400px+) ── */
@media (min-width: 1400px) {
  :root { --nav-w: 100px; }
  .nav-btn span { font-size: 9px; }
  .picker-grid { grid-template-columns: repeat(3, 1fr); }
  .chat-messages { padding: 24px 32px; }
  .bubble { max-width: 55%; }
}
