[hidden] { display: none !important; }

:root {
  --bg: #fbf7f1;
  --bg-alt: #f3ece1;
  --surface: #ffffff;
  --surface-2: #faf5ec;
  --text: #1a120b;
  --text-soft: #5a4a3a;
  --muted: #8a7860;
  --border: #e6dccb;
  --primary: #7a3b2e;
  --primary-hover: #61291f;
  --accent: #d4a24c;
  --accent-soft: #f4dba0;
  --danger: #b3261e;
  --success: #2e7d32;
  --warning: #b07000;
  --shadow: 0 4px 16px rgba(40, 25, 10, 0.08);
  --shadow-lg: 0 18px 50px rgba(30, 18, 8, 0.28);
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Helvetica Neue', Arial, system-ui, sans-serif;
  --font-display: 'Georgia', 'Times New Roman', serif;
}

[data-theme="dark"] {
  --bg: #161210;
  --bg-alt: #1d1813;
  --surface: #221c17;
  --surface-2: #2a221b;
  --text: #f4ece0;
  --text-soft: #d8cab7;
  --muted: #a89177;
  --border: #3a3026;
  --primary: #d99a5c;
  --primary-hover: #e4ad74;
  --accent: #e6bd6c;
  --accent-soft: #4a3a22;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-soft);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--text); line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
h2 { font-size: clamp(1.6rem, 3.5vw, 2.4rem); }
p { margin: 0 0 1rem; }
a { color: var(--primary); text-decoration: none; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 1.25rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(140%) blur(8px);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .65rem; color: var(--text); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; color: #fff; font-size: .85rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--font-display); font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: .72rem; letter-spacing: 1px; text-transform: uppercase; }
.site-nav { display: flex; align-items: center; gap: 1.1rem; }
.site-nav > a { color: var(--text-soft); font-weight: 600; font-size: .92rem; }
.site-nav > a:hover { color: var(--primary); }
.nav-toggle { display: none; }

/* ---------- Buttons ---------- */
button { font-family: var(--font); cursor: pointer; }
.btn-primary, .btn-ghost, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 1.1rem; border-radius: var(--radius-sm);
  font-weight: 600; font-size: .92rem; border: 1px solid transparent;
  transition: .15s ease;
}
.btn-sm { min-height: 36px; padding: 0 .8rem; font-size: .85rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.ghost-light { color: #f4ece0; border-color: rgba(255,255,255,.4); }
.ghost-light:hover { background: rgba(255,255,255,.12); color: #fff; border-color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

/* ---------- Hero ---------- */
.hero {
  position: relative; color: #f4ece0; overflow: hidden;
  background:
    linear-gradient(rgba(20,17,13,0.65), rgba(20,17,13,0.85)),
    radial-gradient(circle at 30% 30%, #7a3b2e, #14110d 70%);
}
.hero::after {
  content: ''; position: absolute; inset: 0; opacity: .04; pointer-events: none;
  background: repeating-linear-gradient(45deg, var(--accent) 0 2px, transparent 2px 14px);
}
.hero-inner { position: relative; padding: clamp(3rem, 8vw, 6rem) 1.25rem; max-width: 1180px; margin: 0 auto; }
.eyebrow { text-transform: uppercase; letter-spacing: 2px; font-size: .8rem; color: var(--accent); font-weight: 700; margin-bottom: .75rem; }
.hero h1 { color: #fff; max-width: 16ch; }
.hero .lead { color: #e7dccb; max-width: 56ch; font-size: 1.08rem; }
.hero-cta { display: flex; flex-wrap: wrap; gap: .75rem; margin: 1.5rem 0 2.25rem; }
.stats-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; max-width: 640px; }
.stat { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius); padding: .9rem .5rem; text-align: center; }
.stat-num { display: block; font-family: var(--font-display); font-size: clamp(1.1rem, 3vw, 1.7rem); color: var(--accent); }
.stat-lbl { display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: 1px; color: #cdbfa9; margin-top: .25rem; }

/* ---------- Sections ---------- */
.section { padding: clamp(2.5rem, 6vw, 4.5rem) 0; }
.section.alt { background: var(--bg-alt); }
.section-title::after { content: ''; display: block; width: 50px; height: 3px; background: var(--accent); margin-top: .5rem; }
.section-sub { color: var(--muted); max-width: 64ch; margin-top: .75rem; }

/* ---------- Day tabs ---------- */
.day-tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.5rem 0 2rem; }
.day-tab {
  position: relative; min-height: 44px; padding: 0 1rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600; transition: .15s ease;
}
.day-tab:hover { border-color: var(--primary); }
.day-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.day-tab .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: .4rem; vertical-align: middle; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); }
.card-title { font-size: 1.2rem; }

.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.routine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 1rem; }
.field-label { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: .35rem; font-weight: 700; }
input, select {
  width: 100%; min-height: 44px; padding: .55rem .7rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: .95rem; font-family: var(--font);
  transition: .15s ease;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--accent-soft); }
input.error { border-color: var(--danger); }
input.valid { border-color: var(--success); }
.field-msg { display: block; min-height: 1.1em; font-size: .78rem; margin-top: .3rem; color: var(--muted); }
.field-msg.show-error { color: var(--danger); }
.field-msg.show-ok { color: var(--success); }
.field-msg.hint { color: var(--muted); }
.plan-actions { margin-top: .5rem; }

/* ---------- Overrides ---------- */
.overrides { margin-top: 1.2rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.overrides-title { font-size: .95rem; }
.override-list { display: flex; flex-direction: column; gap: .5rem; }
.override-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: .5rem .7rem; }
.override-row .ov-info { font-size: .85rem; }
.override-row .ov-info strong { color: var(--text); font-family: var(--font-display); }
.override-row .ov-actions { display: flex; gap: .35rem; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: .5rem 0 0; padding: 0; }
.timeline li { display: flex; align-items: center; gap: .9rem; padding: .7rem 0; border-bottom: 1px dashed var(--border); }
.timeline li:last-child { border-bottom: none; }
.tl-ico { font-size: 1.4rem; width: 2rem; text-align: center; }
.tl-body { flex: 1; }
.tl-body strong { display: block; color: var(--text); font-family: var(--font-display); }
.tl-body small { color: var(--muted); }
.tl-time { font-family: var(--font-display); font-size: 1.25rem; color: var(--primary); font-weight: 700; }
.result-note { margin-top: 1rem; font-size: .85rem; color: var(--muted); padding: .6rem .8rem; background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); }

