/* ===== Theme variables ===== */
:root, [data-theme="midnight"] {
  color-scheme: dark;
  --bg:#0f172a; --surface:#1e293b; --inset:#0f172a; --border:#334155;
  --text:#e2e8f0; --muted:#94a3b8; --accent:#38bdf8; --ink:#0f172a; --accent2:#a5b4fc;
}
[data-theme="light"] {
  color-scheme: light;
  --bg:#f1f5f9; --surface:#ffffff; --inset:#f8fafc; --border:#e2e8f0;
  --text:#0f172a; --muted:#64748b; --accent:#2563eb; --ink:#ffffff; --accent2:#4338ca;
}
[data-theme="ocean"] {
  color-scheme: dark;
  --bg:#04212b; --surface:#0b3344; --inset:#04212b; --border:#155e75;
  --text:#e0f2fe; --muted:#79a9bd; --accent:#22d3ee; --ink:#04212b; --accent2:#67e8f9;
}
[data-theme="sunset"] {
  color-scheme: dark;
  --bg:#1f1326; --surface:#2d1b36; --inset:#1f1326; --border:#4c2a4e;
  --text:#fde4e1; --muted:#c9a9bf; --accent:#fb7185; --ink:#1f1326; --accent2:#fdba74;
}
[data-theme="forest"] {
  color-scheme: dark;
  --bg:#0f1f17; --surface:#16291f; --inset:#0f1f17; --border:#2f4b3a;
  --text:#dcfce7; --muted:#86a596; --accent:#34d399; --ink:#052e1b; --accent2:#a7f3d0;
}
[data-theme="violet"] {
  color-scheme: dark;
  --bg:#15132b; --surface:#221f3f; --inset:#15132b; --border:#3b376b;
  --text:#e9e7ff; --muted:#a5a0cf; --accent:#a78bfa; --ink:#15132b; --accent2:#c4b5fd;
}
/* Persian: lapis blue, turquoise tiles and gold (کاشی‌کاری ایرانی) */
[data-theme="persian"] {
  color-scheme: dark;
  --bg:#0f2544; --surface:#17365c; --inset:#0f2544; --border:#2a5083;
  --text:#fbf1d6; --muted:#c9b68a; --accent:#2fb8c4; --ink:#06243b; --accent2:#e3b23c;
}

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

body {
  margin: 0; min-height: 100vh;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text); padding: 24px;
  display: flex; justify-content: center;
  transition: background .25s, color .25s;
}
main { width: 100%; max-width: 640px; position: relative; z-index: 1; }

/* Persepolis backdrop, only on the Persian theme */
[data-theme="persian"] body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(6,20,40,.55), rgba(6,20,40,.80)),
    url("persepolis.svg") center bottom / cover no-repeat;
}
[data-theme="persian"] .card,
[data-theme="persian"] .quiz-q,
[data-theme="persian"] .deck,
[data-theme="persian"] .dvhead,
[data-theme="persian"] .result,
[data-theme="persian"] .erow,
[data-theme="persian"] .menu .big.alt { background: rgba(23,54,92,0.82); backdrop-filter: blur(3px); }
h1 { font-size: 1.6rem; margin: 0 0 4px; text-align: center; }
h2 { font-size: 1.25rem; margin: 0; }
.sub { text-align: center; color: var(--muted); margin: 0 0 20px; }
.small { font-size: .8rem; color: var(--muted); }

.screen { display: none; }
.screen.active { display: block; }

.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.back { background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 8px 14px; border-radius: 10px; cursor: pointer; }

