:root {
  color-scheme: dark;
  --bg: #000; --surface: #1c1c1e; --surface-raised: #2c2c2e; --ink: #f5f5f7;
  --muted: #98989d; --line: #38383a; --line-strong: #48484a; --accent: #0a84ff;
  --accent-ink: #d9ecff; --accent-soft: rgba(10,132,255,.17); --danger: #ff453a;
  --danger-soft: rgba(255,69,58,.14); --success: #30d158; --shadow: 0 18px 50px rgba(0,0,0,.48);
  --radius: 14px; --font: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-width: 0; min-height: 100dvh; color: var(--ink); background: var(--bg); }
button, input, textarea { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .38; cursor: not-allowed; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(10,132,255,.48); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.network-banner { position: sticky; z-index: 30; top: 0; width: min(100%,430px); margin-inline: auto; padding: max(8px,env(safe-area-inset-top)) 16px 8px; background: #3a2b00; color: #ffd60a; font-size: 11px; font-weight: 700; text-align: center; }
.app-shell { position: relative; width: min(100%,430px); min-height: 100dvh; margin-inline: auto; padding: max(18px,env(safe-area-inset-top)) 18px 0; overflow: hidden; background: var(--bg); box-shadow: 0 0 0 1px rgba(255,255,255,.07), var(--shadow); }
.topbar, .month-header, .daily-heading-row, .sheet-header, .habit-header, .memo-meta, .manager-summary, .manager-actions, .button-row { display: flex; align-items: center; justify-content: space-between; }
.topbar { min-height: 52px; }
.app-name { margin: 0; font-size: 21px; font-weight: 760; letter-spacing: -.03em; }
.today-label { margin: 3px 0 0; color: var(--muted); font-size: 12px; font-weight: 560; }
.icon-button { display: inline-grid; width: 44px; height: 44px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); font-size: 21px; font-weight: 650; cursor: pointer; }
.icon-button:active, .slot-button:active, .add-habit-button:active, .primary-button:active, .secondary-button:active, .danger-button:active { transform: scale(.98); }

.loading-state { display: grid; gap: 16px; padding-top: 30px; }
.skeleton { overflow: hidden; border-radius: 14px; background: var(--surface); }
.skeleton::after { display: block; width: 45%; height: 100%; content: ""; background: linear-gradient(90deg,transparent,rgba(255,255,255,.06),transparent); animation: shimmer 1.25s infinite linear; }
.skeleton-title { width: 45%; height: 28px; }
.skeleton-calendar { height: 270px; }
.skeleton-row { height: 82px; }

.month-section { padding-top: 21px; }
.month-header { padding-inline: 2px; }
.month-nav { border: 0; background: transparent; font-size: 31px; font-weight: 400; }
.month-title { display: grid; gap: 1px; padding: 4px 18px; border: 0; background: transparent; cursor: pointer; }
.month-title span:first-child { font-size: 17px; font-weight: 730; letter-spacing: -.02em; }
.month-caption { color: var(--accent); font-size: 10px; font-weight: 700; }
.weekday-row, .calendar-grid { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); }
.weekday-row { margin-top: 13px; padding: 0 2px 5px; color: var(--muted); font-size: 10px; font-weight: 650; text-align: center; }
.calendar-grid { gap: 3px; padding: 6px 2px 7px; }
.calendar-day { position: relative; display: grid; min-height: 42px; padding: 5px 2px 8px; place-items: center; align-content: space-between; border: 0; border-radius: 12px; background: transparent; color: var(--ink); font-size: 12px; cursor: pointer; }
.calendar-day.outside { color: #636366; }
.calendar-day.future { color: #48484a; cursor: not-allowed; }
.calendar-day.selected { background: var(--accent); color: #fff; }
.calendar-day.today:not(.selected)::before { position: absolute; inset: 2px 6px; border: 1px solid var(--accent); border-radius: 12px; content: ""; }
.day-marks { display: flex; min-height: 5px; gap: 2px; }
.day-mark, .legend-mark { width: 5px; height: 5px; border-radius: 50%; background: var(--habit-color,var(--accent)); }
.day-mark.partial, .legend-mark.partial { background: transparent; border: 1px solid var(--habit-color,var(--accent)); }
.legend-mark.partial { border-color: var(--accent); }
.calendar-day.selected .day-mark { background: #fff; }
.calendar-day.selected .day-mark.partial { background: transparent; border-color: #fff; }
.legend { display: flex; justify-content: center; gap: 18px; color: var(--muted); font-size: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.daily-section { margin: 22px -18px 0; padding: 20px 18px 8px; border-top: 1px solid var(--line); background: var(--surface); }
.section-kicker { margin: 0 0 4px; color: var(--accent); font-size: 10px; font-weight: 760; letter-spacing: .08em; }
h1, h2, h3 { margin: 0; letter-spacing: -.035em; }
h1 { font-size: 22px; } h2 { font-size: 21px; } h3 { font-size: 15px; }
.daily-summary { display: grid; justify-items: end; margin: 0; }
.daily-summary strong { font-size: 24px; line-height: 1; }
.daily-summary span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.progress-line { height: 3px; margin-top: 14px; overflow: hidden; border-radius: 999px; background: var(--line); }
.progress-line span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 180ms ease-out; }
.save-status { min-height: 16px; margin: 7px 0 3px; color: var(--muted); font-size: 10px; text-align: right; }
.save-status[data-kind="success"] { color: var(--success); }
.save-status[data-kind="error"], .error-text { color: var(--danger); }

.habit-card { padding: 17px 0 16px; border-bottom: 1px solid var(--line); }
.habit-card:last-child { border-bottom: 0; }
.habit-title-wrap { display: flex; align-items: center; gap: 10px; }
.habit-color { flex: 0 0 auto; width: 4px; height: 31px; border-radius: 99px; background: var(--accent); }
.habit-title { margin: 0; font-size: 15px; font-weight: 720; }
.habit-progress { margin: 2px 0 0; color: var(--muted); font-size: 10px; }
.slot-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
.slot-memo-button { min-width: 58px; padding: 8px 9px; border: 1px solid var(--line); border-radius: 11px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 650; cursor: pointer; }
.slot-memo-button.has-memo { color: var(--accent); border-color: rgba(10,132,255,.55); background: var(--accent-soft); }
.slot-list { display: grid; grid-template-columns: repeat(auto-fit,minmax(84px,1fr)); gap: 8px; margin-top: 13px; }
.slot-button { display: flex; min-height: 46px; padding: 8px 10px; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface-raised); font-size: 12px; font-weight: 700; cursor: pointer; transition: transform 100ms ease, background 150ms ease, border-color 150ms ease; }
.slot-check { display: grid; width: 18px; height: 18px; place-items: center; border: 1.5px solid #8e8e93; border-radius: 6px; color: transparent; font-size: 12px; }
.slot-button.completed { border-color: rgba(10,132,255,.65); background: var(--accent-soft); color: var(--accent-ink); }
.slot-button.completed .slot-check { border-color: var(--accent); background: var(--accent); color: #fff; }
.empty-state { padding: 44px 16px; text-align: center; }
.empty-state h2 { font-size: 19px; }
.empty-state p { margin: 10px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.empty-state .primary-button { width: auto; margin-inline: auto; padding-inline: 24px; }

.add-habit-button, .primary-button, .secondary-button, .danger-button { display: flex; min-height: 50px; padding: 0 16px; align-items: center; justify-content: center; gap: 7px; border-radius: var(--radius); font-weight: 730; cursor: pointer; }
.add-habit-button { width: 100%; margin: 17px 0 6px; border: 1px dashed var(--line-strong); background: transparent; color: var(--accent); }
.primary-button { border: 0; background: var(--accent); color: #fff; }
.secondary-button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }
.danger-button { border: 1px solid rgba(255,69,58,.38); background: var(--danger-soft); color: var(--danger); }
.full-width { width: 100%; }
.button-row { gap: 10px; }
.button-row > * { flex: 1; }
.bottom-safe-area { height: max(18px,env(safe-area-inset-bottom)); }
.toast { position: fixed; z-index: 40; left: 50%; bottom: max(22px,env(safe-area-inset-bottom)); width: min(calc(100% - 36px),390px); padding: 12px 15px; translate: -50% 0; border-radius: 12px; background: var(--surface-raised); color: #fff; box-shadow: var(--shadow); font-size: 12px; text-align: center; }
.toast[data-kind="error"] { color: #ffd1ce; }

.sheet { width: min(100%,430px); max-width: none; max-height: 94dvh; margin: auto auto 0; padding: 0; overflow: visible; border: 0; border-radius: 18px 18px 0 0; background: transparent; color: var(--ink); }
.sheet::backdrop { background: rgba(0,0,0,.72); }
.sheet-panel { max-height: 94dvh; padding: 9px 18px max(22px,env(safe-area-inset-bottom)); overflow-y: auto; border-radius: 18px 18px 0 0; background: var(--surface-raised); box-shadow: 0 -18px 45px rgba(0,0,0,.42); }
.sheet-handle { width: 38px; height: 4px; margin: 0 auto 18px; border-radius: 99px; background: #636366; }
.sheet-header { margin-bottom: 18px; }
.sheet-copy { margin: -2px 0 20px; color: var(--muted); font-size: 13px; line-height: 1.75; }
.auth-sheet { width: min(calc(100% - 24px),400px); margin: auto; border-radius: 18px; }
.auth-panel { border-radius: 18px; padding-top: 24px; }
.field-group { margin-bottom: 17px; }
.field-group label, .color-fieldset legend, .slots-fieldset legend { display: block; margin-bottom: 7px; color: var(--ink); font-size: 12px; font-weight: 700; }
input, textarea { display: block; width: 100%; min-height: 48px; padding: 12px 13px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--ink); }
input[type="date"] { color-scheme: dark; }
textarea { min-height: 132px; resize: vertical; line-height: 1.65; }
input::placeholder, textarea::placeholder { color: #7b7b80; }
.field-help, .settings-section p, .slots-fieldset > p { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.field-error { margin: 8px 0 0; color: var(--danger); font-size: 11px; line-height: 1.5; }
.memo-meta { gap: 8px; margin: 7px 0 17px; color: var(--muted); font-size: 9px; }
.memo-meta span:first-child { max-width: 240px; }

.settings-link { display: flex; width: 100%; min-height: 66px; padding: 12px 0; align-items: center; justify-content: space-between; border: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.settings-link span:first-child { display: grid; gap: 3px; }
.settings-link strong { font-size: 14px; }
.settings-link small { color: var(--muted); font-size: 10px; }
.settings-link > span:last-child { color: var(--muted); font-size: 26px; }
.settings-section { margin: 22px 0; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.settings-section h3 { margin-bottom: 6px; }
.settings-section p { margin-bottom: 14px; }
.date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.date-range .field-group { margin-bottom: 10px; }

.manager-list { display: grid; gap: 10px; margin-bottom: 18px; }
.manager-item { padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.manager-item.inactive { opacity: .65; }
.manager-summary { justify-content: flex-start; gap: 10px; }
.manager-summary h3 { font-size: 14px; }
.manager-summary p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.manager-actions { justify-content: flex-start; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.manager-action { min-height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-raised); color: var(--ink); font-size: 11px; font-weight: 650; cursor: pointer; }
.manager-message { color: var(--muted); font-size: 12px; text-align: center; }

.color-fieldset, .slots-fieldset { margin: 0 0 21px; padding: 0; border: 0; }
.color-options { display: flex; flex-wrap: wrap; gap: 10px; }
.color-option { display: grid; width: 42px; height: 42px; margin: 0 !important; place-items: center; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.color-option input { position: absolute; width: 1px; min-height: 1px; opacity: 0; }
.color-swatch { width: 24px; height: 24px; border-radius: 50%; }
.color-option:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.slot-editor-list { display: grid; gap: 8px; margin: 13px 0 10px; }
.slot-editor-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.slot-remove-button { min-width: 62px; border: 1px solid rgba(255,69,58,.35); border-radius: 11px; background: var(--danger-soft); color: var(--danger); font-size: 11px; font-weight: 700; }
.slot-suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.slot-suggestions button { min-height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--accent); font-size: 11px; cursor: pointer; }

.confirm-dialog { width: min(calc(100% - 36px),360px); padding: 0; border: 0; border-radius: 16px; background: transparent; color: var(--ink); }
.confirm-dialog::backdrop { background: rgba(0,0,0,.72); }
.confirm-panel { padding: 20px; border-radius: 16px; background: var(--surface-raised); }
.confirm-panel h2 { font-size: 18px; }
.confirm-panel p { margin: 9px 0 19px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.offline .slot-button, .offline .slot-memo-button { opacity: .5; }

@keyframes shimmer { to { transform: translateX(225%); } }
@media (max-width: 360px) { .app-shell { padding-inline: 14px; } .daily-section { margin-inline: -14px; padding-inline: 14px; } .calendar-day { min-height: 39px; } .date-range { grid-template-columns: 1fr; gap: 0; } }
@media (min-width: 700px) { .sheet { margin-bottom: 3dvh; border-radius: 18px; } .sheet-panel { border-radius: 18px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
