/* Jerry's Day — warm, phone-first */
:root {
  --bg: #faf6f1;
  --bg-card: #ffffff;
  --ink: #2c241c;
  --ink-soft: #6b5e52;
  --accent: #c4784a;
  --accent-deep: #a35f35;
  --accent-soft: #f0ddd0;
  --done: #5a8f6a;
  --done-soft: #e4f0e7;
  --line: #e8dfd4;
  --shadow: 0 2px 12px rgba(44, 36, 28, 0.08);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px 24px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  padding: 16px 0 8px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent-deep);
}

.date-line {
  margin: 4px 0 14px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.main-tabs {
  display: flex;
  gap: 6px;
  background: var(--accent-soft);
  padding: 4px;
  border-radius: 999px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 8px;
  border-radius: 999px;
  cursor: pointer;
}

.tab.active {
  background: var(--bg-card);
  color: var(--accent-deep);
  box-shadow: var(--shadow);
}

.icon-btn {
  border: none;
  background: var(--bg-card);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  color: var(--ink);
  line-height: 1;
}

main { flex: 1; padding-bottom: 12px; }

.panel { display: none; animation: fadeIn 0.2s ease; }
.panel.active { display: block; }
.panel[hidden] { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.carryover {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.carryover.hidden { display: none; }

.carryover-label {
  margin: 0 0 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 700;
}

.carryover-text {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

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

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.item.matched {
  background: var(--done-soft);
  border-color: #c5dbc9;
}

.item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  accent-color: var(--done);
  flex-shrink: 0;
}

.item .text {
  flex: 1;
  font-size: 1rem;
  line-height: 1.35;
  word-break: break-word;
}

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

.item .delete {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.1rem;
  padding: 0 4px;
  cursor: pointer;
  opacity: 0.5;
}

.item .delete:hover,
.item .delete:focus { opacity: 1; color: #a44; }

.badge-match {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--done);
  background: #fff;
  padding: 2px 6px;
  border-radius: 6px;
  align-self: center;
}

.add-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.add-form input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 14px;
  font: inherit;
  font-size: 1rem;
  background: var(--bg-card);
  color: var(--ink);
  outline: none;
}

.add-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  border: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:active { background: var(--accent-deep); }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.btn-add {
  background: var(--accent);
  color: #fff;
  width: 48px;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
  border-radius: 12px;
  flex-shrink: 0;
}

.hint {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 28px 12px;
  font-size: 0.95rem;
}

/* Week view */
.week-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.week-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.week-summary {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-pill {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.stat-pill .num {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-deep);
}

.stat-pill .lbl {
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.week-day {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
}

.week-day h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--accent-deep);
}

.week-day ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 0.92rem;
}

.week-day li { margin-bottom: 4px; }
.week-day .none { color: var(--ink-soft); font-style: italic; padding-left: 0; list-style: none; }

/* History sheet */
.history-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(44, 36, 28, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.history-sheet.hidden { display: none; }

.history-sheet-inner {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + var(--safe-bot));
  overflow-y: auto;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.15);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.history-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.chart-wrap {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--line);
  margin-bottom: 14px;
}

.chart-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
}

.chart-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.leg::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.leg.planned::before { background: var(--accent-soft); border: 1px solid var(--accent); }
.leg.done::before { background: var(--done); }

.history-days { display: flex; flex-direction: column; gap: 8px; }

.hist-day {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  border: 1px solid var(--line);
}

.hist-day h3 {
  margin: 0 0 6px;
  font-size: 0.88rem;
  display: flex;
  justify-content: space-between;
}

.hist-day .counts { color: var(--ink-soft); font-weight: 500; }

.hist-day .bars {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--line);
  margin-bottom: 8px;
}

.hist-day .bars .p { background: var(--accent); }
.hist-day .bars .d { background: var(--done); }

.hist-day ul {
  margin: 0;
  padding-left: 16px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  padding: 8px 0;
}

.sunday-nudge {
  background: linear-gradient(135deg, #f5e6d8, #f0ddd0);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--accent-deep);
  font-weight: 600;
  text-align: center;
}

@media (min-width: 500px) {
  #app { padding-top: 12px; }
}

.app-footer {
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
}
.reminder-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.reminder-toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}
.nudge {
  position: sticky;
  bottom: 0;
  margin: 0 12px 12px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
}
.nudge p { margin: 0; font-weight: 600; }
.nudge .btn { width: 100%; }
.nudge.hidden { display: none; }

/* Backup (export / import) */
.footer-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}
.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 10px;
}
.backup-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}
.backup-card h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--accent-deep);
}
.backup-card .hint { margin: 0 0 10px; }
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}
.backup-actions .hidden { display: none; }
.backup-text {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: 0.75rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
  outline: none;
}
.backup-text:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.backup-status {
  margin: 4px 0 0;
  min-height: 1em;
  font-size: 0.8rem;
  color: var(--done);
}
.backup-status.error { color: #a44; }
