/* Palette and type copied from KhatibNotes (khutbah-app/src/index.css): cream paper, white cards,
   burgundy primary, gold accents; Instrument Serif headings, Work Sans body. Arabic: Scheherazade New. */
:root {
  --background: 33 68% 94%;      /* #FAF0E4 cream paper */
  --foreground: 30 8% 22%;
  --heading: 0 0% 5%;
  --card: 0 0% 100%;
  --primary: 0 100% 25%;         /* #800000 burgundy */
  --primary-deep: 0 100% 16%;
  --primary-foreground: 33 68% 94%;
  --secondary: 40 86% 91%;       /* #FCEFD6 highlight panel */
  --secondary-foreground: 37 100% 19%;
  --muted-foreground: 25 5% 40%;
  --border: 35 40% 86%;
  --input: 35 40% 82%;
  --ring: 40 85% 51%;
  --gold: 32 50% 57%;            /* #C8955A */
  --gold-bright: 40 85% 51%;
  --leaf: 40 70% 97%;            /* reading page, warmer than cards */
  --radius: 0.5rem;
  --font-heading: 'Instrument Serif', 'Noto Serif Display', Georgia, serif;
  --font-body: 'Work Sans', ui-sans-serif, system-ui, sans-serif;
  --font-arabic: 'Scheherazade New', 'Traditional Arabic', serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / .08), 0 1px 2px -1px rgb(0 0 0 / .08);
}
:root[data-theme="dark"] {
  --background: 165 16% 5.5%;
  --foreground: 40 32% 84%;
  --heading: 41 58% 91%;
  --card: 165 12% 8.5%;
  --primary: 40 45% 59%;
  --primary-deep: 36 42% 42%;
  --primary-foreground: 165 16% 6%;
  --secondary: 168 9% 11.5%;
  --secondary-foreground: 40 38% 88%;
  --muted-foreground: 38 18% 64%;
  --border: 162 9% 16%;
  --input: 162 9% 19%;
  --ring: 40 45% 59%;
  --gold: 40 45% 59%;
  --gold-bright: 41 62% 72%;
  --leaf: 160 10% 7.5%;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: hsl(var(--background)); color: hsl(var(--foreground)); font: 15px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { color: hsl(var(--heading)); }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: hsl(var(--muted-foreground)); }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
[lang="ar"], .ar { font-family: var(--font-arabic); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; height: 60px; display: flex; align-items: center; gap: 16px;
  padding: 0 18px; background: hsl(var(--card)); border-bottom: 1px solid hsl(var(--border)); }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; font: 400 24px/1 var(--font-heading); color: hsl(var(--heading)); }
.brand-ar { font-family: var(--font-arabic); color: hsl(var(--primary)); font-size: 26px; font-weight: 700; }
.brand-ar.big { font-size: 64px; font-weight: 400; color: hsl(var(--gold)); line-height: 1.2; }
.jump { flex: 1; max-width: 300px; }
.jump input, .search, .field { width: 100%; padding: 8px 12px; border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card)); color: hsl(var(--foreground)); font: inherit; box-shadow: 0 1px 2px rgb(0 0 0 / .04); }
.jump input:focus, .search:focus, .field:focus { outline: 1px solid hsl(var(--ring)); border-color: hsl(var(--ring)); }
::placeholder { color: hsl(var(--muted-foreground)); opacity: .8; }
.top-tabs { display: flex; gap: 4px; margin-left: auto; background: hsl(var(--secondary)); padding: 3px; border-radius: var(--radius); }
.top-tabs button, .seg button { border: 0; background: none; padding: 5px 14px; border-radius: calc(var(--radius) - 2px); color: hsl(var(--muted-foreground)); font-weight: 500; font-size: 14px; }
.top-tabs button.active, .seg button.active { background: hsl(var(--card)); color: hsl(var(--primary)); box-shadow: var(--shadow); }
.seg { display: inline-flex; gap: 4px; background: hsl(var(--secondary)); padding: 3px; border-radius: var(--radius); }
.icon-btn { border: 1px solid hsl(var(--input)); background: hsl(var(--card)); width: 34px; height: 34px; border-radius: calc(var(--radius) - 2px); flex: none; }
.icon-btn:hover { background: hsl(var(--secondary)); color: hsl(var(--primary)); }
.only-mobile { display: none; }

