/* ─── CSS Custom Properties (variables) ───────────────────────────────────────
   Define all colours in one place so they can be swapped easily for theming.
   Default values here are for dark mode.
────────────────────────────────────────────────────────────────────────────── */
:root{
  /* Main UI surface and text colours */
  --ui-bg:#000;
  --ui-fg:#fff;
  --ui-border:#222;
  --nav-muted:#bbb;         /* muted colour for inactive nav labels */

  /* Panel (card-like containers) background and border */
  --panel-bg:#0f0f0f;
  --panel-border:#222;

  /* Quiz card specific colours (always light so text is readable on white card) */
  --card-bg:#fff;
  --card-fg:#111;

  /* Utility colours used throughout */
  --muted:#666;             /* secondary/grey text */
  --line:#e8e8e8;           /* divider lines inside cards */
  --good:#1a7f37;           /* green used for correct answer feedback */
  --bad:#b42318;            /* red used for incorrect answer feedback */
}

/* ─── Light mode overrides ───────────────────────────────────────────────────
   When the <body> has class "light", these values replace the dark defaults.
────────────────────────────────────────────────────────────────────────────── */
body.light{
  --ui-bg:#f4f4f4;
  --ui-fg:#111;
  --ui-border:#ddd;
  --nav-muted:#444;

  --panel-bg:#fff;
  --panel-border:#ddd;
}

/* Apply border-box sizing globally so padding doesn't break layouts */
*{ box-sizing:border-box; }

/* ─── Base body styles ───────────────────────────────────────────────────────
   Lock the viewport height and hide overflow so only the feed scrolls, not
   the whole page.
────────────────────────────────────────────────────────────────────────────── */
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:var(--ui-bg);
  color:var(--ui-fg);
  height:100vh;
  overflow:hidden;      /* prevents body scroll; individual containers scroll instead */
}

/* ─── Top bar ────────────────────────────────────────────────────────────────
   Fixed-height bar at the top containing the logo and settings button.
────────────────────────────────────────────────────────────────────────────── */
.topbar{
  height:56px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 14px;
  border-bottom:1px solid var(--ui-border);
  background:var(--ui-bg);
}

/* Logo and app name side by side */
.brand{
  display:flex;
  align-items:center;
  gap:10px;
}
.brand img{ width:28px; height:28px; object-fit:contain; }
.brand .title{ font-weight:700; }

/* ─── Icon-only button (used for settings) ───────────────────────────────── */
.iconbtn{
  width:38px;
  height:38px;
  border-radius:10px;
  border:1px solid var(--ui-border);
  background:transparent;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}

/* In dark mode: invert the icon so it appears white on dark background */
.iconbtn img{
  width:20px;
  height:20px;
  object-fit:contain;
  filter: brightness(0) invert(1);
}
/* In light mode: show the icon dark (no inversion needed) */
body.light .iconbtn img{
  filter: brightness(0);
}

/* ─── Content area ───────────────────────────────────────────────────────────
   Fills the space between the top bar (56px) and bottom nav (64px).
────────────────────────────────────────────────────────────────────────────── */
.content{
  height:calc(100vh - 56px - 64px);
  position:relative;        /* needed so .actions can be positioned absolutely inside */
}

/* Each tab takes full height; only the active tab is shown */
.tab{ height:100%; display:none; }
.tab.active{ display:block; }

/* ─── Scrollable quiz feed ───────────────────────────────────────────────────
   scroll-snap-type makes each card snap into view like TikTok/Reels.
────────────────────────────────────────────────────────────────────────────── */
.feed{
  height:100%;
  overflow-y:auto;
  scroll-snap-type:y mandatory;         /* snaps vertically to each card */
  -webkit-overflow-scrolling:touch;     /* smooth momentum scrolling on iOS */
}
/* Hide the scrollbar visually while keeping scroll functionality */
.feed::-webkit-scrollbar{ width:0; height:0; }

/* Each feed item fills the full height so one card = one screen */
.feed-item{
  height:100%;
  scroll-snap-align:start;             /* snap point at the top of each card */
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
  position:relative;
}

/* ─── Quiz card (9:16 aspect ratio like a short-form video) ──────────────── */
.short{
  width:min(420px, 92vw);   /* responsive: fills narrow screens, caps on wide ones */
  aspect-ratio:9/16;
  background:var(--card-bg);
  color:var(--card-fg);
  border-radius:18px;
  box-shadow:0 10px 28px rgba(0,0,0,.35);
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:10px;
  overflow:hidden;
  border:1px solid rgba(0,0,0,0.06);
}

/* Bold question text at the top of each card */
.question{
  font-size:16px;
  font-weight:700;
  line-height:1.3;
  margin:2px 0 0;
}

/* Container for the four answer option buttons */
.options{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-top:6px;
  flex:1;               /* fills remaining card space so feedback stays at bottom */
}

