:root {
  --primary: #2e3d34;
  --primary-dark: #1f2b25;
  --secondary: #e8e4d9;
  --accent: #f4a2b6;
  --chalk-white: #f3f0e8;
  --chalk-dim: rgba(243, 240, 232, 0.45);
  --chalk-faint: rgba(243, 240, 232, 0.16);
  --wood: #8a5a33;
  --wood-dark: #6b4424;
  --wood-light: #a9713e;
  --blue: #7fb8e0;
  --pink: #f4a2b6;
  --yellow: #f0d98c;
  --red: #e88b7a;
  --font-chalk: 'Comic Neue', 'Patrick Hand', 'Segoe Print', 'Comic Sans MS', cursive;
  --tray-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #2e3d34;
}

body {
  font-family: var(--font-chalk);
  color: var(--chalk-white);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ------- Chalkboard framing ------- */
#app::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(255,255,255,0.035), transparent 60%),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.06) 0 2px, transparent 2px 4px);
}

#app::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.06), rgba(0,0,0,0.22));
}

/* wood frame */
#app > * { position: relative; z-index: 1; }

header.chalk-header {
  flex: 0 0 auto;
  padding: calc(var(--safe-top) + 14px) 20px 10px;
  background: linear-gradient(180deg, var(--wood-dark), var(--wood));
  border-bottom: 8px solid var(--wood-dark);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.2);
}
header h1 {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.35);
}
.tagline {
  margin: 2px 0 0 28px;
  color: rgba(255,255,255,0.55);
  font-size: 0.82rem;
  font-style: italic;
}

/* ------- Main panels ------- */
#main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 calc(var(--tray-height) + var(--safe-bottom) + 16px);
}

.tab-panel { display: none; padding: 18px 14px 30px; }
.tab-panel.active { display: block; }

h2.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 14px 2px 8px;
  color: var(--chalk-dim);
  text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
}

/* ------- Counters / tally ------- */
.tally-row {
  display: flex;
  gap: 12px;
  margin: 4px 0 8px;
}
.tally-card {
  flex: 1;
  background: rgba(0,0,0,0.12);
  border: 2px solid var(--chalk-faint);
  border-radius: 14px;
  padding: 14px 10px 10px;
  text-align: center;
}
.tally-card.overdue { border-color: rgba(232,139,122,0.4); }
.tally-label {
  font-style: italic;
  font-size: 0.8rem;
  color: var(--chalk-dim);
  margin-bottom: 8px;
}
.tally-marks {
  font-size: 1.5rem;
  line-height: 1.3;
  color: var(--chalk-white);
  min-height: 34px;
}
.tally-marks.empty { color: var(--chalk-faint); font-size: 1.1rem; font-style: italic; }

/* ------- Quick add chalk piece ------- */
.quick-add {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%;
  margin: 8px 0 10px;
  padding: 18px 12px;
  background: linear-gradient(180deg, rgba(244,162,182,0.16), rgba(244,162,182,0.05));
  border: 2px dashed rgba(244,162,182,0.5);
  border-radius: 16px;
  color: var(--accent);
  font-family: var(--font-chalk);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
}
.quick-add .chalk-piece {
  width: 42px; height: 130px;
  background: linear-gradient(180deg, #fdf6f0 0%, #f4d7df 60%, #e8b9c6 100%);
  border-radius: 6px;
  clip-path: polygon(0 0, 70% 0, 100% 100%, 30% 100%);
  box-shadow: inset -3px -4px 6px rgba(0,0,0,0.18), 0 0 8px rgba(255,255,255,0.15);
}
.quick-add .chalk-piece::after {
  content: '';
  position: absolute;
  top: -6px; left: 18%;
  width: 68%; height: 8px;
  background: rgba(120,120,120,0.25);
  border-radius: 50%;
  filter: blur(1px);
}
.quick-add .chalk-piece { position: relative; }

/* ------- Recent list ------- */
.recent-list { display: flex; flex-direction: column; gap: 8px; }

/* ------- Assignment cards ------- */
.card {
  position: relative;
  background: linear-gradient(180deg, #faf7ef, #ece8dc);
  color: #333;
  border-radius: 12px;
  padding: 12px 12px 12px 18px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
  clip-path: polygon(2% 0, 98% 1%, 100% 8%, 99% 92%, 97% 100%, 2% 99%, 0 90%, 1% 8%);
}
.card:active { transform: scale(0.99); }

.card .dot {
  position: absolute;
  top: 10px; left: 10px;
  width: 12px; height: 12px;
  border-radius: 50%;
}
.dot.blue { background: var(--blue); }
.dot.pink { background: var(--pink); }
.dot.yellow { background: var(--yellow); }
.dot.none { background: rgba(0,0,0,0.15); }

.card-title {
  margin: 0 0 2px 16px;
  font-size: 1.05rem;
  font-weight: 700;
}
.card-subject {
  margin: 0 0 4px 16px;
  font-size: 0.8rem;
  color: #7a7466;
  font-style: italic;
}
.card-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin: 6px 0 0 0;
  font-size: 0.78rem;
  color: #6b6658;
}
.due-note { font-style: italic; }
.due-note.overdue { color: #c4533f; font-weight: 700; }
.status-chip { padding: 2px 8px; border-radius: 10px; background: rgba(0,0,0,0.08); }

/* completed crosshatch */
.card.done::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background:
    repeating-linear-gradient(45deg, rgba(120,120,120,0.14) 0 3px, transparent 3px 7px),
    repeating-linear-gradient(-45deg, rgba(120,120,120,0.14) 0 3px, transparent 3px 7px);
  pointer-events: none;
}
.card.done .card-title { color: #666; text-decoration: line-through; }

/* ------- Empty states ------- */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--chalk-faint);
}
.empty-state .board {
  position: relative;
  width: 140px; height: 110px;
  margin: 0 auto 16px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 25% 30%, rgba(255,255,255,0.05) 0 30px, transparent 31px),
    radial-gradient(circle at 75% 65%, rgba(255,255,255,0.04) 0 40px, transparent 41px);
}
.empty-state .board::after {
  content: '';
  position: absolute;
  right: -22px; bottom: -14px;
  width: 70px; height: 26px;
  background: rgba(255,255,255,0.10);
  filter: blur(5px);
  transform: rotate(-18deg);
}
.empty-state p {
  margin: 6px 0;
  font-style: italic;
  font-size: 1rem;
}
.empty-state .prompt { font-size: 0.9rem; }

