/* SpellCast: dark, modern theme */

:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaef;
  --muted: #9aa1ae;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-ink: #062b27;
  --good: #4ade80;
  --good-bg: rgba(74, 222, 128, 0.12);
  --bad: #f87171;
  --bad-bg: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.12);
  --radius: 16px;
  --radius-small: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(45, 212, 191, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

.accent {
  color: var(--accent);
}

.eyebrow {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.header-inner {
  display: flex;
  align-items: center;
  height: 64px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}

/* ---------- Screens ---------- */

.screen {
  padding-bottom: 48px;
  animation: fade-in 0.25s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.hero {
  margin-bottom: 32px;
}

.hero p {
  margin-top: 12px;
  max-width: 34rem;
  font-size: 1.05rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 36px;
  margin-bottom: 12px;
}

.section-head .section-title {
  margin-bottom: 0;
}

.empty-state {
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.list-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.list-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-2px);
}

.list-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.list-card-name {
  font-weight: 700;
  font-size: 1.05rem;
  padding-right: 28px;
}

.list-card-desc {
  color: var(--muted);
  font-size: 0.9rem;
}

.list-card-count {
  margin-top: auto;
  padding-top: 6px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
}

.list-card-wrap {
  position: relative;
}

.delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.delete-btn:hover,
.delete-btn:focus-visible {
  background: var(--bad-bg);
  color: var(--bad);
  outline: none;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.btn-primary:hover {
  background: var(--accent-strong);
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

.btn-small {
  min-height: 38px;
  padding: 0 14px;
  font-size: 0.9rem;
}

.btn-block {
  width: 100%;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Notices ---------- */

.notice {
  padding: 12px 16px;
  border-radius: var(--radius-small);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.notice-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.notice-bad {
  background: var(--bad-bg);
  color: var(--bad);
}

/* ---------- Create list form ---------- */

#create-screen h1 {
  margin-bottom: 8px;
}

.form-card {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
}

.form-card label {
  font-weight: 600;
  margin-bottom: 8px;
  margin-top: 16px;
}

.form-card label:first-child {
  margin-top: 0;
}

input[type="text"],
textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16px stops iOS zooming in */
}

textarea {
  resize: vertical;
  font-family: var(--mono);
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.2);
}

#word-count {
  margin-top: 8px;
}

.form-card .notice {
  margin-top: 16px;
  margin-bottom: 0;
}

/* ---------- Practice ---------- */

.practice-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.progress-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.practice-card {
  padding: 28px 24px;
}

.listen-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.speak-btn {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.5);
  transition: transform 0.15s, background 0.15s;
}

.speak-btn:hover {
  background: var(--accent-strong);
  transform: scale(1.04);
}

.speak-btn:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 4px;
}

.speak-btn.speaking {
  animation: pulse 1.1s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.5); }
  100% { box-shadow: 0 0 0 22px rgba(45, 212, 191, 0); }
}

.listen-actions {
  display: flex;
  gap: 10px;
}

.answer-input {
  text-align: center;
  font-size: clamp(1.5rem, 6vw, 2rem) !important;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 16px !important;
  margin-bottom: 12px;
}

.answer-input:disabled {
  opacity: 0.6;
}

.hint {
  text-align: center;
  margin-bottom: 12px;
  color: var(--warn);
}

/* ---------- Feedback ---------- */

.feedback {
  margin-top: 4px;
  animation: fade-in 0.2s ease;
}

.verdict {
  padding: 14px 16px;
  border-radius: var(--radius-small);
  font-weight: 700;
  font-size: 1.1rem;
  text-align: center;
  margin-bottom: 16px;
}

.verdict.correct {
  background: var(--good-bg);
  color: var(--good);
}

.verdict.incorrect {
  background: var(--bad-bg);
  color: var(--bad);
}

.comparison {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  padding: 16px;
  margin-bottom: 16px;
}

.compare-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.compare-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.letters {
  font-family: var(--mono);
  font-size: clamp(1.25rem, 5vw, 1.6rem);
  letter-spacing: 0.06em;
  word-break: break-all;
}

.ch {
  display: inline-block;
  padding: 0 1px;
  border-radius: 4px;
}

.ch.wrong {
  background: var(--bad-bg);
  color: var(--bad);
}

.ch.extra {
  color: var(--bad);
  text-decoration: line-through;
  opacity: 0.8;
}

.ch.gap-missing {
  color: var(--warn);
}

.ch.fix {
  background: var(--good-bg);
  color: var(--good);
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  color: var(--muted);
  font-family: var(--font);
}

.legend-item {
  white-space: nowrap;
}

.legend .ch {
  font-family: var(--mono);
  margin-right: 2px;
}

/* ---------- Results ---------- */

.results-card {
  text-align: center;
  padding: 36px 24px;
}

.score {
  font-size: clamp(3rem, 14vw, 4.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-top: 8px;
}

.score-message {
  color: var(--muted);
  font-size: 1.1rem;
  margin-top: 4px;
}

#missed-section {
  margin-top: 28px;
  text-align: left;
}

.missed-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.missed-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
}

.missed-word {
  font-family: var(--mono);
  font-size: 1.1rem;
  color: var(--good);
  font-weight: 600;
}

.missed-typed {
  color: var(--muted);
  font-size: 0.9rem;
}

.missed-typed s {
  color: var(--bad);
}

.results-buttons {
  justify-content: center;
}

/* ---------- Small screens ---------- */

@media (max-width: 520px) {
  .site-header {
    margin-bottom: 24px;
  }

  .card,
  .practice-card {
    padding: 20px 16px;
  }

  .results-buttons .btn {
    flex: 1 1 100%;
  }

  .button-row .btn {
    flex: 1 1 auto;
  }
}

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