/* ---------- Routine columns ---------- */
.routine-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: .8rem; }
.routine-total { font-family: var(--font-display); color: var(--accent); font-weight: 700; }
.task-list { display: flex; flex-direction: column; gap: .55rem; margin-bottom: 1rem; min-height: 8px; }
.task-row {
  display: grid; grid-template-columns: 24px 1fr 70px 56px auto; gap: .45rem; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem;
  transition: .12s ease;
}
.task-row.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--accent-soft); }
.task-row.dragging { opacity: .45; }
.task-row.drop-target { border-top: 2px solid var(--primary); }
.task-row input { min-height: 38px; background: var(--surface); }
.task-row .t-name { font-size: .92rem; }
.drag-handle { cursor: grab; color: var(--muted); text-align: center; font-size: 1.1rem; user-select: none; line-height: 1; }
.drag-handle:active { cursor: grabbing; }
.rep-wrap { position: relative; }
.task-del { background: transparent; border: none; color: var(--muted); font-size: 1.1rem; line-height: 1; padding: .3rem; }
.task-del:hover { color: var(--danger); }
.task-empty { color: var(--muted); font-style: italic; padding: .8rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.task-add { display: grid; grid-template-columns: 1fr 64px 50px 1fr auto; gap: .45rem; margin-bottom: 1rem; }
.run-btn { width: 100%; }

/* ---------- Custom routines ---------- */
.custom-wrap { display: grid; gap: 1.5rem; margin: 1.5rem 0; }
.custom-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); }
.custom-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.custom-icon { width: 56px; text-align: center; font-size: 1.3rem; }
.custom-name { flex: 1; min-width: 160px; font-family: var(--font-display); font-size: 1.1rem; }
.custom-total { font-family: var(--font-display); color: var(--accent); font-weight: 700; }
.custom-settings { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; padding: .8rem; background: var(--surface-2); border-radius: var(--radius-sm); }
.custom-settings .mini { display: flex; flex-direction: column; gap: .2rem; }
.custom-settings .mini span { font-size: .68rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.custom-settings select, .custom-settings input { min-height: 38px; width: auto; min-width: 120px; }
.day-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.day-chip {
  min-height: 32px; padding: 0 .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.day-chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.custom-foot { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.custom-foot .run-btn { flex: 1; width: auto; }

/* ---------- Stats ---------- */
.stats-wrap { display: grid; gap: 1rem; margin-top: 1.5rem; }
.stat-group h3 { font-size: 1.1rem; margin-bottom: .5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); transition: .15s ease; }
.stat-card + .stat-card { margin-top: .7rem; }
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-card-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .4rem; }
.stat-card-head strong { font-family: var(--font-display); color: var(--text); font-size: 1.02rem; }
.stat-card-head .cur { color: var(--muted); font-size: .82rem; }
.metric-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .7rem; }
.metric { flex: 1; min-width: 90px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem; text-align: center; }
.metric .m-val { display: block; font-family: var(--font-display); font-size: 1.15rem; color: var(--primary); }
.metric .m-lbl { display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.metric button { margin-top: .4rem; width: 100%; }
.no-data { color: var(--muted); font-style: italic; }

.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .7rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; background: var(--accent-soft); color: var(--warning); }
.badge.off { background: var(--border); color: var(--muted); }
.badge.ondemand { background: var(--accent-soft); color: var(--warning); }
.badge.scheduled { background: rgba(46,125,50,.15); color: var(--success); }