/* Layout */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr) 460px; height: calc(100vh - 60px); }
.nav { border-right: 1px solid hsl(var(--border)); overflow: auto; padding: 12px; background: hsl(var(--card)); }
.surah-list { list-style: none; margin: 10px 0 0; padding: 0; }
.surah-list li { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px; padding: 8px;
  border-radius: calc(var(--radius) - 2px); cursor: pointer; }
.surah-list li:hover { background: hsl(var(--secondary)); }
.surah-list li.active { background: hsl(var(--secondary)); }
.surah-list li.active .en { color: hsl(var(--primary)); }
.surah-list .num { width: 30px; height: 30px; display: grid; place-items: center; font-size: 12px; font-weight: 500;
  color: hsl(var(--gold)); border: 1px solid hsl(var(--border)); border-radius: 6px; transform: rotate(45deg); }
.surah-list .num b { transform: rotate(-45deg); font-weight: 500; }
.surah-list li.active .num { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: hsl(var(--primary)); }
.surah-list .en { font-weight: 500; font-size: 14px; color: hsl(var(--heading)); }
.surah-list .sub { font-size: 12px; color: hsl(var(--muted-foreground)); }
.surah-list .ar { font-size: 20px; font-weight: 700; color: hsl(var(--foreground)); }
.surah-list .dot { display: inline-block; width: 6px; height: 6px; background: hsl(var(--gold-bright)); border-radius: 50%; margin-left: 6px; vertical-align: middle; }

.reader, .notebook { overflow: auto; padding: 24px clamp(16px, 4vw, 56px) 96px; }
.reader > *, .notebook > * { max-width: 900px; margin-left: auto; margin-right: auto; }

/* Surah header, quran.com style */
.surah-header { text-align: center; padding: 8px 0 22px; }
.surah-header .frame { border: 1px solid hsl(var(--border)); border-radius: 12px; padding: 20px 16px 16px;
  background: linear-gradient(180deg, hsl(var(--card)), hsl(var(--leaf))); box-shadow: var(--shadow); position: relative; }
.surah-header .frame::before, .surah-header .frame::after { content: "۞"; position: absolute; top: 50%; transform: translateY(-50%);
  font-family: var(--font-arabic); color: hsl(var(--gold)); font-size: 26px; opacity: .7; }
