:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --text: #1f1f1f;
  --muted: #5f6368;
  --line: #e8eaed;
  --shadow: 0 1px 2px rgba(60, 64, 67, .08), 0 2px 10px rgba(60, 64, 67, .06);
  --shadow-lg: 0 6px 24px rgba(60, 64, 67, .18);
  --radius: 28px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.c-money   { --c: #188038; --cbg: #e6f4ea; }
.c-work    { --c: #1a73e8; --cbg: #e8f0fe; }
.c-backend { --c: #00796b; --cbg: #e0f2f1; }
.c-social  { --c: #d93025; --cbg: #fce8e6; }
.c-sleep   { --c: #5e35b1; --cbg: #ede7f6; }
.c-leisure { --c: #e37400; --cbg: #fef3e0; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
svg .f { fill: currentColor; stroke: none; }

#app {
  max-width: 920px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 120px);
}

/* ---------- Home ---------- */
.top { display: flex; align-items: flex-start; justify-content: space-between; padding: 8px 4px 20px; }
.top h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -.02em; }
.top p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted);
  transition: background .15s;
}
.icon-btn:hover { background: #eceff4; }

.top-btns { display: flex; gap: 2px; }
.cloud-synced { color: #188038; }
.cloud-syncing { color: #1a73e8; animation: pulse 1.2s ease-in-out infinite; }
.cloud-error { color: #d93025; }
@keyframes pulse { 50% { opacity: .35; } }
.cloud-box { background: #f6f8fb; border-radius: 18px; padding: 14px 16px; margin: 0 0 14px; font-size: 14px; }
.cloud-box b { display: block; font-size: 14px; word-break: break-all; }
.cloud-box p { margin: 4px 0 10px; color: var(--muted); line-height: 1.4; }
.cloud-box .btn { height: 44px; width: 100%; font-size: 15px; }
.grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow); text-align: left; min-height: 188px;
  transition: transform .15s, box-shadow .15s;
  animation: rise .45s both;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.card:active { transform: scale(.985); }
.card .badge { width: 40px; height: 40px; border-radius: 14px; background: var(--cbg); color: var(--c); display: grid; place-items: center; }
.card .badge svg { width: 22px; height: 22px; }
.card .chev { position: absolute; top: 20px; right: 16px; color: #9aa0a6; }
.card .chev svg { width: 20px; height: 20px; }
.card .label { margin-top: 6px; font-size: 14px; color: var(--muted); font-weight: 500; }
.card .big { font-size: 34px; line-height: 1.1; font-weight: 650; letter-spacing: -.02em; color: var(--c); font-variant-numeric: tabular-nums; }
.card .sub { font-size: 13px; color: var(--muted); }
.bars { margin-top: auto; padding-top: 10px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; align-items: end; height: 56px; }
.bars span { display: block; background: var(--c); border-radius: 4px; opacity: .35; min-height: 4px; }
.bars span.now { opacity: 1; }
.card:nth-child(2) { animation-delay: .04s; } .card:nth-child(3) { animation-delay: .08s; }
.card:nth-child(4) { animation-delay: .12s; } .card:nth-child(5) { animation-delay: .16s; }

.card.hero {
  grid-column: 1 / -1; min-height: 168px;
  background: linear-gradient(135deg, #e6f4ea 0%, #ffffff 70%);
  border-color: #cfe8d6;
}
.card.hero .label { font-size: 16px; color: #137333; margin-top: 8px; }
.card.hero .big { font-size: 56px; }
.card.hero .bars { position: absolute; right: 20px; bottom: 18px; width: 38%; max-width: 220px; height: 70px; padding: 0; }
.card.hero .bars span { opacity: .3; }
.card.hero .bars span.now { opacity: 1; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (min-width: 720px) {
  #app { padding-top: 40px; }
  .grid { grid-template-columns: repeat(5, 1fr); }
  .card .big { font-size: 30px; }
  .card.hero .big { font-size: 56px; }
  .card.hero { grid-column: 1 / -1; }
}

/* ---------- Detail / calendar ---------- */
.dhead { display: flex; align-items: center; gap: 4px; padding: 4px 0 14px; }
.dhead h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.summary {
  background: var(--cbg); color: var(--c); border-radius: var(--radius);
  padding: 18px 22px; margin-bottom: 16px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.summary b { font-size: 36px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.summary span { font-size: 14px; font-weight: 500; opacity: .85; }

.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 10px 12px; }
.mnav { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 10px; }
.mnav h2 { margin: 0; font-size: 17px; font-weight: 600; }
.mnav .icon-btn { width: 40px; height: 40px; }
.row { display: grid; grid-template-columns: repeat(7, 1fr) 1.25fr; gap: 4px; }
.row + .row { margin-top: 4px; }
.dow { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); text-align: center; padding: 4px 0 8px; }
.day, .wk {
  min-height: 62px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 7px 2px 6px; font-variant-numeric: tabular-nums; position: relative;
}
.day { background: #f6f8fb; transition: background .12s, transform .12s; }
.day:hover { background: var(--cbg); }
.day:active { transform: scale(.94); }
.day .n { font-size: 12px; color: var(--muted); font-weight: 500; }
.day .v { font-size: 12.5px; font-weight: 650; color: var(--c); min-height: 16px; }
.day.out { opacity: .45; }
.day { gap: 2px; align-self: stretch; }
.day .t { display: flex; flex-direction: column; align-items: center; font-size: 8.5px; line-height: 1.25; font-weight: 500; color: var(--muted); letter-spacing: -.01em; }
.day .t i { font-style: normal; }
.day.note::after { content: ""; position: absolute; top: 6px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.day.today.note::after { right: 4px; top: 4px; }
.day.has { background: var(--cbg); }
.day.today .n { background: var(--c); color: #fff; border-radius: 50%; width: 20px; height: 20px; display: grid; place-items: center; font-weight: 600; }
.wk { background: transparent; border-left: 1px dashed var(--line); border-radius: 0; justify-content: center; gap: 2px; }
.wk .v { font-size: 13px; font-weight: 700; color: var(--c); }
.wk .t { font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.wk.zero .v { color: #bdc1c6; font-weight: 500; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0 0; }

/* ---------- FAB + menu ---------- */
#fab {
  position: fixed; right: max(20px, calc((100vw - 920px) / 2 + 16px)); bottom: calc(env(safe-area-inset-bottom) + 22px);
  width: 62px; height: 62px; border-radius: 20px; z-index: 30;
  background: #1a73e8; color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(26, 115, 232, .45), 0 2px 4px rgba(0, 0, 0, .12);
  transition: transform .2s, border-radius .2s;
}
#fab svg { width: 28px; height: 28px; stroke-width: 2.4; transition: transform .25s; }
#fab:hover { transform: translateY(-2px); }
.menu-open #fab svg { transform: rotate(45deg); }
.menu-open #fab { border-radius: 50%; }

#scrim { position: fixed; inset: 0; background: rgba(32, 33, 36, .32); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
.menu-open #scrim, .sheet-open #scrim { opacity: 1; pointer-events: auto; }
.sheet-open #scrim { z-index: 40; }
.sheet-open #fab { opacity: 0; pointer-events: none; }

#menu {
  position: fixed; right: max(20px, calc((100vw - 920px) / 2 + 16px)); bottom: calc(env(safe-area-inset-bottom) + 98px);
  z-index: 30; display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  opacity: 0; transform: translateY(12px) scale(.96); transform-origin: bottom right; pointer-events: none; transition: opacity .18s, transform .18s;
}
.menu-open #menu { opacity: 1; transform: none; pointer-events: auto; }
.mitem {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 18px; padding: 8px 18px 8px 8px;
  box-shadow: var(--shadow-lg); font-weight: 550; font-size: 15px;
}
.mitem .badge { width: 40px; height: 40px; border-radius: 13px; background: var(--cbg); color: var(--c); display: grid; place-items: center; }
.mitem .badge svg { width: 22px; height: 22px; }
.mitem small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.mitem:hover { background: #f1f3f4; }

/* ---------- Sheet ---------- */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-width: 480px; margin: 0 auto;
  background: var(--surface); border-radius: 28px 28px 0 0; padding: 10px 22px calc(env(safe-area-inset-bottom) + 22px);
  box-shadow: 0 -8px 32px rgba(60, 64, 67, .22); transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .9, .3, 1);
  visibility: hidden; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
}
.sheet-open #sheet { transform: none; visibility: visible; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: #dadce0; margin: 0 auto 16px; }
.sh-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.sh-head .badge { width: 48px; height: 48px; border-radius: 16px; background: var(--cbg); color: var(--c); display: grid; place-items: center; flex: none; }
.sh-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.sh-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.fld { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
.fld > input, .fld select {
  display: block; width: 100%; margin-top: 6px; height: 52px; border-radius: 16px; border: 1.5px solid var(--line); background: #f8f9fc;
  font: inherit; font-size: 17px; font-weight: 500; color: var(--text); padding: 0 16px; text-transform: none; letter-spacing: 0;
  outline: none; transition: border-color .15s, background .15s;
}
.fld > input:focus, .fld select:focus, .stepper input:focus { border-color: var(--c, #1a73e8); background: #fff; }
.stepper { display: flex; gap: 8px; margin-top: 6px; }
.stepper input {
  flex: 1; min-width: 0; height: 64px; text-align: center; border-radius: 18px; border: 1.5px solid var(--line); background: #f8f9fc;
  font: inherit; font-size: 32px; font-weight: 650; color: var(--c); outline: none; -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper button { width: 64px; height: 64px; border-radius: 18px; background: var(--cbg); color: var(--c); display: grid; place-items: center; }
.stepper button:active { transform: scale(.94); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chips button { padding: 8px 14px; border-radius: 999px; background: #f1f3f4; font-size: 14px; font-weight: 500; }
.chips button:hover { background: var(--cbg); color: var(--c); }
.opt { font-style: normal; font-weight: 400; text-transform: none; letter-spacing: 0; }
.fld > textarea {
  display: block; width: 100%; margin-top: 6px; border-radius: 16px; border: 1.5px solid var(--line); background: #f8f9fc;
  font: inherit; font-size: 16px; font-weight: 400; color: var(--text); padding: 12px 16px; resize: vertical; min-height: 84px;
  text-transform: none; letter-spacing: 0; outline: none; transition: border-color .15s, background .15s;
}
.fld > textarea:focus { border-color: var(--c, #1a73e8); background: #fff; }
.times-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 -2px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.times-head i { font-style: normal; font-weight: 400; text-transform: none; letter-spacing: 0; }
.link { color: var(--c, #1a73e8); font-size: 13px; font-weight: 600; padding: 6px 4px; }
.times { display: flex; gap: 10px; margin-top: 6px; }
.times .fld { flex: 1; min-width: 0; margin-bottom: 6px; }
.times .fld > input { padding: 0 10px; font-size: 16px; }
.note { min-height: 20px; margin: 4px 2px 16px; font-size: 14px; color: var(--muted); }
.note b { color: var(--c); }
.actions { display: flex; gap: 10px; }
.btn { flex: 1; height: 52px; border-radius: 16px; background: var(--c, #1a73e8); color: #fff; font-weight: 600; font-size: 16px; }
.btn.ghost { flex: none; padding: 0 20px; background: #f1f3f4; color: #5f6368; }
.btn.line { background: #fff; border: 1.5px solid var(--line); color: var(--text); }
.btn:active { transform: scale(.98); }
.row2 { display: flex; gap: 10px; margin-bottom: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 100px); transform: translate(-50%, 20px); z-index: 60;
  background: #202124; color: #fff; padding: 12px 20px; border-radius: 14px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 40px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  #sheet { bottom: auto; top: 50%; border-radius: 28px; padding-bottom: 22px; transform: translateY(-46%) scale(.96); opacity: 0; transition: transform .22s, opacity .22s; }
  .sheet-open #sheet { transform: translateY(-50%); opacity: 1; }
  .grab { display: none; }
  .sh-head { margin-top: 8px; }
  .day, .wk { min-height: 74px; }
  .day .v { font-size: 14px; } .wk .v { font-size: 15px; }
  .day .t { flex-direction: row; font-size: 10.5px; }
  .day .t i + i::before { content: "–"; margin: 0 2px; }
}

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