/* ⚡ Quizzitch — Apple Design System
   Clarity · Deference · Depth · Accessibility First */

/* ── Reset & Variables ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  /* Apple Dark Mode Palette */
  --color-bg: #000000;
  --color-bg-alt: #111111;
  --color-surface: #1c1c1e;
  --color-surface-2: #28282a;
  --color-border: #38383a;
  --color-separator: #48484a;

  --color-text: #ffffff;
  --color-text-secondary: #98989d;
  --color-text-tertiary: #6c6c70;

  --color-accent: #007aff;
  --color-accent-hover: #0066d6;
  --color-accent-pressed: #0055b3;

  --color-success: #34c759;
  --color-warning: #ff9f0a;
  --color-error: #ff453a;
  --color-info: #5ac8fa;

  /* Typography — Apple SF Pro stack */
  --font-body: -apple-system, "SF Pro Text", "Helvetica Neue", sans-serif;
  --font-heading: -apple-system, "SF Pro Display", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", "Menlo", monospace;

  /* Type scale */
  --text-caption: 0.75rem;   /* 12px */
  --text-footnote: 0.8125rem; /* 13px */
  --text-body: 1rem;          /* 16px */
  --text-callout: 1.0625rem;  /* 17px */
  --text-subhead: 1.1875rem;  /* 19px */
  --text-title3: 1.25rem;     /* 20px */
  --text-title2: 1.5rem;      /* 24px */
  --text-title1: 2rem;        /* 32px */
  --text-large: 2.5rem;       /* 40px */

  /* Spacing — 8px grid */
  --space-2xs: 2px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;
  --space-4xl: 40px;
  --space-5xl: 48px;
  --space-6xl: 64px;

  /* RADIUS — Apple-style */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);

  /* Focus */
  --focus-ring: 0 0 0 4px rgba(0, 122, 255, 0.3);
}

/* ── Base ──────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
  }
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.47059;
  font-weight: 400;
  letter-spacing: -0.022em;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

::selection {
  background: rgba(0, 122, 255, 0.3);
}

/* ── Skip link (accessibility) ─────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-lg);
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-accent);
  color: white;
  z-index: 10000;
  font-size: var(--text-body);
  font-weight: 600;
  border-radius: var(--radius-sm);
}
.skip-link:focus {
  top: var(--space-sm);
}

/* ── Header ────────────────────────────────────────────── */
.site-header {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 980px;
  margin: 0 auto;
  padding: 0 var(--space-2xl);
  height: 48px;
}

.logo {
  font-family: var(--font-heading);
  font-size: var(--text-callout);
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.02em;
  transition: opacity 0.2s;
}
.logo:hover { opacity: 0.7; }

.nav-links {
  display: flex;
  gap: var(--space-2xl);
  align-items: center;
}

.nav-links a {
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: var(--text-footnote);
  font-weight: 500;
  transition: color 0.2s;
}
.nav-links a:hover {
  color: var(--color-text);
}

.display-name {
  color: var(--color-accent);
  font-size: var(--text-footnote);
  font-weight: 500;
}

/* ── Main ──────────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: var(--space-5xl) var(--space-2xl);
  width: 100%;
}

/* ── Hero ──────────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: var(--space-6xl) 0;
}

.hero h1 {
  font-family: var(--font-heading);
  font-size: var(--text-large);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 var(--space-lg);
  background: linear-gradient(135deg, #007aff, #5856d6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: var(--text-title3);
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-3xl);
  font-weight: 400;
}

.hero-actions {
  display: flex;
  gap: var(--space-lg);
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-2xl);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 600;
  border: none;
  border-radius: var(--radius-xl);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  letter-spacing: -0.01em;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-primary {
  background: var(--color-accent);
  color: white;
}
.btn-primary:hover {
  background: var(--color-accent-hover);
}
.btn-primary:active {
  background: var(--color-accent-pressed);
}

.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-accent);
}
.btn-secondary:hover {
  background: var(--color-border);
}

/* ── Footer ────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: var(--space-3xl) var(--space-2xl);
  color: var(--color-text-tertiary);
  font-size: var(--text-footnote);
  border-top: 1px solid var(--color-border);
}
.site-footer a {
  color: var(--color-text-secondary);
  text-decoration: none;
}
.site-footer a:hover {
  color: var(--color-text);
}

/* ── Utility ───────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Form styles — Create Quiz ─────────────────────────── */
.create-form {
  max-width: 560px;
}

