:root {
  --ink: #1C2721;
  --muted: #56615A;
  --line: #DDE1DA;
  --line-strong: #B9C1B9;
  --page: #F4F5F1;
  --card: #FFFFFF;
  --empty: #ECEEEA;
  --blank: #F8F9F6;
  --pace: #8A948D;
  /* Theme colors — overwritten from app.js when a theme is picked */
  --accent: #2E7A4C; --dark: #1F5A37; --mid: #5E9E74;
  --s1: #E4F1E8; --s2: #C6E3CF; --s3: #A3D2B2; --s4: #7DBE93; --s6: #1B5634;
  --serif: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  background-color: var(--page); background-image: var(--pattern, none); background-size: 220px 220px;
  transition: background-color 0.4s;
  font-family: 'IBM Plex Sans', system-ui, sans-serif; font-size: 15px; line-height: 1.45;
}
a { color: inherit; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button { font-family: inherit; color: var(--ink); cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
h1, h2 { font-family: var(--serif); font-weight: 500; margin: 0; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.icon { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ── Header ─────────────────────────────────────────── */
header { position: relative; z-index: 5; background: var(--pattern, none) 0 0 / 220px 220px, linear-gradient(90deg, var(--s1) 0%, #FFFFFF 70%); border-bottom: 1px solid var(--line); }
.stripe { height: 5px; background: linear-gradient(90deg, var(--s2), var(--s4), var(--accent), var(--s6)); }
.header-row { padding: 14px 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand span { font-family: var(--serif); font-size: 22px; font-weight: 600; color: var(--ink); }
.header-right { display: flex; align-items: center; gap: 14px; }
#save-status { font-size: 13px; color: var(--muted); }
#save-status.error { color: #A3261B; font-weight: 500; }
.settings-wrap { position: relative; }
.btn-outline {
  min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: #FFFFFF; font-size: 14px; font-weight: 500;
}
.btn-primary {
  min-height: 44px; padding: 0 20px; border: 0; border-radius: 10px; background: var(--accent); color: #FFFFFF;
  font-size: 15px; font-weight: 600;
}
.btn-primary:disabled { opacity: 0.6; cursor: default; }
#settings-panel {
  position: absolute; right: 0; top: 52px; width: 300px; padding: 18px; border-radius: 14px; background: #FFFFFF;
  border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(28, 39, 33, 0.16);
}
#settings-panel h2 { font-size: 18px; margin-bottom: 4px; }
#settings-panel p { margin: 0 0 12px; font-size: 13px; }
#themes { display: flex; flex-direction: column; gap: 6px; }
.theme-group { margin: 6px 0 0; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.theme-group:first-child { margin-top: 0; }

/* Seasonal particles: fixed behind the page content, never interactive */
#season-fx { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
main, #load-error { position: relative; z-index: 1; }
.fx { position: absolute; top: 0; opacity: 0.75; animation-name: fx-fall; animation-timing-function: linear; animation-iteration-count: infinite; will-change: transform; }
.fx.rise { animation-name: fx-rise; }
.fx svg { display: block; width: 100%; height: 100%; animation: fx-sway ease-in-out infinite alternate; }
@keyframes fx-fall { from { transform: translateY(-8vh); } to { transform: translateY(108vh); } }
@keyframes fx-rise { 0% { transform: translateY(104vh); opacity: 0; } 15% { opacity: 0.7; } 85% { opacity: 0.7; } 100% { transform: translateY(-6vh); opacity: 0; } }
@keyframes fx-sway { from { transform: translateX(0) rotate(-25deg); } to { transform: translateX(var(--drift, 30px)) rotate(35deg); } }
@media (prefers-reduced-motion: reduce) { #season-fx { display: none; } }
.theme-btn {
  min-height: 48px; display: flex; align-items: center; gap: 12px; padding: 6px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: #FFFFFF; font-size: 14px; font-weight: 500; text-align: left;
}
.theme-btn[aria-pressed="true"] { border: 2px solid var(--ink); }
.theme-btn .swatch { width: 72px; height: 28px; flex-shrink: 0; border-radius: 7px; }
#settings-panel { max-height: calc(100vh - 96px); overflow-y: auto; }
.theme-btn .label { flex-grow: 1; }
.theme-btn .check { visibility: hidden; }
.theme-btn[aria-pressed="true"] .check { visibility: visible; }
#settings-panel .btn-primary { margin-top: 14px; width: 100%; font-size: 14px; }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; }
.theme-btn:disabled, .wd:disabled { cursor: default; }
.theme-btn:disabled:not([aria-pressed="true"]) { opacity: 0.55; }

/* ── Layout ─────────────────────────────────────────── */
main { padding: 28px 32px 48px; display: flex; flex-wrap: wrap; gap: 24px; align-items: stretch; max-width: 1600px; margin: 0 auto; }
#calendar { flex: 1 1 640px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
aside { flex: 1 1 320px; max-width: 400px; display: flex; flex-direction: column; gap: 20px; }
#progress { flex: 1 1 100%; min-width: 0; padding: 24px; }
aside > .aside-tabs { display: none; }

/* ── Calendar ───────────────────────────────────────── */
.cal-card { flex-grow: 1; padding: 24px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.month-nav { display: flex; align-items: center; gap: 8px; }
/* Fixed width (fits "September 2026") so the arrows don't shift between months */
.month-nav h1 { margin: 0 8px; font-size: 32px; white-space: nowrap; width: 8em; text-align: center; flex-shrink: 0; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #FFFFFF; display: flex; align-items: center; justify-content: center; }
.today-btn { min-height: 36px; padding: 0 12px; font-size: 13px; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.legend .swatches { display: flex; gap: 3px; }
.legend .swatches span { width: 16px; height: 16px; border-radius: 4px; }
.dow, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.dow { margin-bottom: 8px; }
.dow div { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 4px; }
.cell-blank { min-height: 108px; border-radius: 12px; background: var(--blank); }
.cell {
  user-select: none; -webkit-user-select: none;
  min-height: 108px; min-width: 0; padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: #FFFFFF;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px; text-align: left;
}
.cell.editing { background: #FFFFFF; color: var(--ink); box-shadow: 0 0 0 2px var(--accent); container-type: inline-size; }
.edit-hint { white-space: nowrap; }
/* Only show the hint when it fits on one line in the day box */
@container (max-width: 100px) { .edit-hint { display: none; } }
.edit-label { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }
.edit-input {
  width: 100%; min-width: 0; height: 36px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 8px;
  font-family: inherit; font-size: 16px; font-weight: 600; text-align: center; color: var(--ink); background: #FFFFFF;
  -moz-appearance: textfield;
}
.edit-input::-webkit-outer-spin-button, .edit-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell.off { background: repeating-linear-gradient(135deg, #F1F2EE 0 6px, #E8EAE5 6px 12px); color: var(--muted); }
.cell.today { box-shadow: 0 0 0 2px var(--ink); }
.cell[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.cell .top { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-size: 14px; font-weight: 500; }
.cell .today-tag { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--dark); }
.badge { display: flex; flex-direction: column; align-items: center; padding: 8px 4px; border-radius: 8px; min-width: 0; }
.badge .big { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.badge .small { font-size: 12px; }
.badge .compact { display: none; }
.badge.need { padding: 7px 4px; background: #FFFFFF; border: 1px dashed var(--mid); color: var(--dark); }
.badge.dayoff { color: var(--muted); }
.badge.buffer { padding: 7px 4px; border: 1px dashed var(--line-strong); color: var(--muted); font-weight: 500; }
.badge.dayoff .small { font-weight: 500; }

.stats { display: flex; flex-wrap: wrap; gap: 12px; }
.stats-head { display: flex; justify-content: flex-start; margin-bottom: -8px; }
.segmented.compact { margin-bottom: 0; padding: 3px; }
.segmented.compact button { flex: 0 0 auto; min-height: 34px; padding: 0 14px; font-size: 13px; }
.stat { flex: 1 1 130px; min-width: 0; background: #FFFFFF; border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-family: var(--serif); font-size: 24px; line-height: 1.2; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Side panels ────────────────────────────────────── */
aside h2 { font-size: 22px; margin-bottom: 4px; }
.lede { margin: 0 0 16px; font-size: 14px; color: var(--muted); }
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--empty); margin-bottom: 14px; }
.segmented button { flex: 1 1 0; min-height: 40px; border: 0; border-radius: 8px; font-size: 14px; font-weight: 500; background: transparent; }
.segmented button[aria-pressed="true"] { background: #FFFFFF; }
label.field { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.input {
  width: 100%; min-width: 0; height: 48px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 10px;
  font-family: inherit; font-size: 17px; color: var(--ink); background: #FFFFFF;
}
.log-row { display: flex; gap: 8px; }
.log-row .input { flex: 1 1 auto; }
.log-row .btn-primary { height: 48px; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
#dayoff-btn { margin-top: 14px; width: 100%; }
#dayoff-btn[aria-pressed="true"] { background: var(--empty); }
#weekdays { margin-top: 14px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.wd { min-height: 44px; min-width: 0; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--page); color: var(--muted); font-size: 13px; font-weight: 600; }
.wd[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: #FFFFFF; }

#goal { flex-grow: 1; }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal-head h2 { margin: 0; overflow-wrap: anywhere; }
.link-btn { border: 0; background: none; padding: 10px 0; font-size: 14px; font-weight: 500; text-decoration: underline; text-decoration-thickness: 1px; white-space: nowrap; }
.link-btn:hover { text-decoration-thickness: 2px; }
.buffer-tag {
  display: inline-flex; align-items: center; gap: 6px; margin: -8px 0 16px; padding: 4px 10px 4px 8px;
  border-radius: 99px; background: var(--s1); color: var(--dark); font-size: 13px; white-space: nowrap;
}
.buffer-tag strong { font-weight: 600; }
.goal-total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.goal-total .big { font-family: var(--serif); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.goal-total .pct { font-size: 14px; font-weight: 600; color: var(--dark); }
.bar { height: 10px; border-radius: 99px; background: var(--empty); overflow: hidden; }
.bar div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--s3), var(--accent), var(--s6)); transition: width 0.3s; }
.goal-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.goal-stats .k { font-size: 12px; color: var(--muted); }
.goal-stats .v { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pace-note { margin-top: 16px; padding: 10px 12px; border-radius: 10px; background: var(--s1); color: var(--dark); font-size: 14px; font-weight: 500; }

/* ── Chart ──────────────────────────────────────────── */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.chart-head h2 { font-size: 24px; }
.chart-legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend .actual { width: 18px; height: 3px; border-radius: 2px; background: var(--accent); }
.chart-legend .target { width: 18px; height: 0; border-top: 2px dashed var(--pace); }
#chart-wrap { position: relative; cursor: crosshair; touch-action: pan-y; }
#chart-wrap svg { width: 100%; height: auto; display: block; font-family: 'IBM Plex Sans', system-ui, sans-serif; }
#chart-tip {
  position: absolute; top: 8px; display: none; min-width: 180px; padding: 10px 12px; border-radius: 10px; background: #FFFFFF;
  border: 1px solid var(--line-strong); box-shadow: 0 4px 14px rgba(28, 39, 33, 0.12); pointer-events: none;
  font-size: 13px; line-height: 1.5; white-space: nowrap;
}
#chart-tip .d { font-size: 14px; font-weight: 600; }

/* ── Goal dialog ────────────────────────────────────── */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: min(480px, calc(100vw - 32px)); color: var(--ink); box-shadow: 0 12px 32px rgba(28, 39, 33, 0.2); }
dialog::backdrop { background: rgba(28, 39, 33, 0.35); }
dialog h2 { font-size: 24px; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 18px 0; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-error { color: #A3261B; font-size: 14px; font-weight: 500; min-height: 1.4em; margin: 0 0 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

#load-error { margin: 48px auto; max-width: 520px; text-align: center; }

/* ── Phones / narrow screens ────────────────────────── */
@media (max-width: 760px) {
  .header-row { padding: 12px 16px; }
  .brand span { font-size: 18px; }
  #settings-btn { padding: 0 12px; }
  #settings-btn .btn-text { display: none; }
  main { padding: 16px 16px 32px; gap: 16px; }
  aside { max-width: none; order: -1; }
  /* One panel at a time on phones */
  aside > .aside-tabs { display: flex; margin-bottom: -6px; }
  .fx:nth-child(n+9) { display: none; }
  .theme-btn { min-height: 44px; }
  .aside-tabs button { min-height: 38px; font-size: 13px; }
  aside > [data-panel]:not(.tab-active) { display: none; }
  .card, .cal-card, #progress { padding: 16px; }
  /* Calendar header on one line; the color legend moves below the grid */
  .cal-card { display: flex; flex-direction: column; }
  .cal-head { display: contents; }
  .month-nav { order: 0; width: 100%; gap: 6px; margin-bottom: 14px; }
  .month-nav h1 { font-size: clamp(16px, 5vw, 24px); margin: 0; }
  .month-nav .icon-btn { width: 36px; height: 36px; flex-shrink: 0; }
  .today-btn { margin-left: auto; min-height: 32px; padding: 0 10px; font-size: 12px; flex-shrink: 0; }
  .dow { order: 1; }
  .grid { order: 2; }
  .legend { order: 3; margin-top: 12px; justify-content: center; }
  .legend > span:not(.swatches) { display: none; }
  .dow, .grid { gap: 4px; }
  .dow div { padding: 0; text-align: center; font-size: 12px; }
  .cell, .cell-blank { min-height: 64px; }
  .cell { padding: 4px; gap: 4px; border-radius: 8px; }
  .cell .top { justify-content: center; font-size: 12px; }
  .cell .today-tag { display: none; }
  .badge { padding: 4px 2px; border-radius: 6px; }
  .badge.need { padding: 3px 2px; }
  .badge .big { font-size: 12px; }
  .badge .full-num, .badge .small { display: none; }
  .badge .compact { display: inline; }
  .badge.dayoff svg { width: 14px; height: 14px; }
  .edit-input { height: 30px; padding: 0 2px; font-size: 13px; }
  .stat .v { font-size: 20px; }
}
@media (max-width: 345px) {
  .month-nav { gap: 4px; }
  .month-nav h1 { font-size: 16px; }
  .month-nav .icon-btn { width: 32px; height: 32px; }
  .today-btn { padding: 0 8px; }
}
@media (max-width: 420px) {
  .form-grid { grid-template-columns: 1fr; }
}
