/* ============ Pixel Chores — stile Game Boy ============ */
:root {
  --paper: #f8f4e6;
  --paper-2: #eef0d4;
  --ink: #2b2b2b;
  --muted: #6f6e58;
  --green: #8bac0f;
  --magenta: #d73a6e;
  --cyan: #2ea8b8;
  --orange: #f5871f;
  --blue: #6b8cae;
  --yellow: #ffd23f;
  --faint: #e0d9bd;
  --white: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}
html {
  background: transparent;
}
body {
  background: #e8eecf;
  min-height: 100vh;
}

body {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 20px;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
  transition: background-color .35s ease;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

/* ---------- Pixel render ---------- */
.pixel { display: grid; image-rendering: pixelated; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  background: var(--paper);
  border-bottom: 3px solid var(--ink);
}
.brand {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  line-height: 1.4;
  margin: 0;
  color: var(--green);
}
.date { display: block; margin-top: 3px; font-size: 17px; color: var(--muted); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  flex: 0 0 auto;
  padding: 0;
}
.icon-btn:active { transform: scale(.92); }
.settings-icon { width: 26px; height: 26px; }
.head-actions { display: flex; align-items: center; gap: 4px; }

/* ---------- Views ---------- */
.views { padding: 12px 12px 0; }
.view.hidden { display: none; }

/* ---------- Home ---------- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 0 12px;
}
.hero .pixel { image-rendering: pixelated; }
.speech {
  font-size: 18px;
  background: var(--white);
  border: 2px solid var(--ink);
  padding: 2px 10px;
}
.streak {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border: 2px solid var(--ink);
  padding: 5px 12px;
  box-shadow: 3px 3px 0 rgba(0,0,0,.2);
  font-size: 19px;
}
.streak .streak-num { font-family: 'Press Start 2P', monospace; font-size: 16px; }

.mini-title {
  font-size: 18px;
  letter-spacing: 2px;
  border-bottom: 2px solid var(--ink);
  margin: 10px 0 6px;
  color: var(--muted);
}
.ghost {
  font-family: inherit;
  font-size: 18px;
  border: 2px dashed var(--ink);
  background: transparent;
  color: var(--muted);
  padding: 4px 12px;
  cursor: pointer;
  margin: 12px auto;
  display: block;
}
.empty { color: var(--muted); font-size: 19px; padding: 6px 2px; }

/* ---------- Sezioni ---------- */
.section {
  border: 3px solid var(--ink);
  background: var(--paper);
  margin-bottom: 12px;
}
.sec-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0,0,0,.35);
}
.sec-head .pixel { background: #fff; border: 2px solid var(--ink); padding: 2px; }
.sec-head .t { font-size: 22px; letter-spacing: 1px; flex: 1 1 auto; }
.sec-head .pct { font-size: 17px; opacity: .95; }
.s-grass   { background: var(--green); }
.s-week    { background: var(--orange); }
.s-month   { background: var(--magenta); }
.s-whenever{ background: var(--cyan); }
.s-bins    { background: var(--blue); }

.sec-body { padding: 4px 8px 8px; }

/* ---------- Chore ---------- */
.chore {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--faint);
}
.chore:last-child { border-bottom: none; }
.chore .name { flex: 1 1 auto; font-size: 21px; line-height: 1.05; }
.chore.done .name { color: var(--muted); text-decoration: line-through; }

.boxes { display: inline-flex; gap: 6px; align-items: center; }
.box {
  width: 28px;
  height: 28px;
  border: 2px solid var(--ink);
  background: var(--white);
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  user-select: none;
}
.box.sm { width: 26px; height: 26px; }
.box.filled { background: var(--yellow); }
.box.filled::after {
  content: '';
  position: absolute;
  left: 7px; top: 2px;
  width: 9px; height: 15px;
  border: solid var(--ink);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}
.box.sm.filled::after { left: 6px; top: 1px; width: 8px; height: 13px; border-width: 0 3px 3px 0; }

