:root {
  --bg: #08090f;
  --text: #f4f4f8;
  --muted: rgba(228, 228, 240, 0.58);
  --card: rgba(18, 19, 30, 0.62);
  --edge: rgba(255, 255, 255, 0.09);
  --row: rgba(255, 255, 255, 0.045);
  --row-hover: rgba(255, 255, 255, 0.08);
  --row-edge: rgba(255, 255, 255, 0.06);
  --field: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.22);
  --accent: #818cf8;
  --done: #34d399;
  --pill: rgba(255, 255, 255, 0.1);
  --dot: rgba(255, 255, 255, 0.07);
  --aurora-opacity: 0.38;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.3, 1.5, 0.5, 1);
  color-scheme: dark;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  --bg: #f4f5fb;
  --text: #191a2c;
  --muted: rgba(25, 26, 44, 0.55);
  --card: rgba(255, 255, 255, 0.72);
  --edge: rgba(255, 255, 255, 0.9);
  --row: rgba(255, 255, 255, 0.75);
  --row-hover: #ffffff;
  --row-edge: rgba(25, 26, 44, 0.06);
  --field: rgba(25, 26, 44, 0.05);
  --line: rgba(25, 26, 44, 0.25);
  --accent: #6366f1;
  --done: #10b981;
  --pill: #ffffff;
  --dot: rgba(25, 26, 44, 0.08);
  --aurora-opacity: 0.45;
  --shadow: 0 30px 70px rgba(70, 70, 140, 0.18);
  color-scheme: light;
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(24px, 8vh, 80px) 16px 32px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ============ Background: a slowly turning aurora over a dot grid ============ */

.aurora {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: -2;
  width: 150vmax;
  height: 150vmax;
  margin: -75vmax 0 0 -75vmax;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #6366f1, #22d3ee, #34d399, #a855f7, #f472b6, #6366f1);
  filter: blur(100px);
  opacity: var(--aurora-opacity);
  animation: turn 48s linear infinite;
  will-change: transform;
}

.dots {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.6px);
  background-size: 22px 22px;
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 30%, #000, transparent);
  mask-image: radial-gradient(ellipse 70% 60% at 50% 30%, #000, transparent);
}

.theme {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--edge);
  border-radius: 50%;
  background: var(--card);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  cursor: pointer;
  transition: transform 0.3s var(--spring);
}
.theme:hover {
  transform: rotate(-20deg) scale(1.05);
}
.theme svg {
  width: 20px;
  height: 20px;
}
:root[data-theme="light"] .sun,
:root:not([data-theme="light"]) .moon {
  display: none;
}

/* ============ Card ============ */

.app {
  width: min(560px, 100%);
  padding: 28px;
  border: 1px solid var(--edge);
  border-radius: 32px;
  background: var(--card);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
  box-shadow: var(--shadow);
  animation: arrive 0.8s var(--ease) backwards;
}

.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.date,
.summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}
h1 {
  margin: 2px 0 4px;
  font-size: clamp(1.7rem, 6vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.ring {
  position: relative;
  flex: none;
  width: 76px;
  height: 76px;
}
.ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.ring circle {
  stroke-width: 4.5;
}
.ring-track {
  stroke: var(--line);
  opacity: 0.45;
}
.ring-progress {
  stroke: url(#ring-gradient);
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset 0.8s var(--ease);
}
.ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ring.complete {
  animation: glow 1.4s var(--ease);
}

/* ============ Add ============ */

.add {
  display: flex;
  gap: 10px;
  padding: 6px;
  border: 1px solid var(--row-edge);
  border-radius: 20px;
  background: var(--field);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.add:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}
.add.shake {
  animation: shake 0.4s ease;
}
.add input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  background: none;
  outline: none;
  font-size: 1.02rem;
}
.add input::placeholder {
  color: var(--muted);
}
.add button {
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(99, 102, 241, 0.4);
  transition: transform 0.35s var(--spring);
}
.add button:hover {
  transform: rotate(90deg);
}
.add button:active {
  transform: rotate(90deg) scale(0.9);
}
.add button svg {
  width: 22px;
  height: 22px;
  stroke-width: 2.6;
}

/* ============ Filter tabs with a sliding pill ============ */

.tabs {
  position: relative;
  display: flex;
  gap: 4px;
  margin: 18px 0 14px;
  padding: 4px;
  border-radius: 16px;
  background: var(--field);
}
.tabs::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: var(--pill-w, 0);
  border-radius: 12px;
  background: var(--pill);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  transform: translateX(var(--pill-x, 0));
  transition:
    transform 0.45s var(--spring),
    width 0.45s var(--spring);
}
.tabs a {
  position: relative;
  flex: 1;
  padding: 9px 10px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: color 0.2s;
}
.tabs a[aria-current="page"] {
  color: var(--text);
}
.tabs span {
  display: inline-block;
  min-width: 1.6em;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--field);
  font-size: 0.78rem;
}

/* ============ Tasks ============ */