/* ------- Tasks: search + list ------- */
.search-wrap { position: relative; margin: 4px 0 12px; }
.search-wrap input {
  width: 100%;
  padding: 13px 14px 13px 38px;
  background: rgba(0,0,0,0.15);
  border: 2px solid var(--chalk-faint);
  border-radius: 12px;
  color: var(--chalk-white);
  font-family: var(--font-chalk);
  font-size: 1rem;
  outline: none;
}
.search-wrap input::placeholder { color: var(--chalk-faint); font-style: italic; }
.search-wrap .search-glyph {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  border: 2px solid var(--chalk-dim);
  border-radius: 50%;
}
.search-wrap .search-glyph::after {
  content: '';
  position: absolute; right: -6px; bottom: -3px;
  width: 7px; height: 2px;
  background: var(--chalk-dim);
  transform: rotate(45deg);
}

/* swipe rows */
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-row { position: relative; border-radius: 12px; overflow: hidden; }
.swipe-bg {
  position: absolute; inset: 0;
  display: flex; justify-content: flex-end;
  align-items: center;
  background: rgba(0,0,0,0.25);
  border-radius: 12px;
}
.swipe-actions { display: flex; gap: 6px; padding-right: 8px; }
.swipe-btn {
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  color: #fff;
  font-family: var(--font-chalk);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.swipe-btn.edit { background: var(--wood-light); }
.swipe-btn.del { background: #a84433; }

.card.swipe {
  transition: transform 0.2s ease;
  touch-action: pan-y;
}
.card.swipe.dragging { transition: none; }

/* ------- Board lanes ------- */
.board-lanes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-items: start;
}
.lane {
  border-radius: 10px;
  padding: 6px 5px 80px;
  min-height: 220px;
  border: 2px solid var(--chalk-faint);
  border-left: 3px solid var(--chalk-white);
  position: relative;
}
.lane .lane-title {
  text-align: center;
  font-size: 0.72rem;
  font-style: italic;
  color: var(--chalk-dim);
  margin: 0 0 8px;
  border-bottom: 1px dashed var(--chalk-faint);
  padding-bottom: 6px;
}
.lane .drop-hint {
  position: absolute;
  left: 6px; right: 6px; bottom: 6px;
  text-align: center;
  font-size: 0.68rem;
  font-style: italic;
  color: var(--chalk-faint);
}
.lane .mini-card {
  position: relative;
  background: linear-gradient(180deg, #faf7ef, #ece8dc);
  color: #333;
  border-radius: 8px;
  padding: 8px 6px 8px 12px;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: grab;
  clip-path: polygon(4% 0, 97% 1%, 100% 8%, 99% 92%, 96% 100%, 3% 99%, 0 90%, 1% 8%);
  box-shadow: 0 2px 0 rgba(0,0,0,0.2);
  touch-action: none;
}
.lane .mini-card .mini-dot {
  position: absolute; top: 7px; left: 7px;
  width: 8px; height: 8px; border-radius: 50%;
}
.mini-dot.blue { background: var(--blue); }
.mini-dot.pink { background: var(--pink); }
.mini-dot.yellow { background: var(--yellow); }
.mini-dot.none { background: rgba(0,0,0,0.15); }
.lane .mini-card.done::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 8px;
  background:
    repeating-linear-gradient(45deg, rgba(120,120,120,0.12) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(-45deg, rgba(120,120,120,0.12) 0 2px, transparent 2px 6px);
}
.lane .mini-card.dragging {
  opacity: 0.6;
  transform: rotate(2deg) scale(1.03);
}
.lane.hover { background: rgba(255,255,255,0.05); }

/* ------- Add form ------- */
.form-card {
  background: rgba(0,0,0,0.10);
  border: 2px solid var(--chalk-faint);
  border-radius: 16px;
  padding: 20px 16px 24px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--chalk-dim);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 13px 12px;
  background: rgba(255,255,255,0.06);
  border: 2px solid var(--chalk-faint);
  border-radius: 12px;
  color: var(--chalk-white);
  font-family: var(--font-chalk);
  font-size: 1rem;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}
.field select option { color: #222; background: #fff; }
.field input[type="date"] { color-scheme: dark; }

.field-error {
  color: var(--red);
  font-size: 0.78rem;
  font-style: italic;
  margin-top: 5px;
  min-height: 1em;
}
input.invalid, select.invalid { border-color: var(--red) !important; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1;
  padding: 14px 12px;
  border: none;
  border-radius: 12px;
  font-family: var(--font-chalk);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}
.btn.save {
  background: linear-gradient(180deg, #f6f3ea, #ded9c8);
  color: #2e3d34;
}
.btn.save:hover { background: #fff; }
.btn.ghost {
  background: transparent;
  border: 2px solid var(--chalk-dim);
  color: var(--chalk-dim);
}
.btn.erase { background: linear-gradient(180deg, #c4614d, #a84433); color: #fff; }
.btn.hidden { display: none; }

/* ------- Modal ------- */
.modal {
  position: fixed; inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  background: linear-gradient(180deg, #f3f0e8, #e4dfd2);
  color: #333;
  border-radius: 16px;
  padding: 24px 20px;
  width: 100%;
  max-width: 300px;
  text-align: center;
  clip-path: polygon(3% 0, 97% 1%, 100% 7%, 99% 93%, 97% 100%, 3% 99%, 0 92%, 1% 7%);
}
.modal-title { margin: 0 0 6px; font-size: 1.2rem; font-weight: 700; }
.modal-sub { margin: 0 0 20px; font-size: 0.9rem; font-style: italic; color: #6b6658; }
.modal-actions { display: flex; gap: 10px; }

/* ------- Bottom tray ------- */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: var(--tray-height);
  padding: 0 4px calc(var(--safe-bottom) + 8px);
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  background:
    linear-gradient(180deg, var(--wood-light), var(--wood) 40%, var(--wood-dark)),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.08) 0 3px, transparent 3px 7px);
  border-top: 6px solid var(--wood-dark);
  box-shadow: 0 -4px 14px rgba(0,0,0,0.45);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 6px 2px 2px;
  cursor: pointer;
  color: rgba(255,255,255,0.6);
  font-family: var(--font-chalk);
  font-size: 0.72rem;
  position: relative;
  border-radius: 10px;
}
.tab-btn.active { color: #fff; }
.tab-btn.active .tab-label { text-shadow: 0 0 6px rgba(255,255,255,0.6); }

/* chalk sticks */
.chalk-stick {
  position: relative;
  width: 34px;
  height: 96px;
  display: block;
  transition: transform 0.25s ease;
}
.chalk-stick::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 4px;
}
.chalk-stick[data-color="blue"]::before { background: linear-gradient(180deg, #b9daf2, #7fb8e0 55%, #5f9dcb); }
.chalk-stick[data-color="pink"]::before { background: linear-gradient(180deg, #fbd3de, #f4a2b6 55%, #e2849b); }
.chalk-stick[data-color="yellow"]::before { background: linear-gradient(180deg, #f6e9bb, #f0d98c 55%, #e0c05f); }
.chalk-stick[data-color="white"]::before { background: linear-gradient(180deg, #fdfbf5, #ece8dc 55%, #d9d3c0); }

/* tapered chalk tip */
.chalk-stick::after {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px; height: 12px;
  border-radius: 50% 50% 40% 40%;
  background: rgba(140,140,130,0.7);
  clip-path: polygon(0 0, 100% 0, 68% 100%, 32% 100%);
}

/* active: lift + dusty shadow */
.tab-btn.active .chalk-stick {
  transform: translateY(-22px) rotate(-4deg);
}
.tab-btn.active .chalk-stick::before {
  filter: saturate(0.7);
  box-shadow: 0 12px 16px rgba(0,0,0,0.4);
}
.tab-btn.active .chalk-stick::after {
  width: 8px; height: 16px;
  background: radial-gradient(circle at 40% 30%, rgba(255,255,255,0.5), rgba(160,150,130,0.4));
}
/* chalk dust on board under active stick */
.tab-btn.active .chalk-stick + .tab-label::before {
  content: '';
  position: absolute;
  top: -46px; left: 50%;
  transform: translateX(-50%);
  width: 26px; height: 10px;
  background: rgba(255,255,255,0.18);
  filter: blur(3px);
  border-radius: 50%;
}
.tab-label { position: relative; }