:root {
  --ink: #17211b;
  --muted: #69756e;
  --paper: #f6f3eb;
  --card: #fffdf8;
  --line: #dedbd1;
  --green: #356859;
  --green-soft: #dbe9e2;
  --coral: #e56b52;
  --shadow: 0 18px 45px rgba(23, 33, 27, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--green); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, .primary-button, .secondary-button { cursor: pointer; }

.site-header { min-height: 68px; padding: 0 5vw; display: flex; align-items: center; justify-content: space-between; background: rgba(255,253,248,.94); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px); }
.brand { color: var(--ink); font-weight: 900; font-size: 1.3rem; }
.site-header nav { display: flex; gap: 18px; align-items: center; font-size: .92rem; }
.site-header form { margin: 0; }
.link-button { border: 0; background: transparent; color: var(--green); padding: 0; }
.flash { max-width: 1100px; margin: 14px auto; padding: 12px 18px; border-radius: 12px; }
.flash.notice { background: var(--green-soft); }.flash.alert, .form-errors, .api-error { background: #fde5df; color: #8a2f1f; }
.form-notice { padding: 12px 14px; border-radius: 12px; background: var(--green-soft); color: var(--ink); line-height: 1.45; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 10% 5%, #e7efe9, transparent 33%), radial-gradient(circle at 90% 90%, #f5d9cd, transparent 30%), var(--paper); }
.login-card { width: min(440px, 100%); padding: 46px; border: 1px solid var(--line); background: rgba(255,253,248,.94); box-shadow: var(--shadow); border-radius: 28px; }
.kapsme-mark { width: 52px; height: 52px; border-radius: 50% 50% 44% 44%; display: grid; place-items: center; color: white; background: var(--coral); box-shadow: inset 0 -8px 0 rgba(0,0,0,.08); margin-bottom: 24px; }
.oauth-note { margin: 18px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .78rem; line-height: 1.5; }
h1, h2, h3, p { margin-top: 0; } h1 { font-size: clamp(2rem, 5vw, 3.6rem); line-height: 1; }
.eyebrow { color: var(--coral); font-size: .78rem; font-weight: 800; margin-bottom: 8px; }
.muted { color: var(--muted); }

.stack-form { display: grid; gap: 16px; }.stack-form label { display: grid; gap: 7px; font-weight: 700; font-size: .9rem; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--ink); background: white; font-size: 1rem; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(53,104,89,.15); border-color: var(--green); }
.checkbox { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 9px !important; }.checkbox input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 14px; } legend { font-weight: 800; padding: 0 5px; }
.primary-button, .secondary-button { display: inline-flex; justify-content: center; align-items: center; border-radius: 12px; padding: 11px 16px; border: 1px solid var(--green); font-weight: 800; }
.primary-button { background: var(--green); color: white; }.secondary-button { color: var(--green); background: transparent; }

