/*
 * WordQuiz frontend — Apple Human Interface Guidelines style.
 * Design tokens follow Apple.com CSS and HIG:
 * restrained color (near-black text + one interactive blue), SF/system
 * typography, generous whitespace, subtle depth, motion with purpose.
 */

:root {
  /* ── Color: foreground ── */
  --color-text-primary: #1d1d1f;
  --color-text-secondary: #6e6e73;
  --color-text-tertiary: #86868b;

  /* ── Color: background ── */
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f5f5f7;

  /* ── Color: borders ── */
  --color-border: #d2d2d7;
  --color-border-subtle: #ececf0;

  /* ── Color: interactive blue (interactive elements only) ── */
  --color-link: #0071e3;
  --color-link-hover: #0077ed;
  --color-link-active: #006edb;

  /* ── Color: fills ── */
  --color-fill-secondary: #e8e8ed;
  --color-fill-tertiary: #f5f5f7;

  /* ── Color: status (semantic use only) ── */
  --color-error: #ff3b30;
  --color-error-text: #c41e14;
  --color-error-bg: rgba(255, 59, 48, 0.08);
  --color-success: #34c759;
  --color-success-text: #1a7c34;
  --color-success-bg: rgba(52, 199, 89, 0.10);

  /* ── Typography ── */
  --font-system:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;

  /* ── Radius ── */
  --radius-input: 12px;
  --radius-card: 20px;
  --radius-pill: 980px;

  /* ── Shadow (subtle depth) ── */
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.04), 0 12px 32px rgba(0, 0, 0, 0.06);

  /* ── Motion ── */
  --motion-duration-instant: 100ms;
  --motion-duration-standard: 200ms;
  --motion-duration-modal: 350ms;
  --motion-ease-standard: cubic-bezier(0.25, 0.1, 0.25, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-text-primary: #f5f5f7;
    --color-text-secondary: #a1a1a6;
    --color-text-tertiary: #86868b;

    --color-bg-primary: #000000;
    --color-bg-secondary: #1d1d1f;

    --color-border: #424245;
    --color-border-subtle: #333336;

    --color-link: #2997ff;
    --color-link-hover: #4da6ff;
    --color-link-active: #1a87f5;

    --color-fill-secondary: #2c2c2e;
    --color-fill-tertiary: #1d1d1f;

    --color-error-text: #ff6961;
    --color-error-bg: rgba(255, 69, 58, 0.12);
    --color-success-text: #4be07a;
    --color-success-bg: rgba(48, 209, 88, 0.12);

    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.32), 0 12px 32px rgba(0, 0, 0, 0.40);
  }
}

* {
  box-sizing: border-box;
}

html {
  font-size: 106.25%; /* 17px base, scales with user preference */
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-system);
  font-size: 1rem;
  line-height: 1.47;
  color: var(--color-text-primary);
  background: var(--color-bg-secondary);
  -webkit-font-smoothing: antialiased;
}

/* Skip link — visible on keyboard focus only */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  z-index: 1000;
  padding: 8px 16px;
  background: var(--color-link);
  color: #ffffff;
  font-size: 14px;
  border-radius: 0 0 8px 0;
}

.skip-link:focus {
  top: 0;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 64px 24px 80px;
}

/* ── Hero: progressive disclosure (eyebrow → title → subtitle) ── */