.tasks {
  position: relative; /* rows measure their offsetTop from here while dragging */
  margin: 0;
  padding: 0;
  list-style: none;
}
.task {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  padding: 0 6px 0 2px;
  overflow: hidden;
  border: 1px solid var(--row-edge);
  border-radius: 18px;
  background: var(--row);
  transition:
    background-color 0.2s,
    box-shadow 0.25s,
    scale 0.25s var(--spring);
}
.task:hover {
  background: var(--row-hover);
}
.task.dragging {
  z-index: 3;
  overflow: visible;
  background: var(--row-hover);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  scale: 1.03;
}

.grip {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: grab;
  opacity: 0;
  touch-action: none;
  transition: opacity 0.2s;
}
.grip svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  stroke: none;
}
.task:hover .grip,
.grip:focus-visible,
.dragging .grip {
  opacity: 1;
}
.dragging .grip {
  cursor: grabbing;
}

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 14px 4px;
  cursor: pointer;
}
.check input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.box {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 8px;
  transition:
    background-color 0.25s,
    border-color 0.25s;
}
.box svg {
  width: 16px;
  height: 16px;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  transition: stroke-dashoffset 0.3s 0.06s ease;
}
.check:hover .box {
  border-color: var(--accent);
}
.check input:focus-visible + .box {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.done .box {
  border-color: transparent;
  background: linear-gradient(135deg, #34d399, #10b981);
  animation: pop 0.4s var(--spring);
}
.done .box svg {
  stroke-dashoffset: 0;
}

.label-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
/* The strike-through draws itself left to right, line by line. */
.text {
  background: linear-gradient(currentColor, currentColor) no-repeat 0 58% / 0 1.6px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition:
    background-size 0.4s var(--ease),
    color 0.3s;
}
.done .text {
  color: var(--muted);
  background-size: 100% 1.6px;
}

.icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition:
    opacity 0.2s,
    background-color 0.2s,
    color 0.2s;
}
.icon svg {
  width: 18px;
  height: 18px;
}
.task:hover .icon,
.task:focus-within .icon {
  opacity: 1;
}
.icon:hover {
  background: var(--field);
  color: var(--text);
}
.delete:hover {
  color: #f87171;
}

.editing .label-text {
  display: none;
}
.editing .check {
  flex: none;
}
.edit-input {
  flex: 1;
  min-width: 0;
  margin: 8px 4px;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--field);
  outline: none;
}

@media (hover: none) {
  .grip,
  .icon {
    opacity: 0.7;
  }
}

/* ============ Empty state ============ */

.empty {
  padding: 24px 0 12px;
  color: var(--muted);
  text-align: center;
  animation: fade-up 0.5s var(--ease);
}
.empty svg {
  width: 120px;
  height: 120px;
}
.empty .board {
  fill: var(--field);
  stroke: var(--line);
}
.empty .clip {
  fill: var(--bg);
  stroke: var(--line);
}
.empty .tick {
  stroke: var(--done);
  stroke-width: 4;
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
  animation: draw 3.6s var(--ease) infinite;
}
.empty .line {
  stroke: var(--line);
  stroke-width: 4;
}
.empty .t2 {
  animation-delay: 0.35s;
}
.empty .t3 {
  animation-delay: 0.7s;
}
.empty p {
  margin: 4px 0 0;
}

/* ============ Footer, hint, toast ============ */

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}
.link {
  padding: 6px 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.link:hover:not(:disabled) {
  background: var(--field);
}
.link:disabled {
  color: var(--muted);
  opacity: 0.5;
  cursor: default;
}

.hint {
  max-width: 560px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.9;
  text-align: center;
}
kbd {
  padding: 1px 6px;
  border: 1px solid var(--row-edge);
  border-radius: 6px;
  background: var(--row);
  font: inherit;
  font-size: 0.78rem;
}
@media (hover: none) {
  .hint {
    display: none;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 18px;
  border-radius: 16px;
  background: #191a2c;
  color: #f4f4f8;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  translate: -50% 0;
}
.toast.show {
  animation: toast-in 0.45s var(--spring);
}
.toast span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toast button {
  flex: none;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: #6366f1;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 30;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Theme switch: the new theme grows out of the button. */
::view-transition-old(root) {
  animation: none;
}
::view-transition-new(root) {
  animation: reveal 0.6s ease-in-out;
}

/* ============ Keyframes ============ */

@keyframes turn {
  to {
    transform: rotate(1turn);
  }
}
@keyframes arrive {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.98);
  }
}
@keyframes pop {
  40% {
    transform: scale(1.25);
  }
}
@keyframes glow {
  30% {
    transform: scale(1.12);
    filter: drop-shadow(0 0 16px rgba(52, 211, 153, 0.8));
  }
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-8px);
  }
  40%,
  80% {
    transform: translateX(8px);
  }
}
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@keyframes draw {
  0% {
    stroke-dashoffset: 22;
  }
  25%,
  80% {
    stroke-dashoffset: 0;
  }
  100% {
    stroke-dashoffset: 22;
  }
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
}
@keyframes reveal {
  from {
    clip-path: circle(0 at var(--reveal-x, 100%) var(--reveal-y, 0));
  }
  to {
    clip-path: circle(150vmax at var(--reveal-x, 100%) var(--reveal-y, 0));
  }
}

@media (max-width: 480px) {
  .app {
    padding: 20px 16px;
    border-radius: 26px;
  }
  .ring {
    width: 64px;
    height: 64px;
  }
}

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