.surah-header .frame::before { left: 22px; } .surah-header .frame::after { right: 22px; }
.surah-header .ar { font-size: 44px; font-weight: 700; color: hsl(var(--primary)); line-height: 1.5; }
.surah-header h1 { margin: 2px 0; font: 400 30px/1.2 var(--font-heading); }
.surah-header .meta { color: hsl(var(--muted-foreground)); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.surah-tools { display: flex; justify-content: center; margin-top: 18px; }
.bismillah { font-family: var(--font-arabic); font-size: 36px; margin-top: 22px; color: hsl(var(--heading)); line-height: 1.8; }

/* Translation mode: one row per ayah, actions at the left like quran.com */
.verse { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 20px; padding: 28px 8px 26px;
  border-bottom: 1px solid hsl(var(--border)); cursor: pointer; transition: background .15s; }
.verse:hover { background: hsl(var(--leaf)); }
.verse.active { background: hsl(var(--secondary)); border-radius: var(--radius); }
.verse.playing .arabic { color: hsl(var(--primary)); }
.verse-actions { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.verse-key { font-size: 13px; font-weight: 500; color: hsl(var(--muted-foreground)); margin-bottom: 4px; }
.verse.active .verse-key { color: hsl(var(--primary)); }
.act { width: 30px; height: 30px; border: 0; background: none; border-radius: 50%; display: grid; place-items: center;
  color: hsl(var(--muted-foreground)); }
.act:hover { background: hsl(var(--border)); color: hsl(var(--primary)); }
.act svg { width: 17px; height: 17px; }
.act.has-note { color: hsl(var(--gold-bright)); }
.arabic { font-family: var(--font-arabic); font-size: var(--ar-size, 34px); line-height: 2.15; direction: rtl; text-align: right;
  color: hsl(var(--heading)); word-spacing: .12em; }
.ayah-end { color: hsl(var(--gold)); font-size: .92em; margin-inline-start: .2em; white-space: nowrap; }
.translation { font-size: 17px; line-height: 1.75; margin-top: 14px; color: hsl(var(--foreground)); }
.translator { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 6px; }

/* Notebook annotations under each ayah: a margin line and ruled writing lines */
.annots { margin-top: 16px; padding-left: 16px; border-left: 2px solid hsl(var(--primary) / .35); cursor: text; }
.annot { position: relative; padding: 2px 0 6px; margin-bottom: 8px; border-bottom: 1px dashed hsl(var(--border)); }
.annot-body { font-size: 15px; line-height: 1.7; }
.annot-body > :first-child { margin-top: 0; } .annot-body > :last-child { margin-bottom: 4px; }
.annot-body ul, .annot-body ol { padding-left: 18px; margin: 4px 0; }
.annot-body p { margin: 4px 0; }
.annot-body > p:last-child > em:only-child { color: hsl(var(--muted-foreground)); font-size: 13px; }
.annot.formatting .annot-body { opacity: .75; }
.annot-tools { display: flex; gap: 2px; align-items: center; font-size: 12px; min-height: 22px; }
.annot-state { color: hsl(var(--gold)); margin-right: auto; font-weight: 500; }
.annot.formatting .annot-state { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.annot-tools button { border: 0; background: none; padding: 2px 7px; border-radius: 4px; color: hsl(var(--muted-foreground)); font-size: 12px; opacity: 0; transition: opacity .15s; }
.annot:hover .annot-tools button, .annot:focus-within .annot-tools button { opacity: 1; }
.annot-tools button:hover { background: hsl(var(--border)); color: hsl(var(--primary)); }
.annot-input, .annot-edit { display: block; width: 100%; border: 0; outline: 0; resize: none; overflow: hidden; background-color: transparent;
  color: hsl(var(--foreground)); font: 15px/28px var(--font-body); padding: 0; min-height: 28px;
  background-image: repeating-linear-gradient(transparent, transparent 27px, hsl(var(--border)) 27px, hsl(var(--border)) 28px); }
.annot-input::placeholder { font-style: italic; opacity: .6; }
.annot-input:focus, .annot-edit { background-image: repeating-linear-gradient(transparent, transparent 27px, hsl(var(--gold) / .6) 27px, hsl(var(--gold) / .6) 28px); }
@media (hover: none) { .annot-tools button { opacity: 1; } }

/* Reading mode: continuous mushaf-style text */
.reading { font-family: var(--font-arabic); direction: rtl; text-align: justify; text-align-last: center;
  font-size: calc(var(--ar-size, 34px) + 2px); line-height: 2.3; color: hsl(var(--heading)); padding: 18px 8px; }
.reading .ayah { cursor: pointer; border-radius: 6px; padding: 2px 0; transition: background .15s; }
.reading .ayah:hover { background: hsl(var(--leaf)); }
.reading .ayah.active { background: hsl(var(--secondary)); }
.reading .ayah.playing { color: hsl(var(--primary)); }
.reading .ayah.has-note .ayah-end { color: hsl(var(--gold-bright)); font-weight: 700; }

/* Audio bar */
.audio-bar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 15; display: flex; align-items: center; gap: 12px;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: 999px; padding: 6px 8px 6px 16px; box-shadow: 0 8px 28px rgb(0 0 0 / .14); font-size: 14px; }

/* Panel */
.panel { border-left: 1px solid hsl(var(--border)); background: hsl(var(--card)); overflow: auto; }
.panel-empty { padding: 60px 30px; text-align: center; color: hsl(var(--muted-foreground)); }
.panel-body { padding: 16px 18px 60px; }
.panel-head { display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; }
.eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; color: hsl(var(--gold)); font-weight: 600; }
.panel-ayah { font-family: var(--font-arabic); font-size: 25px; line-height: 2; margin-top: 4px; max-height: 150px; overflow: auto; color: hsl(var(--heading)); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid hsl(var(--border)); margin: 12px 0 14px; }
.tabs button { border: 0; background: none; padding: 8px 12px; color: hsl(var(--muted-foreground)); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs button.active { color: hsl(var(--primary)); border-color: hsl(var(--primary)); }
.editor { display: grid; gap: 8px; }
textarea.field { resize: vertical; line-height: 1.6; }
.mono { font-family: var(--font-mono) !important; font-size: 13px !important; }
.extra summary { font-size: 13px; color: hsl(var(--muted-foreground)); cursor: pointer; margin-bottom: 6px; }
.btn { border: 1px solid hsl(var(--input)); background: transparent; padding: 7px 14px; border-radius: calc(var(--radius) - 2px);
  font-weight: 500; font-size: 14px; box-shadow: 0 1px 2px rgb(0 0 0 / .05); transition: background .15s, color .15s; }
.btn:hover { background: hsl(var(--secondary)); color: hsl(var(--primary)); }
.btn.primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: hsl(var(--primary)); box-shadow: var(--shadow); }
.btn.primary:hover { background: hsl(var(--primary) / .9); color: hsl(var(--primary-foreground)); }
.btn.primary:disabled { opacity: .6; cursor: wait; }
.btn.ghost { border-color: transparent; box-shadow: none; }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.status { font-size: 13px; color: hsl(var(--muted-foreground)); min-height: 18px; }
.formatted-wrap { margin-top: 18px; border-top: 1px solid hsl(var(--border)); padding-top: 14px; }

.existing-note { border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; background: hsl(var(--leaf)); }
.existing-note:hover { border-color: hsl(var(--gold)); }
.existing-note.editing { border-color: hsl(var(--primary)); background: hsl(var(--secondary)); }
.existing-note .t { font-weight: 500; color: hsl(var(--heading)); }
.existing-note .d { font-size: 12px; color: hsl(var(--muted-foreground)); }

/* Prose (formatted markdown and tafsir text) */
.prose { font-size: 15.5px; line-height: 1.75; overflow-wrap: anywhere; }
.prose h2 { font: 400 26px/1.25 var(--font-heading); margin: 8px 0 10px; color: hsl(var(--primary)); }
.prose h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; color: hsl(var(--gold)); margin: 22px 0 6px; font-weight: 600; }
.prose strong { color: hsl(var(--heading)); }
.prose blockquote { margin: 10px 0; padding: 10px 16px; border-left: 3px solid hsl(var(--gold)); background: hsl(var(--secondary)); border-radius: 0 var(--radius) var(--radius) 0; }
.prose blockquote p { margin: 4px 0; }
.prose blockquote p:first-child { font-family: var(--font-arabic); font-size: 24px; line-height: 2; direction: rtl; text-align: right; color: hsl(var(--heading)); }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 3px 0; }
.prose code { font-family: var(--font-mono); font-size: 13px; }
.tafsir-text { margin-top: 12px; }
.tafsir-text.rtl { direction: rtl; font-family: var(--font-arabic); font-size: 21px; line-height: 2.1; }
.tafsir-text h2 { font-size: 22px; }
.tafsir-text .arabic, .tafsir-text [lang="ar"] { font-size: 23px; line-height: 2; }