.app-shell, .admin-shell { width: min(1100px, calc(100% - 32px)); margin: 32px auto 80px; }
.app-shell { max-width: 760px; }
.hero-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 30px; border-radius: 28px; color: white; background: linear-gradient(135deg, #274f44, #487f6f); box-shadow: var(--shadow); }.hero-card h1 { font-size: clamp(2rem, 7vw, 3.8rem); max-width: 520px; margin-bottom: 0; }.hero-card .eyebrow { color: #f8b09f; }
.score-ring { flex: 0 0 92px; height: 92px; display: grid; place-items: center; border: 8px solid rgba(255,255,255,.25); border-top-color: white; border-radius: 50%; font-size: 1.2rem; font-weight: 900; }
.app-tabs { display: grid; grid-template-columns: repeat(5, 1fr); margin: 22px 0; padding: 5px; border-radius: 14px; background: #e9e5dc; }.app-tabs button { border: 0; background: transparent; padding: 10px 5px; border-radius: 10px; color: var(--muted); font-size: .82rem; }.app-tabs button.active { background: var(--card); color: var(--ink); box-shadow: 0 3px 12px rgba(0,0,0,.06); font-weight: 800; }
.day-nav, .section-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; }.day-nav { margin: 28px 0 18px; text-align: center; }.day-nav button { width: 42px; height: 42px; border: 1px solid var(--line); background: var(--card); border-radius: 50%; }.day-nav small { display: block; color: var(--muted); margin-top: 3px; }
.habit-list { display: grid; gap: 12px; }.habit-item, .panel { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: 0 7px 22px rgba(23,33,27,.04); }.habit-item { display: flex; align-items: center; gap: 14px; }.habit-item .content { flex: 1; min-width: 0; }.habit-item h3 { margin-bottom: 4px; font-size: 1rem; }.habit-item p { margin: 0; color: var(--muted); font-size: .86rem; }.habit-item.completed { opacity: .66; }.habit-item.completed h3 { text-decoration: line-through; }.habit-item.paused { background: #efede7; }.check-button { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--green); color: transparent; background: transparent; font-weight: 900; }.completed .check-button { background: var(--green); color: white; }.badge { font-size: .72rem; padding: 5px 8px; border-radius: 99px; background: var(--green-soft); color: var(--green); font-weight: 800; }
.habit-item .habit-metadata { margin-top: 7px; color: var(--green); font-size: .78rem; }.notification-day > h3 { margin: 18px 0 7px; color: var(--muted); font-size: .82rem; font-weight: 700; }.notification-item .unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }.notification-item.completed .unread-dot { background: transparent; }.invite-panel { margin-bottom: 18px; }.invite-panel summary { width: max-content; padding: 10px 15px; border-radius: 12px; color: var(--green); background: var(--green-soft); cursor: pointer; font-weight: 700; }.invite-panel .inline-form { margin-top: 12px; }
.habit-actions { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }.text-button { border: 0; padding: 5px 7px; background: transparent; color: var(--green); font-weight: 700; font-size: .78rem; }.text-button.danger { color: #9a493b; }
.friend-card, .template-card { display: flex; align-items: center; gap: 14px; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: 0 7px 22px rgba(23,33,27,.04); }.friend-card .content, .template-card .content { flex: 1; min-width: 0; }.friend-card h3, .template-card h3 { margin-bottom: 4px; font-size: 1rem; }.friend-card p, .template-card p { margin: 0; color: var(--muted); font-size: .86rem; }.friend-avatar { flex: 0 0 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; overflow: hidden; background: var(--green-soft); color: var(--green); font-weight: 800; }.friend-avatar img { width: 100%; height: 100%; object-fit: cover; }.friend-progress { height: 6px; margin-top: 11px; border-radius: 99px; overflow: hidden; background: #e7e5de; }.friend-progress span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.panel { margin-bottom: 16px; }.panel h3 { margin-bottom: 8px; }.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }.form-actions, .inline-form { display: flex; gap: 10px; align-items: center; }.inline-form { margin-bottom: 18px; }.inline-form input { flex: 1; }
.habit-form { padding: 24px; gap: 18px; }
.form-intro { display: flex; gap: 12px; align-items: flex-start; }.form-intro h3 { margin: 1px 0 3px; }.form-intro p, .field-hint { color: var(--muted); font-size: .82rem; margin: 0; font-weight: 500; line-height: 1.45; }
.form-step { flex: 0 0 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: white; font-size: .8rem; font-weight: 900; }.schedule-heading { margin-top: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.schedule-presets { border: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.schedule-preset { --preset-color: #356859; --preset-bg: #f3f8f5; position: relative; display: flex !important; grid-template-columns: none !important; flex-direction: row; align-items: center; gap: 11px !important; padding: 13px; border: 1px solid color-mix(in srgb, var(--preset-color) 24%, var(--line)); border-radius: 14px; background: var(--preset-bg); cursor: pointer; transition: border-color .16s, background .16s, transform .16s; }.schedule-preset:nth-of-type(2) { --preset-color: #5577a5; --preset-bg: #f1f5fb; }.schedule-preset:nth-of-type(3) { --preset-color: #b87542; --preset-bg: #fff5ec; }.schedule-preset:nth-of-type(4) { --preset-color: #7c65a7; --preset-bg: #f7f2fc; }.schedule-preset:nth-of-type(5) { --preset-color: #317c82; --preset-bg: #edf8f8; }.schedule-preset:nth-of-type(6) { --preset-color: #be635b; --preset-bg: #fff1ef; }.schedule-preset:nth-of-type(7) { --preset-color: #887129; --preset-bg: #fbf7e8; }.schedule-preset:hover { transform: translateY(-1px); border-color: var(--preset-color); }.schedule-preset.selected { border-color: var(--preset-color); background: color-mix(in srgb, var(--preset-bg) 45%, var(--preset-color) 15%); box-shadow: inset 0 0 0 1px var(--preset-color); }.schedule-preset input { position: absolute; opacity: 0; pointer-events: none; }.schedule-preset-icon { flex: 0 0 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: color-mix(in srgb, var(--preset-bg) 55%, white); font-size: 1.05rem; }.schedule-preset > span:last-child { min-width: 0; }.schedule-preset strong, .schedule-preset small { display: block; overflow-wrap: anywhere; }.schedule-preset strong { font-size: .84rem; line-height: 1.2; }.schedule-preset small { color: var(--muted); font-size: .7rem; font-weight: 500; margin-top: 3px; line-height: 1.25; }
.schedule-detail { background: #faf8f2; }.choice-chips { display: flex; flex-wrap: wrap; gap: 7px; }.choice-chips label { display: inline-flex; cursor: pointer; }.choice-chips input { position: absolute; opacity: 0; pointer-events: none; }.choice-chips span { display: grid; place-items: center; min-width: 38px; min-height: 38px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--muted); font-size: .78rem; font-weight: 800; }.choice-chips input:checked + span { color: white; border-color: var(--green); background: var(--green); }.weekday-chips { justify-content: space-between; }.weekday-chips label { flex: 1; }.weekday-chips span { width: 100%; }.month-day-chips { display: grid; grid-template-columns: repeat(7, 1fr); }.month-day-chips span { min-width: 0; }.month-day-chips .last-day-chip { grid-column: 1 / -1; }.month-day-chips .last-day-chip span { width: 100%; }.month-chips { display: grid; grid-template-columns: repeat(6, 1fr); }.month-chips span { min-width: 0; }
.monthly-shortcuts { margin-bottom: 10px; }.month-days-more { border: 0; padding: 0; }.month-days-more summary { width: max-content; padding: 7px 2px; color: var(--green); cursor: pointer; font-size: .84rem; font-weight: 700; }.month-days-more .month-day-chips { margin-top: 8px; }
.schedule-preset input, .choice-chips input { width: 1px; height: 1px; margin: 0; }
.interval-row { display: grid; grid-template-columns: auto 90px 1fr; gap: 10px; align-items: center; }.interval-row span { font-weight: 700; }.schedule-detail .field-hint { margin-top: 10px; }
.schedule-summary { display: grid; gap: 4px; padding: 14px 16px; border-left: 4px solid var(--green); border-radius: 4px 12px 12px 4px; background: var(--green-soft); }.schedule-summary strong { font-size: .9rem; }.schedule-summary span { color: var(--muted); font-size: .76rem; }
.advanced-schedule { border: 1px solid var(--line); border-radius: 14px; }.advanced-schedule summary { padding: 13px 15px; cursor: pointer; color: var(--green); font-weight: 800; font-size: .88rem; }.advanced-schedule-content { display: grid; gap: 15px; padding: 2px 14px 14px; }
.template-filters { display: grid; gap: 10px; margin-bottom: 16px; }.template-categories { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 3px; scrollbar-width: none; }.template-categories::-webkit-scrollbar { display: none; }.category-chip { flex: 0 0 auto; min-height: 36px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--muted); font-weight: 700; }.category-chip.selected { border-color: var(--green); background: var(--green-soft); color: var(--green); }.template-meta { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 7px; }.template-meta span { padding: 4px 7px; border-radius: 99px; background: #eeeae0; color: var(--muted); font-size: .7rem; font-weight: 700; }
.section-heading { margin: 28px 0 16px; }.section-heading h1, .section-heading h2 { margin-bottom: 0; }.api-error { padding: 12px 16px; border-radius: 12px; }.empty-state { text-align: center; padding: 42px 20px; color: var(--muted); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }.stats-grid article { padding: 22px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); }.stats-grid strong { display: block; font-size: 2rem; }.stats-grid span { color: var(--muted); font-size: .86rem; }
table { width: 100%; border-collapse: collapse; } th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; } th { color: var(--muted); font-size: .76rem; }.admin-list { list-style: none; padding: 0; }.admin-list li { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }.admin-list span { color: var(--muted); }

@media (max-width: 700px) {
  .site-header { position: static; padding: 16px; align-items: flex-start; }.site-header nav { gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
  .app-shell, .admin-shell { width: min(100% - 20px, 760px); margin-top: 16px; }.hero-card { padding: 23px; }.score-ring { flex-basis: 72px; height: 72px; border-width: 6px; }
  .app-tabs button { font-size: .72rem; }.form-grid, .stats-grid { grid-template-columns: 1fr 1fr; }.panel { overflow: visible; }
  .schedule-presets { grid-template-columns: 1fr; }.month-chips { grid-template-columns: repeat(4, 1fr); }.habit-form { padding: 18px; }.schedule-preset small { font-size: .74rem; }
}

@media (max-width: 430px) {
  .form-grid { grid-template-columns: 1fr; }.interval-row { grid-template-columns: auto 76px 1fr; }.month-day-chips { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }.month-day-chips span { min-height: 34px; padding: 4px; }.month-chips { grid-template-columns: repeat(3, 1fr); }
}

@media (max-height: 720px) {
  .oauth-shell { min-height: 100dvh; place-items: start center; padding: 12px 12px calc(88px + env(safe-area-inset-bottom)); }
  .oauth-shell .login-card { padding: 24px; border-radius: 22px; }
  .oauth-shell .kapsme-mark { width: 40px; height: 40px; margin-bottom: 14px; }
  .oauth-shell h1 { font-size: 2rem; margin-bottom: 12px; }
  .oauth-shell .muted { font-size: .9rem; margin-bottom: 14px; }
  .oauth-shell .stack-form { gap: 11px; }
  .oauth-shell .oauth-note { margin-top: 12px; padding-top: 10px; }
}
