/* Night & gold. Dark at night, light in the daytime: follows the phone. */
:root {
  --bg: #FAF5EA;
  --card: #FFFFFF;
  --card-2: #F3ECDC;
  --line: #E8DFCB;
  --ink: #1B2333;
  --ink-2: #3B4252;
  --muted: #5E6678;
  --gold: #B08A3E;        /* lines, beads, borders */
  --gold-text: #7A5C22;   /* gold used as text: darker so it reads on cream */
  --gold-soft: #E2D3B0;
  --btn: #8A6A2B;        /* gold button: dark enough for white text */
  --on-gold: #FFFFFF;
  --danger: #A33A2C;
  --toast-bg: #1B2333;
  --toast-ink: #FAF5EA;
  --toast-act: #E5C47F;
  --shadow: 0 1px 2px rgba(27, 35, 51, 0.06);
  --ar: 'Amiri', 'Geeza Pro', serif;
  --quran: 'Amiri Quran', 'Amiri', serif;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1726;
    --card: #16223A;
    --card-2: #131F35;
    --line: #26334A;
    --ink: #F3EBDD;
    --ink-2: #D9D0C0;
    --muted: #A9B2C3;
    --gold: #D4AF6A;
    --gold-text: #D4AF6A;
    --gold-soft: #5C5033;
    --btn: #D4AF6A;
    --on-gold: #0E1726;
    --danger: #E07A6A;
    --toast-bg: #F3EBDD;
    --toast-ink: #0E1726;
    --toast-act: #7A5C22;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

.screen { position: relative; min-height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }

/* The faint star in the corner */
.screen::before {
  content: ''; position: fixed; top: -110px; right: -110px; width: 320px; height: 320px; pointer-events: none; opacity: 0.1; z-index: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%23C9A55E' stroke-width='0.8'%3E%3Crect x='20' y='20' width='60' height='60'/%3E%3Crect x='20' y='20' width='60' height='60' transform='rotate(45 50 50)'/%3E%3Ccircle cx='50' cy='50' r='18'/%3E%3Ccircle cx='50' cy='50' r='42'/%3E%3C/g%3E%3C/svg%3E") no-repeat;
}
.screen > * { position: relative; z-index: 1; }

.iconbtn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--gold-text); border-radius: 22px; flex-shrink: 0; }
.iconbtn svg { width: 22px; height: 22px; }
.display { font-family: var(--serif); font-weight: 600; letter-spacing: 0.3px; }
.ar { font-family: var(--ar); direction: rtl; }
.quran { font-family: var(--quran); direction: rtl; }

/* ---------- list ---------- */
.lhead { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-top) + 24px) 20px 2px 20px; }
.lhead h1 { margin: 0; font-size: 40px; }
.addbtn { width: 48px; height: 48px; border-radius: 24px; border: 1px solid var(--gold-soft); color: var(--gold-text); display: flex; align-items: center; justify-content: center; }
.addbtn svg { width: 22px; height: 22px; }
.hint { margin: 0; padding: 0 20px 16px; font-size: 13px; color: var(--muted); }
.rows { display: flex; flex-direction: column; gap: 10px; padding: 0 16px calc(var(--safe-bottom) + 130px); }

.row { position: relative; border-radius: 16px; touch-action: pan-y; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.row-del { position: absolute; inset: 0; border-radius: 16px; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: flex-end; padding-right: 22px; font-weight: 600; font-size: 15px; opacity: 0; }
.row.swiping .row-del { opacity: 1; }
.row-in { position: relative; background: var(--card); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); transition: transform 0.2s ease; width: 100%; text-align: left; }
.row.swiping .row-in, .row.dragging .row-in { transition: none; }
.row.dragging { z-index: 5; }
.row.dragging .row-in { box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35), 0 0 0 1.5px var(--gold); transform: scale(1.03) rotate(-1deg); }
.row.new .row-in { box-shadow: inset 0 0 0 1px var(--gold-soft), var(--shadow); }
.row-top { display: flex; align-items: center; gap: 8px; }
.row-title { font-size: 16px; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-prev { font-size: 20px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.6; }
.row-prev.big { font-size: 22px; color: var(--ink); }
.row-prev.latin { font-size: 16px; line-height: 1.4; }
.row-new { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--gold-text); }
.row-new::before { content: ''; width: 7px; height: 7px; border-radius: 4px; background: var(--gold); }
.dots { display: flex; gap: 6px; align-items: center; padding-right: 2px; color: var(--gold-text); font-size: 12px; font-weight: 600; }
.dots i { width: 6px; height: 6px; transform: rotate(45deg); background: var(--gold); display: block; }

