* { box-sizing: border-box; }

:root {
  --bg: #f4f6f8;
  --panel: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0f172a;
  --danger: #b91c1c;
  --sun: #dc2626;
  --sat: #2563eb;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(15,23,42,.07);
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding:
    max(20px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

h1,h2,p { margin: 0; }
h1 { font-size: clamp(24px,4vw,34px); letter-spacing: -.03em; }
h2 { font-size: 20px; letter-spacing: -.02em; }

.eyebrow {
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .16em;
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.tabs {
  display: flex;
  width: fit-content;
  max-width: 100%;
  gap: 6px;
  margin-bottom: 14px;
  padding: 5px;
  border-radius: 14px;
  background: #e5e7eb;
  overflow-x: auto;
}

.tab {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  padding: 0 17px;
  background: transparent;
  color: #475569;
  font-weight: 800;
  white-space: nowrap;
}

.tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(15,23,42,.08);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

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

.primary,.ghost,.danger,.icon-btn {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 14px;
  font-weight: 800;
}
.primary { background: var(--accent); color: #fff; }
.ghost { background: #f1f5f9; color: var(--text); }
.danger { background: #fee2e2; color: var(--danger); }

.icon-btn {
  width: 44px;
  padding: 0;
  background: #f1f5f9;
  color: var(--text);
  font-size: 25px;
}

button:disabled { opacity: .35; cursor: default; }

.calendar-card { padding: 18px; }

.calendar-toolbar,
.month-nav,
.week-toolbar,
.week-nav,
.memo-head,
.memo-actions,
.dialog-head,
.dialog-actions,
.timeline-head {
  display: flex;
  align-items: center;
}

.calendar-toolbar,
.week-toolbar,
.memo-head,
.dialog-head,
.timeline-head {
  justify-content: space-between;
  gap: 12px;
}

.month-nav,.week-nav,.memo-actions,.dialog-actions { gap: 8px; }
.date-selectors { display: flex; gap: 8px; }

.date-selectors select {
  min-width: 100px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  text-align: center;
}

.weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0,1fr));
}

.weekdays {
  margin-top: 17px;
  text-align: center;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
}
.weekdays span { padding: 9px 0; }
.weekdays span:first-child { color: var(--sun); }
.weekdays span:last-child { color: var(--sat); }

.calendar-grid {
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.day-cell {
  position: relative;
  min-height: 105px;
  padding: 7px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
  overflow: hidden;
}

.day-cell:hover { background: #f8fafc; }
.day-cell.other-month { background: #fafafa; opacity: .58; }
.day-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }

.day-number {
  display: inline-grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 900;
}

.day-cell:nth-child(7n+1) .day-number { color: var(--sun); }
.day-cell:nth-child(7n) .day-number { color: var(--sat); }

.day-cell.today .day-number {
  background: var(--accent);
  color: #fff !important;
}

.holiday-label {
  display: block;
  margin-top: 2px;
  color: var(--sun);
  font-size: 9px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-events {
  display: grid;
  gap: 3px;
  margin-top: 5px;
}

.cell-event {
  display: block;
  min-width: 0;
  padding: 3px 5px;
  border-radius: 6px;
  font-size: 10px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-仕事 { background: #dbeafe; }
.cat-教習所 { background: #fef3c7; }
.cat-YouTube { background: #fee2e2; }
.cat-制作 { background: #e0e7ff; }
.cat-私用 { background: #dcfce7; }
.cat-その他 { background: #f3e8ff; }

.event-initials {
  display: none;
  gap: 3px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.event-initial {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  color: #0f172a;
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
}

/* Week timeline */
.week-card { padding: 18px; }

.week-day-selector {
  display: grid;
  grid-template-columns: repeat(7,minmax(0,1fr));
  gap: 7px;
  margin: 16px 0;
}

.week-day-btn {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: 7px 4px;
  font-weight: 800;
}

.week-day-btn .dow {
  display: block;
  margin-bottom: 4px;
  font-size: 10px;
  color: var(--muted);
}

.week-day-btn .day {
  display: block;
  font-size: 17px;
}

.week-day-btn.sun .dow,
.week-day-btn.sun .day { color: var(--sun); }
.week-day-btn.sat .dow,
.week-day-btn.sat .day { color: var(--sat); }

.week-day-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.week-day-btn.active .dow,
.week-day-btn.active .day { color: #fff; }

.week-day-btn.has-event::after {
  content: "";
  display: block;
  width: 5px;
  height: 5px;
  margin: 4px auto 0;
  border-radius: 50%;
  background: currentColor;
}

.timeline-head {
  margin-top: 8px;
  padding: 4px 1px 10px;
}

.holiday-heading {
  margin-top: 3px;
  color: var(--sun);
  font-size: 12px;
  font-weight: 800;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.timeline-scroller {
  max-height: 650px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  overscroll-behavior: contain;
}

.timeline {
  position: relative;
  min-height: 420px;
}

.timeline-row {
  position: relative;
  height: 28px;
  border-bottom: 1px solid #edf2f7;
}

.timeline-row.hour {
  border-bottom-color: #cbd5e1;
}

.timeline-time {
  position: absolute;
  top: -7px;
  left: 8px;
  width: 48px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.timeline-line {
  position: absolute;
  top: 0;
  left: 58px;
  right: 0;
  border-top: 1px solid #edf2f7;
}

.timeline-row.hour .timeline-line { border-top-color: #cbd5e1; }

.timeline-events-layer {
  position: absolute;
  top: 0;
  left: 63px;
  right: 8px;
}

.timeline-event {
  position: absolute;
  left: 0;
  right: 0;
  min-height: 24px;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  color: #0f172a;
  text-align: left;
  overflow: hidden;
  box-shadow: inset 3px 0 0 rgba(15,23,42,.35);

  /* ブラウザ標準buttonの縦中央寄せを打ち消し、予定開始位置の上から表示 */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
}

.timeline-event strong {
  display: block;
  flex: 0 0 auto;
  font-size: 12px;
  line-height: 1.25;
}

.timeline-event-time {
  display: block;
  flex: 0 0 auto;
  margin-top: 2px;
  font-size: 10px;
  opacity: .72;
}

.timeline-event-memo {
  display: block;
  flex: 0 0 auto;
  margin-top: 7px;
  max-width: 100%;
  font-size: 11px;
  line-height: 1.45;
  font-weight: 700;
  white-space: normal;
  overflow-wrap: anywhere;
  opacity: .9;
}

/* 週間予定の上部に、その日のメモを必ず全文表示 */
.timeline-memo-list {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.timeline-memo-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8fafc;
}

.timeline-memo-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.timeline-memo-meta strong {
  font-size: 12px;
}

.timeline-memo-meta span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.timeline-memo-item p {
  margin-top: 5px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Memo */
.memo-card { padding: 18px; }

.notes-card { padding: 18px; }

.memo-current {
  flex: 1;
  min-width: 0;
}

.memo-title-input {
  width: min(560px, 100%);
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  padding: 3px 0 5px;
  background: transparent;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -.02em;
}

.memo-title-input:focus {
  border-bottom-color: var(--line);
  box-shadow: none;
}

.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.notes-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.note-list-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.note-list-card.selected {
  border-color: #64748b;
  box-shadow: 0 0 0 2px rgba(15,23,42,.05);
}

.note-list-main {
  min-width: 0;
  border: 0;
  padding: 14px 15px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.note-list-main:hover {
  background: #f8fafc;
}

.note-list-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.note-list-title-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.note-selected-badge {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  font-size: 9px;
  font-weight: 900;
}

.note-list-main p {
  margin-top: 7px;
  overflow: hidden;
  color: #475569;
  font-size: 12px;
  line-height: 1.55;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-list-main time {
  display: block;
  margin-top: 8px;
  color: #94a3b8;
  font-size: 10px;
}

.note-delete-btn {
  border: 0;
  border-left: 1px solid var(--line);
  padding: 0 15px;
  background: #fff;
  color: #b91c1c;
  font-size: 11px;
  font-weight: 800;
}

.note-delete-btn:hover {
  background: #fef2f2;
}

.notes-empty {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 260px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}

.save-status {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}

.save-status.saving { color: #b45309; }
.save-status.saved { color: #15803d; }

.memo-editor {
  width: 100%;
  min-height: 560px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: #fffef7;
  color: var(--text);
  outline: none;
  resize: vertical;
  font: inherit;
  line-height: 1.7;
}

.memo-editor:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(15,23,42,.06);
}

/* Dialog */
dialog {
  width: min(580px,calc(100vw - 24px));
  border: 0;
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(0,0,0,.24);
}

dialog::backdrop { background: rgba(15,23,42,.48); }
dialog form { padding: 20px; }

dialog label {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

dialog label > span {
  font-size: 12px;
  font-weight: 800;
  color: #475569;
}

input,textarea,select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,textarea:focus,select:focus {
  border-color: #64748b;
  box-shadow: 0 0 0 3px rgba(15,23,42,.06);
}

textarea { resize: vertical; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.toast {
  position: fixed;
  z-index: 999;
  left: 50%;
  bottom: max(18px,env(safe-area-inset-bottom));
  transform: translate(-50%,12px);
  padding: 10px 15px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%,0);
}

@media (max-width: 680px) {
  .app-shell {
    padding-left: 9px;
    padding-right: 9px;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
  }

  .topbar .primary {
    min-height: 42px;
    padding: 0 11px;
    font-size: 13px;
  }

  .tabs {
    width: 100%;
    margin-bottom: 12px;
  }

  .tab {
    flex: 1;
    padding: 0 7px;
    font-size: 13px;
  }

  .calendar-card,.week-card,.memo-card {
    padding: 10px;
    border-radius: 15px;
  }

  .calendar-toolbar {
    align-items: center;
  }

  .month-nav { gap: 4px; }
  .date-selectors { gap: 4px; }

  .date-selectors select {
    min-width: 76px;
    padding: 8px 5px;
    font-size: 13px;
  }

  .calendar-toolbar .ghost {
    width: 44px;
    padding: 0 6px;
    font-size: 12px;
  }

  .weekdays {
    margin-top: 10px;
    font-size: 11px;
  }

  /*
    7列×6週の月間カレンダーをほぼ正方形セルで維持。
    スマホ幅でも縦に間延びしない。
  */
  .calendar-grid {
    aspect-ratio: 7 / 6;
    grid-template-rows: repeat(6,minmax(0,1fr));
  }

  .day-cell {
    min-height: 0;
    padding: 3px;
  }

  .day-number {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .holiday-label {
    margin-top: 0;
    font-size: 7px;
    line-height: 1.05;
  }

  .cell-events { display: none; }
  .event-initials { display: flex; }

  .week-toolbar { align-items: center; }
  .week-nav { gap: 4px; }
  .week-nav h2 { font-size: 15px; }

  .week-day-selector {
    gap: 4px;
    margin: 12px 0;
  }

  .week-day-btn {
    min-height: 58px;
    padding: 5px 2px;
    border-radius: 9px;
  }

  .week-day-btn .dow { font-size: 9px; }
  .week-day-btn .day { font-size: 15px; }

  .timeline-scroller { max-height: 600px; }
  .timeline-time { width: 43px; left: 5px; font-size: 9px; }
  .timeline-line { left: 49px; }
  .timeline-events-layer { left: 54px; right: 4px; }
  .timeline-event { padding: 6px 8px; }

  .timeline-event-memo {
    margin-top: 5px;
    font-size: 10px;
  }

  .timeline-memo-item {
    padding: 9px 10px;
  }

  .timeline-memo-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .timeline-memo-item p {
    font-size: 11px;
  }

  .memo-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .memo-actions {
    width: 100%;
    gap: 6px;
    justify-content: flex-end;
  }

  .memo-title-input {
    font-size: 18px;
  }

  .notes-head {
    align-items: flex-start;
  }

  .note-list-card {
    grid-template-columns: minmax(0,1fr) 58px;
  }

  .note-delete-btn {
    padding: 0 8px;
  }

  .event-initial {
    width: 15px;
    height: 15px;
    border-radius: 4px;
    font-size: 8px;
  }

  .memo-editor {
    min-height: calc(100vh - 245px);
    margin-top: 12px;
    padding: 13px;
  }

  .two-col { grid-template-columns: 1fr; gap: 0; }
  dialog form { padding: 16px; }
}

@media (max-width: 390px) {
  .topbar h1 { font-size: 22px; }
  .topbar .primary { font-size: 12px; }
  .date-selectors select { min-width: 70px; }
  .holiday-label { display: none; }
}
