/* Friggin awesome minimal design */
:root {
  --bg: #0b0d12;
  --surface: #111827;
  --card: #0f172a;
  --muted: #9ca3af;
  --ink: #e5e7eb;
  --accent: #10b981;
  --accent-ink: #052e25;
  --danger: #ef4444;
  --shadow: 0 20px 60px rgba(0,0,0,.35);
  --radius: 16px;
  --ease-out: cubic-bezier(.16,.84,.44,1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg), #0a0f1e 60%);
  color: var(--ink);
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.app-header {
  position: sticky; top: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px clamp(12px, 3vw, 28px);
  background: linear-gradient(180deg, rgba(17,24,39,0.98), rgba(17,24,39,0.7));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand .cart { width: 28px; height: 28px; fill: var(--accent); filter: drop-shadow(0 4px 16px rgba(16,185,129,.35)); }
.brand h1 { margin: 0; font-weight: 750; font-size: clamp(18px, 2.6vw, 26px); letter-spacing: .3px; }
.brand .tag { margin: 0; font-size: 12px; color: var(--muted); }

.actions { display: flex; align-items: center; gap: 8px; }

.btn {
  background: var(--accent);
  color: #052e25; font-weight: 700;
  border: none; padding: 10px 14px; border-radius: 999px;
  box-shadow: 0 10px 26px rgba(16,185,129,.25);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent; color: var(--ink);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: none;
}

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: var(--ink); }
.icon-btn:hover { background: rgba(255,255,255,.12); }

main {
  padding: 18px clamp(10px, 3.4vw, 28px);
  overscroll-behavior-y: contain;  /* tame mobile overscroll/bounce */
}

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

.item {
  display: grid;
  grid-template-columns: 36px 42px 1fr auto;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(17,24,39,.8), rgba(15,23,42,.9));
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 10px;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
  touch-action: pan-y;
}
.item.dragging {
  transform: scale(1.01);
  border-color: rgba(16,185,129,.45);
  background: linear-gradient(180deg, rgba(17,24,39,.9), rgba(15,23,42,1));
  touch-action: none;                    /* stop scroll while dragging */
}
.item.done .title { text-decoration: line-through; opacity: .55; }
.item .title { display: inline-block; min-width: 40px; }

.drag-handle {
  display: grid; place-items: center; cursor: grab;
  width: 44px; height: 44px;            /* bigger touch target */
  touch-action: none;                    /* let JS handle gestures */
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 18px; height: 18px; fill: var(--muted); }

.check {
  display: inline-grid; grid-template-columns: 1em;
  place-items: center;
}
.check input { appearance: none; width: 0; height: 0; position: absolute; }
.check .box {
  width: 26px; height: 26px; border-radius: 8px;
  border: 2px solid rgba(255,255,255,.2);
  display: grid; place-items: center;
  transition: all .15s ease;
}
.item.done .check .box { background: var(--accent); border-color: var(--accent); }
.item.done .check .box::after {
  content: "✓"; font-weight: 900; color: var(--accent-ink);
}

.row-actions { display: flex; gap: 8px; }

.composer {
  position: sticky; bottom: 0;
  padding: 12px clamp(12px, 3vw, 28px);
  background: linear-gradient(0deg, rgba(17,24,39,0.98), rgba(17,24,39,0.75));
  border-top: 1px solid rgba(255,255,255,0.08);
}

#addForm {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px; align-items: center;
}

.input {
  width: 100%;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: var(--ink);
  padding: 12px 14px;
  border-radius: 12px;
  outline: none;
}
.input:focus { border-color: var(--accent); }

.dialog-form {
  display: grid; gap: 12px;
  min-width: min(90vw, 420px);
  background: var(--surface);
  color: var(--ink);
  padding: 18px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
}

.dialog-actions {
  display: flex; gap: 10px; justify-content: flex-end;
}