/* Individual answer option button */
.opt{
  border:1px solid var(--line);
  background:#fff;
  padding:12px;
  border-radius:12px;
  text-align:left;
  cursor:pointer;
  font-size:14px;
}
.opt:hover{ background:#fafafa; }
/* Disable pointer cursor once an answer has been selected */
.opt:disabled{ cursor:default; opacity:0.98; }

/* Green highlight applied to the correct answer after submission */
.opt.correct{
  border-color:rgba(26,127,55,.35);
  background:rgba(26,127,55,.08);
}
/* Red highlight applied to the wrong answer chosen by the user */
.opt.wrong{
  border-color:rgba(180,35,24,.35);
  background:rgba(180,35,24,.08);
}

/* Feedback section shown below options after the user answers */
.feedback{
  border-top:1px solid var(--line);
  padding-top:10px;
  min-height:52px;
  font-size:13px;
}
/* "Correct!" or "Incorrect." label */
.status{ font-weight:800; margin-bottom:4px; }
.status.good{ color:var(--good); }   /* green for correct */
.status.bad{ color:var(--bad); }     /* red for incorrect */
/* Explanation text shown beneath the status */
.explain{ color:var(--muted); }

/* ─── Right-side action buttons (Like, Comment, Share, Save) ─────────────── */
.actions{
  position:absolute;    /* positioned over the feed without affecting layout */
  right:18px;
  bottom:92px;          /* sits above the bottom nav bar */
  display:flex;
  flex-direction:column;
  gap:14px;
  user-select:none;     /* prevents text selection when tapping quickly */
}

/* Each action button stacks icon + label vertically */
.action-btn{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  color:var(--ui-fg);
  font-size:12px;
  background:transparent;
  border:none;
  cursor:pointer;
  width:64px;
}
/* Drop shadow makes icons visible against both light and dark cards */
.action-btn img{
  width:28px;
  height:28px;
  object-fit:contain;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.4));
}
/* Bold label text when the action is in its active/toggled state */
.action-btn.active .label{ font-weight:800; }

/* ─── Bottom navigation bar ──────────────────────────────────────────────── */
.bottomnav{
  height:64px;
  border-top:1px solid var(--ui-border);
  display:flex;
  align-items:center;
  justify-content:space-around;
  padding:8px 10px;
  background:var(--ui-bg);
}

/* Each nav button takes equal space */
.navbtn{
  flex:1;
  background:transparent;
  border:none;
  color:var(--nav-muted);   /* muted/grey when inactive */
  cursor:pointer;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  padding:6px 0;
}
/* Active nav button uses full foreground colour */
.navbtn.active{ color:var(--ui-fg); }

/* White rounded square behind each nav icon */
.iconbox{
  width:34px;
  height:34px;
  border-radius:10px;
  background:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
}
/* Nav icons are always shown dark (icons are on a white background) */
.navbtn img{
  width:20px;
  height:20px;
  object-fit:contain;
  filter: brightness(0);    /* renders icon as solid black */
}

/* ─── Create / About panel wrappers ──────────────────────────────────────── */
/* Scrollable wrapper so long forms/content don't overflow */
.create-wrap{
  height:100%;
  overflow:auto;
  padding:16px;
}

/* Centred panel card used in both Create and About tabs */
.panel{
  max-width:520px;
  margin:0 auto;
  background:var(--panel-bg);
  border:1px solid var(--panel-border);
  border-radius:14px;
  padding:14px;
  color:var(--ui-fg);
}
/* Ensure panel text is dark in light mode */
body.light .panel{ color:#111; }

.panel h2{ margin:0 0 12px; font-size:18px; }

/* Form labels styled small and muted */
label{
  display:block;
  font-size:12px;
  color:var(--nav-muted);
  margin:10px 0 6px;
}

/* Form inputs adapt to the current theme colours */
input, textarea, select{
  width:100%;
  padding:10px;
  border-radius:10px;
  border:1px solid var(--panel-border);
  background:transparent;   /* inherits panel background */
  color:var(--ui-fg);
  outline:none;
}
/* Override text colour in light mode so it stays readable */
body.light input, body.light textarea, body.light select{
  color:#111;
}
textarea{ min-height:72px; resize:vertical; }

/* Primary action button in the Create form */
.btn{
  margin-top:12px;
  width:100%;
  padding:12px;
  border-radius:12px;
  border:none;
  background:#fff;
  color:#000;
  font-weight:800;
  cursor:pointer;
}

/* ─── About tab specific styles ──────────────────────────────────────────── */
.about h3{ margin:14px 0 8px; font-size:14px; }
.about p{ margin:8px 0 0; line-height:1.4; }
.about ul{ margin:8px 0 0 18px; line-height:1.5; }

/* Legal/footer section at the bottom of the About panel */
.legal{
  margin-top:16px;
  padding-top:12px;
  border-top:1px solid var(--panel-border);
  color:var(--nav-muted);
  font-size:12px;
  line-height:1.35;
}

/* ─── Settings modal ─────────────────────────────────────────────────────────
   Full-screen dark overlay with a centred settings box.
   Hidden by default; the "show" class makes it visible.
────────────────────────────────────────────────────────────────────────────── */
.modal{
  position:fixed;
  inset:0;                          /* covers the entire viewport */
  background:rgba(0,0,0,.55);      /* semi-transparent dark overlay */
  display:none;                     /* hidden until .show class is added */
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:9999;                     /* sits above all other content */
}
.modal.show{ display:flex; }        /* toggled by app.js to reveal the modal */

/* The white/dark box inside the modal overlay */
.modal-box{
  width:min(420px, 92vw);
  background:var(--panel-bg);
  border:1px solid var(--panel-border);
  border-radius:14px;
  padding:14px;
  color:var(--ui-fg);
}
body.light .modal-box{ color:#111; }

/* Modal header row: title on the left, close button on the right */
.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}
.modal-title{ font-weight:800; }

/* Close button styled to match the panel border */
.modal-close{
  border:1px solid var(--panel-border);
  background:transparent;
  color:var(--ui-fg);
  border-radius:10px;
  padding:8px 10px;
  cursor:pointer;
}
body.light .modal-close{ color:#111; }

/* Row containing the "Light mode" label and the checkbox toggle */
.toggle-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 0;
}

/* Small note beneath the toggle explaining local storage persistence */
.modal-note{
  margin-top:8px;
  font-size:12px;
  color:var(--nav-muted);
}