/* ==========================================================================
   Sunotes — calm study theme
   Quiet colours, no decorative motion, lots of room for the document.
   ========================================================================== */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --canvas: #ebeae5;          /* area behind the document pages */
  --text: #1f2328;
  --muted: #6a6f76;
  --border: #e2e0da;
  --accent: #2f6f8f;
  --accent-ink: #ffffff;
  --accent-soft: #e4eef3;
  --highlight: #ffeaa0;
  --highlight-word: rgba(47, 111, 143, .25);
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  --radius: 10px;
  --player-h: 72px;
  --side-w: 340px;
  --read-font: Literata, Georgia, "Noto Sans Devanagari", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1e2124;
    --surface-2: #262a2e;
    --canvas: #121416;
    --text: #e6e6e3;
    --muted: #9aa0a6;
    --border: #30353a;
    --accent: #7fb3cc;
    --accent-ink: #10181c;
    --accent-soft: #22323a;
    --highlight: rgba(255, 214, 102, .32);
    --highlight-word: rgba(127, 179, 204, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, "Noto Sans Devanagari", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
kbd {
  font: 11px/1 ui-monospace, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font: 500 14px Inter, sans-serif;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--text); background: var(--surface-2); }
.btn-lg { padding: 12px 26px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn svg { width: 17px; height: 17px; fill: currentColor; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Top bar ---------- */
.topbar {
  height: 56px;
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  border-radius: 8px; padding: 4px 6px 4px 2px; margin-left: -2px;
}
.brand:hover { background: var(--surface-2); }
.logo { width: 32px; height: 32px; display: block; border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; min-width: 0; }
.file-name {
  color: var(--muted); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw;
}

/* ---------- Home ---------- */
.upload-screen { flex: 1; overflow-y: auto; }
.home { width: min(1080px, 100%); margin: 0 auto; padding: 56px 24px 32px; }

.hero {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 48px;
  align-items: center;
}
.eyebrow {
  display: inline-block;
  margin: 0 0 14px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px; font-weight: 600;
}
.hero h1 {
  font: 700 clamp(32px, 4.6vw, 48px)/1.12 Inter, sans-serif;
  letter-spacing: -.025em;
  margin: 0 0 16px;
}
.lead { color: var(--muted); font-size: 18px; line-height: 1.6; margin: 0 0 22px; max-width: 520px; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 15px; }
.hero-points li { position: relative; padding-left: 28px; }
.hero-points li::before {
  content: ""; position: absolute; left: 0; top: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-soft) no-repeat center / 12px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2 5 8.5l4.5-5' fill='none' stroke='%232f6f8f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.drop-zone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 44px 28px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: border-color .15s, background .15s;
}
.drop-zone:hover { border-color: var(--accent); }
.drop-zone.drag { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 52px; height: 52px; color: var(--accent); }
.drop-title { font-size: 18px; font-weight: 600; margin: 10px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0; }

.home h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 14px; }

