/* Flashcards stylesheet: one hand-written file for the whole site.
   Colours are variables so light and dark mode share every rule below. */

:root {
  color-scheme: light dark;
  --bg: #f8f5f2;
  --bg-2: #f3efe9;
  --surface: #ffffff;
  --surface-strong: #f4efe9;
  --surface-soft: #f0e9e3;
  --fg: #1f1c1a;
  --muted: #5d5653;
  --line: #e6d9d1;
  --accent: #c09f80;
  --accent-strong: #a77f68;
  --accent-soft: #f4e9e0;
  --accent-fg: #221d1b;
  --link: #7a5548;
  --focus: #c49b74;
  --shadow: rgba(31, 28, 26, 0.06);
  --error: #a35f5c;
  --error-soft: #f8e7e5;
  --success: #667b69;
  --success-soft: #ebf1eb;
  --again: #b76769;
  --hard: #d7a277;
  --good: #6f8a78;
  --easy: #5c6d7a;
  --rating-fg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
   --bg: #201d1b;
   --bg-2: #2a2624;
   --surface: #302b29;
   --surface-strong: #393433;
   --surface-soft: #433e3b;
   --fg: #f2efee;
   --muted: #d0c2b9;
   --line: #5c544f;
   --accent: #d9c3b1;
   --accent-strong: #e8d3c2;
   --accent-soft: #453833;
   --accent-fg: #221d1b;
   --link: #ecc7b4;
   --focus: #e2be8f;
   --shadow: rgba(0, 0, 0, 0.28);
   --error: #efb0a5;
   --error-soft: rgba(239, 176, 165, 0.12);
   --success: #cfe0c1;
   --success-soft: rgba(207, 224, 193, 0.12);
   --again: #dca6a1;
   --hard: #f0c78f;
   --good: #bfd0b9;
   --easy: #c6d0d9;
   --rating-fg: #1f1c1a;
  }
}

/* ---- Base ---- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--fg);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 58rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

main.container {
  background: transparent;
}

h1,
h2,
h3,
h4 {
  font-family: "Georgia", "Times New Roman", serif;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--fg);
}

h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  margin: 0.2rem 0 1rem;
}

h2 {
  font-size: 1.25rem;
  margin: 2rem 0 0.85rem;
}

p {
  margin: 0.75rem 0;
}

small {
  color: var(--muted);
}

ul {
  padding-left: 1.25rem;
}

li {
  margin: 0.25rem 0;
}

/* Links: same colour when visited, so no purple. */
a,
a:visited {
  color: var(--link);
  text-decoration: none;
  text-underline-offset: 0.2em;
  font-weight: 600;
}

a:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

p a,
p a:visited {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.58rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(32, 29, 27, 0.02);
}

p a:hover {
  background: var(--surface);
  border-color: var(--accent);
  text-decoration: none;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.error {
  color: var(--error);
}

code {
  word-break: break-all;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  padding: 0.08em 0.4em;
}

.message {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 0.9rem;
  box-shadow: 0 8px 20px var(--shadow);
  padding: 1rem 1.1rem;
  margin: 1rem 0;
}

.message.success {
  background: var(--success-soft);
  border-left-color: var(--success);
}

.message.error {
  background: var(--error-soft);
  border-left-color: var(--error);
}

.message p:first-child {
  margin-top: 0;
}

.message p:last-child {
  margin-bottom: 0;
}

/* ---- Forms ---- */
label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 600;
  margin: 0.5rem 0;
}

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  width: 100%;
  min-height: 46px;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(31, 95, 74, 0.12);
  outline: none;
}

