:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-2: #8e8e93;
  --sep: rgba(60, 60, 67, 0.12);
  --blue: #007aff;
  --orange: #ff9500;
  --red: #ff3b30;
  --green: #34c759;
  --ink: #1c1c1e;
  --sheet: #ffffff;
  --input-bg: #f2f2f7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --text-2: #8e8e93;
    --sep: rgba(84, 84, 88, 0.5);
    --ink: #f2f2f7;
    --sheet: #2c2c2e;
    --input-bg: #3a3a3c;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* hidden 속성은 어떤 display 규칙보다 항상 우선한다 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

#app { max-width: 760px; margin: 0 auto; min-height: 100%; }

.tab-page {
  padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom));
}

/* ===== 헤더 ===== */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  padding: 16px 4px 12px;
}
.app-header h1 { font-size: clamp(18px, 5.5vw, 24px); font-weight: 700; white-space: nowrap; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: none; background: var(--card); color: var(--blue);
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 22px; line-height: 1; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.header-right { display: flex; align-items: center; gap: 8px; }
.segmented.small { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.segmented.small button { padding: 6px 12px; font-size: 13px; }
.segmented.small button.active { background: var(--blue); color: #fff; }
.pill-btn {
  border: none; background: var(--card); color: var(--blue);
  padding: 8px 16px; border-radius: 999px; font-size: 15px; font-weight: 600;
  cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  white-space: nowrap;
}

/* ===== 캘린더 ===== */
.calendar {
  background: var(--card); border-radius: 16px; padding: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.weekday-row {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: 12px; font-weight: 600; color: var(--text-2);
  margin-bottom: 6px;
}
.weekday-row .sun { color: var(--red); }
.weekday-row .sat { color: var(--blue); }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 2px; }
.day-cell {
  border: none; background: transparent; color: var(--text);
  aspect-ratio: 1 / 1.05; max-height: 76px; border-radius: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 16px; position: relative;
}
.day-cell.other-month { color: var(--sep); }
.day-cell.selected { background: var(--input-bg); }
.day-cell .num {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.day-cell.today .num { background: var(--red); color: #fff; font-weight: 700; }
.day-cell .dots { display: flex; gap: 3px; height: 5px; }
.day-cell .dots i { width: 5px; height: 5px; border-radius: 50%; }
.dot-event { background: var(--blue); }
.dot-reminder { background: var(--orange); }
.dot-note { background: var(--green); }

/* ===== 아젠다 ===== */
.agenda { margin-top: 20px; }
.agenda-title { font-size: 17px; font-weight: 700; padding: 0 4px 10px; }
.agenda-list, .reminders-page { display: flex; flex-direction: column; gap: 8px; }
.empty-state {
  text-align: center; color: var(--text-2); padding: 32px 0; font-size: 15px;
}
.item-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05); cursor: pointer;
}
.item-card .bar { width: 4px; align-self: stretch; border-radius: 2px; }
.item-card.event .bar { background: var(--blue); }
.item-card.reminder .bar { background: var(--orange); }
.item-card.note .bar { background: var(--green); }
.item-card.note .note-icon { font-size: 20px; }
.item-card .time-col {
  min-width: 52px; text-align: center; font-size: 13px; color: var(--text-2);
  display: flex; flex-direction: column;
}
.item-card .time-col b { color: var(--text); font-size: 15px; }
.item-main { flex: 1; min-width: 0; }
.item-main .title { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-main .sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.item-card.done .title { text-decoration: line-through; color: var(--text-2); }
.check {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--orange); background: transparent;
  flex-shrink: 0; cursor: pointer; font-size: 14px; color: #fff; line-height: 1;
}
.check.checked { background: var(--orange); border-color: var(--orange); }
.priority-mark { color: var(--orange); font-weight: 700; margin-right: 4px; }

.section-h {
  font-size: 15px; font-weight: 700; color: var(--text-2);
  padding: 14px 4px 4px;
}

/* ===== 탭바 ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  gap: clamp(24px, 16vw, 180px);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--sep);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.tab-btn {
  border: none; background: none; color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; cursor: pointer; width: 90px;
}
.tab-btn.active { color: var(--blue); }
.tab-icon { font-size: 22px; }
.fab {
  position: fixed; right: 20px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--blue); color: #fff; font-size: 30px; line-height: 1;
  cursor: pointer; box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
  z-index: 60;
}

/* ===== 메모 그리드 ===== */
.notes-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.note-card {
  background: var(--card); border-radius: 14px; overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); cursor: pointer;
  border: none; text-align: left; color: var(--text); padding: 0;
  display: flex; flex-direction: column;
}
.note-card canvas { width: 100%; height: 110px; display: block; background: var(--card); }
.note-card .note-card-body { padding: 8px 12px 10px; border-top: 0.5px solid var(--sep); }
.note-card .note-card-title {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note-card .note-card-date { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ===== 메모 편집기 ===== */
.note-editor {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.note-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 8px;
}
.note-title {
  flex: 1; min-width: 0; border: none; background: transparent; color: var(--text);
  font-size: 18px; font-weight: 700; outline: none;
}
.note-date {
  border: none; background: var(--card); color: var(--blue);
  border-radius: 8px; padding: 6px 8px; font-size: 14px; outline: none;
  font-family: inherit;
}
.text-btn.danger { color: var(--red); }
.back-btn {
  border: none; background: var(--card); color: var(--blue);
  font-size: 17px; font-weight: 700; cursor: pointer;
  padding: 8px 14px 8px 10px; border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15); white-space: nowrap;
}
.note-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; padding: 4px 16px 8px;
}
.pen-colors { display: flex; gap: 8px; }
.pen-color {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; padding: 0;
}
.pen-color.active { border-color: var(--blue); box-shadow: 0 0 0 2px color-mix(in srgb, var(--blue) 30%, transparent); }
.pen-color[data-color="ink"] { background: var(--ink); }
.pen-color[data-color="blue"] { background: #007aff; }
.pen-color[data-color="red"] { background: #ff3b30; }
.pen-color[data-color="green"] { background: #34c759; }
.pen-color[data-color="orange"] { background: #ff9500; }
.note-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-btn.accent { background: var(--blue); color: #fff; }
.mini-btn.eraser-on { background: var(--red); color: #fff; }
.note-canvas-wrap {
  position: relative; flex: 1; min-height: 0;
  margin: 0 16px; border-radius: 14px; overflow: hidden;
  background: var(--card); box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
#note-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.note-text {
  margin: 10px 16px; border: none; background: var(--card); color: var(--text);
  border-radius: 12px; padding: 10px 14px; font-size: 15px;
  outline: none; resize: none; font-family: inherit;
}

/* ===== 시트 ===== */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 90;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  max-width: 760px; margin: 0 auto;
  background: var(--sheet); border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.25);
  max-height: 92vh; overflow-y: auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  animation: slide-up 0.25s ease-out;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle {
  width: 40px; height: 5px; border-radius: 3px; background: var(--sep);
  margin: 8px auto 4px;
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
}
.text-btn { border: none; background: none; color: var(--blue); font-size: 17px; cursor: pointer; }
.text-btn.bold { font-weight: 700; }
.segmented {
  display: flex; background: var(--input-bg); border-radius: 9px; padding: 2px;
}
.segmented button {
  border: none; background: none; color: var(--text);
  padding: 6px 14px; border-radius: 7px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.segmented button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

.sheet-body { padding: 8px 16px 0; display: flex; flex-direction: column; gap: 14px; }
.title-input {
  border: none; background: var(--input-bg); color: var(--text);
  border-radius: 12px; padding: 14px; font-size: 18px; font-weight: 600;
  outline: none; width: 100%;
}

/* ===== 필기 영역 ===== */
.ink-box {
  border: 1.5px dashed color-mix(in srgb, var(--blue) 45%, transparent);
  border-radius: 14px; overflow: hidden; background: var(--card);
}
.ink-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; gap: 8px; flex-wrap: wrap;
  border-bottom: 0.5px solid var(--sep);
}
.ink-label { font-size: 12px; color: var(--text-2); }
.ink-tools { display: flex; gap: 6px; }
.mini-btn {
  border: none; background: var(--input-bg); color: var(--blue);
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 8px; cursor: pointer;
}
.canvas-wrap { position: relative; }
#ink-canvas {
  display: block; width: 100%; height: 150px;
  touch-action: none; cursor: crosshair;
}
.ink-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--sep); font-size: 20px; font-weight: 600; pointer-events: none;
}
.ink-status {
  position: absolute; top: 8px; right: 10px;
  font-size: 12px; color: var(--blue); font-weight: 600;
  background: var(--input-bg); border-radius: 8px; padding: 3px 8px;
}
.ink-candidates {
  display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto;
  border-top: 0.5px solid var(--sep);
}
.ink-candidates button {
  border: 1px solid var(--sep); background: var(--input-bg); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 14px; cursor: pointer;
  white-space: nowrap;
}
.ink-candidates button.top { border-color: var(--blue); color: var(--blue); font-weight: 700; }

/* ===== 필드 ===== */
.field-group {
  background: var(--input-bg); border-radius: 12px; overflow: hidden;
}
.field {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 0.5px solid var(--sep); font-size: 16px;
}
.field:last-child { border-bottom: none; }
.field[hidden] { display: none; }
.field input, .field select {
  border: none; background: transparent; color: var(--blue);
  font-size: 16px; text-align: right; outline: none;
  font-family: inherit;
}
.notes-input {
  border: none; background: var(--input-bg); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 15px;
  outline: none; width: 100%; resize: vertical; font-family: inherit;
}
/* ===== 동기화 ===== */
.sync-desc { font-size: 14px; color: var(--text-2); line-height: 1.5; }
.sync-code {
  font-size: 30px; font-weight: 800; letter-spacing: 3px; text-align: center;
  background: var(--input-bg); border-radius: 14px; padding: 18px;
  font-family: ui-monospace, "SF Mono", monospace;
}
.sync-status { font-size: 13px; color: var(--text-2); text-align: center; min-height: 16px; }
.sync-btn {
  display: block; width: 100%; text-align: center; text-decoration: none;
  border: none; background: var(--input-bg); color: var(--blue);
  border-radius: 12px; padding: 13px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.sync-btn.accent { background: var(--blue); color: #fff; }
.sync-btn.danger { color: var(--red); }
.sync-input {
  border: none; background: var(--input-bg); color: var(--text);
  border-radius: 12px; padding: 13px; font-size: 18px; text-align: center;
  letter-spacing: 2px; outline: none; width: 100%;
  font-family: ui-monospace, "SF Mono", monospace;
}

.delete-btn {
  border: none; background: var(--input-bg); color: var(--red);
  border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 600; cursor: pointer;
}