/* Notebook */
.notebook-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.notebook-head h2 { font: 400 34px/1.1 var(--font-heading); margin: 0; }
.notebook-head .search { width: 260px; }
.notebook-list { display: grid; gap: 14px; }
.nb-card { background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: 12px; padding: 20px 24px; box-shadow: var(--shadow); }
.nb-card .nb-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.badge { font-size: 12px; color: hsl(var(--primary)); background: hsl(var(--secondary)); padding: 2px 10px; border-radius: 999px; font-weight: 500; text-decoration: none; }
.tag { font-size: 12px; border: 1px solid hsl(var(--border)); padding: 1px 8px; border-radius: 999px; color: hsl(var(--muted-foreground)); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 230px minmax(0, 1fr); }
  .panel { position: fixed; right: 0; top: 60px; bottom: 0; width: min(460px, 100vw); box-shadow: -8px 0 30px rgb(0 0 0 / .15); z-index: 20; transform: translateX(100%); transition: transform .2s; }
  .panel.open { transform: none; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .nav { position: fixed; top: 60px; bottom: 0; left: 0; width: 280px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .nav.open { transform: none; box-shadow: 8px 0 30px rgb(0 0 0 / .15); }
  .only-mobile { display: inline-block; }
  .brand { font-size: 20px; }
  .topbar { gap: 8px; padding: 0 12px; }
  .top-tabs button { padding: 5px 9px; }
  .verse { grid-template-columns: 1fr; gap: 8px; padding: 20px 4px; }
  .verse-actions { flex-direction: row; }
  .verse-key { margin: 0 6px 0 0; }
  :root { --ar-size: 28px; }
  .surah-header .frame::before, .surah-header .frame::after { display: none; }
}