/* ---- Buttons ---- */
button {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.7rem 1.2rem;
  border: 1px solid rgba(34, 29, 27, 0.08);
  border-radius: 0.18rem;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  box-shadow: 0 5px 12px rgba(96, 74, 63, 0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

button:hover {
  filter: brightness(1.02);
  box-shadow: 0 6px 14px rgba(96, 74, 63, 0.12);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: var(--surface-strong);
  color: var(--fg);
  border: 1px solid var(--line);
  box-shadow: none;
}

button.secondary:hover {
  background: var(--surface);
}

.app-shell {
  max-width: 36rem;
  margin: 0 auto;
  padding: 1rem 0 0;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.user-pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 0.8rem;
  color: var(--muted);
  font-size: 0.85rem;
  box-shadow: 0 4px 10px var(--shadow);
}

.home-nav {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}

.home-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 1rem 1.1rem;
  background: var(--accent);
  color: var(--accent-fg) !important;
  border: 1px solid rgba(31, 28, 26, 0.08);
  border-radius: 0.2rem;
  box-shadow: 0 8px 18px var(--shadow);
  text-decoration: none !important;
}

.home-action.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: rgba(31, 28, 26, 0.08);
}

.home-action .action-meta {
  color: rgba(31, 28, 26, 0.72);
}

.home-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px var(--shadow);
}

.action-label {
  font-size: 1.05rem;
  font-weight: 700;
}