/* ---------- Footer ---------- */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); margin-top: 2rem; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 1.5rem; padding: 2.5rem 1.25rem 1.5rem; }
.footer-grid h4 { font-size: .9rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.footer-grid a { display: block; color: var(--text-soft); padding: .15rem 0; }
.footer-grid a:hover { color: var(--primary); }
.footer-blurb { color: var(--muted); font-size: .9rem; max-width: 40ch; }
.footer-brand { margin-bottom: .8rem; }
.social { display: flex; gap: .5rem; margin-top: .6rem; }
.social-chip { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; }
.footer-bottom { border-top: 1px solid var(--border); text-align: center; padding: 1rem; font-size: .82rem; color: var(--muted); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(20,14,8,.55); backdrop-filter: blur(3px);
  padding: 1.25rem; overflow-y: auto;
  align-items: flex-start; justify-content: center;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 520px; width: 100%; margin: 4vh auto; padding: 1.6rem; position: relative;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.modal-close { position: absolute; top: .8rem; right: .8rem; background: transparent; border: none; font-size: 1.2rem; color: var(--muted); }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }
.rule { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; margin: 0 0 1rem; }
legend { font-size: .76rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 0 .4rem; font-weight: 700; }
.chk { display: inline-flex; align-items: center; gap: .4rem; margin: .25rem .8rem .25rem 0; font-size: .92rem; }
.chk input { width: auto; min-height: auto; }
.copy-days { display: flex; flex-wrap: wrap; }
.seg { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ---------- Runner ---------- */
.runner-box { max-width: 560px; text-align: center; }
.runner-task { font-size: 1.6rem; margin-top: .2rem; }
.runner-clock { font-family: var(--font-display); font-size: clamp(3rem, 14vw, 5.5rem); color: var(--primary); line-height: 1; margin: .5rem 0; font-variant-numeric: tabular-nums; }
.runner-clock.over { color: var(--danger); }
.runner-banner { background: var(--danger); color: #fff; border-radius: var(--radius-sm); padding: .5rem; font-weight: 700; margin-bottom: .8rem; }
.runner-meta { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.runner-steps { list-style: none; padding: 0; margin: 0 0 1.2rem; text-align: left; max-height: 200px; overflow-y: auto; }
.runner-steps li { display: flex; justify-content: space-between; padding: .45rem .6rem; border-radius: var(--radius-sm); font-size: .9rem; color: var(--text-soft); }
.runner-steps li.cur { background: var(--accent-soft); color: var(--text); font-weight: 700; }
.runner-steps li.done { color: var(--muted); text-decoration: line-through; }
.runner-steps li.done::after { content: '✓'; color: var(--success); }
.runner-controls { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.runner-controls .btn-primary { flex: 1; min-width: 140px; }
.runner-flash { animation: flash .4s ease 3; }
@keyframes flash { 50% { box-shadow: 0 0 0 6px var(--danger), var(--shadow-lg); } }
.runner-summary { text-align: left; }
.runner-summary .sum-row { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px dashed var(--border); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  z-index: 100; min-width: 220px; max-width: 90vw;
  background: var(--text); color: var(--bg);
  padding: .8rem 1.2rem; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); opacity: 0; transition: .25s ease;
  font-weight: 600; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .nav-toggle { display: inline-flex; }
  .site-nav {
    position: absolute; top: 64px; left: 0; right: 0; flex-direction: column;
    align-items: stretch; gap: .4rem; background: var(--surface);
    border-bottom: 1px solid var(--border); padding: 0 1.25rem;
    max-height: 0; overflow: hidden; transition: max-height .25s ease, padding .25s ease;
  }
  .site-nav.open { max-height: 460px; padding: 1rem 1.25rem; }
  .site-nav > a { padding: .5rem 0; }
}
@media (max-width: 768px) {
  .plan-grid, .routine-grid { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 540px) {
  .stats-strip { grid-template-columns: repeat(2, 1fr); }
  .footer-grid { grid-template-columns: 1fr; }
  .task-add { grid-template-columns: 1fr 1fr; }
  .task-add button { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .task-row { grid-template-columns: 22px 1fr 58px 48px auto; }
}