.tally-clear {
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  line-height: 1;
  padding: 3px 7px;
  cursor: pointer;
  user-select: none;
}

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--paper);
  border-top: 3px solid var(--ink);
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 20;
}
.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 2px 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
  user-select: none;
}
.tab .pixel { filter: grayscale(1) opacity(.55); }
.tab-icon { width: 24px; height: 24px; image-rendering: pixelated; filter: grayscale(1) opacity(.55); }
.tab .label { font-size: 14px; letter-spacing: .5px; }
.tab.active { color: var(--ink); background: var(--paper-2); }
.tab.active .pixel { filter: none; }
.tab.active .tab-icon { filter: none; }
.tab.active .label { font-family: 'Press Start 2P', monospace; font-size: 9px; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.overlay.hidden { display: none; }
.modal {
  background: var(--paper);
  border: 3px solid var(--ink);
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  padding: 14px;
}
.modal h2 { font-family: 'Press Start 2P', monospace; font-size: 16px; margin: 0 0 10px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h2 { margin: 0; }
.modal-close {
  width: 36px; height: 36px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  font-family: inherit;
  font-size: 20px;
  cursor: pointer;
}
.modal h3 { font-size: 20px; letter-spacing: 1px; border-bottom: 2px solid var(--ink); margin: 14px 0 6px; }
.modal input[type="text"], .modal input[type="number"], .modal select {
  font-family: inherit;
  font-size: 20px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  padding: 4px 6px;
  width: 100%;
}
#add-form { display: grid; grid-template-columns: 1fr; gap: 6px; }

.data-row { display: flex; gap: 8px; margin-top: 6px; }
.hint { font-size: 16px; color: var(--muted); }
.modal button {
  font-family: inherit;
  font-size: 20px;
  padding: 6px 14px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0,0,0,.2);
}
.modal button:active { transform: translate(1px,1px); box-shadow: none; }
.modal button.danger { background: var(--magenta); color: #fff; }
.modal button.close { display: block; margin: 14px auto 0; }

/* ---------- Note ---------- */
.name-wrap { flex: 1 1 auto; display: flex; flex-direction: column; gap: 1px; }
.name-wrap .note { font-size: 16px; color: var(--muted); line-height: 1.05; }

/* ---------- Quick add ---------- */
.fab-wrap {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  padding: 0 16px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  z-index: 15;
  pointer-events: none;
}
.fab-wrap form { pointer-events: auto; }
.fab {
  width: 48px; height: 48px;
  border: 2px solid var(--ink);
  background: var(--green);
  color: #fff;
  font-family: inherit;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0,0,0,.2);
  flex: 0 0 auto;
}
.fab:active { transform: translate(1px,1px); box-shadow: none; }
.hidden { display: none !important; }
.quick-add { display: flex; gap: 6px; flex: 1 1 auto; }
.quick-add input {
  flex: 1 1 auto;
  font-family: inherit;
  font-size: 20px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  padding: 6px 8px;
}
.quick-add button {
  font-family: inherit;
  font-size: 22px;
  border: 2px solid var(--ink);
  background: var(--green);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
}

/* ---------- Record / streak ---------- */
.record { display: flex; align-items: center; gap: 6px; font-size: 17px; color: var(--muted); }

/* ---------- Undo toast ---------- */
.undo-toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: none;
  font-family: inherit;
  font-size: 19px;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  padding: 6px 16px;
  cursor: pointer;
  z-index: 60;
  box-shadow: 2px 2px 0 rgba(0,0,0,.25);
}
.undo-toast.visible { display: block; }

/* ---------- Confetti ---------- */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.confetti-piece { position: absolute; top: -24px; animation: confetti-fall linear forwards; }
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ---------- Chore editor (impostazioni) ---------- */
.chore-group-title {
  font-size: 16px;
  letter-spacing: 1px;
  color: var(--muted);
  border-bottom: 2px solid var(--ink);
  margin: 12px 0 4px;
}
.swipe-row {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--faint);
}
.swipe-row.dragging { opacity: .92; }
.swipe-del {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 76px;
  background: var(--magenta);
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 18px;
  cursor: pointer;
}
.swipe-content {
  display: flex;
  align-items: stretch;
  background: var(--paper);
  position: relative;
  z-index: 1;
  transition: transform .18s ease;
  touch-action: pan-y;
}
.swipe-row.open .swipe-content { transform: translateX(-76px); }
.cr-lines { flex: 1 1 auto; display: flex; flex-direction: column; padding: 4px 8px 4px 0; }
.cr-line { display: flex; gap: 6px; align-items: center; }
.cr-line input[type="text"] {
  flex: 1 1 auto;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 20px;
  color: var(--ink);
  padding: 2px 0;
}
.cr-line input[type="number"] {
  width: 48px;
  border: 2px solid var(--faint);
  background: var(--white);
  font-family: inherit;
  font-size: 18px;
  color: var(--ink);
  padding: 2px 4px;
}
.cr-line select {
  border: 2px solid var(--faint);
  background: var(--white);
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  padding: 2px 4px;
  max-width: 120px;
}
.drag-handle {
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--muted);
  font-size: 22px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Dark mode ---------- */
body.dark {
  --paper: #2a2a26;
  --paper-2: #36362f;
  --ink: #ece8da;
  --muted: #a9a995;
  --faint: #4b4b43;
  --white: #23231f;
  background: #171712;
}