.action-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.logout-form {
  margin-top: 1.5rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.actions form {
  display: inline;
}

/* ---- Card text (formatted content from the renderer) ---- */
.card-text {
  font-size: 1.2rem;
  line-height: 1.7;
}

.card-text p {
  margin: 0 0 1rem;
}

.card-text p:last-child {
  margin-bottom: 0;
}

.card-text p[dir="auto"] {
  text-align: start;
}

.ar {
  font-family: "Amiri", "Noto Naskh Arabic", "Geeza Pro", serif;
  font-size: 1.4em;
  line-height: 2;
}

/* Bundled Arabic font (SIL Open Font License; see fonts/OFL.txt). Served from this server only. */
@font-face {
  font-family: "Amiri";
  src: url("fonts/Amiri-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

/* ---- Study page ---- */
.study-kind {
  display: block;
  width: max-content;
  margin: 1.25rem auto 0.75rem;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.study-page {
  display: flex;
  flex-direction: column;
  padding-bottom: 6.5rem; /* room so the fixed bar never covers the card */
}

.study-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

.study-card {
  max-width: 38rem;
  width: 100%;
  margin: 0 auto 0.75rem;
  padding: 1.6rem 1.25rem 1.35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  box-shadow: 0 10px 24px var(--shadow);
  flex: 0 0 auto;
}

.study-card .card-text {
  text-align: start;
}

.study-answer {
  max-width: 38rem;
  width: 100%;
  margin: 0 auto;
  position: relative;
}

.study-answer-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  box-shadow: 0 10px 24px var(--shadow);
  padding: 1.15rem 1.2rem 1rem;
  margin-top: 0.7rem;
}

.study-actions {
  position: fixed;
  left: 50%;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(38rem, calc(100% - 2rem));
  z-index: 10;
  margin: 0;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  box-shadow: 0 6px 18px var(--shadow);
  overflow: hidden;
}
/* "Reveal answer" acts as a secondary button */
.study-answer summary {
  position: fixed;
  left: 50%;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(38rem, calc(100% - 2rem));
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(34, 29, 27, 0.08);
  border-radius: 0.35rem;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  list-style: none;
  box-shadow: 0 6px 18px var(--shadow);
}

.study-answer summary::-webkit-details-marker {
  display: none;
}

.study-answer summary:hover {
  background: var(--accent-soft);
}

.study-answer[open] summary {
  display: none;
}

.study-back {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

/* Rating buttons: colour-coded and laid out like a compact mobile app action bar */
.rating-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin-top: 0;
  background: transparent;
  overflow: hidden;
  border-radius: 0.35rem;
}

.rating-form button {
  min-height: 3.2rem;
  font-size: 0.9rem;
  color: var(--rating-fg);
  box-shadow: none;
  border: 1px solid rgba(32, 29, 27, 0.08);
  border-left: none;
  border-radius: 0;
}

.rating-form button:first-child {
  border-left: 1px solid rgba(32, 29, 27, 0.08);
  border-top-left-radius: 0.35rem;
  border-bottom-left-radius: 0.35rem;
}

.rating-form button:last-child {
  border-top-right-radius: 0.35rem;
  border-bottom-right-radius: 0.35rem;
}

.rating-form button:nth-child(1) { background: var(--again); }
.rating-form button:nth-child(2) { background: var(--hard); }
.rating-form button:nth-child(3) { background: var(--good); }
.rating-form button:nth-child(4) { background: var(--easy); }

/* ---- Dashboard and history ---- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1rem 0;
  font-size: 0.95rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 10px 24px var(--shadow);
}

th,
td {
  text-align: start;
  vertical-align: top;
  padding: 0.8rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

tr:last-child td {
  border-bottom: none;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--surface-soft);
}

tbody tr:hover {
  background: rgba(31, 95, 74, 0.03);
}

svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.5rem 0;
}

svg line {
  stroke: var(--line);
}

svg rect {
  fill: var(--accent);
}

svg rect:hover {
  opacity: 0.75;
}

/* ---- Undo (Stage 4g) ---- */
.undo-form {
  display: flex;
  justify-content: center;
  margin: 0 0 0.5rem;
}

.undo-form button {
  min-height: 40px;
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
}

/* ---- All cards page (Stage 4h) ---- */
.deck-sort {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}

.deck-sort a,
.deck-sort a:visited {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.9rem;
}

.deck-sort a.current {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.deck-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.deck-item {
  margin: 0.75rem 0;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  box-shadow: 0 4px 12px var(--shadow);
}


.deck-meta {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- Next-interval labels on rating buttons (Stage 4i) ---- */
.rating-form button {
  flex-direction: column;
  gap: 0.1rem;
  line-height: 1.2;
}

.rate-time {
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.85;
}

/* ---- All cards: question and answer (Stage 4j) ---- */
.deck-qa {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.deck-side .card-text {
  font-size: 1.05rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.deck-label {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Phones: stacked. Wider screens: question left, answer right. */
@media (min-width: 40rem) {
  .deck-qa {
    grid-template-columns: 1fr 1fr;
    gap: 0;
  }

  .deck-side:first-child {
    padding-inline-end: 1rem;
    border-inline-end: 1px solid var(--line);
  }

  .deck-side:last-child {
    padding-inline-start: 1rem;
  }
}

@media (max-width: 39.99rem) {
  .deck-side:last-child {
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
  }
}

/* ---- Chart axis labels (Stage 4j) ---- */
svg text {
  fill: var(--muted);
  font-size: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---- Card images and paste box (Stage 5a) ---- */
.side-image,
.side-preview {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 0.5rem auto;
}

.paste-zone {
  min-height: 5.5rem;
  margin-top: 0.5rem;
  padding: 0.9rem;
  border: 2px dashed var(--line);
  border-radius: 0.6rem;
  background: var(--surface);
  color: var(--muted);
  outline: none;
  white-space: pre-wrap;
}

.paste-zone:focus {
  border-color: var(--accent);
}

.paste-status {
  min-height: 1.4rem;
  margin: 0.4rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---- Quick add (Stage 5b) ---- */
[hidden] {
  display: none !important;
}

.quick-side {
  margin: 1rem 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  box-shadow: 0 4px 12px var(--shadow);
}

.quick-side textarea {
  width: 100%;
  min-height: 7rem;
  margin-top: 0.4rem;
  padding: 0.75rem;
  font: inherit;
  font-size: 1.1rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

.quick-preview {
  outline-offset: 4px;
}

.quick-preview img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.5rem auto 0.75rem;
  border-radius: 0.5rem;
}

td .side-image {
  max-width: 8rem;
}
/* ---- Reference, card list (Stage 5c) ---- */
.card-reference {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-weight: 600;
  text-align: start;
}

.muted {
  color: var(--muted);
}

.quick-ref {
  margin: 1rem 0;
}

.table-scroll {
  overflow-x: auto;
}

.cards-table {
  min-width: 44rem;
}

.cards-table .card-text {
  font-size: 1rem;
  line-height: 1.5;
}

.cards-table td .side-image {
  max-width: 7rem;
  margin: 0;
}