:root {
  color-scheme: dark;
  --bg: #111;
  --panel: #1a1a1a;
  --panel-surface: rgba(26, 26, 26, 0.9);
  --card: #1a1a1a;
  --card-strong: #151515;
  --input: #111;
  --text: #f1f1f1;
  --muted: #bdbdbd;
  --line: #3a3a3a;
  --accent: #f5b12a;
  --accent-strong: #d69316;
  --danger: #ff6b6b;
  --glow-1: rgba(245, 177, 42, 0.12);
  --glow-2: rgba(245, 177, 42, 0.08);
  --heat-0: #2a2a2a;
  --heat-1: #4b3719;
  --heat-2: #6a4a18;
  --heat-3: #8d621b;
  --heat-4: #b47b1d;
  --heat-5: #d99722;
  --heat-6: var(--accent);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

:root[data-theme="blue-dark"] { --accent: #60a5fa; --accent-strong: #3b82f6; --glow-1: rgba(96, 165, 250, 0.14); --glow-2: rgba(59, 130, 246, 0.1); --heat-1: #14253d; --heat-2: #1e3a5f; --heat-3: #245188; --heat-4: #2f6eb8; --heat-5: #3b82f6; }
:root[data-theme="green-dark"] { --accent: #5ee0a0; --accent-strong: #22c55e; --glow-1: rgba(94, 224, 160, 0.14); --glow-2: rgba(34, 197, 94, 0.1); --heat-1: #123322; --heat-2: #174b30; --heat-3: #1c6940; --heat-4: #228a53; --heat-5: #34c879; }
:root[data-theme="rose"] { --accent: #f472b6; --accent-strong: #ec4899; --glow-1: rgba(244, 114, 182, 0.16); --glow-2: rgba(236, 72, 153, 0.1); --heat-1: #3f1530; --heat-2: #641d48; --heat-3: #8d2764; --heat-4: #bd367f; --heat-5: #ec4899; }
:root[data-theme="lavender"] { --accent: #c4b5fd; --accent-strong: #a78bfa; --glow-1: rgba(196, 181, 253, 0.16); --glow-2: rgba(167, 139, 250, 0.1); --heat-1: #2b214b; --heat-2: #42316f; --heat-3: #5b4598; --heat-4: #7c61cc; --heat-5: #a78bfa; }
:root[data-theme="peach"] { --accent: #fbab7e; --accent-strong: #f97316; --glow-1: rgba(251, 171, 126, 0.16); --glow-2: rgba(249, 115, 22, 0.1); --heat-1: #442313; --heat-2: #66351a; --heat-3: #8c4b24; --heat-4: #bd682f; --heat-5: #f08a45; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, var(--glow-1), transparent 32rem),
    radial-gradient(circle at 90% 0%, var(--glow-2), transparent 28rem),
    var(--bg);
}

button, input, select { font: inherit; }

button {
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.1rem;
  background: var(--accent);
  color: #111;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease;
}

button:hover { background: var(--accent-strong); transform: translateY(-1px); }
button:disabled { cursor: wait; opacity: 0.65; transform: none; }

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.85rem 0.95rem;
  background: var(--input);
  color: var(--text);
}

label { font-size: 0.88rem; font-weight: 800; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0.45rem; font-size: clamp(2rem, 5vw, 4.5rem); line-height: 0.95; letter-spacing: -0.055em; }
h2 { margin-bottom: 0.35rem; font-size: 1.25rem; letter-spacing: -0.025em; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.app-shell { width: min(1320px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0; }
.auth-card, .panel { border: 1px solid var(--line); background: var(--panel-surface); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.auth-card { max-width: 520px; margin: 8vh auto 0; border-radius: 34px; padding: clamp(24px, 5vw, 48px); }
.stack { display: grid; gap: 0.75rem; }
.eyebrow { margin-bottom: 0.5rem; color: var(--accent); font-size: 0.75rem; font-weight: 900; letter-spacing: 0.18em; text-transform: uppercase; }
.muted { color: var(--muted); }
.message { min-height: 1.25rem; color: var(--muted); }
.message.error { color: var(--danger); }
.ghost { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--text); }
.ghost:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

.topbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 0.75rem; margin-bottom: 14px; }
.home-logo-button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; background: transparent; }
.home-logo-button:hover { background: transparent; transform: none; }
.brand-logo { width: 36px; height: 36px; flex: 0 0 auto; }
#userLine { margin: 0; min-width: 0; padding-block: 0.12rem; overflow-x: auto; overflow-y: visible; line-height: 1.3; white-space: nowrap; text-align: center; scrollbar-width: thin; }
.header-menu-wrap { position: relative; }
.header-menu-button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; }
.header-menu-button svg { width: 19px; height: 19px; fill: currentColor; }
.header-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 40; display: grid; gap: 0.35rem; min-width: 212px; padding: 0.45rem; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.menu-item { display: flex; align-items: center; justify-content: flex-start; gap: 0.5rem; width: 100%; padding: 0.55rem 0.65rem; border-radius: 12px; font-size: 0.86rem; }
.menu-item svg { width: 16px; height: 16px; fill: currentColor; }
.primary-menu-item { color: var(--accent); }
.primary-menu-item:hover { color: #111; background: var(--accent); }
.danger-menu-item { color: var(--danger); }
.menu-theme-section { margin-top: 0.1rem; padding: 0.55rem 0.45rem 0.45rem; border-top: 1px solid var(--line); }
.menu-theme-section p { margin: 0 0 0.45rem; color: var(--muted); font-size: 0.68rem; font-weight: 900; letter-spacing: 0.12em; text-transform: uppercase; }
.theme-menu-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.32rem; }
.theme-choice { display: flex; align-items: center; justify-content: flex-start; gap: 0.35rem; min-height: 30px; padding: 0.35rem 0.42rem; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.04); color: var(--text); font-size: 0.72rem; font-weight: 800; }
.theme-choice:hover { background: rgba(255, 255, 255, 0.08); transform: none; }
.theme-choice.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); }
.theme-choice i { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 999px; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08); }
.theme-choice span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; margin-top: 18px; }
.nav-panel { grid-column: 1 / -1; padding-block: 14px; }
.today-panel { grid-column: 1 / -1; }
.top-nav-row { display: grid; grid-template-columns: minmax(230px, 1fr) auto; gap: 0.65rem; align-items: center; }
.today-actions { display: flex; align-items: center; gap: 0.55rem; }
.today-actions button { padding: 0.5rem 0.75rem; font-size: 0.86rem; }
.panel { border-radius: 28px; padding: clamp(18px, 3vw, 28px); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.65rem; }
.compact-head { align-items: center; margin-bottom: 0.75rem; }
.compact-head h2 { margin: 0; font-size: 1.05rem; }
.score-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 0.5rem 0.75rem; background: var(--accent); color: #111; font-weight: 900; }

