/* Pearl Reader — the students' app. Mobile first; follows the system theme. */
:root {
  --bg: #f4f7fa;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #111d23;
  --muted: #5b6e79;
  --border: #dde5ec;
  --primary: #002d5b;
  --on-primary: #ffffff;
  --accent: #ef8633;
  --accent-tint: rgba(239, 134, 51, 0.16);
  --word: rgba(239, 134, 51, 0.42);
  --success: #00a383;
  --error: #d64535;
  --shadow: 0 1px 2px rgba(17, 29, 35, 0.06), 0 4px 16px rgba(17, 29, 35, 0.06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1628;
    --surface: #112240;
    --surface-2: #162a4b;
    --text: #e4e9f2;
    --muted: #8fa0b8;
    --border: #213a5e;
    --primary: #6eaadc;
    --on-primary: #0b1628;
    --accent-tint: rgba(239, 134, 51, 0.2);
    --word: rgba(239, 134, 51, 0.5);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Manrope", -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: default;
}
.hidden {
  display: none !important;
}
.muted {
  color: var(--muted);
  margin: 0;
}
.error {
  color: var(--error);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 0;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.row {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ── Controls ── */
.field {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  outline: none;
  min-height: 46px;
}
.field:focus {
  border-color: var(--primary);
}
.field.code {
  text-align: center;
  letter-spacing: 0.4em;
  font-size: 1.3rem;
}
.label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 46px;
  padding: 0 1.1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
}
.btn.primary {
  background: var(--primary);
  color: var(--on-primary);
}
.btn.ghost {
  background: var(--surface);
  border-color: var(--border);
}
.btn.danger {
  background: var(--error);
  color: #fff;
}
.link {
  background: none;
  border: 0;
  color: var(--primary);
  font-weight: 600;
  padding: 0.25rem;
}
.icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: transparent;
}
.icon:hover:not(:disabled) {
  background: var(--surface-2);
}
.icon:disabled {
  opacity: 0.35;
}

/* ── Screens ── */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  flex: 1;
  padding-left: 0.25rem;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
  background-size: cover;
}

/* ── Sign in ── */
.signin {
  justify-content: center;
  align-items: center;
  padding: 1.5rem 1rem;
}
.signin-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: center;
}
.signin-card h1 {
  margin: 0;
  font-size: 1.6rem;
}
.signin-logo {
  margin: 0 auto;
}
.or {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.or::before,
.or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Library ── */
.library {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 72px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
}
.drop.over,
.drop:hover {
  border-color: var(--primary);
}
.drop.busy {
  pointer-events: none;
  color: var(--muted);
}
.docs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.doc {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.5rem 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.doc-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
}
.doc-icon {
  flex: none;
  width: 40px;
  height: 48px;
  border-radius: 6px;
  background: var(--accent-tint);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  font-weight: 800;
}
.doc-text {
  min-width: 0;
}
.doc-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-meta {
  font-size: 0.8rem;
  color: var(--muted);
}
.doc-meta .ready {
  color: var(--success);
  font-weight: 600;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

/* ── Reader ── */
.reader {
  height: 100dvh;
  min-height: 0;
}
.title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.page-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
}
.page {
  position: relative;
  max-width: 860px;
  margin: 0 auto;
  background: #fff;
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 200px;
}
.page img {
  display: block;
  width: 100%;
  height: auto;
}
.page.loading img {
  opacity: 0.4;
}
.marks {
  position: absolute;
  inset: 0;
}
.mark {
  position: absolute;
  border-radius: 3px;
  cursor: pointer;
}
.mark.sent {
  background: var(--accent-tint);
}
.mark.word {
  background: var(--word);
}

/* Discuss */
.discuss {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 55%;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.chat {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.chat-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
  text-align: center;
}
.msg {
  max-width: 88%;
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.you {
  align-self: flex-end;
  background: var(--primary);
  color: var(--on-primary);
  border-bottom-right-radius: 4px;
}
.msg.pearl {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-left-radius: 4px;
}
.msg.pearl.thinking {
  color: var(--muted);
}
.ask {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border);
}
.ask .field {
  min-height: 44px;
  border-radius: 22px;
}
.mic.on {
  background: var(--error);
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    box-shadow: 0 0 0 8px rgba(214, 69, 53, 0.15);
  }
}

/* Dock */
.dock {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}
.progress {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.4rem;
}
.progress-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s ease;
}
.progress.ready .progress-fill {
  background: var(--success);
}
.progress-text {
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 1.1em;
}
.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}
.modes {
  display: inline-flex;
  justify-self: start;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
}
.mode {
  border: 0;
  background: none;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.mode.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.transport {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.play {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.play:disabled {
  opacity: 0.45;
}
.play .i-pause,
.play .spinner,
.play.playing .i-play,
.play.waiting .i-play {
  display: none;
}
.play.playing .i-pause {
  display: block;
}
.play.waiting .spinner {
  display: block;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.page-no {
  justify-self: end;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Sheets */
.sheet {
  border: 0;
  border-radius: 18px;
  padding: 1.25rem;
  width: min(420px, calc(100vw - 2rem));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.sheet::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
.sheet h3 {
  margin: 0;
}

/* Wide screens: the conversation sits beside the page */
@media (min-width: 900px) {
  .reader-body {
    flex-direction: row;
  }
  .discuss {
    max-height: none;
    width: 380px;
    border-top: 0;
    border-left: 1px solid var(--border);
  }
  .dock {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}
@media (max-width: 380px) {
  .mode {
    padding: 0.4rem 0.6rem;
  }
}
