:root {
  --ink: #2b241c;
  --ink-soft: #5c5348;
  --line: rgba(43, 36, 28, 0.55);
  --line-soft: rgba(43, 36, 28, 0.22);
  --paper: #f3ead8;
  --card: rgba(255, 250, 240, 0.55);
  --shadow: rgba(43, 36, 28, 0.12);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font-body: "Gowun Dodum", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-heading: "Jua", "Gowun Dodum", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--paper);
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 400;
}

.paper {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #f1e6cf;
  background-image:
    radial-gradient(ellipse at 18% 12%, rgba(255, 255, 255, 0.35), transparent 46%),
    radial-gradient(ellipse at 82% 88%, rgba(180, 150, 110, 0.18), transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(90, 70, 40, 0.015) 3px
    ),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.72  0 0 0 0 0.64  0 0 0 0 0.5  0 0 0 0.22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.95;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.masthead {
  border-bottom: 1px dashed var(--line);
  padding-bottom: 16px;
  margin-bottom: 28px;
}

.masthead__mark {
  margin: 0 0 4px;
  letter-spacing: 0.28em;
  font-size: 12px;
}

.masthead h1 {
  margin: 0;
  font-size: 34px;
}

.sync-status {
  margin: 12px 0 0;
  padding: 9px 14px;
  border: 1px solid rgba(155, 61, 51, 0.4);
  border-radius: var(--radius-sm);
  background: rgba(155, 61, 51, 0.08);
  color: #7a2e26;
  font-size: 13px;
}

.today,
.calendar,
.history,
.login {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 22px 22px 12px;
  margin-bottom: 24px;
  background: rgba(255, 250, 240, 0.4);
  box-shadow: 0 6px 18px var(--shadow);
}

.today__head,
.calendar__head,
.history__head {
  display: flex;
  align-items: center;
  gap: 12px 16px;
  flex-wrap: wrap;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.today__head h2,
.history__head h2 {
  margin: 0;
  font-size: 23px;
}

.today__date {
  margin: 0 auto 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  line-height: 1.3;
}

.btn:hover,
.btn:focus-visible {
  background: rgba(43, 36, 28, 0.07);
}

.btn--ink {
  background: var(--ink);
  border-color: var(--ink);
  color: #f6eedd;
}

.btn--ink:hover,
.btn--ink:focus-visible {
  background: #1c1813;
}

.btn--ghost {
  min-width: 38px;
}

.btn--danger {
  border-color: #9b3d33;
  color: #9b3d33;
}

.btn--danger:hover,
.btn--danger:focus-visible,
.btn--danger.is-armed {
  background: #9b3d33;
  color: #fff7ee;
}

.btn--small {
  padding: 4px 11px;
  font-size: 13px;
}

.todo-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.todo-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  background: var(--card);
}

.todo-item.is-editable {
  cursor: pointer;
}

.todo-item.is-editable:hover {
  background: rgba(255, 250, 240, 0.9);
}

.todo-item__body:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
  border-radius: 6px;
}

/* 할 일 기록: 완료한 항목은 카드 색을 조금 어둡게 */
.history .todo-item.is-done {
  background: rgba(120, 100, 70, 0.17);
}

.history .todo-item.is-done:hover {
  background: rgba(120, 100, 70, 0.23);
}

.todo-item.is-done .todo-item__title {
  text-decoration: line-through;
  color: var(--ink-soft);
}

