:root {
  --cream: #FFF8EE;
  --ink: #1C1C1C;
  --coral: #FF6B6B;
  --tangerine: #FFA94D;
  --sunflower: #FFD43B;
  --lime: #A9E34B;
  --mint: #20C997;
  --sky: #4DABF7;
  --grape: #9775FA;
  --pink: #F783AC;
  --border: 3px solid var(--ink);
  --shadow: 5px 5px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: 100px;
  min-height: 100vh;
}

.topbar {
  padding: max(20px, env(safe-area-inset-top)) 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.settings-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: var(--border);
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink);
}

.brand { display: flex; flex-direction: column; }

.brand-mark {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: -1px;
  color: var(--coral);
  text-shadow: 2px 2px 0 var(--ink);
}

.tabs {
  display: flex;
  gap: 10px;
  padding: 8px 20px 16px;
}

.tab {
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 8px 16px;
  background: #fff;
  border: var(--border);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  color: var(--ink);
}

.tab.active {
  background: var(--sunflower);
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

main#view {
  padding: 4px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-label {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.55;
  margin: 10px 0 -4px;
}

.empty-state {
  border: var(--border);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 32px 20px;
  text-align: center;
  font-weight: 700;
  font-size: 17px;
}

.empty-state .sub {
  display: block;
  font-weight: 500;
  font-size: 14px;
  opacity: 0.65;
  margin-top: 6px;
}

.card {
  border: var(--border);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.05s ease;
}

.card:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--ink); }

.badge {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}

.card-body { flex: 1; min-width: 0; }

.card-title {
  font-weight: 800;
  font-size: 16px;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  font-size: 12.5px;
  font-weight: 600;
  opacity: 0.6;
}

.card-meta.overdue { color: var(--coral); opacity: 1; }

.tag-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.tag-chip {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  color: var(--ink);
}

.done-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: var(--border);
  background: #fff;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.done-btn.checked {
  background: var(--lime);
}

.fab {
  position: fixed;
  right: 22px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  border: var(--border);
  box-shadow: var(--shadow);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  z-index: 20;
}

.fab:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--ink); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28,28,28,0.5);
  display: none;
  align-items: flex-end;
  z-index: 30;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--cream);
  border-top: var(--border);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 20px calc(28px + env(safe-area-inset-bottom));
}

.modal h2 {
  font-size: 22px;
  font-weight: 900;
  margin: 4px 0 16px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
  opacity: 0.7;
}

.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 14px;
  border: var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
}

.row { display: flex; gap: 10px; }
.row .field { flex: 1; }

.seg {
  display: flex;
  border: var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.seg button {
  flex: 1;
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  padding: 11px 8px;
  background: #fff;
  border: none;
  border-right: var(--border);
  cursor: pointer;
  color: var(--ink);
}

.seg button:last-child { border-right: none; }
.seg button.active { background: var(--sunflower); }

.weekday-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.weekday-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: var(--border);
  background: #fff;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}

.weekday-btn.active { background: var(--sky); }

.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: var(--border);
  background: var(--lime);
  font-family: inherit;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  margin-top: 6px;
}

.btn-primary:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--ink); }

.btn-danger {
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  border: var(--border);
  background: #fff;
  color: var(--coral);
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  margin-top: 10px;
}

.btn-secondary {
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  border: var(--border);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  margin-top: 10px;
}

.btn-secondary:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

.detail-stat-row {
  display: flex;
  gap: 10px;
  margin: 14px 0;
}

.stat-box {
  flex: 1;
  border: var(--border);
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  text-align: center;
}

.stat-box .num {
  font-size: 22px;
  font-weight: 900;
}

.stat-box .lab {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  opacity: 0.55;
  margin-top: 2px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  background: #fff;
}

.history-item button {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.5;
}

.stat-tag-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: var(--border);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px 16px;
}

.stat-tag-row .name {
  font-weight: 800;
  font-size: 15px;
}

.stat-tag-row .count {
  font-weight: 900;
  font-size: 18px;
}

.stats-period-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
