* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #2495FF;
  --orange: #FF9700;
  --red: #E03131;
  --ink: #1a1a1a;
  --muted: #8a8a8e;
  --line: #ececec;
  --weekend-bg: #f4f4f6;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: #f0f0f2;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: #ffffff;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
@media (min-width: 760px) {
  #app { box-shadow: 0 0 24px rgba(0, 0, 0, 0.08); }
}

button { font-family: inherit; cursor: pointer; background: none; border: none; color: inherit; }

/* ---------- ヘッダー ---------- */
#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px 4px;
}
#monthTitle {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
  min-width: 5.9em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-btn {
  font-size: 26px;
  line-height: 1;
  width: 34px;
  height: 36px;
  color: var(--muted);
  border-radius: 8px;
}
.nav-btn:active { background: var(--weekend-bg); }
#todayBtn {
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border: 1px solid #e2e2e6;
  border-radius: 999px;
  margin-left: 4px;
}
#todayBtn:active { background: var(--weekend-bg); }
#syncStatus {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}
#logoutBtn {
  font-size: 10.5px;
  color: var(--muted);
  padding: 4px 2px 4px 8px;
  white-space: nowrap;
}

/* ---------- 月一覧 ---------- */
#calendar {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none; /* 横スワイプ・長押しドラッグを Pointer Events で処理する */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#days {
  height: 100%;
  display: grid;
  grid-template-rows: repeat(var(--rows, 31), minmax(0, 1fr));
}
#days.slide-next { animation: slide-next 0.22s ease; }
#days.slide-prev { animation: slide-prev 0.22s ease; }
@keyframes slide-next { from { transform: translateX(36px); opacity: 0.35; } to { transform: none; opacity: 1; } }
@keyframes slide-prev { from { transform: translateX(-36px); opacity: 0.35; } to { transform: none; opacity: 1; } }