.beginbar { position: fixed; left: 0; right: 0; bottom: 0; padding: 28px 16px calc(var(--safe-bottom) + 20px); background: linear-gradient(to bottom, transparent, var(--bg) 40%); z-index: 4; max-width: 560px; margin: 0 auto; }
.begin { width: 100%; height: 60px; border-radius: 30px; background: var(--btn); color: var(--on-gold); display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 17px; font-weight: 700; }
.begin svg { width: 20px; height: 20px; }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.empty p { margin: 0; color: var(--muted); font-size: 15px; }

/* ---------- reader ---------- */
.reader { height: 100dvh; min-height: 0; overflow: hidden; }
.progress { display: flex; gap: 4px; padding: calc(var(--safe-top) + 12px) 20px 0; }
.progress span { flex: 1; height: 2px; background: var(--line); border-radius: 1px; }
.progress span.on { background: var(--gold); }
.progress .fill { flex: none; height: 2px; background: var(--gold); }
.rhead { display: flex; align-items: center; gap: 2px; padding: 6px 8px 0; transition: opacity 0.6s ease; }
.rhead.faded { opacity: 0; pointer-events: none; }
.rhead .rtitle { flex: 1; min-width: 0; font-family: var(--serif); font-size: 20px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 2px; }
.sizebtn { font-weight: 600; color: var(--gold-text); }
.reveal { position: absolute; left: 0; right: 0; top: 0; height: calc(var(--safe-top) + 64px); z-index: 3; }
.rbody { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; padding: 8px 28px 16px; }
.rbody-in { margin: auto 0; display: flex; flex-direction: column; gap: 22px; }
.ornament { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--gold); }
.ornament .ln { width: 40px; height: 1px; background: var(--gold); opacity: 0.6; }
.ornament svg { width: 14px; height: 14px; }
.rtext { margin: 0; text-align: center; line-height: 2.1; white-space: pre-line; overflow-wrap: break-word; width: 100%; }
.rtext.latin { font-family: var(--sans); line-height: 1.55; font-weight: 500; }
.rtext.counts { cursor: pointer; }
.beads { display: flex; justify-content: center; flex-wrap: wrap; gap: 16px; }
.beads i { width: 12px; height: 12px; border: 1.5px solid var(--gold); transform: rotate(45deg); display: block; transition: transform 0.25s ease, background 0.25s ease; }
.beads i.on { background: var(--gold); }
.beads i.last { transform: rotate(45deg) scale(1.3); }
.bigcount { text-align: center; font-family: var(--sans); font-variant-numeric: tabular-nums; font-size: 44px; font-weight: 600; letter-spacing: -1px; color: var(--gold-text); line-height: 1; }
.bigcount small { font-size: 22px; letter-spacing: 0; font-weight: 500; color: var(--muted); }
.meaning { margin: 0; font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 20px; line-height: 1.45; color: var(--ink-2); text-align: center; white-space: pre-line; }
.meta { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 12px; }
.source { font-size: 12px; letter-spacing: 1.2px; color: var(--muted); text-transform: uppercase; text-align: center; }
.chip { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--gold-soft); color: var(--gold-text); font-size: 13px; font-weight: 600; }
.chip.open { background: var(--card); }
.virtue { background: var(--card); border-radius: 14px; padding: 14px 16px; font-size: 15px; line-height: 1.55; color: var(--ink-2); white-space: pre-line; box-shadow: inset 0 0 0 1px var(--line); }
.checkbar { background: var(--card); border-radius: 16px; padding: 10px 8px 10px 16px; display: flex; align-items: center; gap: 10px; box-shadow: inset 0 0 0 1px var(--gold-soft); }
.checkbar::before { content: ''; width: 8px; height: 8px; border-radius: 4px; background: var(--gold); flex-shrink: 0; }
.checkbar span { flex: 1; font-size: 13px; line-height: 1.4; color: var(--ink-2); }
.checkbar button { height: 40px; padding: 0 14px; border-radius: 20px; background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 700; flex-shrink: 0; }
.rfoot { min-height: 104px; padding-bottom: var(--safe-bottom); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.rfoot .hintline { font-size: 13px; color: var(--muted); }
.next { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 24px; border-radius: 26px; border: 1px solid var(--gold); color: var(--gold-text); font-size: 15px; font-weight: 600; }
.next svg { width: 18px; height: 18px; }
.slide-l { animation: slideL 0.25s ease; }
.slide-r { animation: slideR 0.25s ease; }
@keyframes slideL { from { opacity: 0; transform: translateX(30px); } }
@keyframes slideR { from { opacity: 0; transform: translateX(-30px); } }

/* ---------- editor ---------- */
.ehead { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-top) + 14px) 8px 8px; position: sticky; top: 0; background: var(--bg); z-index: 3; }
.ehead h1 { margin: 0; font-size: 21px; }
.ehead .txtbtn { height: 44px; padding: 0 12px; font-size: 16px; color: var(--muted); }
.ehead .save { color: var(--gold-text); font-weight: 700; }
.ehead .save:disabled { color: var(--muted); opacity: 0.6; cursor: default; }
.ebody { display: flex; flex-direction: column; gap: 18px; padding: 8px 16px calc(var(--safe-bottom) + 40px); }
.pastebig { height: 210px; border-radius: 20px; border: 1.5px dashed var(--gold); background: var(--card-2); color: var(--gold-text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.pastebig svg { width: 40px; height: 40px; }
.pastebig b { font-size: 20px; }
.pastebig .sub { font-size: 13px; color: var(--muted); }
.pastebox { width: 100%; min-height: 140px; border-radius: 16px; border: 1px dashed var(--gold); background: var(--card-2); color: var(--ink); font: inherit; font-size: 16px; padding: 14px; resize: none; }
.banner { display: flex; align-items: center; gap: 8px; border: 1px solid var(--gold-soft); color: var(--gold-text); border-radius: 12px; padding: 6px 6px 6px 14px; font-size: 13px; font-weight: 600; }
.banner span { flex: 1; }
.banner button { height: 36px; padding: 0 10px; font-weight: 700; color: var(--gold-text); }
.section-label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 1.2px; text-transform: uppercase; }
.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.field { display: flex; align-items: flex-start; gap: 8px; padding: 4px 6px 4px 16px; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field label { width: 76px; flex-shrink: 0; font-size: 15px; color: var(--muted); padding-top: 13px; }
.field textarea { flex: 1; min-width: 0; min-height: 48px; border: 0; outline: none; font: inherit; font-size: 15px; line-height: 1.45; background: transparent; color: var(--ink); resize: none; padding: 13px 0; overflow: hidden; }
.field .iconbtn { color: var(--muted); }
.field .iconbtn svg { width: 20px; height: 20px; }
.textcard { padding: 12px 8px 12px 18px; gap: 4px; }
.textcard-top { display: flex; align-items: center; gap: 8px; }
.textcard-top .section-label { flex: 1; font-size: 11px; }
.textcard textarea { width: 100%; border: 0; outline: none; background: transparent; color: var(--ink); resize: none; overflow: hidden; font-size: 25px; line-height: 2; padding: 0 10px 0 0; }
.textcard textarea.latin { font-family: var(--sans); font-size: 17px; line-height: 1.5; }
.stepper { display: flex; flex-direction: row; align-items: center; gap: 8px; padding: 4px 6px 4px 16px; }
.stepper > span { flex: 1; font-size: 15px; color: var(--muted); }
.stepper button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 22px; color: var(--gold-text); font-size: 20px; }
.stepper b { min-width: 52px; text-align: center; font-size: 16px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px 12px; }
.quick button { height: 36px; min-width: 48px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--line); color: var(--ink-2); font-size: 14px; }
.quick button.on { border-color: var(--gold); color: var(--gold-text); font-weight: 700; }
.danger { height: 52px; border-radius: 16px; color: var(--danger); background: var(--card); font-weight: 600; box-shadow: var(--shadow); }
.note { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.45; }

