:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --surface: rgba(255, 255, 255, 0.9);
  --background: linear-gradient(160deg, #f9fafb 0%, #e2e8f0 40%, #f9fafb 100%);
  --shadow: 0 18px 35px rgba(15, 23, 42, 0.12);
  --success: #16a34a;
  --cell: #60a5fa;
  --cell-edge: #1d4ed8;
  --new: #f97316;
  --new-edge: #c2410c;
  --stick: #b45309;
  --stick-head: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 2rem;
  background: var(--background);
  color: var(--text-primary);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.page {
  width: min(1100px, 100%);
  padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 2rem) 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

.page__header {
  text-align: center;
  display: grid;
  gap: 0.75rem;
}

.page__header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
}

.page__header p {
  margin: 0;
  color: var(--text-secondary);
}

/* ---------- Modes ---------- */

.modes {
  display: inline-flex;
  justify-self: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
}

.modes button {
  border: none;
  background: none;
  padding: 0.55rem 1.3rem;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.modes button[aria-selected="true"] {
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.modes button:focus-visible,
.btn:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 2px;
}

.mode-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

/* ---------- Cards & controls ---------- */

.card {
  background: var(--surface);
  border-radius: 24px;
  padding: clamp(1.1rem, 3vw, 1.75rem);
  box-shadow: var(--shadow);
}

.settings {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
}

.settings__buttons {
  display: flex;
  gap: 0.5rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.field select,
.question__form input,
.sequence__input {
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-primary);
}

.field select {
  min-width: 15rem;
  max-width: 100%;
}

.field select:focus,
.question__form input:focus,
.sequence__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  padding-bottom: 0.6rem;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.check input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, transform 100ms ease;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

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

.btn--ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn--ghost:hover {
  border-color: #cbd5e1;
  color: var(--text-primary);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.action-row--start {
  justify-content: flex-start;
}

/* ---------- Figures ---------- */

.figures-card {
  display: grid;
  gap: 1.25rem;
}

.figures {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 28px;
  min-height: 140px;
}

.figure {
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 0.6rem;
}

.figure figcaption {
  font-weight: 700;
  color: var(--text-secondary);
}

.figure__placeholder {
  display: grid;
  place-items: center;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-muted);
}

.pattern {
  display: block;
  overflow: visible;
}

.cell {
  fill: var(--cell);
  stroke: var(--cell-edge);
  stroke-width: 0.05;
}

.dot {
  fill: var(--cell-edge);
}

.cell.is-new {
  fill: var(--new);
  stroke: var(--new-edge);
}

.dot.is-new {
  fill: var(--new);
}

.stick {
  stroke: var(--stick);
  stroke-width: 0.1;
  stroke-linecap: round;
}

.stick.is-new {
  stroke: var(--accent);
}

.stick__head {
  fill: var(--stick-head);
}

.cell.is-new,
.dot.is-new,
.stick.is-new {
  animation: glow 500ms ease both;
}

@keyframes glow {
  from {
    opacity: 0.2;
  }
}

/* ---------- Table & question ---------- */

.analysis {
  display: grid;
  gap: 1.5rem;
}

.table-wrap {
  overflow-x: auto;
}

.pattern-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.pattern-table th,
.pattern-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.pattern-table tr:first-child th {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.pattern-table th:first-child {
  text-align: left;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.pattern-table td {
  font-size: 1.35rem;
  font-weight: 700;
}

.pattern-table td.growth {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--new-edge);
}

.pattern-table .is-unknown {
  color: var(--text-muted);
}

.pattern-table .is-answer {
  color: var(--success);
}

.pattern-table .is-formula {
  font-size: 1.05rem;
}

.pattern-table .gap {
  color: var(--text-muted);
  width: 1.5rem;
}

.question {
  display: grid;
  gap: 0.75rem;
}

.question__form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.75rem;
}

.question__form label {
  font-size: 1.15rem;
  font-weight: 700;
}

.question__form input {
  width: 7rem;
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.feedback {
  margin: 0;
  min-height: 1.5em;
  font-weight: 600;
}

.feedback--center {
  text-align: center;
}

.feedback.is-right {
  color: var(--success);
}

.feedback.is-wrong {
  color: #dc2626;
}

.feedback.is-hint {
  color: var(--text-secondary);
}

.rule {
  display: grid;
  gap: 0.4rem;
  padding: 1rem 1.2rem;
  border-radius: 16px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.rule--center {
  text-align: center;
}

.rule__formula {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 800;
  color: #166534;
  font-variant-numeric: tabular-nums;
}

.rule__text {
  margin: 0;
  color: #166534;
}

/* ---------- Sequences ---------- */

.sequence-card {
  display: grid;
  gap: 1.1rem;
}

.sequence-prompt {
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
}

.sequence {
  display: grid;
  justify-items: center;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.sequence__terms {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0.35rem 0.2rem;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.sequence__term {
  min-width: 1.4em;
  text-align: center;
}

.sequence__term.is-revealed {
  color: var(--success);
}

.sequence__comma {
  color: var(--text-muted);
  margin-right: 0.35rem;
}

.sequence__input {
  width: 3.4em;
  padding: 0.2rem 0.3rem;
  font-size: inherit;
  font-weight: 800;
  text-align: center;
}

.sequence__input.is-right {
  border-color: var(--success);
  background: #f0fdf4;
  color: var(--success);
}

.sequence__input.is-wrong {
  border-color: #dc2626;
  background: #fef2f2;
  color: #dc2626;
}

.sequence__diffs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.sequence__diff {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: var(--new-edge);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sequence__diff.is-unknown {
  background: #f8fafc;
  border-color: var(--border);
  color: var(--text-muted);
}

.score {
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
  min-height: 1.4em;
}

/* ---------- Notes ---------- */

.notes {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  display: grid;
  gap: 1rem;
}

.notes h2 {
  margin: 0;
  font-size: 1.25rem;
}

.notes ul {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.5rem;
}

.notes li {
  color: var(--text-secondary);
}

@media (max-width: 560px) {
  .field select {
    min-width: 0;
    width: 100%;
  }

  .field {
    flex: 1 1 100%;
  }

  .figures {
    gap: 16px;
  }
}

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