/*
 * TriviaYou web — visual port of the Android Material 3 theme.
 *
 * Mirrors Theme.TriviaEU (Material3 Light + Dark) at the visual-token
 * level — palette, corner radii, elevation, typography, top app bar,
 * FAB, bottom navigation, list rows, pill-shaped answer buttons.
 *
 * Tokens follow the M3 baseline palette (purple primary). Anything
 * that needed an Android-specific value (28dp dialog corner, 40dp
 * pill corner on AnswerButton, 80dp answer min-height) is preserved.
 */

/* The HTML5 `hidden` attribute relies on the UA stylesheet's default
 * `[hidden] { display: none }`, which is overridden by any author rule
 * setting `display:` on the element (.empty-state, .btn, .icon-btn,
 * .menu, etc). Force [hidden] to win so JS toggles like
 * `el.hidden = true` actually hide elements with their own display: rule. */
[hidden] { display: none !important; }

:root {
  /* M3 baseline (purple) — light scheme */
  --md-primary: #6750a4;
  --md-on-primary: #ffffff;
  --md-primary-container: #eaddff;
  --md-on-primary-container: #21005d;
  --md-secondary-container: #e8def8;
  --md-on-secondary-container: #1d192b;
  --md-surface: #fffbfe;
  --md-on-surface: #1c1b1f;
  --md-surface-variant: #e7e0ec;
  --md-on-surface-variant: #49454f;
  --md-surface-container: #f3edf7;
  --md-surface-container-low: #f7f2fa;
  --md-surface-container-high: #ece6f0;
  --md-outline: #79747e;
  --md-outline-variant: #cac4d0;
  --md-error: #b3261e;
  --md-on-error: #ffffff;
  --md-error-container: #f9dedc;
  --md-success: #146c2e;       /* not in baseline; mirrors the green Android uses for "correct" */
  --md-success-container: #d3edda;

  /* Shape — matches Android values */
  --shape-corner-xs: 4px;
  --shape-corner-sm: 8px;
  --shape-corner-md: 12px;
  --shape-corner-lg: 16px;
  --shape-corner-xl: 28px;     /* dialogCornerRadius */
  --shape-pill: 999px;         /* AnswerButton uses fixed 40dp; effectively pill */

  /* Elevation (M3 levels 1–3 only) */
  --elev-1: 0 1px 2px rgba(0,0,0,.10), 0 1px 3px 1px rgba(0,0,0,.06);
  --elev-2: 0 1px 2px rgba(0,0,0,.12), 0 2px 6px 2px rgba(0,0,0,.08);
  --elev-3: 0 4px 8px 3px rgba(0,0,0,.10), 0 1px 3px rgba(0,0,0,.12);

  /* Hit-state overlays — M3 uses 8% / 12% on-surface tint, no animated ripple */
  --state-hover: rgba(0,0,0,.06);
  --state-press: rgba(0,0,0,.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --md-primary: #d0bcff;
    --md-on-primary: #381e72;
    --md-primary-container: #4f378b;
    --md-on-primary-container: #eaddff;
    --md-secondary-container: #4a4458;
    --md-on-secondary-container: #e8def8;
    --md-surface: #1c1b1f;
    --md-on-surface: #e6e1e5;
    --md-surface-variant: #49454f;
    --md-on-surface-variant: #cac4d0;
    --md-surface-container: #211f26;
    --md-surface-container-low: #1d1b20;
    --md-surface-container-high: #2b2930;
    --md-outline: #938f99;
    --md-outline-variant: #49454f;
    --md-error: #f2b8b5;
    --md-on-error: #601410;
    --md-error-container: #8c1d18;
    --md-success: #92d6a4;
    --md-success-container: #1d3322;

    --state-hover: rgba(255,255,255,.08);
    --state-press: rgba(255,255,255,.12);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: Roboto, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system,
               BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--md-surface);
  color: var(--md-on-surface);
  /* Bottom-nav (80px) + safe gap; FAB sits above it. */
  padding-bottom: calc(80px + 16px);
}

/* ---------- Top app bar (MaterialToolbar) ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 4px 0 16px;
  background: var(--md-surface);
  color: var(--md-on-surface);
  border-bottom: 1px solid var(--md-outline-variant);
}

.appbar h1 {
  margin: 0;
  font-size: 1.375rem;   /* M3 titleLarge ≈ 22sp */
  font-weight: 500;
  letter-spacing: 0;
  flex: 1;
}

.appbar-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Material 3 icon-only toolbar button (40dp circle, 24dp glyph) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--md-on-surface);
  cursor: pointer;
}
.icon-btn:hover { background: var(--state-hover); }
.icon-btn:active { background: var(--state-press); }
.icon-btn svg {
  width: 24px; height: 24px;
  fill: currentColor;
}

