/* ─── Custom properties ───────────────────────────────────────────── */
:root {
  --paper:      #F4EEDE;
  --paper-edge: #E7DEC4;
  --line:       #D9CDAB;
  --ink:        #2B2924;
  --ink-soft:   #756F5C;
  --blue:       #2F4D7A;
  --gold:       #C08A32;

  /* Section accent palette — washi tape strips */
  --accent-0: #7B9E87;  /* sage */
  --accent-1: #C4704F;  /* terracotta */
  --accent-2: #6E8FB3;  /* dusty blue */
  --accent-3: #B07DB0;  /* mauve */
  --accent-4: #C4A24F;  /* ochre */
  --accent-5: #7AADA8;  /* teal */

  --font-display: 'Caveat', cursive;
  --font-content: 'Kalam', cursive;
  --font-ui:      -apple-system, 'Segoe UI', sans-serif;

  --card-rot-even: 1.2deg;
  --card-rot-odd:  -0.9deg;
}

/* ─── Reset / base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  min-height: 100dvh;
  padding-bottom: 80px;
}

/* ─── Header ──────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--paper);
  border-bottom: 1.5px solid var(--paper-edge);
  padding: 0 1.25rem;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.app-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tally {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-right: 0.25rem;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--paper-edge); color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ─── Canvas ──────────────────────────────────────────────────────── */
.canvas {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 1rem;
}

/* ─── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem 2rem;
}
.empty-state.hidden { display: none; }
.empty-heading {
  font-family: var(--font-content);
  font-size: 1.4rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
}
.empty-sub {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--ink-soft);
  max-width: 340px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ─── Sections grid ───────────────────────────────────────────────── */
.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2.5rem 2rem;
  align-items: start;
}

/* ─── Section card ────────────────────────────────────────────────── */
.section-card {
  background: #FFFDF7;
  border: 1.5px solid var(--paper-edge);
  border-radius: 3px;
  box-shadow: 2px 3px 10px rgba(43,41,36,0.10), 0 1px 2px rgba(43,41,36,0.06);
  position: relative;
  padding: 0 0 1rem;
  /* rotation applied inline per card */
}

/* Washi tape strip */
.section-card::before {
  content: '';
  display: block;
  height: 22px;
  width: 60%;
  max-width: 140px;
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  border-radius: 2px;
  opacity: 0.82;
  /* background-color set inline per card */
}

.section-header {
  padding: 1.5rem 1rem 0.5rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  position: relative;
}

.section-name-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.section-name {
  font-family: var(--font-content);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  word-break: break-word;
  line-height: 1.2;
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 3px;
  transition: background 0.12s;
}
.section-name:hover { background: var(--paper-edge); }

.section-name-input {
  font-family: var(--font-content);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  border: none;
  border-bottom: 2px solid var(--blue);
  background: transparent;
  outline: none;
  width: 100%;
  padding: 1px 3px;
}

.section-meta {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--ink-soft);
  white-space: nowrap;
  padding-top: 4px;
  flex-shrink: 0;
}

.section-controls {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-shrink: 0;
}

.section-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s;
}
.section-menu-btn:hover { background: var(--paper-edge); color: var(--ink); }
.section-menu-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ─── Hide-done toggle ────────────────────────────────────────────── */
.hide-done-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0 1rem 0.6rem;
  user-select: none;
}
.hide-done-label input { accent-color: var(--blue); cursor: pointer; }

/* ─── Items list ──────────────────────────────────────────────────── */
.items-list {
  list-style: none;
  padding: 0;
}

.item-row {
  border-top: 1px solid var(--line);
  padding: 0.55rem 1rem 0;
}
.item-row:last-child { padding-bottom: 0.4rem; }

.item-main {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

/* ─── Hand-drawn checkbox ─────────────────────────────────────────── */
.checkbox-wrap {
  flex-shrink: 0;
  margin-top: 3px;
}

.hand-checkbox {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.hand-checkbox input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 20px;
  height: 20px;
  margin: 0;
  cursor: pointer;
  z-index: 1;
  -webkit-appearance: none;
  appearance: none;
}

.hand-checkbox .box {
  display: block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--ink-soft);
  border-radius: 3px 4px 3px 5px / 4px 3px 5px 3px;
  background: transparent;
  position: relative;
  transition: border-color 0.15s;
}