.day-row {
  display: grid;
  grid-template-columns: 34px 20px 24px minmax(0, 1fr);
  align-items: center;
  column-gap: 2px;
  padding: 0 10px 0 6px;
  border-bottom: 1px solid var(--line);
  min-height: 0;
  overflow: hidden;
}
.day-row.weekend, .day-row.holiday { background: var(--weekend-bg); }
.day-row.drop-target { background: #fff1dd !important; box-shadow: inset 0 0 0 2px var(--orange); }
.day-row.pressing { background: #fff7ea !important; }

.date-num {
  justify-self: center;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  min-width: 26px;
  text-align: center;
  padding: 1px 4px;
  border-radius: 999px;
}
.day-row.sun .date-num, .day-row.holiday .date-num { color: var(--red); }
.day-row.sat .date-num { color: var(--blue); }
.day-row.today .date-num { box-shadow: inset 0 -2.5px 0 var(--red); border-radius: 2px; }
.day-row.selected .date-num {
  background: var(--orange);
  color: #ffffff;
  border-radius: 999px;
}
.day-row.selected.today .date-num { box-shadow: inset 0 -2.5px 0 var(--red); }

.weekday { font-size: 11.5px; color: #55555a; text-align: center; }
.day-row.sun .weekday, .day-row.holiday .weekday { color: var(--red); }
.day-row.sat .weekday { color: var(--blue); }

.mark-icon {
  width: 20px; height: 20px;
  justify-self: center;
  display: flex; align-items: center; justify-content: center;
}
.mark-icon svg { width: 17px; height: 17px; display: block; }

.day-events {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  height: 100%;
  align-content: center;
  flex-wrap: nowrap;
}
.event-chip {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  padding: 2px 1px;
  border-radius: 4px;
}
.event-chip.drag-source { opacity: 0.3; }
.event-chip.pending { opacity: 0.55; text-decoration: underline dotted; text-underline-offset: 3px; }
.more-events { font-size: 11px; color: var(--muted); flex: 0 0 auto; }

/* ---------- 下部固定バー（色・アイコン） ---------- */
#markBar {
  flex: 0 0 auto;
  padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #ffffff;
}
.mark-grid {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 2px;
  align-items: center;
}
.mark-grid + .mark-grid { margin-top: 5px; }
.mark-btn {
  aspect-ratio: 1 / 1;
  max-height: 36px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.mark-btn:active { background: var(--weekend-bg); }
.mark-btn .swatch {
  width: min(22px, 72%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: block;
}
.mark-btn .none-mark {
  width: min(22px, 72%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1.5px solid #c9c9ce;
  position: relative;
  display: block;
}
.mark-btn .none-mark::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 130%; height: 1.5px;
  background: #c9c9ce;
  transform: translate(-50%, -50%) rotate(-45deg);
}
.mark-btn svg { width: min(21px, 74%); height: auto; display: block; }
.mark-btn.chosen { box-shadow: inset 0 0 0 2px #1a1a1a; }

/* ---------- ログイン ---------- */
#loginOverlay {
  position: fixed; inset: 0;
  background: #ffffff;
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  padding: 24px;
}
#loginOverlay[hidden] { display: none; }
.login-card { text-align: center; max-width: 340px; }
.login-card h2 { font-size: 26px; margin-bottom: 12px; }
.login-card p { font-size: 14px; color: var(--muted); line-height: 1.6; margin-bottom: 28px; }
#loginBtn {
  font-size: 16px; font-weight: 700;
  color: #ffffff; background: var(--blue);
  padding: 13px 34px; border-radius: 999px;
}
#loginBtn:active { opacity: 0.8; }

/* ---------- 予定シート ---------- */
#sheetBackdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
#sheetBackdrop[hidden] { display: none; }
#eventSheet {
  background: #ffffff;
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  animation: sheet-up 0.24s ease;
}
@keyframes sheet-up { from { transform: translateY(48px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
  #sheetBackdrop { align-items: center; padding: 24px; }
  #eventSheet { border-radius: 18px; }
}
.sheet-head {
  position: sticky; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
.sheet-head h2 { font-size: 16px; }
#sheetCancel { font-size: 15px; color: var(--muted); padding: 4px 2px; min-width: 72px; text-align: left; }
#sheetSave {
  font-size: 15px; font-weight: 700; color: #ffffff;
  background: var(--orange);
  padding: 7px 20px; border-radius: 999px;
  min-width: 72px;
}
#sheetSave:active { opacity: 0.8; }
#sheetSave[hidden] { display: none; }
.sheet-body { padding: 14px 16px 4px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field input[type="text"], .field textarea, .field select,
.field input[type="date"], .field input[type="time"] {
  font-family: inherit;
  font-size: 16px; /* iOSの自動ズーム防止 */
  color: var(--ink);
  border: 1px solid #e2e2e6;
  border-radius: 10px;
  padding: 9px 11px;
  background: #fbfbfc;
  width: 100%;
  min-width: 0;
}
.field textarea { resize: vertical; }
.switch-field {
  flex-direction: row; align-items: center; justify-content: space-between;
  font-size: 14.5px; color: var(--ink);
}
.switch-field input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 50px; height: 30px; border-radius: 999px;
  background: #e2e2e6; position: relative; cursor: pointer;
  transition: background 0.18s;
  flex: 0 0 auto;
}
.switch-field input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #ffffff; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.18s;
}
.switch-field input[type="checkbox"]:checked { background: var(--orange); }
.switch-field input[type="checkbox"]:checked::after { transform: translateX(20px); }
.datetime-inputs { display: flex; gap: 8px; }
.datetime-inputs input[type="date"] { flex: 1 1 auto; }
.datetime-inputs input[type="time"] { flex: 0 0 118px; }
#eventSheet.all-day .datetime-inputs input[type="time"] { display: none; }
#evDelete {
  font-size: 14.5px; font-weight: 600; color: var(--red);
  border: 1px solid #f3d2d2; border-radius: 10px; padding: 10px;
}
#evDelete:active { background: #fdf0f0; }

/* ---------- ドラッグ・トースト ---------- */
#dragGhost {
  position: fixed; z-index: 50;
  pointer-events: none;
  font-size: 13.5px; font-weight: 700;
  background: #ffffff;
  border: 1.5px solid var(--orange);
  border-radius: 8px;
  padding: 5px 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, -130%);
  max-width: 70vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#dragGhost[hidden] { display: none; }
#toast {
  position: fixed; left: 50%; bottom: calc(118px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(26, 26, 26, 0.88); color: #ffffff;
  font-size: 13px; padding: 8px 16px; border-radius: 999px;
  max-width: 88vw; text-align: center;
}
#toast[hidden] { display: none; }