@media (max-width: 600px) {
  .item { grid-template-columns: 32px 38px 1fr auto; }
  .row-actions .icon-btn { width: 36px; height: 36px; }
}
.item.placeholder {
  opacity: .5;
  background: transparent;
  border: 2px dashed rgba(255,255,255,.18);
}
/* --- Page-open animations & visual burst --- */
@media (prefers-reduced-motion: no-preference) {
  .app-header { animation: drop-in 420ms var(--ease-out) both; }
  .composer   { animation: rise-in 420ms var(--ease-out) 50ms both; }

  /* subtle shine across the brand once */
  .brand { position: relative; overflow: hidden; }
  .brand::after {
    content: "";
    position: absolute; inset: -20% 0 -20% 0;
    left: -140%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.18), transparent);
    transform: skewX(-25deg);
    animation: brand-shine 900ms ease 600ms both;
    pointer-events: none;
  }

  /* staggered list entrance on initial load */
  .animate-in .item {
    animation: float-in 320ms var(--ease-out) both;
    animation-delay: calc(30ms * var(--i, 0));
  }
}

@keyframes drop-in   { from { opacity:0; transform: translateY(-12px) } to { opacity:1; transform:none } }
@keyframes rise-in   { from { opacity:0; transform: translateY(12px) }  to { opacity:1; transform:none } }
@keyframes float-in  { from { opacity:0; transform: translateY(8px) scale(.98) } to { opacity:1; transform:none } }
@keyframes brand-shine { to { left: 140%; } }

/* input pulse cue */
@keyframes pulse-glow {
  0% { box-shadow: 0 0 0 0 rgba(16,185,129,.45); }
  70% { box-shadow: 0 0 0 18px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
.input.glow { animation: pulse-glow 900ms var(--ease-out) 500ms 1; }

/* visible placeholder slot during drag (if not already present) */
.item.placeholder {
  opacity: .5;
  background: transparent;
  border: 2px dashed rgba(255,255,255,.18);
}

/* confetti burst */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 999; overflow: hidden; }
.confetti i {
  position: absolute;
  width: 8px; height: 12px; border-radius: 2px;
  opacity: 0;
  will-change: transform, opacity;
  animation: shoot 700ms var(--ease-out) forwards;
}
@keyframes shoot {
  0%   { transform: translate(var(--x), var(--y)) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translate(calc(var(--x) + var(--dx)), calc(var(--y) + var(--dy))) rotate(var(--rot)); opacity: 0; }
}
body, main, .list-container {
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}


/* Tiny, intentionally-subtle history control */
.history-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.09);
  background: rgba(255,255,255,.035);
  color: var(--muted);
  opacity: .68;
  cursor: pointer;
  padding: 0;
  transition: opacity .15s ease, background .15s ease, border-color .15s ease, transform .15s ease;
}
.history-btn:hover, .history-btn:focus-visible {
  opacity: 1;
  color: var(--ink);
  background: rgba(255,255,255,.075);
  border-color: rgba(16,185,129,.28);
}
.history-btn:active { transform: rotate(-10deg) scale(.96); }
.history-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.history-btn .history-hand { stroke-width: 1.65; }

.history-dialog {
  width: min(94vw, 620px);
  max-height: min(82vh, 760px);
  padding: 0;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.history-dialog::backdrop { background: rgba(0,0,0,.58); backdrop-filter: blur(2px); }
.history-panel { display: grid; grid-template-rows: auto 1fr; max-height: min(82vh, 760px); }
.history-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.history-head h3 { margin: 0; font-size: 17px; }
.history-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.history-head .icon-btn { font-size: 24px; color: var(--ink); line-height: 1; }
.history-list { overflow: auto; padding: 8px 12px 14px; }
.history-row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.history-mark { font-size: 15px; opacity: .8; text-align: center; }
.history-title { font-weight: 650; overflow-wrap: anywhere; }
.history-meta { margin-top: 2px; font-size: 11px; color: var(--muted); }
.history-restore {
  border: 1px solid rgba(16,185,129,.35);
  background: rgba(16,185,129,.08);
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}
.history-restore:hover { background: rgba(16,185,129,.16); }
.history-empty { color: var(--muted); padding: 24px 8px; text-align: center; font-size: 13px; }