button { font-size: .95rem; padding: 10px 16px; border: none; border-radius: 10px; background: var(--accent); color: var(--ink); font-weight: 600; cursor: pointer; }
button:active { transform: scale(0.97); }
button:disabled { opacity: .5; cursor: default; }
button.primary { display: block; width: 100%; font-size: 1.1rem; padding: 16px; border-radius: 14px; margin: 8px 0 12px; }
button.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.danger { background: #ef4444; color: #fff; }

.authbox { max-width: 360px; margin: 30px auto 0; display: flex; flex-direction: column; gap: 10px; }
.authbox input { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1rem; }
.authbox button { width: 100%; }

.menu { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; }
.menu .big { font-size: 1.15rem; padding: 22px; text-align: left; border-radius: 16px; }
.menu .big.alt { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.settings-body input, .settings-body select, select, textarea, input[type="text"] {
  width: 100%; margin: 8px 0; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1rem;
}
textarea { min-height: 160px; line-height: 1.6; resize: vertical; }
label.fld { display: block; margin-top: 16px; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs .tab { flex: 1; background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.tabs .tab.active { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.panel { display: none; }
.panel.active { display: block; }
.upload { display: block; border: 2px dashed var(--border); border-radius: 18px; padding: 36px 20px; text-align: center; font-size: 1.1rem; cursor: pointer; background: var(--surface); transition: border-color .2s, background .2s; }
.upload.drag { border-color: var(--accent); }
.status { text-align: center; color: var(--accent); min-height: 1.4em; margin: 14px 0; }

.deck { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.deck .info { cursor: pointer; flex: 1; }
.deck .info .nm { font-weight: 600; font-size: 1.05rem; }
.deck .info .meta { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.deck .del { background: var(--border); color: #fca5a5; padding: 8px 12px; }

.dvhead { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px; margin-bottom: 16px; }
.dvstats { color: var(--muted); }
.dvgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dvgrid .full { grid-column: 1 / -1; }

.modebar { display: flex; gap: 8px; margin: 8px 0 12px; }
.modebar .mode { flex: 1; background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.modebar .mode.active { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.progress { text-align: center; color: var(--muted); margin-bottom: 12px; font-size: .9rem; }

.cards { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border-radius: 16px; padding: 18px 20px; border: 1px solid var(--border); }
.card .row, .arow { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card .q { font-weight: 600; line-height: 1.5; cursor: pointer; }
.card .num { color: var(--accent); margin-right: 6px; }
.card .a { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--text); line-height: 1.6; }
.card .tap { font-size: .8rem; color: var(--muted); margin-top: 10px; cursor: pointer; }
.speak { background: var(--border); color: var(--text); padding: 6px 10px; font-size: .85rem; border-radius: 8px; flex-shrink: 0; }

.quiz-q { background: var(--surface); border-radius: 16px; padding: 22px; border: 1px solid var(--border); }
.quiz-q .qtext { font-size: 1.15rem; font-weight: 600; line-height: 1.5; margin-bottom: 16px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option { text-align: left; background: var(--inset); color: var(--text); border: 1px solid var(--border); padding: 14px 16px; border-radius: 12px; font-weight: 500; line-height: 1.5; }
.option.correct { background: #14532d; border-color: #22c55e; color: #dcfce7; }
.option.wrong { background: #4c1d1d; border-color: #ef4444; color: #fee2e2; }
.reveal { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--text); line-height: 1.6; }
.btnrow { display: flex; gap: 10px; margin-top: 16px; }
.btnrow button { flex: 1; }
.good { background: #22c55e; color:#052e1b; }
.bad { background: #ef4444; color: #fff; }
.result { text-align: center; background: var(--surface); border-radius: 16px; padding: 30px; border: 1px solid var(--border); }
.result .score { font-size: 2.5rem; font-weight: 700; color: var(--accent); margin: 10px 0; }

.arow { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.tractions { margin-top: 12px; }
.translate { background: var(--border); color: var(--text); padding: 6px 12px; font-size: .85rem; border-radius: 8px; }
.tr:not(:empty) { margin-top: 12px; padding: 12px 14px; background: var(--inset); border: 1px solid var(--border); border-radius: 12px; }
.trq { font-weight: 600; color: var(--accent2); line-height: 1.5; }
.tra { margin-top: 8px; color: var(--text); line-height: 1.6; }

.erow { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.erow textarea { min-height: 60px; }
.erow .del { background: var(--border); color: #fca5a5; margin-top: 6px; }