.field { margin-bottom: var(--space-2xl); }

.field label {
  display: block;
  font-size: var(--text-footnote);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-sm);
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.field input,
.field select {
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 400;
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2398998d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

.field-help {
  margin: var(--space-xs) 0 0;
  font-size: var(--text-footnote);
  color: var(--color-text-tertiary);
}

.field-row {
  display: flex;
  gap: var(--space-lg);
}

.field-row .field { flex: 1; }

.subtitle {
  color: var(--color-text-secondary);
  font-size: var(--text-callout);
  margin-bottom: var(--space-3xl);
}

/* ── Messages & Quiz Result ────────────────────────────── */
.messages { margin-bottom: var(--space-lg); }

.message {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--text-footnote);
  font-weight: 500;
}
.message.success { background: rgba(52, 199, 89, 0.15); color: var(--color-success); }
.message.error { background: rgba(255, 69, 58, 0.15); color: var(--color-error); }

.quiz-result-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  margin: var(--space-2xl) 0;
}

.quiz-result-card h3 {
  margin: 0 0 var(--space-sm);
  font-size: var(--text-title3);
  font-weight: 600;
  color: var(--color-text);
}

.quiz-result-card p {
  margin: 0 0 var(--space-xs);
  color: var(--color-text-secondary);
  font-size: var(--text-body);
}

.quiz-result-card .meta {
  color: var(--color-text-tertiary);
  font-size: var(--text-footnote);
}

.quiz-result-card.error {
  border-left: 4px solid var(--color-error);
}
.quiz-result-card.error h3 { color: var(--color-error); }

/* ── Recent quizzes on homepage ────────────────────────── */
.recent-quizzes {
  margin-top: var(--space-6xl);
}

.recent-quizzes h2 {
  font-size: var(--text-title3);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 var(--space-lg);
}

.quiz-list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.quiz-card {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s;
}
.quiz-card:last-child { border-bottom: none; }
.quiz-card:hover { background: var(--color-surface-2); }

.quiz-card .quiz-title {
  font-weight: 500;
  color: var(--color-text);
  font-size: var(--text-body);
}
.quiz-card .quiz-meta {
  font-size: var(--text-footnote);
  color: var(--color-text-tertiary);
}

/* ── Auth forms (login/signup/logout) ──────────────────── */
.auth-form {
  max-width: 400px;
  margin: var(--space-6xl) auto;
}

.auth-form h1 {
  font-family: var(--font-heading);
  font-size: var(--text-title2);
  font-weight: 700;
  margin: 0 0 var(--space-2xl);
  letter-spacing: -0.03em;
}

.auth-form p {
  color: var(--color-text-secondary);
  font-size: var(--text-body);
  margin: 0 0 var(--space-xl);
  line-height: 1.47059;
}

.auth-form p a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}
.auth-form p a:hover { text-decoration: underline; }

.auth-form label {
  display: block;
  font-size: var(--text-footnote);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

.auth-form input,
.auth-form select {
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-body);
  font-size: var(--text-body);
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 0.2s;
  appearance: none;
}

.auth-form input:focus,
.auth-form select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

.auth-form .helptext,
.auth-form .form-help {
  font-size: var(--text-footnote);
  color: var(--color-text-tertiary);
  margin-top: var(--space-xs);
}

.auth-form ul.errorlist {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-md);
}
.auth-form ul.errorlist li {
  color: var(--color-error);
  font-size: var(--text-footnote);
  font-weight: 500;
}

.auth-form hr {
  border: none;
  border-top: 1px solid var(--color-separator);
  margin: var(--space-2xl) 0;
}

.auth-form .btn {
  width: 100%;
  margin-top: var(--space-xl);
}

.auth-form input[type="checkbox"] {
  width: auto;
  accent-color: var(--color-accent);
}