.todo-item__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.todo-item__meta {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.todo-item__detail {
  margin: 8px 0 0;
  white-space: pre-wrap;
}

.todo-item__actions {
  display: flex;
  gap: 8px;
  align-items: start;
}

.empty {
  color: var(--ink-soft);
  padding: 18px 0 22px;
}

.segmented {
  display: flex;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* 달력 섹션: Month / Week 선택 버튼을 가운데에 */
.calendar__head {
  justify-content: center;
}

.calendar__head .segmented {
  margin: 0;
}

.segmented__btn {
  background: transparent;
  border: 0;
  padding: 7px 14px;
  cursor: pointer;
}

.segmented__btn.is-active {
  background: var(--ink);
  color: #f6eedd;
}

/* 달력 이동 줄: [오늘] — [‹ 연월 ›] — (빈칸) 으로 연월이 정가운데 오도록 */
.calendar__nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.calendar__nav-left {
  justify-self: start;
}

.calendar__nav-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.calendar__label {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 22px;
  text-align: center;
  word-break: keep-all;
}

.cal {
  width: calc(100% + 10px);
  margin: -5px;
  border-collapse: separate;
  border-spacing: 5px;
  table-layout: fixed;
}

.cal th {
  font-weight: 400;
  font-size: 13px;
  padding: 6px 4px;
  text-align: center;
  color: var(--ink-soft);
}

.cal td {
  height: 104px;
  padding: 0;
  vertical-align: top;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  background: var(--card);
  overflow: hidden;
}

.cal td:hover {
  background: rgba(255, 250, 240, 0.9);
}

.cal td.is-muted {
  color: #9a9084;
  background: rgba(255, 250, 240, 0.25);
}

.cal td.is-today {
  background: rgba(235, 210, 160, 0.35);
}

.cal td.is-selected {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.cal button.day {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  width: 100%;
  height: 100%;
  min-height: 102px;
  text-align: left;
  background: none;
  border: 0;
  padding: 7px 8px;
  cursor: pointer;
}

.cal button.day:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -4px;
  border-radius: var(--radius-md);
}

.day__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7em;
  height: 1.7em;
  border-radius: 999px;
  font-size: 14px;
}

.cal td.is-today .day__num {
  background: var(--ink);
  color: #f6eedd;
}

/* 날짜 칸 안의 할 일 (월간·주간 공통) */
.day__dots,
.week__todos {
  width: 100%;
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chip {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 12px;
  line-height: 1.35;
  padding: 2px 6px;
  border-radius: 7px;
  background: rgba(43, 36, 28, 0.09);
  overflow: hidden;
  white-space: nowrap;
}

.chip:not(.chip--more) {
  cursor: pointer;
}

.chip:not(.chip--more):hover {
  background: rgba(43, 36, 28, 0.17);
}

.chip__time {
  flex: none;
  font-size: 11px;
  color: var(--ink-soft);
}

.chip__title {
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip.is-done {
  opacity: 0.55;
}

.chip.is-done .chip__title {
  text-decoration: line-through;
}

.chip--more {
  background: none;
  padding: 0 4px;
  font-size: 11px;
  color: var(--ink-soft);
}

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.week__cell {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  background: var(--card);
  min-height: 180px;
  padding: 8px;
}

.week__cell.is-today {
  background: rgba(235, 210, 160, 0.35);
}

.week__cell.is-selected {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.week__cell button.head {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: 0;
  padding: 0 2px 8px;
  cursor: pointer;
  border-bottom: 1px dashed var(--line-soft);
  margin-bottom: 8px;
}

.week__todos {
  margin-top: 0;
}

.week__todos .chip {
  white-space: normal;
  flex-wrap: wrap;
  font-size: 13px;
}

.week__todos .chip__title {
  white-space: normal;
  word-break: keep-all;
}

.modal {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: #f7efdd;
  color: var(--ink);
  padding: 0;
  width: min(480px, calc(100% - 32px));
  box-shadow: 0 16px 40px rgba(43, 36, 28, 0.22);
}

.modal--day {
  width: min(560px, calc(100% - 32px));
}

.modal::backdrop {
  background: rgba(43, 36, 28, 0.28);
}

.modal__form {
  padding: 22px 22px 18px;
}

.modal h2 {
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line);
  font-size: 21px;
}

.modal__hint {
  margin: 0 0 14px;
  color: var(--ink-soft);
}

.modal label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
}

.modal input,
.modal textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.55);
  padding: 9px 12px;
  resize: vertical;
}

.modal input:focus,
.modal textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(43, 36, 28, 0.12);
}

.date-fields {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  padding: 12px;
  margin: 8px 0 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
}

.date-fields legend {
  padding: 0 6px;
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.modal__actions-left {
  display: flex;
  gap: 8px;
  margin-right: auto;
}

@media (max-width: 720px) {
  .page {
    padding: 28px 14px 60px;
  }

  .today,
  .calendar,
  .history {
    padding: 16px 14px 6px;
  }

  .calendar__nav {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .calendar__nav-center {
    order: -1;
  }

  .calendar__nav-left {
    justify-self: center;
  }

  .calendar__label {
    font-size: 16px;
  }

  .cal {
    width: calc(100% + 6px);
    margin: -3px;
    border-spacing: 3px;
  }

  .cal td {
    height: 84px;
  }

  .cal button.day {
    min-height: 82px;
    padding: 4px 3px;
  }

  .day__num {
    font-size: 12px;
  }

  .day__dots {
    margin-top: 3px;
    gap: 2px;
  }

  .chip {
    font-size: 10px;
    padding: 1px 3px;
    border-radius: 5px;
  }

  .chip__time {
    display: none;
  }

  .week {
    grid-template-columns: 1fr;
  }

  .week__cell {
    min-height: 0;
  }

  .week__cell button.head {
    justify-content: flex-start;
    gap: 8px;
  }

  .week__todos .chip__time {
    display: inline;
  }
}

/* 로그인 화면 / 사용자 표시줄 */
.masthead {
  position: relative;
}

.userbar {
  display: none;
  align-items: center;
  gap: 10px;
  position: absolute;
  right: 0;
  top: 2px;
  font-size: 13px;
  color: var(--ink-soft);
}

.login {
  display: none;
  text-align: center;
  padding: 36px 22px 32px;
}

.login h2 {
  margin: 0 0 8px;
  font-size: 23px;
}

.login__text {
  margin: 0 0 18px;
  color: var(--ink-soft);
}

.login__error {
  margin: 16px auto 0;
  max-width: 480px;
  color: #7a2e26;
  font-size: 13px;
  line-height: 1.5;
}

main[data-auth="in"] .userbar {
  display: flex;
}

main[data-auth="out"] .login {
  display: block;
}

main[data-auth="loading"] .today,
main[data-auth="loading"] .calendar,
main[data-auth="loading"] .history,
main[data-auth="out"] .today,
main[data-auth="out"] .calendar,
main[data-auth="out"] .history {
  display: none;
}

@media (max-width: 720px) {
  .userbar {
    position: static;
    margin-top: 10px;
  }
}

/* 광고 영역: 로그인 후(또는 로컬 모드)에만 보여요 */
.ad {
  display: none;
  margin-top: 24px;
  overflow: hidden;
  text-align: center;
}

/* 광고 크기: 화면 폭에 따라 정해진 크기를 써요 (모바일 320x100 / 중간 468x60 / 큰 화면 728x90) */
.ad-slot {
  display: inline-block;
  width: 320px;
  height: 100px;
}

@media (min-width: 500px) {
  .ad-slot {
    width: 468px;
    height: 60px;
  }
}

@media (min-width: 800px) {
  .ad-slot {
    width: 728px;
    height: 90px;
  }
}

main[data-auth="in"] .ad,
main[data-auth="local"] .ad {
  display: block;
}
