:root {
  --bg: #f4f2ed;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1c1b18;
  --ink-2: #6f6a5f;
  --ink-3: #a8a294;
  --line: #e9e6de;
  --line-2: #dcd8cd;
  --work: #eab308;
  --work-ink: #241f0b;
  --work-soft: rgba(234, 179, 8, 0.16);
  --rest: #2f9d6b;
  --rest-ink: #ffffff;
  --rest-soft: rgba(47, 157, 107, 0.16);
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --over-blue: #2563eb;
  --over-red: #dc2626;
  --today: #17140f;
  --today-stripe: rgba(255, 255, 255, 0.6);
  --shadow: 0 1px 2px rgba(28, 27, 24, 0.04), 0 10px 30px -18px rgba(28, 27, 24, 0.18);
  --radius: 22px;
  --r-lg: 18px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #15181a;
  --surface: #1d2124;
  --surface-2: #23282c;
  --ink: #f1ede6;
  --ink-2: #a49d8e;
  --ink-3: #6e6a5f;
  --line: #2a2f33;
  --line-2: #363c40;
  --work: #f2c014;
  --work-ink: #1d190a;
  --work-soft: rgba(242, 192, 20, 0.16);
  --rest: #34a06e;
  --rest-ink: #ffffff;
  --rest-soft: rgba(52, 160, 110, 0.16);
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.12);
  --over-blue: #60a5fa;
  --over-red: #f87171;
  --today: #f1ede6;
  --today-stripe: rgba(0, 0, 0, 0.5);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 14px 34px -20px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
  transition: background 0.25s ease, color 0.25s ease;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px calc(32px + env(safe-area-inset-bottom));
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.brand-mark {
  display: inline-flex;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--work);
  align-items: center;
  justify-content: center;
  gap: 3px;
  box-shadow: var(--shadow);
}
.brand-mark i {
  width: 3px;
  border-radius: 2px;
  background: var(--work-ink);
  display: block;
}
.brand-mark i:nth-child(1) { height: 10px; opacity: .55; }
.brand-mark i:nth-child(2) { height: 16px; }
.brand-name {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  transition: background 0.18s ease, color 0.18s ease;
}
.icon-btn:hover { background: var(--line); color: var(--ink); }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ---------- hero ---------- */
.hero {
  position: relative;
  border-radius: var(--radius);
  padding: 26px 24px 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 100% 0%, var(--work-soft) 0%, transparent 55%),
    linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}
.hero-left, .hero-right { position: relative; }
.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.hero-day {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.hero-date-num {
  display: block;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.hero-status { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.hero-pill {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 10px 18px;
  border-radius: 999px;
  color: var(--work-ink);
  background: var(--work);
  box-shadow: var(--shadow);
  transition: background 0.2s ease, color 0.2s ease;
}
.hero-pill.rest {
  background: var(--rest);
  color: var(--rest-ink);
}
.hero-week {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink-2);
}
.hero-sub {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--ink-2);
  position: relative;
}

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* calendar head */
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 0;
}
.cal-title {
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: capitalize;
}
.nav-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  transition: background 0.18s ease, color 0.18s ease;
}
.nav-btn:hover { background: var(--surface-2); color: var(--ink); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 14px 10px 6px;
  gap: 4px;
}
.cal-weekdays span {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 0 10px 8px;
}

.day {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}
.day.blank {
  pointer-events: none;
  visibility: hidden;
}
.day.work {
  background: var(--work);
  color: var(--work-ink);
  box-shadow: var(--shadow);
}
.day.rest {
  background: var(--rest);
  color: var(--rest-ink);
}
.day.work.ovr-to-work,
.day.ovr-to-work {
  background: var(--work);
  color: var(--work-ink);
  box-shadow: inset 0 0 0 2.5px var(--over-red), var(--shadow);
}
.day.rest.ovr-to-rest,
.day.ovr-to-rest {
  background: var(--rest);
  color: var(--rest-ink);
  box-shadow: inset 0 0 0 2.5px var(--over-blue);
}
.day:not(.blank):hover { transform: translateY(-1px); }
.day.work:not(.today):hover { box-shadow: var(--shadow); filter: brightness(1.05); }

.day .week-tag {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: inherit;
  opacity: 0.55;
  z-index: 1;
}
.day .num {
  position: relative;
  z-index: 1;
}

