:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #5b6ee1;
  --accent-hover: #4c5dcc;
  --accent-soft: #eef0ff;
  --shadow: 0 18px 50px rgba(30, 41, 59, 0.08);
  --focus: rgba(91, 110, 225, 0.24);
  --danger: #d95c5c;
  --danger-soft: #fff0f0;
  --priority-high: #d05d65;
  --priority-high-bg: #fff0f1;
  --priority-medium: #b7791f;
  --priority-medium-bg: #fff8df;
  --priority-low: #398172;
  --priority-low-bg: #eaf8f4;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --surface: #1b2433;
  --surface-muted: #222d3e;
  --text: #f1f5f9;
  --text-muted: #a8b3c4;
  --border: #334155;
  --accent: #91a0ff;
  --accent-hover: #a8b3ff;
  --accent-soft: #2b3659;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.24);
  --focus: rgba(145, 160, 255, 0.3);
  --danger: #ff8e8e;
  --danger-soft: #492b31;
  --priority-high: #ff9ca1;
  --priority-high-bg: #4a2d33;
  --priority-medium: #f0c66a;
  --priority-medium-bg: #443b27;
  --priority-low: #77d2be;
  --priority-low-bg: #263f3b;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(91, 110, 225, 0.08), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  transition: background-color 180ms ease, color 180ms ease;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.app-shell {
  width: min(100% - 32px, 920px);
  margin: 0 auto;
  padding: 56px 0 28px;
}

.app-header,
.list-heading,
.dialog-heading,
.dialog-actions,
.task-content-top,
.task-actions {
  display: flex;
  align-items: center;
}

.app-header,
.list-heading,
.dialog-heading {
  justify-content: space-between;
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: clamp(2rem, 6vw, 3rem);
  letter-spacing: -0.04em;
  line-height: 1;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.25rem;
}

h3 {
  margin-bottom: 8px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.subtitle,
.task-count,
.app-footer,
.dialog-note,
.delete-copy {
  color: var(--text-muted);
}

.subtitle,
.task-count {
  margin-bottom: 0;
}

.icon-button,
.close-button,
.task-action {
  display: inline-grid;
  place-items: center;
  border: 0;
  color: var(--text-muted);
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  transition: transform 150ms ease, border-color 150ms ease, color 150ms ease;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
}

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

.panel {
  border-radius: 22px;
}

.task-composer {
  padding: 22px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px auto;
  align-items: end;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field label,
.sort-control span {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
  color: var(--text);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input {
  padding: 0 14px;
}

select {
  padding: 0 38px 0 13px;
}

input::placeholder {
  color: var(--text-muted);
  opacity: 0.72;
}

input:hover,
select:hover,
input:focus,
select:focus {
  border-color: var(--accent);
}

.field-error {
  min-height: 1em;
  margin: 0;
  color: var(--danger);
  font-size: 0.78rem;
}

.primary-button,
.secondary-button,
.danger-button,
.filter-button {
  border-radius: 12px;
  font-weight: 750;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  padding: 0 18px;
  border: 0;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(91, 110, 225, 0.2);
  transition: background-color 150ms ease, transform 150ms ease;
}

.primary-button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
}

.danger-button {
  background: var(--danger);
  color: #fff;
}

.list-section {
  margin-top: 36px;
}

.list-heading {
  gap: 16px;
  margin-bottom: 16px;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 9px;
}

.sort-control select {
  width: auto;
  min-height: 40px;
  background: var(--surface);
}

.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.filter-button {
  flex: 1;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  transition: background-color 150ms ease, color 150ms ease;
}

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

.filter-button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.filter-count {
  display: inline-block;
  min-width: 1.45rem;
  margin-left: 4px;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.12);
  font-size: 0.72rem;
}

.task-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task-card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  overflow: hidden;
  padding: 17px 18px 17px 21px;
  border-radius: 17px;
  transition: border-color 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.task-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--priority-color);
  content: "";
}

.task-card:hover {
  border-color: color-mix(in srgb, var(--priority-color) 40%, var(--border));
  transform: translateY(-1px);
}

.task-card[data-priority="high"] {
  --priority-color: var(--priority-high);
  --priority-bg: var(--priority-high-bg);
}

.task-card[data-priority="medium"] {
  --priority-color: var(--priority-medium);
  --priority-bg: var(--priority-medium-bg);
}

.task-card[data-priority="low"] {
  --priority-color: var(--priority-low);
  --priority-bg: var(--priority-low-bg);
}

.task-card.is-completed {
  opacity: 0.72;
}

.task-checkbox {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: 0;
  padding: 0;
  appearance: none;
  border: 2px solid color-mix(in srgb, var(--priority-color) 65%, var(--border));
  border-radius: 50%;
  background: var(--surface);
}

.task-checkbox:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.task-checkbox:checked::after {
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  content: "";
  transform: translateY(-1px) rotate(45deg);
}

.task-content {
  min-width: 0;
}

.task-content-top {
  flex-wrap: wrap;
  gap: 8px;
}

.task-title {
  overflow-wrap: anywhere;
  font-weight: 700;
  line-height: 1.45;
}

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

.priority-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--priority-bg);
  color: var(--priority-color);
  font-size: 0.7rem;
  font-weight: 800;
}

.task-date {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.task-actions {
  gap: 4px;
}

.task-action,
.close-button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: transparent;
  font-size: 1rem;
}

.task-action:hover,
.close-button:hover {
  background: var(--surface-muted);
  color: var(--accent);
}

.task-action.delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.empty-state p {
  margin-bottom: 0;
}

.empty-icon,
.danger-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  font-size: 1.5rem;
  font-weight: 800;
}

.empty-icon {
  background: var(--accent-soft);
  color: var(--accent);
}

.app-footer {
  margin-top: 30px;
  font-size: 0.78rem;
  text-align: center;
}

.dialog {
  width: min(100% - 32px, 470px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--text);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.54);
  backdrop-filter: blur(4px);
}

.dialog-card {
  display: grid;
  gap: 17px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.24);
}

.dialog-heading h2,
.dialog-small h2,
.delete-copy,
.dialog-note {
  margin-bottom: 0;
}

.dialog-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 2px;
}

.dialog-small {
  text-align: center;
}

.danger-icon {
  margin-bottom: -4px;
  background: var(--danger-soft);
  color: var(--danger);
}

.delete-copy {
  max-height: 4.2em;
  overflow: hidden;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.dialog-note {
  margin-top: -10px;
  font-size: 0.83rem;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(360px, calc(100% - 40px));
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 24px, 920px);
    padding-top: 30px;
  }

  .form-row {
    grid-template-columns: 1fr 150px;
  }

  .task-field {
    grid-column: 1 / -1;
  }

  .primary-button {
    align-self: end;
  }
}

@media (max-width: 520px) {
  .app-header {
    align-items: flex-start;
  }

  .task-composer {
    padding: 17px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .list-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .sort-control {
    width: 100%;
  }

  .sort-control select {
    flex: 1;
  }

  .filter-tabs {
    gap: 3px;
  }

  .filter-button {
    padding-inline: 5px;
    font-size: 0.86rem;
  }

  .filter-count {
    margin-left: 1px;
  }

  .task-card {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    padding: 16px;
  }

  .task-checkbox {
    margin-top: 1px;
  }

  .task-actions {
    grid-column: 2;
    justify-content: flex-end;
    margin-top: -2px;
  }

  .dialog-card {
    padding: 20px;
  }
}

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