:root {
  --header-bg-1: #000000;
  --header-bg-2: #1a1a1a;
  --cream: #fdf8f1;
  --line: #b8ab97;
  --text-main: #2c2118;
  --text-sub: #7a6a58;
  --sun-red: #d9463c;
  --sat-blue: #2f6fc7;
  --accent-orange: #e8963f;
  --today-bg: #fde6c8;
}

* { box-sizing: border-box; }

html, body {
  overflow: hidden;
  overscroll-behavior: none;
  height: 100%;
  margin: 0;
}

body {
  font-family: "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 16px;
  background: var(--cream);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

.hidden { display: none !important; }

/* Header */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 12px;
  background: linear-gradient(180deg, var(--header-bg-2), var(--header-bg-1));
  color: #fff;
}

.title-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
  justify-content: center;
  min-width: 0;
}

.header-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  min-width: 38px;
}

.icon-btn {
  background: none;
  border: none;
  color: inherit;
  padding: 5px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: rgba(255,255,255,0.15);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* Main area */
.main-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  flex: 1 1 58%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Weekday row */
.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #fff;
  border-bottom: 2px solid var(--line);
  flex: 0 0 auto;
}

.wd {
  text-align: center;
  padding: 8px 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-sub);
}

.wd.sun { color: var(--sun-red); }
.wd.sat { color: var(--sat-blue); }

/* Month grid */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
}

.day-cell {
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  background: #fff;
}

.day-cell.other-month {
  background: #faf6ef;
}

.day-cell.selected {
  outline: 2px solid var(--accent-orange);
  outline-offset: -2px;
  background: #fff7ec;
}

.day-num {
  font-size: 18px;
  font-weight: 700;
  width: 28px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  border-radius: 50%;
  color: var(--text-main);
}

.other-month .day-num { color: #c9bda9; }
.day-cell .day-num.sun { color: var(--sun-red); }
.day-cell .day-num.sat { color: var(--sat-blue); }
.day-cell .day-num.today {
  background: var(--sun-red);
  color: #fff;
}

.event-chip {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 5px;
  color: #4a2e10;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-more {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-sub);
  padding-left: 4px;
}

/* Agenda panel */
.agenda-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: none;
  background: #fff;
  border-top: 6px solid var(--cream);
}

.agenda-date {
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-sub);
  background: #f4efe6;
  border-bottom: 1px solid var(--line);
}

.agenda-item {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.agenda-time {
  flex: 0 0 auto;
  font-size: 15px;
  color: var(--text-sub);
  text-align: right;
  line-height: 1.5;
  min-width: 52px;
}

.agenda-bar {
  flex: 0 0 auto;
  width: 5px;
  border-radius: 3px;
}

.agenda-title {
  flex: 1 1 auto;
  font-size: 16px;
  font-weight: 700;
  align-self: center;
}

.agenda-empty {
  padding: 24px 16px;
  color: var(--text-sub);
  font-size: 15px;
  text-align: center;
}

/* Floating add button */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-orange);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 12px rgba(0,0,0,0.3);
  z-index: 20;
}

.fab svg {
  width: 26px;
  height: 26px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}

.modal {
  background: #fff;
  width: 100%;
  max-height: 88vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-sub);
  margin: 14px 0 6px;
}

.field-label:first-child { margin-top: 0; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-main);
  font-size: 16px;
}

.toggle-row input {
  width: 22px;
  height: 22px;
}

.text-input {
  width: 100%;
  font-size: 16px;
  font-weight: 700;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cream);
  color: var(--text-main);
}

.time-fields {
  display: flex;
  gap: 12px;
}

.time-field {
  flex: 1 1 0;
}

.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
}

.color-dot.selected {
  border-color: var(--text-main);
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.btn {
  flex: 1 1 0;
  font-size: 16px;
  font-weight: 700;
  padding: 12px 0;
  border-radius: 10px;
  border: none;
}

.btn-primary {
  background: var(--accent-orange);
  color: #fff;
}

.btn-danger {
  background: #fff;
  color: var(--sun-red);
  border: 1px solid var(--sun-red);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cream: #1c1712;
    --line: #3a3128;
    --text-main: #f0e9df;
    --text-sub: #b3a793;
    --today-bg: #6b4a22;
  }
  :root:not([data-theme="light"]) body { background: var(--cream); }
  :root:not([data-theme="light"]) .weekday-row,
  :root:not([data-theme="light"]) .month-grid .day-cell,
  :root:not([data-theme="light"]) .agenda-panel,
  :root:not([data-theme="light"]) .modal { background: #241d16; }
  :root:not([data-theme="light"]) .day-cell.other-month { background: #1a1510; }
  :root:not([data-theme="light"]) .day-cell.selected { background: #33260f; }
  :root:not([data-theme="light"]) .agenda-date { background: #2c2419; }
  :root:not([data-theme="light"]) .text-input { background: #1a1510; color: var(--text-main); border-color: var(--line); }
  :root:not([data-theme="light"]) .agenda-empty { color: var(--text-sub); }
}

:root[data-theme="dark"] {
  --cream: #1c1712;
  --line: #3a3128;
  --text-main: #f0e9df;
  --text-sub: #b3a793;
  --today-bg: #6b4a22;
}
:root[data-theme="dark"] body { background: var(--cream); }
:root[data-theme="dark"] .weekday-row,
:root[data-theme="dark"] .month-grid .day-cell,
:root[data-theme="dark"] .agenda-panel,
:root[data-theme="dark"] .modal { background: #241d16; }
:root[data-theme="dark"] .day-cell.other-month { background: #1a1510; }
:root[data-theme="dark"] .day-cell.selected { background: #33260f; }
:root[data-theme="dark"] .agenda-date { background: #2c2419; }
:root[data-theme="dark"] .text-input { background: #1a1510; color: var(--text-main); border-color: var(--line); }
:root[data-theme="dark"] .agenda-empty { color: var(--text-sub); }