.day.today {
  outline: 2.5px solid var(--today);
  outline-offset: 1.5px;
  z-index: 1;
}
.day.today::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    135deg,
    transparent 0px,
    transparent 8px,
    var(--today-stripe) 8px,
    var(--today-stripe) 11px
  );
  pointer-events: none;
}
.day.has-note::after {
  content: "";
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-3);
  box-shadow: 0 0 0 2.5px var(--surface);
}

.cal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 14px 14px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.ghost-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  padding: 8px 12px;
  border-radius: 10px;
  transition: background 0.18s ease, color 0.18s ease;
}
.ghost-btn:hover { background: var(--surface-2); color: var(--ink); }
.date-jump {
  display: flex;
  align-items: center;
  gap: 8px;
}
.date-jump-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
}
.date-jump input {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 8px 10px;
  max-width: 148px;
}
::-webkit-calendar-picker-indicator { opacity: 0.55; }

/* ---------- legend & hint ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 16px 4px 0;
}
.lg {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
}
.sw {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 6px;
}
.sw-work { background: var(--work); box-shadow: var(--shadow); }
.sw-rest { background: var(--rest); }
.sw-today { border: 2.5px solid var(--today); background: transparent; border-radius: 6px; box-sizing: border-box; }
.sw-to-rest {
  background: var(--rest);
  box-shadow: inset 0 0 0 2px var(--over-blue);
  border-radius: 6px;
  box-sizing: border-box;
}
.sw-to-work {
  background: var(--work);
  box-shadow: inset 0 0 0 2px var(--over-red);
  border-radius: 6px;
  box-sizing: border-box;
}

.hint {
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-3);
  margin: 18px 0 0;
}

.foot {
  margin-top: 34px;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

/* ---------- bottom sheet / modal ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 14, 12, 0.42);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  padding: 10px 22px calc(26px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
  max-height: 88dvh;
  overflow-y: auto;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: var(--line-2);
  margin: 6px auto 14px;
}
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.sheet-weekday {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.sheet-full {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 3px;
  text-transform: capitalize;
}

.sheet-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.sheet-pill {
  font-size: 15px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--work);
  color: var(--work-ink);
}
.sheet-pill.rest {
  background: var(--rest);
  color: var(--rest-ink);
}
.sheet-week {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}
.sheet-base {
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 13px;
  margin-bottom: 18px;
}

.sheet-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.act-btn {
  padding: 14px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 650;
  transition: filter 0.15s ease, transform 0.1s ease;
  border: 1px solid transparent;
}
.act-btn:active { transform: scale(0.98); }
.act-work { background: var(--work); color: var(--work-ink); box-shadow: var(--shadow); }
.act-rest { background: var(--rest); color: var(--rest-ink); border-color: transparent; }
.act-ghost {
  grid-column: 1 / -1;
  background: var(--surface-2);
  color: var(--ink-2);
  border-color: var(--line);
  font-weight: 600;
}
.act-ghost.danger { color: #c0564a; border-color: rgba(192, 86, 74, 0.3); }
[data-theme="dark"] .act-ghost.danger { color: #e58a77; }

.sheet-note { display: block; margin-bottom: 8px; }
.sheet-note > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  margin-bottom: 7px;
}
.sheet-note em { font-style: normal; font-weight: 400; opacity: 0.75; }
.sheet-note input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 12px 14px;
}
.sheet-note input::placeholder { color: var(--ink-3); }
.sheet-hint {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 6px;
}

/* settings */
.sheet-settings { border-radius: 26px 26px 0 0; }
.settings-desc {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 0 0 20px;
}
.settings-desc strong { color: var(--ink); }
.settings-field { margin-bottom: 20px; }
.settings-field > label, .settings-field > span {
  display: block;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.03em;
  color: var(--ink-3);
  margin-bottom: 8px;
  text-transform: uppercase;
}
.settings-field input[type="date"] {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 12px 14px;
}
.settings-note {
  font-size: 12px;
  color: var(--ink-2);
  margin: 8px 0 0;
  line-height: 1.4;
}
.seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.seg-btn {
  flex: 1;
  padding: 11px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--ink-2);
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.seg-btn.active {
  background: var(--work);
  color: var(--work-ink);
  box-shadow: var(--shadow);
}

/* responsive */
@media (min-width: 600px) {
  .shell { padding-top: 40px; }
  .sheet, .sheet-settings { border-radius: 26px; margin-bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}