.hand-checkbox input:focus-visible + .box {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.hand-checkbox .check-mark {
  position: absolute;
  top: 1px;
  left: 2px;
  width: 14px;
  height: 12px;
  pointer-events: none;
  overflow: visible;
}

.hand-checkbox .check-path {
  stroke: var(--blue);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  stroke-dasharray: 28;
  stroke-dashoffset: 28;
}

.hand-checkbox input:checked + .box {
  border-color: var(--blue);
  background: rgba(47, 77, 122, 0.07);
}

.hand-checkbox input:checked ~ .check-mark .check-path {
  animation: ink-check 0.28s cubic-bezier(.4,0,.2,1) forwards;
}

/* When already checked on load (no animation) */
.hand-checkbox.already-checked .check-path {
  stroke-dashoffset: 0;
  animation: none;
}

@keyframes ink-check {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .hand-checkbox .check-path { transition: stroke-dashoffset 0s; }
  @keyframes ink-check { to { stroke-dashoffset: 0; } }
}

/* ─── Item text ───────────────────────────────────────────────────── */
.item-text-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.item-text {
  font-family: var(--font-content);
  font-size: 1rem;
  color: var(--ink);
  word-break: break-word;
  line-height: 1.4;
  cursor: pointer;
  border-radius: 3px;
  padding: 0 2px;
  flex: 1;
  transition: background 0.12s;
}
.item-text:hover { background: var(--paper-edge); }

.item-text-input {
  font-family: var(--font-content);
  font-size: 1rem;
  color: var(--ink);
  border: none;
  border-bottom: 1.5px solid var(--blue);
  background: transparent;
  outline: none;
  width: 100%;
  padding: 0 2px;
  line-height: 1.4;
}

.item-done .item-text {
  text-decoration: line-through;
  color: var(--ink-soft);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

.item-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.item-btn:hover { background: var(--paper-edge); color: var(--ink); }
.item-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.item-btn.expand-btn.open { color: var(--blue); }

/* ─── Item expand panel ───────────────────────────────────────────── */
.item-expand {
  display: none;
  padding: 0.5rem 0 0.4rem 2rem;
  gap: 0.5rem;
  flex-direction: column;
}
.item-expand.open { display: flex; }

.expand-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.expand-label {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.expand-notes {
  font-family: var(--font-content);
  font-size: 0.92rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255,255,255,0.5);
  padding: 0.4rem 0.5rem;
  resize: vertical;
  min-height: 60px;
  outline: none;
  line-height: 1.5;
  width: 100%;
}
.expand-notes:focus { border-color: var(--blue); }

.expand-date {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255,255,255,0.5);
  padding: 0.3rem 0.5rem;
  outline: none;
  width: auto;
}
.expand-date:focus { border-color: var(--blue); }

/* ─── Star rating ─────────────────────────────────────────────────── */
.star-rating {
  display: flex;
  gap: 0.15rem;
  align-items: center;
}

.star-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--line);
  transition: color 0.12s, transform 0.1s;
  line-height: 1;
}
.star-btn:hover,
.star-btn.active { color: var(--gold); }
.star-btn:hover { transform: scale(1.15); }
.star-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 3px; }

.star-btn svg { display: block; }

/* ─── Add item form ───────────────────────────────────────────────── */
.add-item-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem 0;
  border-top: 1px solid var(--line);
}

.add-item-input {
  flex: 1;
  font-family: var(--font-content);
  font-size: 0.95rem;
  color: var(--ink);
  border: none;
  border-bottom: 1px dashed var(--line);
  background: transparent;
  outline: none;
  padding: 2px 2px 3px;
  transition: border-color 0.15s;
}
.add-item-input::placeholder { color: var(--line); }
.add-item-input:focus { border-color: var(--ink-soft); }

.add-item-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.add-item-btn:hover { background: var(--blue); border-color: var(--blue); color: #fff; }
.add-item-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ─── Item done state ─────────────────────────────────────────────── */
.item-done {
  opacity: 0.62;
}

/* ─── Add section bar ─────────────────────────────────────────────── */
.add-section-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--paper);
  border-top: 1.5px solid var(--paper-edge);
  padding: 0.75rem 1.25rem;
  z-index: 100;
}

.add-section-form {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.add-section-input {
  flex: 1;
  font-family: var(--font-content);
  font-size: 1rem;
  color: var(--ink);
  border: 1.5px solid var(--paper-edge);
  border-radius: 6px;
  background: #FFFDF7;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
}
.add-section-input::placeholder { color: var(--line); }
.add-section-input:focus { border-color: var(--blue); }

.add-section-btn {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: var(--blue);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.add-section-btn:hover { opacity: 0.88; }
.add-section-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

/* ─── Modal ───────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43,41,36,0.35);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: #FFFDF7;
  border: 1.5px solid var(--paper-edge);
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(43,41,36,0.18);
  padding: 1.5rem;
  max-width: 360px;
  width: 100%;
}

.modal-title {
  font-family: var(--font-content);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.modal-body {
  font-family: var(--font-ui);
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.btn-secondary {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: 1.5px solid var(--paper-edge);
  border-radius: 5px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--paper-edge); }
.btn-secondary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.btn-danger {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: #B84040;
  border: none;
  border-radius: 5px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-danger:hover { opacity: 0.88; }
.btn-danger:focus-visible { outline: 2px solid #B84040; outline-offset: 2px; }

/* ─── Section empty state ─────────────────────────────────────────── */
.section-empty {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--line);
  padding: 0.6rem 1rem 0.4rem;
  border-top: 1px solid var(--line);
  font-style: italic;
}

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .sections-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  .section-card {
    /* straighten slightly on narrow screens so it fits */
    transform: rotate(0deg) !important;
  }
}
