/* ---------- Theme ---------- */

/* Pastel orange and green. Pastel tones fill backgrounds, badges and the
   progress bar; darker shades of the same hues are used for text, buttons
   and links so every text pair meets WCAG AA (4.5:1). */
:root {
  color-scheme: light; /* keep native controls light even in OS dark mode */

  /* Neutrals */
  --bg: #fff8f0;              /* warm cream page background */
  --surface: #ffffff;         /* cards */
  --text: #2f2a25;
  --muted: #6b5f55;           /* secondary text */
  --border: #f1e4d6;          /* card edges and dividers (decorative) */
  --control-border: #a08b78;  /* inputs and the check circle (3:1) */

  /* Orange: brand / primary actions */
  --primary: #c2410c;
  --primary-hover: #9a3412;
  --primary-soft: #ffe6d5;

  /* Green: completion */
  --done: #2f7a4d;
  --progress: #8fd3a8;
  --success-bg: #e6f6ec;
  --success-text: #22663c;

  /* Red: errors and destructive actions (kept apart from the brand orange) */
  --error-bg: #fde4e2;
  --error-text: #b42318;

  /* Priority badges */
  --high-bg: #ffdcc7;
  --high-text: #9a3412;
  --medium-bg: #fff0c7;
  --medium-text: #7a5300;
  --low-bg: #d8f2e1;
  --low-text: #22663c;
  --done-badge-bg: #f3ece4;

  --radius: 12px;
  --shadow: 0 1px 2px rgb(120 72 30 / 6%), 0 4px 12px rgb(120 72 30 / 5%);
}

/* ---------- Font ----------
   Nunito (SIL Open Font License, see fonts/OFL.txt), self-hosted so it works
   offline and in the static demo. Latin subset, only the weights in use. */

@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/nunito-400.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: "Nunito";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/nunito-600.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: "Nunito";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/nunito-700.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;
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 20px;
}

[hidden] {
  display: none !important;
}

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

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

/* ---------- Header and progress ---------- */

.app-header {
  margin-bottom: 24px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.app-header h1 a {
  color: inherit;
  text-decoration: none;
}

.progress-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--progress);
  transition: width 0.3s ease;
}

/* ---------- Forms and buttons ---------- */

input,
select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  padding: 10px 12px;
}

input:focus,
select:focus,
.btn:focus-visible,
.check:focus-visible,
.filter:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

input[aria-invalid="true"] {
  border-color: var(--error-text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

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

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
}

.btn-ghost:hover {
  color: var(--primary-hover);
  background: var(--primary-soft);
}

.btn-danger:hover {
  color: var(--error-text);
  background: var(--error-bg);
}

.field-error {
  flex-basis: 100%;
  margin: 0;
  color: var(--error-text);
  font-size: 0.9rem;
}

.add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  margin-bottom: 20px;
}

.add-form input {
  flex: 1 1 240px;
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
}

.edit-form h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.edit-form label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 8px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- Alerts ---------- */

.alert {
  padding: 10px 14px;
  border-left: 4px solid currentColor;
  border-radius: 8px;
  margin: 0 0 16px;
  font-size: 0.95rem;
}

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

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

/* ---------- Filters ---------- */

.filters {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.filter {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.filter:hover {
  color: var(--primary-hover);
}

.filter.is-active {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.filter.is-active .count {
  color: inherit;
}

.count {
  margin-left: 4px;
  color: var(--muted);
  font-weight: 400;
}

/* ---------- Task list ---------- */

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.task {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.task:last-child {
  border-bottom: none;
}

.task form {
  margin: 0;
}

.check {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid var(--control-border);
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
}

.check:hover {
  border-color: var(--primary);
}

.task.is-done .check {
  background: var(--done);
  border-color: var(--done);
}

.task-title {
  flex: 1 1 200px;
  overflow-wrap: anywhere;
}

.task.is-done .task-title {
  color: var(--muted);
  text-decoration: line-through;
}

.badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: capitalize;
}

.badge-high {
  background: var(--high-bg);
  color: var(--high-text);
}

.badge-medium {
  background: var(--medium-bg);
  color: var(--medium-text);
}

.badge-low {
  background: var(--low-bg);
  color: var(--low-text);
}

/* Completed tasks fade to neutral while keeping readable contrast. */
.task.is-done .badge {
  background: var(--done-badge-bg);
  color: var(--muted);
}

.task-actions {
  display: flex;
  gap: 2px;
}

/* ---------- Empty state ---------- */

.empty-state {
  padding: 48px 24px;
  text-align: center;
}

.empty-title {
  margin: 0 0 4px;
  font-weight: 600;
  font-size: 1.1rem;
}

.empty-text {
  margin: 0;
  color: var(--muted);
}

/* ---------- Footer note ---------- */

.note {
  margin: 32px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.note a,
.link-button {
  color: var(--primary);
  text-decoration: underline;
}

.note a:hover,
.link-button:hover {
  color: var(--primary-hover);
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

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

@media (max-width: 520px) {
  .container {
    padding: 24px 12px;
  }

  .add-form .btn,
  .add-form select {
    flex: 1;
  }

  /* Row 1: check, title, badge. Row 2: actions, aligned with the title. */
  .task {
    display: grid;
    grid-template-columns: auto 1fr auto;
    column-gap: 12px;
    row-gap: 2px;
    padding-bottom: 6px; /* the ghost buttons already add their own padding */
  }

  .task-actions {
    grid-column: 2 / -1;
    margin-left: -10px; /* line up the button text with the title */
  }
}