/* M3 menu — dropdown shown by overflow icon. Visually 12px corners + elev-2. */
.menu {
  position: absolute;
  right: 0;
  top: 48px;
  list-style: none;
  margin: 0;
  padding: 8px 0;
  min-width: 180px;
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
  border-radius: var(--shape-corner-md);
  box-shadow: var(--elev-2);
  z-index: 5;
}
.menu li { margin: 0; }
.menu button {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.menu button:hover { background: var(--state-hover); }
.menu button:active { background: var(--state-press); }

/* ---------- Main content ---------- */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

h2 {
  margin: 16px 0 8px;
  font-size: 1rem;          /* M3 titleSmall */
  font-weight: 500;
  color: var(--md-on-surface-variant);
}

h3 {
  margin: 16px 0 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
}

.muted { color: var(--md-on-surface-variant); }

/* Inline status banner — uses M3 surface-variant styling.
   Snackbar would be the closer Android analog but introduces motion + auto-dismiss
   we don't need at file:// scale. */
#status {
  min-height: 1.5em;
  margin-bottom: 12px;
  padding: 0;
  font-size: 0.875rem;
  color: var(--md-on-surface-variant);
}
#status.ok    { color: var(--md-success); }
#status.err   { color: var(--md-error); }

/* ---------- Buttons (Material 3) ---------- */

/* Filled button — primary action */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--shape-pill);
  background: var(--md-primary);
  color: var(--md-on-primary);
  font: inherit;
  font-weight: 500;
  letter-spacing: .05em;
  cursor: pointer;
  transition: box-shadow .12s ease;
}
.btn:hover { box-shadow: var(--elev-1); }
.btn:active { box-shadow: none; }
.btn:disabled { opacity: .38; cursor: default; box-shadow: none; }

/* Outlined button — secondary actions */
.btn.outlined {
  background: transparent;
  color: var(--md-primary);
  border: 1px solid var(--md-outline);
}
.btn.outlined:hover { background: var(--state-hover); box-shadow: none; }

/* Text button — tertiary / back actions */
.btn.text {
  background: transparent;
  color: var(--md-primary);
  padding: 0 12px;
}
.btn.text:hover { background: var(--state-hover); box-shadow: none; }
.btn.text svg { width: 18px; height: 18px; fill: currentColor; }

/* Danger variant */
.btn.danger {
  background: transparent;
  color: var(--md-error);
  border: 1px solid var(--md-error);
}
.btn.danger:hover { background: var(--md-error-container); }

/* ---------- FAB (FloatingActionButton) ---------- */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(80px + 16px);  /* clear the bottom nav */
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: var(--shape-corner-lg);
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  box-shadow: var(--elev-3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
}
.fab:hover { box-shadow: var(--elev-3), 0 0 0 8px var(--state-hover); }
.fab:active { box-shadow: var(--elev-1); }
.fab svg { width: 24px; height: 24px; fill: currentColor; }

/* ---------- Bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 80px;
  display: flex;
  background: var(--md-surface-container);
  border-top: 1px solid var(--md-outline-variant);
  z-index: 2;
}
.nav-item {
  flex: 1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--md-on-surface-variant);
  font: inherit;
  font-size: 0.75rem;     /* M3 labelMedium */
  font-weight: 500;
  cursor: pointer;
  padding: 12px 0 16px;
  position: relative;
}
.nav-item .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 32px;
  border-radius: var(--shape-pill);
  transition: background-color .12s ease;
}
.nav-item svg { width: 24px; height: 24px; fill: currentColor; }
.nav-item:hover .nav-icon { background: var(--state-hover); }
.nav-item:active .nav-icon { background: var(--state-press); }
.nav-item.active { color: var(--md-on-secondary-container); }
.nav-item.active .nav-icon {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

/* ---------- Library list ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 16px;
  color: var(--md-on-surface-variant);
  text-align: center;
}
.empty-state svg {
  width: 100px;
  height: 100px;
  fill: currentColor;
  opacity: .6;
  margin-bottom: 16px;
}
.empty-state p {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.quiz-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.quiz-list li {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  background: transparent;
  cursor: default;
  min-height: 64px;
}
.quiz-list li + li { border-top: 1px solid var(--md-outline-variant); }
.quiz-list li.playable { cursor: pointer; }
.quiz-list li.playable:hover { background: var(--state-hover); }
.quiz-list li.playable:active { background: var(--state-press); }
.quiz-list li.unplayable { color: var(--md-on-surface-variant); }

.quiz-list .row-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.quiz-list .name {
  font-size: 1rem;          /* 16sp */
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quiz-list .meta {
  font-size: 0.875rem;
  color: var(--md-on-surface-variant);
}
.quiz-list .row-actions { display: inline-flex; gap: 4px; }

/* ---------- Quiz play view ---------- */

.screen-back {
  margin: 4px 0 8px;
}

.quiz-header-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 16px;
  margin: 16px 0;
}
.quiz-name {
  flex: 1;
  font-size: 1rem;          /* 16sp */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quiz-progress {
  font-size: 0.875rem;      /* 14sp */
  color: var(--md-on-surface-variant);
}

.quiz-stats {
  margin: 12px 10px 4px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
}

.quiz-question {
  margin: 16px 10px;
  text-align: center;
  font-size: 1rem;
}

/* Answer buttons — match Android AnswerButton style:
   - 80dp min-height
   - 40dp pill corners (fixed 40px so corners don't grow with height)
   - Elevated (M3 ElevatedButton)
   - 5dp vertical / 20dp horizontal margins
   - 16sp text */
.answer-list { list-style: none; padding: 0; margin: 0 0 30px; }
.answer-list li { margin: 5px 20px; }
.answer-list button {
  width: 100%;
  min-height: 80px;
  padding: 15px 24px;
  border: 0;
  border-radius: 40px;
  background: var(--md-surface-container-low);
  color: var(--md-on-surface);
  font: inherit;
  font-size: 1rem;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--elev-1);
  transition: box-shadow .12s ease, background-color .12s ease;
}
.answer-list button:hover:not(:disabled) {
  background: var(--md-surface-container);
  box-shadow: var(--elev-2);
}
.answer-list button:active:not(:disabled) {
  box-shadow: var(--elev-1);
  background: var(--md-surface-container-high);
}
.answer-list button.correct {
  background: var(--md-success-container);
  color: var(--md-on-surface);
  box-shadow: none;
}
.answer-list button.incorrect {
  background: var(--md-error-container);
  color: var(--md-on-surface);
  box-shadow: none;
}

