@property --c {
  syntax: '<color>';
  inherits: true;
  initial-value: #ff4355;
}

:root {
  --paper: #fdfdfb;
  --sheet: #ffffff;
  --line: #8fd8f5;
  --ink: #24125c;
  --muted: #5c4f87;
  --red: #c4002f;
  --shadow: 36 18 92;
  --body: 'Playpen Sans Thai', 'Thonburi', 'Leelawadee UI', cursive;
  --hand: var(--body);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: minmax(36px, 5dvh) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  font: 400 1rem/1.55 var(--body);
}

html { background: var(--paper); }

.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }

.ground {
  position: absolute;
  inset: -40px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .3 0 0 0 0 .4 0 0 0 .1 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(90deg, transparent 2.2vw, #d98c86 2.2vw calc(2.2vw + 1px), transparent calc(2.2vw + 1px) calc(2.2vw + 4px), #d98c86 calc(2.2vw + 4px) calc(2.2vw + 5px), transparent calc(2.2vw + 5px)),
    repeating-linear-gradient(transparent 0 31px, var(--line) 31px 32px),
    var(--paper);
}

.ground::before {
  content: '';
  position: absolute;
  right: -20px;
  bottom: -20px;
  width: 320px;
  aspect-ratio: 1;
  border: 9px double rgb(120 78 40 / .28);
  border-radius: 50% 48% 51% 49%;
  filter: blur(.6px);
}

.cracks { position: absolute; inset: 0; width: 100%; height: 100%; fill: none; stroke: #221536; stroke-linejoin: miter; filter: drop-shadow(1.5px 1.5px 0 rgb(255 255 255 / .8)); }
.cracks polygon { fill: #221536; stroke: none; }

.siren-light { position: absolute; inset: 0; opacity: 0; transition: opacity .6s; }
.siren-light::before, .siren-light::after { content: ''; position: absolute; inset: 0; }
.siren-light::before { background: linear-gradient(100deg, rgb(255 20 50 / .85), rgb(255 60 80 / .5) 45%, transparent 85%); }
.siren-light::after { background: linear-gradient(260deg, rgb(20 90 255 / .85), rgb(60 120 255 / .5) 45%, transparent 85%); opacity: 0; }

.siren .siren-light { opacity: 1; }
.siren .siren-light::before { animation: siren 1.1s ease-in-out infinite; }
.siren .siren-light::after { animation: siren 1.1s ease-in-out -.55s infinite; }
.siren .tab { filter: drop-shadow(0 -2px 3px rgb(var(--shadow) / .55)); }
.siren .board { padding-inline: clamp(.9rem, 7vw, 7rem); }

@keyframes siren {
  0%, 100% { opacity: 1; }
  50% { opacity: .05; }
}

.quake .ground { --amp: 8px; animation: quake .6s linear infinite; }
.cracking .ground { --amp: 14px; animation-duration: .45s; }

@keyframes quake {
  0%, 100% { transform: none; }
  12% { transform: translate(calc(var(--amp) * -1), calc(var(--amp) * .6)) rotate(-.3deg); }
  25% { transform: translate(var(--amp), calc(var(--amp) * -.7)) rotate(.3deg); }
  37% { transform: translate(calc(var(--amp) * -.6), calc(var(--amp) * -1)) rotate(-.15deg); }
  50% { transform: translate(calc(var(--amp) * .8), var(--amp)) rotate(.25deg); }
  62% { transform: translate(calc(var(--amp) * -1), calc(var(--amp) * -.4)) rotate(-.25deg); }
  75% { transform: translate(calc(var(--amp) * .5), calc(var(--amp) * .9)) rotate(.2deg); }
  88% { transform: translate(calc(var(--amp) * -.4), calc(var(--amp) * -.8)) rotate(-.1deg); }
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 3px solid #1c6dd0; outline-offset: 2px; }

.bar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 clamp(.75rem, 3vw, 2.5rem);
}

.burger {
  display: grid;
  gap: 5px;
  padding: 8px;
  border: 0;
  background: none;
}

.burger i {
  width: 26px;
  height: 3px;
  border-radius: 2px;
  background: var(--ink);
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
}

.burger:hover i:nth-child(1) { transform: translateX(4px); }
.burger:hover i:nth-child(3) { transform: translateX(-4px); }

.page-title {
  flex: 1;
  margin: 0;
  overflow: hidden;
  font: 600 1rem/1.5 var(--body);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.add-task {
  padding: 0 .9rem;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--sheet);
  font-weight: 600;
  line-height: 1.75;
  white-space: nowrap;
  transition: transform .2s, box-shadow .2s;
}

.add-task:hover { transform: translateY(-1px) rotate(-1deg); box-shadow: 2px 3px 0 rgb(var(--shadow) / .25); }

#view { min-height: 0; overflow: auto; }
[data-page='home'] #view { overflow: hidden; }

.board {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin: 0;
  padding: .25rem clamp(.75rem, 3vw, 2.5rem) 0;
  list-style: none;
}

.folder {
  position: relative;
  flex: 1;
  min-height: 0;
  z-index: var(--i);
  --tab: clamp(26px, 4.4dvh, 42px);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.folder[data-slot='0'] { --c: #ff4355; }
.folder[data-slot='1'] { --c: #ff8f1f; }
.folder[data-slot='2'] { --c: #17c964; }
.folder[data-slot='3'] { --c: #2196ff; }
.folder[data-slot='4'] { --c: #a855ff; }

.back, .sheet, .pocket { position: absolute; left: 0; right: 0; }

.back {
  top: var(--tab);
  bottom: 0;
  border-radius: 10px 10px 0 0;
  background: color-mix(in oklab, var(--c), white 38%);
  box-shadow: 0 -5px 14px rgb(var(--shadow) / .28);
}

.tab {
  position: absolute;
  top: 0;
  left: calc(1.5% + var(--i) * 19.6%);
  width: 18%;
  height: calc(var(--tab) + 1px);
  display: grid;
  place-items: center;
  padding: 0 1rem;
  color: var(--ink);
  font: 800 clamp(.85rem, 2.1dvh, 1.2rem)/1.8 var(--hand);
}

.tab::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px 10px 0 0;
  background: color-mix(in oklab, var(--c), white 38%);
  transform: perspective(60px) rotateX(9deg);
  transform-origin: bottom;
}

.tab span {
  position: relative;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sheet {
  top: calc(var(--tab) + 5px);
  bottom: 0;
  left: 1.2%;
  right: 1.2%;
  border-radius: 3px 3px 0 0;
  background: repeating-linear-gradient(transparent 0 5px, #cdd9e4 5px 6px), #fdfdfa;
  transform-origin: bottom;
  transition: transform .4s cubic-bezier(.3, 1.8, .5, 1);
  animation: peek 7s ease-in-out infinite;
  animation-delay: calc(var(--i) * -1.7s);
}

.folder:hover .sheet { transform: translateY(-9px) rotate(-.25deg); animation: none; }

@keyframes peek {
  0%, 70%, 100% { transform: none; }
  80% { transform: translateY(-5px) rotate(.2deg); }
  88% { transform: translateY(-2px); }
}

.pocket {
  top: calc(var(--tab) + 17px);
  bottom: -60px;
  border-radius: 8px 8px 0 0;
  background: var(--c);
  box-shadow: 0 -2px 5px rgb(0 0 0 / .25);
}

.face {
  position: absolute;
  inset: calc(var(--tab) + 17px) 0 0;
  container-type: size;
  display: flex;
  align-items: center;
  padding: 0 clamp(1rem, 3vw, 3rem);
}

.title {
  flex: 1;
  min-width: 0;
  margin: 0;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  padding: .15em .1em .14em;
  margin-left: -.1em;
  color: #fff;
  -webkit-text-stroke: .13em var(--ink);
  paint-order: stroke fill;
  font-size: clamp(1.05rem, max(min(4.4cqw, 28cqh), min(44cqh, 130cqw / var(--len))), 11rem);
  font-weight: 800;
  line-height: 1.6;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.board[data-count='1'] .title, .board[data-count='2'] .title { -webkit-line-clamp: 4; }

.tools {
  position: absolute;
  right: clamp(.75rem, 2vw, 2rem);
  top: 50%;
  display: flex;
  gap: .5rem;
  padding: .4rem;
  border-radius: 8px;
  background: rgb(255 255 255 / .45);
  opacity: 0;
  transform: translate(16px, -50%);
  transition: opacity .2s, transform .3s cubic-bezier(.3, 1.5, .5, 1);
}

.folder:hover .tools, .folder:focus-within .tools { opacity: 1; transform: translate(0, -50%); }

.tools button {
  padding: .25rem .8rem;
  border: 0;
  border-radius: 4px;
  background: #fdfdfa;
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
  transition: transform .15s;
}

.tools button:hover { transform: translateY(-2px); }
.tools button:active { transform: scale(.94); }
.tools .finish { background: var(--ink); color: #fff; }

.stamp {
  position: absolute;
  top: 55%;
  left: 50%;
  padding: 0 1.4rem;
  border: 5px double var(--red);
  border-radius: 8px;
  background: #fdfdfa;
  color: var(--red);
  font: 800 clamp(1.6rem, 6dvh, 4rem)/1.5 var(--body);
  transform: translate(-50%, -50%) rotate(-9deg);
}

.plane { position: fixed; z-index: 60; width: 90px; pointer-events: none; filter: drop-shadow(0 10px 8px rgb(var(--shadow) / .35)); }

.empty {
  display: grid;
  place-content: center;
  justify-items: center;
  height: 100%;
  padding: 1rem;
  text-align: center;
}

.empty p { margin: 1.2rem 0; color: var(--muted); }
.empty .empty-title { margin: 1.5rem 0 0; color: var(--ink); font-size: clamp(2rem, 7vw, 5.5rem); font-weight: 800; line-height: 1.4; }

.envelope { position: relative; width: clamp(150px, 20vw, 260px); aspect-ratio: 8 / 5; animation: float 4s ease-in-out infinite; }
.envelope i { position: absolute; inset: 0; border-radius: 6px; background: #ffa94d; box-shadow: 0 14px 24px rgb(var(--shadow) / .25); }
.envelope b { position: absolute; inset: 0; background: #ff7f32; clip-path: polygon(0 0, 100% 0, 50% 62%); }

@keyframes float { 50% { transform: translateY(-10px) rotate(-2deg); } }

.primary, .plain, .danger { padding: .4rem 1.1rem; border: 1.5px solid transparent; border-radius: 4px; font-weight: 600; white-space: nowrap; transition: transform .15s; }
.primary { background: var(--ink); color: #fff; }
.plain { border-color: var(--line); background: none; }
.danger { background: none; color: var(--red); }
.primary:active, .plain:active, .danger:active { transform: scale(.95); }

.paper {
  width: min(860px, calc(100% - 2rem));
  min-height: calc(100% - 2rem);
  margin: .5rem auto 1.5rem;
  padding: clamp(1.25rem, 4vw, 3rem);
  background: var(--sheet);
  box-shadow: 0 2px 3px rgb(var(--shadow) / .18), 0 16px 34px rgb(var(--shadow) / .14);
}

.paper h2 { margin: 0 0 1.25rem; font-size: 2rem; font-weight: 800; line-height: 1.4; }

.add-row { display: flex; gap: .6rem; margin-bottom: 1.25rem; }

input, textarea { width: 100%; min-width: 0; padding: .4rem .7rem; border: 1.5px solid #8a7cc0; border-radius: 4px; background: #fff; }
::placeholder { color: #6d6196; opacity: 1; }
.add-row .tag-input { width: 11rem; flex: none; }

.rows { margin: 0; padding: 0; list-style: none; }
.rows li { display: flex; align-items: center; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.row-text { flex: 1; min-width: 0; }
.row-title { display: block; font-size: 1.1rem; overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; color: var(--muted); font-size: .9rem; }
.chip { padding: 0 .55rem; border-radius: 6px 6px 0 0; background: #ffd84d; color: var(--ink); font-family: var(--hand); }
.row-tools { display: flex; gap: .25rem; }
.row-tools button { padding: .25rem .7rem; border: 0; border-radius: 4px; background: none; font-weight: 600; white-space: nowrap; }
.row-tools button:not(:disabled):hover { background: #fff2a0; }
.row-tools .start { background: #17c964; }
.row-tools .start:not(:disabled):hover { background: #4adb88; }
.tag-name { padding: 0 .4rem; margin-left: -.4rem; border-color: transparent; background: none; font-size: 1.1rem; }
.tag-name:hover, .tag-name:focus { border-color: #8a7cc0; background: #fff; }
.no-rows { padding: 2rem 0; color: var(--muted); text-align: center; }

dialog { border: 0; color: var(--ink); }
dialog::backdrop { background: rgb(36 18 92 / .45); opacity: 0; transition: opacity .3s, overlay .3s allow-discrete, display .3s allow-discrete; }
dialog[open]::backdrop { opacity: 1; }

.drawer {
  width: min(320px, 86vw);
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 1.5rem 1.5rem 1.5rem 0;
  background: #00b5c8;
  box-shadow: 8px 0 30px rgb(0 0 0 / .35);
  transform: translateX(-105%);
  transition: transform .45s cubic-bezier(.2, 1, .3, 1), overlay .45s allow-discrete, display .45s allow-discrete;
}

.drawer[open] { transform: none; }
.brand { margin: 0 0 2rem 1.5rem; color: var(--ink); font-size: 1.9rem; font-weight: 800; line-height: 1.2; }
.drawer-close { position: absolute; top: .75rem; right: .75rem; width: 40px; height: 40px; border: 0; background: none; color: var(--ink); font-size: 1.8rem; line-height: 1; }

.drawer nav { display: grid; gap: .7rem; }
.drawer a {
  display: flex;
  justify-content: space-between;
  padding: .8rem 1.2rem .8rem 1.5rem;
  border-radius: 0 8px 8px 0;
  background: #ffd84d;
  color: var(--ink);
  font: 600 1.1rem/1.5 var(--hand);
  text-decoration: none;
  box-shadow: 0 3px 6px rgb(0 0 0 / .25);
  transition: translate .3s cubic-bezier(.3, 1.6, .5, 1);
}
.drawer a:hover { translate: 10px 0; }
.drawer a[aria-current] { background: var(--sheet); }

.note {
  width: min(480px, calc(100% - 2rem));
  padding: 1.75rem;
  border-radius: 3px;
  background: #ffc1de;
  box-shadow: 0 20px 44px rgb(0 0 0 / .35);
  opacity: 0;
  transform: translateY(-50px) rotate(-5deg);
  transition: transform .4s cubic-bezier(.3, 1.4, .5, 1), opacity .25s, overlay .4s allow-discrete, display .4s allow-discrete;
}

.note[open] { opacity: 1; transform: none; }
@starting-style {
  .drawer[open] { transform: translateX(-105%); }
  .note[open] { opacity: 0; transform: translateY(-50px) rotate(-5deg); }
  dialog[open]::backdrop { opacity: 0; }
}

.note h2 { margin: 0 0 1rem; font-size: 1.4rem; line-height: 1.4; }
.note label { display: block; margin-bottom: 1rem; font-weight: 600; }
.note input, .note textarea { display: block; border-color: #b04a80; background: #fff; font-weight: 400; resize: vertical; }
.note textarea { font-size: 1.2rem; }
.note-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.note .plain { border-color: #b04a80; }
.note .danger { margin-right: auto; padding-left: 0; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  width: max-content;
  max-width: calc(100% - 2rem);
  padding: .6rem 1.2rem;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 8px 24px rgb(0 0 0 / .35);
  visibility: hidden;
  transform: translate(-50%, 160%);
  transition: transform .4s cubic-bezier(.3, 1.4, .5, 1), visibility .4s;
}

.toast.show { visibility: visible; transform: translate(-50%, 0); }
.toast button { border: 0; background: none; color: #ffd98a; font-weight: 600; text-decoration: underline; white-space: nowrap; }

.sorting .folder { transition: translate .28s cubic-bezier(.3, 1.4, .5, 1), --c .3s; }
.sorting .tab { transition: left .28s; }
.sorting .tools { visibility: hidden; }
.is-dragging, .is-dragging * { cursor: grabbing !important; }

.sorting .folder.dragging { z-index: 40; scale: .9; transition: scale .25s cubic-bezier(.3, 1.5, .5, 1), --c .3s; }
.sorting .folder.over-trash { scale: .3; }
.folder.crumpling, .sorting .folder.crumpling { z-index: 45; scale: none; transition: none; }
.crumpling .tools { visibility: hidden; }
.dragging .pocket { bottom: 0; }
.dragging .back { box-shadow: 0 18px 36px rgb(var(--shadow) / .4); }

.trash {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 70;
  width: 72px;
  pointer-events: none;
  visibility: hidden;
  transform-origin: bottom;
  scale: 0;
  transition: scale .3s cubic-bezier(.3, 1.7, .5, 1), visibility .3s;
}

.trash.show { visibility: visible; scale: 1; }
.trash.open { scale: 1.25; }
.trash svg { display: block; overflow: visible; filter: drop-shadow(0 5px 6px rgb(var(--shadow) / .35)); }
.lid { transform-box: fill-box; transform-origin: 100% 100%; transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.trash.open .lid { transform: rotate(58deg); }

.paper-ball { position: fixed; z-index: 60; width: 96px; height: 96px; transform: translate(-50%, -50%); pointer-events: none; }
.paper-ball svg { display: block; }

@media (hover: none) {
  .tools { position: static; opacity: 1; transform: none; }
  .folder:hover .tools, .folder:focus-within .tools { transform: none; }
}

@media (max-width: 640px) {
  .tab { left: calc(1% + var(--i) * 14%); width: 42%; }
  .face { flex-direction: column; align-items: stretch; justify-content: center; gap: .3rem; }
  .title { flex: none; font-size: clamp(1rem, min(7cqw, 18cqh), 3rem); line-height: 1.6; }
  .tools { align-self: flex-end; padding: .2rem; }
  .tools button { padding: 0 .6rem; font-size: .9rem; }
  .add-row { flex-wrap: wrap; }
  .add-row .tag-input { width: auto; flex: 1; }
  .add-row [name='title']:first-child { flex-basis: 100%; }
  .rows li { flex-direction: column; align-items: stretch; gap: .3rem; }
  .row-tools { justify-content: flex-end; }
}

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