/* ---------- sign in ---------- */
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; }
.center .logo { width: 88px; height: 88px; border-radius: 22px; }
.center h1 { margin: 0; font-size: 42px; }
.center p { margin: 0; color: var(--muted); max-width: 320px; line-height: 1.5; }
.center code { font-size: 13px; background: var(--card); padding: 2px 6px; border-radius: 6px; }
.primary { height: 56px; padding: 0 28px; border-radius: 28px; background: var(--btn); color: var(--on-gold); font-size: 16px; font-weight: 700; display: inline-flex; align-items: center; gap: 10px; }
.primary:disabled { opacity: 0.6; }
.narrow { width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.narrow label { font-size: 13px; color: var(--muted); }
.narrow input { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; padding: 0 14px; }
.error { color: var(--danger) !important; min-height: 1.4em; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--safe-bottom) + 100px); max-width: 528px; margin: 0 auto; background: var(--toast-bg); color: var(--toast-ink); border-radius: 14px; padding: 4px 4px 4px 18px; min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); z-index: 20; font-size: 15px; }
#toast button { height: 44px; padding: 0 16px; font-weight: 700; color: var(--toast-act); }

/* iOS has no vibrate API; toggling a hidden switch gives a light tap instead. */
.haptic { position: fixed; left: -100px; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; }

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