.habit-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 320px)); gap: 0.8rem; align-items: start; }
.date-nav { display: grid; grid-template-columns: 38px minmax(136px, 1fr) 38px 38px; gap: 0.35rem; align-items: center; }
.date-nav button { padding: 0; font-size: 0.86rem; }
.date-icon-button { display: grid; place-items: center; width: 38px; height: 38px; }
.date-icon-button svg { width: 18px; height: 18px; fill: currentColor; }
.date-display-wrap { position: relative; display: grid; align-items: center; min-height: 38px; border: 1px solid var(--line); border-radius: 999px; background: var(--input); overflow: hidden; cursor: pointer; }
.date-display { display: block; padding: 0.42rem 0.62rem; color: var(--text); font-size: 0.9rem; font-weight: 800; text-align: center; user-select: none; }
.date-display-wrap input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.category-add-button { white-space: nowrap; padding: 0.5rem 0.75rem; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.04); color: var(--text); font-size: 0.86rem; font-weight: 800; }
.category-add-button { flex: 0 0 auto; }
.category-add-button svg { width: 15px; height: 15px; fill: currentColor; }
.category-add-button { display: inline-flex; align-items: center; gap: 0.35rem; }
.list-title { margin: 0.65rem 0 0.45rem; font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }
.secondary-title { margin-top: 1.35rem; }
.inactive-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 1rem; padding: 0.58rem 0.75rem; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, 0.04); color: var(--muted); font-size: 0.82rem; letter-spacing: 0.1em; text-transform: uppercase; }
.inactive-toggle:hover { background: rgba(245, 177, 42, 0.12); color: var(--text); transform: none; }
.inactive-toggle:active { background: rgba(245, 177, 42, 0.18); color: var(--text); }
.inactive-toggle::after { content: '+'; margin-left: 0.5rem; color: var(--text); font-size: 1rem; line-height: 1; }
.inactive-toggle[aria-expanded="true"]::after { content: '-'; }
.inactive-toggle small { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; margin-left: auto; border-radius: 999px; background: var(--accent); color: #111; font-size: 0.72rem; letter-spacing: 0; }
.inactive-toggle + .habit-list { margin-top: 0.65rem; }
.category-group { display: grid; gap: 0.5rem; width: 100%; max-width: 320px; min-width: 0; border: 1px solid var(--line); border-radius: 16px; padding: 0.75rem; background: rgba(255, 255, 255, 0.03); }
.category-heading { color: var(--text); }
.category-title-wrap { min-width: 0; font-size: 1.05rem; font-weight: 900; letter-spacing: 0.01em; }
.category-title-wrap span { min-width: 0; overflow-wrap: anywhere; }
.category-control-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding-top: 0.05rem; }
.category-progress { display: grid; grid-template-columns: 24px auto 74px; align-items: center; gap: 0.36rem; color: var(--text); font-size: 0.82rem; font-weight: 900; }
.category-progress-settings { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; color: var(--muted); }
.category-progress-settings svg { width: 13px; height: 13px; fill: currentColor; }
.category-progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: var(--card-strong); }
.category-progress-track i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.category-heading-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 0.3rem; flex: 0 0 auto; }
.category-add-habit { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; background: var(--accent); color: #111; }
.category-add-habit:hover { background: var(--accent-strong); }
.category-add-habit svg { width: 16px; height: 16px; fill: currentColor; }
.category-edit-toggle { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 auto; padding: 0; color: var(--muted); }
.category-edit-toggle.active { border-color: var(--accent); color: var(--accent); background: rgba(245, 177, 42, 0.1); }
.category-edit-toggle svg { width: 15px; height: 15px; fill: currentColor; }
.category-items { display: grid; margin-top: 0.1rem; }
.habit-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.36rem; align-items: center; min-height: 30px; padding: 0.18rem 0.1rem; border-bottom: 1px solid var(--line); background: transparent; }
.habit-card:last-child { border-bottom: 0; }
.habit-card[data-toggle-row] { cursor: pointer; }
.habit-card[data-toggle-row]:active { background: rgba(245, 177, 42, 0.08); }
.habit-card.inactive { opacity: 0.78; }
.habit-card h3 { margin: 0; overflow-wrap: anywhere; font-size: 0.88rem; line-height: 1.04; user-select: none; }
.habit-meta { margin: 0.04rem 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.64rem; line-height: 1.04; }
.habit-actions { display: flex; align-items: center; gap: 0.32rem; }
.right-controls { display: inline-flex; align-items: center; gap: 0.35rem; }
.order-button { color: var(--muted); }
.quick-controls { display: inline-flex; align-items: center; gap: 0.04rem; }
.quick-value { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; font-size: 0.78rem; color: var(--text); user-select: none; }
.habit-checkbox { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.check-spacer { width: 16px; height: 16px; }
.icon-button { display: grid; place-items: center; width: 26px; height: 26px; padding: 0; }
.icon-button svg { width: 14px; height: 14px; fill: currentColor; }
.delete-button { color: var(--danger); }
.danger-action { color: var(--danger); }
.edit-info { margin: -0.1rem 0 0.75rem; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, 0.04); color: var(--muted); font-size: 0.78rem; line-height: 1.25; }
.empty { grid-column: 1 / -1; padding: 2rem; text-align: center; border: 1px dashed var(--line); border-radius: 22px; color: var(--muted); background: rgba(255, 255, 255, 0.04); }