#play-feedback { text-align: center; margin: 8px 0; font-weight: 500; }
#play-feedback.ok { color: var(--md-success); }
#play-feedback.err { color: var(--md-error); }

#play-advance-hint {
  margin: 4px 16px;
  text-align: center;
  font-style: italic;
  font-size: 0.875rem;
}

#play-next {
  display: block;
  margin: 16px auto 0;
}

/* ---------- Result view ---------- */

.result-content {
  max-width: 480px;
  margin: 64px auto 0;
  padding: 0 30px;
  text-align: center;
}
.result-headline {
  font-size: 1.875rem;       /* 30sp */
  font-weight: 500;
  margin: 0;
}
.result-score {
  margin-top: 20px;
  font-size: 1.25rem;        /* 20sp */
  color: var(--md-on-surface-variant);
}
#result-replay { margin-top: 20px; }

/* ---------- Edit / Create view ---------- */

.field {
  display: block;
  margin: 12px 4px;
}
.field input[type="text"],
.field textarea,
.field select {
  display: block;
  width: 100%;
  padding: 12px 14px;
  margin-top: 4px;
  border: 1px solid var(--md-outline);
  border-radius: var(--shape-corner-xs);
  background: var(--md-surface);
  color: var(--md-on-surface);
  font: inherit;
}
.field input[type="text"]:focus,
.field textarea:focus,
.field select:focus {
  outline: 2px solid var(--md-primary);
  outline-offset: -1px;
  border-color: var(--md-primary);
}
.field textarea { min-height: 4rem; resize: vertical; }

.create-quiz-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 20px 15px 10px;
}
.create-quiz-header .field { flex: 1; margin: 0; }
.create-quiz-header #edit-question-count {
  font-size: 1rem;
  color: var(--md-on-surface-variant);
}

.question-editors { list-style: decimal inside; padding: 0; margin: 0; }
.question-editors > li {
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--shape-corner-md);
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--md-surface-container-low);
}
.question-editors .remove-q { float: right; }

/* Sticky footer so Save / Delete / Add-question stay above the fixed
 * bottom-nav (height 80px, z-index 2) even when the form has hundreds
 * of questions. Without this, scrolling to the natural bottom of the
 * edit view buries the action row behind the nav and clicks are
 * intercepted — the user has no way to save an edit or delete a quiz.
 * z-index: 1 keeps it under the nav so the nav still wins at the very
 * bottom of the viewport. The background hides scrolling content. */
.edit-actions {
  display: flex;
  gap: 8px;
  padding: 16px;
  align-items: center;
  position: sticky;
  bottom: 80px;
  z-index: 1;
  background: var(--md-surface);
  border-top: 1px solid var(--md-outline-variant);
  margin: 0 -16px -16px;  /* bleed across main's 16px padding */
  padding-left: 32px;
  padding-right: 32px;
}
.edit-actions #edit-add-question { margin-right: auto; }

/* ---------- Stats ---------- */

.stats-total {
  font-size: 1.125rem;
  margin: 8px 0 16px;
}
.stats-table {
  width: 100%;
  border-collapse: collapse;
}
.stats-table th, .stats-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--md-outline-variant);
}
.stats-table th {
  color: var(--md-on-surface-variant);
  font-weight: 500;
  font-size: 0.875rem;
}