/* Continue where you left off */
.recent { margin-top: 56px; }
.recent-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.recent-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.file-badge {
  flex: none; width: 42px; height: 50px; border-radius: 6px;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px;
  font-size: 10px; font-weight: 700; color: #fff; letter-spacing: .04em;
}
.file-badge.pdf { background: #c2493d; }
.file-badge.docx { background: #2f5fa8; }
.recent-info { flex: 1; min-width: 0; }
.recent-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.recent-bar { height: 4px; border-radius: 2px; background: var(--border); margin-top: 8px; overflow: hidden; }
.recent-bar div { height: 100%; background: var(--accent); }
.recent-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.recent-actions .btn { padding: 6px 12px; font-size: 13px; }
.recent-remove { border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; padding: 2px 4px; }
.recent-remove:hover { color: var(--text); text-decoration: underline; }

/* How it works */
.how { margin-top: 56px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.steps li { display: flex; gap: 14px; align-items: flex-start; }
.step-num {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px;
}
.steps b { font-size: 15px; }
.steps p { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }

/* Feature cards */
.feature-grid { margin-top: 48px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.feature {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.feature svg {
  width: 36px; height: 36px; padding: 7px; border-radius: 10px;
  background: var(--accent-soft); stroke: var(--accent); fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.feature b { display: block; margin-top: 12px; font-size: 15px; }
.feature p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.home-footer { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; text-align: center; }

/* Resume banner above the document */
.resume-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px 10px 18px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.resume-actions { display: flex; gap: 6px; }
.resume-actions .btn { padding: 6px 14px; font-size: 13px; }

/* ---------- Loading ---------- */
.loading-screen {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: min(300px, 80vw); height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- Reader layout ---------- */
.reader {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr var(--side-w);
  padding-bottom: var(--player-h);
}
.reader.wide { grid-template-columns: 1fr; }
.reader.wide .side { display: none; }
.viewer-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--canvas); }
.viewer-toolbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 6px 12px 6px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tip { font-size: 13px; color: var(--muted); }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.zoom { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.zoom .icon-btn { width: 30px; height: 30px; font-size: 16px; }
#zoomLabel { min-width: 42px; text-align: center; }

.viewer {
  flex: 1;
  overflow: auto;
  padding: 24px 20px 48px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 28px;
  scrollbar-gutter: stable; /* pages are sized to fit; keep the width steady when the scrollbar appears */
  touch-action: manipulation; /* double-tap starts reading instead of zooming */
}

/* PDF pages */
.page {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 3px;
  flex: none;
  margin-inline: auto; /* centred, but still scrollable when zoomed wider than the viewer */
}
.page canvas { display: block; border-radius: 3px; }
.page-num {
  position: absolute; top: -20px; left: 2px;
  font-size: 12px; color: var(--muted);
}
.page.no-text::after {
  content: "No selectable text on this page (scanned image)";
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .7); color: #fff; font-size: 12px;
  padding: 4px 10px; border-radius: 6px;
}

/* Text layer (own implementation, positioned over the canvas) */
.text-layer { position: absolute; inset: 0; overflow: hidden; line-height: 1; z-index: 2; }
.text-layer span {
  position: absolute;
  white-space: pre;
  color: transparent;
  transform-origin: 0 0;
  cursor: pointer;
}
.text-layer span::selection { background: var(--highlight-word); }
.text-layer span.reading { background: rgba(255, 214, 80, .45); border-radius: 2px; }

/* Word pages: a comfortable reading column */
.doc-mode { --doc-zoom: 1; }
.doc-page {
  position: relative;
  flex: none;
  width: min(100%, calc(820px * var(--doc-zoom)));
  margin-inline: auto;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 4px;
  padding: clamp(28px, 6vw, 64px) clamp(22px, 7vw, 76px);
}
.doc-body {
  font-family: var(--read-font);
  font-size: calc(19px * var(--doc-zoom));
  line-height: 1.85;
  color: var(--text);
  overflow-wrap: break-word;
}
.doc-body p { margin: 0 0 1.05em; }
.doc-body h1, .doc-body h2, .doc-body h3, .doc-body h4 { font-family: Inter, sans-serif; line-height: 1.3; margin: 1.4em 0 .6em; }
.doc-body h1 { font-size: 1.6em; }
.doc-body h2 { font-size: 1.35em; }
.doc-body h3 { font-size: 1.15em; }
.doc-body > div > :first-child { margin-top: 0; }
.doc-body ul, .doc-body ol { padding-left: 1.4em; margin: 0 0 1.05em; }
.doc-body li { margin: .3em 0; }
.doc-body table { border-collapse: collapse; width: 100%; margin: 0 0 1.2em; font-size: .9em; }
.doc-body td, .doc-body th { border: 1px solid var(--border); padding: .45em .6em; vertical-align: top; }
.doc-body td p, .doc-body th p { margin: 0; }
.doc-body img { max-width: 100%; height: auto; }
.doc-body a { color: var(--accent); }
.doc-body .sent { cursor: pointer; border-radius: 3px; }
.doc-body .sent::selection { background: var(--highlight-word); }
.doc-body .sent.reading { background: var(--highlight); box-shadow: 0 0 0 2px var(--highlight); }

/* ---------- Side panel ---------- */
.side {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); flex: none; }
.tab {
  flex: 1;
  padding: 13px 10px;
  border: 0; background: none;
  font: 600 14px Inter, sans-serif;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.tab-panel > * { flex-shrink: 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field-label .muted { font-weight: 400; }
select, .music-source input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: 14px Inter, sans-serif;
}
select:focus, .music-source input:focus { outline: none; border-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
input[type=checkbox], input[type=range] { accent-color: var(--accent); }

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}
.segmented button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 16px;
  border-radius: 6px;
  font: 500 14px Inter, "Noto Sans Devanagari", sans-serif;
  cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }

.now-reading {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 14px;
}
.now-text { margin: 8px 0 0; line-height: 1.65; font-size: 15px; font-family: var(--read-font); }
.now-text.hi { font-family: "Noto Sans Devanagari", sans-serif; color: var(--accent); font-size: 16px; }

/* Reading-time stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  min-width: 0;
}
.stat-label { font-size: 11px; color: var(--muted); }
.stat-value { font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-progress { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.stat-progress div { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.stat-note { grid-column: 1 / -1; margin: 0; }

/* ---------- Background music ---------- */
.music {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.music .check { font-weight: 500; }
.music-controls { display: flex; flex-direction: column; gap: 10px; }
.music-controls input[type=range] { width: 100%; }
.music-source { display: flex; gap: 6px; }
.music-source input { flex: 1; min-width: 0; font-size: 13px; }
.music-source .btn { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
#musicName { margin: 0; }
/* YouTube requires embedded players to be visible and at least 200×200. */
.music-player { width: 100%; height: 200px; border-radius: 8px; overflow: hidden; background: #000; }
.music-player iframe { display: block; }

/* ---------- Notes ---------- */
.notes-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.download-group { display: flex; gap: 6px; }
.download-group .btn { padding: 6px 11px; font-size: 13px; }
.notes-list { display: flex; flex-direction: column; gap: 12px; }
.note-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}
.note-card.current { border-color: var(--accent); }
.note-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.note-page { font-size: 12px; font-weight: 600; color: var(--accent); }
.note-title { margin: 2px 0 8px; font-size: 15px; line-height: 1.4; }
.note-card h4 { margin: 10px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.note-card ul { margin: 0; padding-left: 18px; }
.note-card li { font-size: 14px; line-height: 1.6; margin: 3px 0; }
.note-tools { display: flex; gap: 4px; flex: none; }
.note-tools button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 6px; padding: 3px 7px; font-size: 12px; cursor: pointer;
}
.note-tools button:hover { background: var(--surface-2); }
.notes-list .hi, .print-area .hi { font-family: "Noto Sans Devanagari", sans-serif; }

/* ---------- Player ---------- */
.player {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--player-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px;
  z-index: 10;
}
.player-controls { display: flex; align-items: center; gap: 8px; }
.play-btn {
  width: 50px; height: 50px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
}
.play-btn:hover { filter: brightness(1.07); }
.play-btn svg { width: 22px; height: 22px; fill: currentColor; }
.play-btn .i-pause, .play-btn.playing .i-play { display: none; }
.play-btn.playing .i-pause { display: block; }
.seek { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.seek input { flex: 1; min-width: 0; }
#seekLabel { white-space: nowrap; }
.time-left {
  white-space: nowrap;
  font-size: 13px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--player-h) + 16px); transform: translateX(-50%);
  background: #1f2328; color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 14px; max-width: min(520px, calc(100vw - 32px));
  box-shadow: var(--shadow);
  z-index: 20;
}

.print-area { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 28px; }
  .home { padding-top: 32px; }
  .steps { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
  body { height: auto; min-height: 100%; }
  .reader, .reader.wide { grid-template-columns: 1fr; }
  .viewer { max-height: 70vh; padding: 16px 10px 32px; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
  .reader.wide .side { display: flex; } /* panel sits below the document on small screens */
  #panelToggle, .tip { display: none; }
  .player { gap: 10px; padding: 0 10px; }
  .player .icon-btn { width: 34px; height: 34px; }
  .player .icon-btn svg { width: 14px; height: 14px; }
  .play-btn { width: 44px; height: 44px; }
  #stopBtn { display: none; }
}
@media (max-width: 520px) {
  :root { --player-h: 104px; }
  .topbar { padding: 0 12px; }
  body:has(#readerScreen:not([hidden])) .brand-name,
  body:has(#readerScreen:not([hidden])) .file-name { display: none; }
  #changeFileBtn { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .player { flex-direction: column; justify-content: center; gap: 6px; }
  .seek { width: 100%; gap: 8px; }
  #seekLabel { display: none; }
  .home { padding: 24px 16px; }
  .feature-grid { grid-template-columns: 1fr; }
  .recent-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; }
}

/* ---------- Print (Save notes as PDF) ---------- */
@media print {
  body { background: #fff; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; color: #000; font-family: Inter, "Noto Sans Devanagari", sans-serif; }
  .print-area h1 { font-size: 22px; }
  .print-area section { page-break-inside: avoid; border-bottom: 1px solid #ccc; padding: 8px 0 12px; }
  .print-area h2 { font-size: 16px; margin: 6px 0; }
  .print-area h3 { font-size: 12px; text-transform: uppercase; color: #555; margin: 8px 0 2px; }
  .print-area li { font-size: 13px; line-height: 1.5; }
}