.inline-fields { display: grid; grid-template-columns: auto 90px 1fr; align-items: center; gap: 0.65rem; }
.weekday-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem; }
.weekday-grid label { display: grid; place-items: center; gap: 0.25rem; border: 1px solid var(--line); border-radius: 14px; padding: 0.55rem 0.25rem; background: var(--card-strong); font-size: 0.78rem; }
.weekday-grid input { width: auto; }
.monthday-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem; }
.monthday-grid label { display: grid; place-items: center; gap: 0.25rem; border: 1px solid var(--line); border-radius: 14px; padding: 0.5rem 0.2rem; background: var(--card-strong); font-size: 0.76rem; }
.monthday-grid input { width: auto; }
.monthday-grid .month-end { grid-column: span 3; }
.date-add-fields { grid-template-columns: minmax(0, 1fr) auto; }
.date-chip-list { display: flex; flex-wrap: wrap; gap: 0.35rem; min-height: 2rem; }
.date-chip { padding: 0.42rem 0.62rem; font-size: 0.76rem; }
.date-chip span { color: var(--danger); font-weight: 900; }
.mini-help { font-size: 0.78rem; }
.category-manage-list { display: grid; gap: 0.45rem; margin-top: 1rem; }
.category-manage-item { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.55rem 0.65rem; border: 1px solid var(--line); border-radius: 14px; background: var(--card-strong); }
.category-manage-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }

