/* styles.css
   Single responsibility: design tokens + shared visual rules.
   Component-specific layout lives inline in each view's render, but all
   colors/type/spacing decisions are centralized here so the identity is
   never duplicated or drifted across modules. */

:root {
  /* Color */
  --color-paper: #FAF7F0;
  --color-paper-raised: #FFFFFF;
  --color-ink: #1C1B19;
  --color-ink-soft: #5B5650;
  --color-accent: #8B5E3C;
  --color-accent-soft: #C9A876;
  --color-correct: #3F6B5C;
  --color-incorrect: #A6453A;
  --color-border: #E8E2D4;
  --color-shadow: rgba(28, 27, 25, 0.12);

  /* Type */
  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* Radius */
  --radius-card: 14px;
  --radius-control: 10px;
}

/* Dark theme — same warm/wood identity, inverted for low light.
   Activated by setting data-theme="dark" on <html> (owned by ThemeService).
   Token NAMES never change between themes, only their values, so every
   component that already uses var(--color-x) gets dark mode for free. */
[data-theme="dark"] {
  --color-paper: #1C1B19;
  --color-paper-raised: #28251F;
  --color-ink: #F2EEE4;
  --color-ink-soft: #A39E92;
  --color-accent: #C9A876;
  --color-accent-soft: #8B5E3C;
  --color-correct: #5C9683;
  --color-incorrect: #D17C6F;
  --color-border: #3A352C;
  --color-shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  /* Use safe-area-insets so the navbar clears the iOS notch/status bar */
  padding-top: calc(var(--space-5) + env(safe-area-inset-top, 0px));
  padding-left: calc(var(--space-4) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--space-4) + env(safe-area-inset-right, 0px));
  padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
  color: var(--color-ink-soft);
  line-height: 1.5;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

input, textarea {
  font-family: var(--font-body);
  font-size: 16px; /* prevents iOS zoom-on-focus */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  padding: var(--space-3);
  background: var(--color-paper-raised);
  color: var(--color-ink);
  width: 100%;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-control);
  font-weight: 600;
  font-size: 15px;
  min-height: 44px;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--color-accent);
  color: var(--color-paper-raised);
}

.btn-secondary {
  background: transparent;
  color: var(--color-ink);
  border: 1px solid var(--color-border);
}

.btn-correct {
  background: var(--color-correct);
  color: var(--color-paper-raised);
}

.btn-incorrect {
  background: var(--color-incorrect);
  color: var(--color-paper-raised);
}

.btn-icon {
  min-height: 44px;
  min-width: 44px;
  padding: var(--space-2);
  border-radius: var(--radius-control);
  color: var(--color-ink-soft);
}

.btn-icon:hover {
  background: var(--color-border);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
}

.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-5) 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- Loading screen ----
   Note: .static-loader (the first-paint HTML loader in index.html) is
   intentionally NOT styled here. It already has its own complete inline
   <style> block so it can render before this stylesheet downloads, and
   re-declaring it here with different values would silently change its
   layout the moment styles.css finishes loading. */
.loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  padding: var(--space-7) var(--space-4);
  min-height: 50vh;
}

.loading-stack {
  position: relative;
  width: 72px;
  height: 48px;
  animation: loading-breathe 2.2s ease-in-out infinite;
  animation-delay: 0.9s;
}

.loading-stack__card {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-control);
  background: var(--color-paper-raised);
  animation: loading-settle 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.loading-stack__card:nth-child(1) {
  --start-rot: -10deg;
  --end-rot: -6deg;
  border: 1.5px solid var(--color-accent-soft);
  animation-delay: 0s;
}

.loading-stack__card:nth-child(2) {
  --start-rot: 8deg;
  --end-rot: 4deg;
  border: 1.5px solid var(--color-accent);
  animation-delay: 0.12s;
}

.loading-stack__card:nth-child(3) {
  --start-rot: 0deg;
  --end-rot: 0deg;
  border: 2px solid var(--color-accent);
  animation-delay: 0.24s;
}

@keyframes loading-settle {
  0% { transform: translateY(-6px) rotate(var(--start-rot)); opacity: 0; }
  60% { transform: translateY(1px) rotate(var(--end-rot)); opacity: 1; }
  100% { transform: translateY(0) rotate(var(--end-rot)); opacity: 1; }
}

@keyframes loading-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.loading-label {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--color-ink-soft) !important;
  letter-spacing: 0.06em;
}

/* ---- Offline available badge toast ---- */
.offline-badge {
  position: fixed;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-correct);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: var(--space-2) var(--space-5);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 9999;
  pointer-events: none;
}

.offline-badge--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Footer & Version badge ---- */
.footer-container {
  text-align: center;
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.footer-version {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-ink-soft);
  opacity: 0.25; /* minimalistic and transparent */
  letter-spacing: 0.05em;
}

/* ---- Storage full banner ---- */
.storage-banner {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-incorrect);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}

.storage-banner button {
  color: #fff;
  font-size: 12px;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: var(--radius-control);
  padding: 2px 10px;
}
