/* ── Fonts ───────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/newsreader-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/newsreader-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #F9F5FF;
  --brand: #4052B6;
  --accent: #8899FF;
  --muted: #696682;
  --muted-light: #D5D2E8;
  --card: #FFFFFF;
  --shadow: 0 20px 40px rgba(44,42,81,0.06);
  --warn: #A06020;
  --over: #c23b5a;
  --radius: 16px;
  --serif: 'Newsreader', Georgia, serif;
  --sans: 'Inter', system-ui, sans-serif;
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: #2C2A51;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--brand);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  z-index: 999;
  transition: top 0.15s;
}
.skip-link:focus { top: 16px; }

/* Focus rings */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Layout */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 24px 0;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Header */
header { margin-bottom: 40px; }

.logo-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.logo-icon {
  color: var(--brand);
  flex-shrink: 0;
  height: 40px;
  width: auto;
}
.wordmark h1 {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 700;
  color: var(--brand);
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.tagline {
  font-size: 14px;
  color: var(--muted);
  margin-top: 3px;
}

/* Editor card */
.editor-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 0 0 2px rgba(64,82,182,0.2);
  overflow: hidden;
  margin-bottom: 20px;
  transition: box-shadow 0.2s ease;
}
.editor-card:focus-within {
  box-shadow: 0 0 0 2px var(--brand);
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(64,82,182,0.12);
  flex-wrap: wrap;
}
.toolbar-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  margin-right: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.preset-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.preset-bar::-webkit-scrollbar { display: none; }

.preset-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1.5px solid var(--muted-light);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.preset-btn:hover { border-color: var(--accent); color: var(--brand); }
.preset-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.preset-count {
  opacity: 0.65;
  font-size: 11px;
}
.preset-btn.active .preset-count { opacity: 0.75; }

/* Custom preset input */
.custom-input {
  width: 72px;
  background: var(--brand);
  border: none;
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  outline: none;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}
.custom-input::-webkit-outer-spin-button,
.custom-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.custom-input::placeholder { color: rgba(255,255,255,0.65); }

/* Action buttons */
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1.5px solid var(--muted-light);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  position: relative;
  overflow: hidden;
}
.action-btn:hover { border-color: var(--accent); color: var(--brand); }

/* Hold-to-clear ring */
.clear-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: conic-gradient(var(--over) calc(var(--hold, 0) * 1%), transparent 0);
  mask:
    linear-gradient(#000, #000) content-box,
    linear-gradient(#000, #000);
  -webkit-mask:
    linear-gradient(#000, #000) content-box,
    linear-gradient(#000, #000);
  mask-composite: exclude;
  -webkit-mask-composite: xor;
  padding: 2px;
  pointer-events: none;
  opacity: 0.9;
}
.clear-btn.holding {
  color: var(--over);
  background: rgba(194,59,90,0.08);
}

/* Textarea */
#editor {
  display: block;
  width: 100%;
  min-height: 240px;
  padding: 22px 26px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.65;
  color: #2C2A51;
  background: transparent;
  border: none;
  resize: vertical;
  outline: none;
}
#editor::placeholder { color: var(--muted-light); }

/* Selection note */
.selection-note {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 26px 14px;
  border-top: 1px dashed rgba(64,82,182,0.12);
  font-size: 13px;
  color: var(--muted);
}
.selection-note[hidden] { display: none; }
.clear-sel-btn {
  margin-left: auto;
  appearance: none;
  border: 1px solid rgba(64,82,182,0.12);
  background: transparent;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.clear-sel-btn:hover { color: var(--brand); border-color: var(--accent); }

/* Pulse / selection dot */
.pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 4px rgba(64,82,182,0.15);
  flex-shrink: 0;
}
.pulse-dot.over { background: var(--over); box-shadow: none; }
@keyframes sel-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(64,82,182,0.15); }
  50%       { box-shadow: 0 0 0 7px rgba(64,82,182,0.06); }
}
@keyframes hint-pulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 0 0   rgba(194,59,90,0.45); }
  50%      { transform: scale(1.15); box-shadow: 0 0 0 5px rgba(194,59,90,0); }
}
.pulse-dot.pulsing { animation: sel-pulse 1.6s ease-in-out infinite; }
.pulse-dot.over.pulsing { animation: hint-pulse 1.2s ease-in-out infinite; }

/* Card selection indicator */
.stat-card.sel-active::after {
  content: '';
  position: absolute;
  top: 10px;
  right: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px 24px;
  position: relative;
  overflow: hidden;
}
.card-eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 8px;
}
.stat-num {
  display: block;
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  color: var(--brand);
  transition: color 0.2s;
}
.stat-num.is-zero { color: var(--muted-light); }
.card-caption {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.wpm-pill {
  display: inline-block;
  background: rgba(136,153,255,0.15);
  color: var(--brand);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 4px;
}
.stat-num .unit {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
  margin-left: 4px;
}
.stat-num.is-zero .unit { color: var(--muted-light); }

/* Hero card */
.hero-card {
  grid-column: span 2;
  padding: 26px 28px;
}
.hero-inner {
  display: flex;
  align-items: center;
  gap: 28px;
}
.hero-inner.no-ring { justify-content: center; }

/* Ring */
.ring-wrap {
  position: relative;
  width: 116px;
  height: 116px;
  flex-shrink: 0;
}
.ring-wrap.hidden { display: none; }
.ring-svg {
  width: 116px;
  height: 116px;
  transform: rotate(-90deg);
}
.ring-svg circle { fill: none; stroke-width: 8; }
.prog-track { stroke: rgba(64,82,182,0.18); }
.prog-base {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 314.159;
  stroke-dashoffset: 314.159;
  transition: stroke-dashoffset 0.35s ease, stroke 0.2s, opacity 0.2s;
}
.prog-over {
  stroke: var(--over);
  stroke-linecap: round;
  stroke-dasharray: 314.159;
  stroke-dashoffset: 314.159;
  transition: stroke-dashoffset 0.35s ease;
}
.ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pct {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 700;
  color: var(--brand);
  transition: color 0.2s;
  line-height: 1;
}

/* Hero count column */
.hero-count {
  flex: 1;
  min-width: 0;
}
.hero-count .card-eyebrow { margin-bottom: 6px; }
.hero-count .stat-num { font-size: 52px; }
.limit-hint {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  min-height: 20px;
}
.hint-over {
  color: var(--over);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.hint-sub { color: var(--muted); font-weight: 400; }

/* Hero card state colors */
.hero-card[data-state="warn"] .pct,
.hero-card[data-state="warn"] .stat-num { color: var(--warn); }
.hero-card[data-state="over"] .pct,
.hero-card[data-state="over"] .stat-num { color: var(--over); }

/* Footer */
footer {
  margin-top: auto;
  padding: 32px 0 28px;
  text-align: center;
  font-size: 12px;
  color: var(--muted-light);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: #2C2A51;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(44,42,81,0.2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }

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

/* Responsive */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .hero-card { grid-column: span 2; }
}
@media (max-width: 768px) {
  .app { padding: 24px 16px 0; }
  header { margin-bottom: 24px; }
  .hero-inner { gap: 16px; }
  .ring-wrap { width: 96px; height: 96px; }
  .ring-svg { width: 96px; height: 96px; }
  .hero-count .stat-num { font-size: 40px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .hero-card { grid-column: span 1; }
  .hero-inner { flex-direction: column; align-items: flex-start; gap: 16px; }
  .stat-num { font-size: 36px; }
}