.heatmap-panel { margin-top: 20px; }
.top-heatmap { margin: 0 0 0; padding: 12px 16px 14px; }
.heatmap-panel { position: relative; z-index: 20; }
.today-panel { position: relative; z-index: 1; }
.year-select { width: auto; min-width: 82px; padding: 0.42rem 0.62rem; border-radius: 999px; font-size: 0.88rem; font-weight: 800; }
.heatmap-toolbar { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 0.55rem; }
.heatmap-wrap { overflow-x: hidden; padding-bottom: 0.2rem; scrollbar-width: none; }
.heatmap-wrap.is-scrollable { overflow-x: auto; }
.heatmap-wrap::-webkit-scrollbar { display: none; }
.month-labels { display: grid; grid-auto-flow: column; gap: 3px; width: max-content; margin: 0 auto 4px; padding-left: 32px; color: var(--muted); font-size: 0.66rem; line-height: 1; }
.month-labels span { min-width: 24px; }
.heatmap-body { display: flex; align-items: flex-start; gap: 6px; width: max-content; margin: 0 auto; }
.weekday-labels { position: sticky; left: 0; z-index: 2; display: grid; grid-template-rows: repeat(7, 10px); gap: 3px; width: 26px; padding-right: 6px; padding-bottom: 5px; background: var(--panel); color: var(--muted); font-size: 0.58rem; line-height: 10px; text-align: right; }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 10px); grid-auto-columns: 10px; gap: 3px; width: max-content; min-height: 88px; }
.day { display: block; width: 10px; height: 10px; min-width: 0; padding: 0; border: 0; border-radius: 2.5px; background: #e8dece; cursor: pointer; }
.day:hover { transform: none; }
.day:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.day.selected { outline: 2px solid #fff; outline-offset: 2px; }
.level-0 { background: var(--heat-0); }
.level-1 { background: var(--heat-1); }
.level-2 { background: var(--heat-2); }
.level-3 { background: var(--heat-3); }
.level-4 { background: var(--heat-4); }
.level-5 { background: var(--heat-5); }
.level-6 { background: var(--heat-6); }
.legend { display: flex; align-items: center; justify-content: flex-end; gap: 0.28rem; color: var(--muted); font-size: 0.72rem; }
.legend i { width: 10px; height: 10px; border-radius: 2.5px; display: inline-block; }
.heatmap-date-nav { width: min(360px, 100%); margin: 0.65rem auto 0; }
.modal-open { overflow: hidden; }
.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; background: rgba(0, 0, 0, 0.68); backdrop-filter: blur(8px); }
.modal-card { position: relative; width: min(440px, 100%); max-height: min(760px, calc(100vh - 36px)); overflow: auto; }
.modal-close { position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; }
.modal-card h2 { padding-right: 2.5rem; }
.app-version { margin: 14px 0 6px; text-align: center; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; }

@media (max-width: 850px) {
  .app-shell { width: min(100% - 20px, 1180px); padding: 16px 0; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .panel-head { align-items: stretch; flex-direction: column; }
  .today-actions { justify-content: space-between; }
  .layout-grid { grid-template-columns: 1fr; }
  .top-nav-row { grid-template-columns: 1fr; }
  .date-nav { grid-template-columns: 36px minmax(0, 1fr) 36px 36px; gap: 0.3rem; }
  .date-display { font-size: 0.82rem; }
  .date-icon-button { width: 36px; height: 36px; }
  .heatmap-toolbar { justify-content: space-between; gap: 0.65rem; }
  .heatmap-wrap.is-scrollable { overflow-x: auto; }
  .month-labels { margin-left: 0; margin-right: 0; }
  .heatmap-body { margin-left: 0; margin-right: 0; }
  .habit-list { grid-template-columns: 1fr; }
  .category-group { max-width: none; }
  .habit-card { grid-template-columns: auto minmax(0, 1fr) auto; }
  .habit-actions { grid-column: auto; justify-content: flex-end; }
  .toggle-button { flex: 1; }
  .weekday-grid { grid-template-columns: repeat(4, 1fr); }
  .monthday-grid { grid-template-columns: repeat(5, 1fr); }
}