.hero {
  text-align: center;
  margin-bottom: 48px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.011em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

h1 {
  margin: 0 0 12px;
  font-size: 40px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.subtitle {
  margin: 0 auto;
  max-width: 480px;
  font-size: 19px;
  line-height: 1.47;
  color: var(--color-text-secondary);
}

/* ── Cards: white surface on gray page, subtle shadow ── */

.card {
  background: var(--color-bg-primary);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 32px;
  margin-bottom: 24px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.21;
  letter-spacing: -0.015em;
}

.hint {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.47;
  color: var(--color-text-secondary);
}

/* ── Forms ── */

.form-group {
  margin-bottom: 20px;
}

.card .form-group:last-of-type {
  margin-bottom: 0;
}

#ai-extract-btn {
  margin-top: 4px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

input[type="number"],
input[type="file"],
textarea {
  width: 100%;
  padding: 11px 16px;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.47;
  color: var(--color-text-primary);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  outline: none;
  transition:
    border-color var(--motion-duration-instant) linear,
    box-shadow var(--motion-duration-instant) linear;
}

textarea {
  resize: vertical;
  min-height: 140px;
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-tertiary);
}

input[type="number"]:hover,
input[type="file"]:hover,
textarea:hover {
  border-color: var(--color-text-tertiary);
}

input[type="number"]:focus,
input[type="file"]:focus,
textarea:focus {
  border-color: var(--color-link);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

input[type="number"]:disabled,
textarea:disabled {
  background: var(--color-fill-tertiary);
  color: var(--color-text-tertiary);
  border-color: var(--color-border-subtle);
  cursor: not-allowed;
}

/* File selector button: quiet pill inside the input */
input[type="file"] {
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text-primary);
  background: var(--color-fill-secondary);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--motion-duration-instant) linear;
}

input[type="file"]::file-selector-button:hover {
  background: var(--color-border);
}

/* ── Toggle switch (iOS-style) for the shuffle option ── */

.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
}

.toggle-label {
  margin-bottom: 0;
  font-size: 1rem;
  font-weight: 400;
  color: var(--color-text-primary);
  cursor: pointer;
}

.toggle {
  flex-shrink: 0;
  position: relative;
  width: 51px;
  height: 31px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: var(--color-border);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--motion-duration-standard) var(--motion-ease-standard);
}

.toggle::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--motion-duration-standard) var(--motion-ease-standard);
}

.toggle:checked {
  background: var(--color-success);
}

.toggle:checked::before {
  transform: translateX(20px);
}

.toggle:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}

/* ── Buttons ── */

.actions {
  display: flex;
  justify-content: center;
  margin-top: 32px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  min-width: 200px;
  padding: 12px 28px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1;
  color: #ffffff;
  background: var(--color-link);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--motion-duration-instant) linear,
    transform var(--motion-duration-instant) var(--motion-ease-standard);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-link-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-link-active);
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.56;
  cursor: wait;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  color: var(--color-link);
  background: var(--color-fill-secondary);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition:
    background var(--motion-duration-instant) linear,
    transform var(--motion-duration-instant) var(--motion-ease-standard);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-border);
}

.btn-secondary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-secondary:disabled {
  opacity: 0.56;
  cursor: wait;
}

/* ── Focus ring: visible for keyboard navigation ── */

.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.toggle:focus-visible,
.skip-link:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 3px;
}

/* ── Spinner (loading feedback, inherits button text color) ── */

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(128, 128, 128, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

/* ── Inline status message ── */

.message {
  margin-top: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-input);
  font-size: 14px;
  line-height: 1.47;
  text-align: center;
}

.message.error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.message.success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

/* ── Footnote ── */

.footnote {
  margin-top: 40px;
  text-align: center;
}

.footnote p {
  margin: 0;
  font-size: 12px;
  line-height: 1.47;
  color: var(--color-text-tertiary);
}

/* ── Responsive ── */

@media (max-width: 734px) {
  .container {
    padding: 40px 16px 64px;
  }

  .hero {
    margin-bottom: 32px;
  }

  h1 {
    font-size: 32px;
  }

  .subtitle {
    font-size: 17px;
  }

  .card {
    padding: 24px 20px;
  }

  .btn-primary {
    width: 100%;
  }
}

/* ── Accessibility: increased contrast ── */

@media (prefers-contrast: more) {
  :root {
    --color-text-secondary: #424245;
    --color-text-tertiary: #515154;
    --color-border: #86868b;
  }
}

/* ── Accessibility: reduced motion ── */

@media (prefers-reduced-motion: reduce) {
  html:focus-within {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Static loading fallback: keep the spinner visible as a static dot */
  .spinner {
    animation: none !important;
  }
}
