:root {
  --bg: #ffffff;
  --surface: #f4f5f7;
  --text: #16181d;
  --muted: #7a808c;
  --line: #e4e6eb;
  --accent: #2563eb;
  --sun: #dc2626;
  --sat: #2563eb;
  --danger: #dc2626;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1b1f26;
    --text: #eceef2;
    --muted: #8b92a0;
    --line: #2a2f38;
    --accent: #5b8def;
    --sun: #f87171;
    --sat: #7aa5f5;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.spacer { flex: 1; }

.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 12px) 8px calc(env(safe-area-inset-left) + 12px);
}
.bar h1 { margin: 0 4px; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 24px; line-height: 1; }
.icon-btn:active, .text-btn:active { background: var(--surface); }
.text-btn { height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 17px; font-size: 14px; }

.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 calc(env(safe-area-inset-right) + 4px) 0 calc(env(safe-area-inset-left) + 4px);
}
.weekdays { font-size: 12px; color: var(--muted); text-align: center; padding-bottom: 4px; }
.sun { color: var(--sun); }
.sat { color: var(--sat); }

.grid {
  flex: 1 1 56%;
  min-height: 0;
  grid-template-rows: repeat(6, 1fr);
  border-top: 1px solid var(--line);
  touch-action: pan-y;
}
.day {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
  padding: 3px 1px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  text-align: center;
}
.day .num {
  align-self: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 13px;
  line-height: 24px;
  font-variant-numeric: tabular-nums;
}
.day.other { opacity: .35; }
.day.today .num { background: var(--accent); color: #fff; font-weight: 700; }
.day.selected { background: var(--surface); }
.chip {
  display: block;
  margin-top: 2px;
  padding: 0 3px;
  border-radius: 3px;
  color: #fff;
  font-size: 10px;
  line-height: 14px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.more { font-size: 10px; line-height: 14px; color: var(--muted); }

.agenda {
  flex: 1 1 44%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 88px) calc(env(safe-area-inset-left) + 16px);
  border-top: 1px solid var(--line);
}
.agenda h2 { margin: 0 0 8px; font-size: 15px; }
.agenda ul { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
}
.item .stripe { flex: none; width: 4px; border-radius: 2px; }
.item .body { min-width: 0; flex: 1; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .meta, .item .memo { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

.fab {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 20px);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.fab:active { transform: scale(.95); }

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  color: var(--text);
  user-select: text;
  -webkit-user-select: text;
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet h2 { margin: 0; font-size: 18px; }
.sheet label, .sheet legend { display: block; font-size: 13px; color: var(--muted); }
.sheet input, .sheet select, .sheet textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.sheet textarea { resize: none; }
.sheet fieldset { margin: 0; padding: 0; border: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.colors { display: flex; gap: 10px; margin-top: 6px; }
.colors input { position: absolute; opacity: 0; width: 0; min-height: 0; height: 0; padding: 0; margin: 0; }
.colors span { display: block; width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--bg); }
.colors input:checked + span { box-shadow: 0 0 0 2px var(--text); }
.actions { display: flex; gap: 8px; margin-top: 4px; }
.actions button, .wide {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
}
.actions .primary { background: var(--accent); color: #fff; }
.actions .danger { color: var(--danger); }
.wide { width: 100%; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
