:root {
  --paper: #E9EBE6;
  --card: #FCFCFA;
  --ink: #1F2328;
  --ink-soft: #656D74;
  --rule: #CDD2CB;
  --rule-soft: #DFE3DC;
  --seal: #A8322D;
  --sat: #2F5D8C;
  --shade: rgba(31,35,40,.06);

  --c-red: #A8322D;
  --c-navy: #2B4A6F;
  --c-moss: #4A6741;
  --c-ochre: #9A6B1E;
  --c-plum: #6B3A5E;

  --sans: "Pretendard Variable", Pretendard, system-ui, -apple-system, sans-serif;
  --serif: "Gowun Batang", serif;

  --t-xs: .75rem;
  --t-sm: .8125rem;
  --t-md: .9375rem;
  --t-lg: 1.125rem;
  --t-xl: 1.5rem;
  --t-2xl: 2rem;

  --tap: 44px;
  --slot: 52px;
  --gutter: 52px;
  --radius: 10px;
}

:root:not([data-theme="light"]) {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14161A;
    --card: #1C1F24;
    --ink: #E6E9E5;
    --ink-soft: #98A0A6;
    --rule: #2E343A;
    --rule-soft: #23282D;
    --seal: #D9695E;
    --sat: #7FA6CE;
    --shade: rgba(0,0,0,.35);

    --c-red: #C9564C;
    --c-navy: #5B85B8;
    --c-moss: #7C9B6F;
    --c-ochre: #C79A4A;
    --c-plum: #A87399;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #14161A;
  --card: #1C1F24;
  --ink: #E6E9E5;
  --ink-soft: #98A0A6;
  --rule: #2E343A;
  --rule-soft: #23282D;
  --seal: #D9695E;
  --sat: #7FA6CE;
  --shade: rgba(0,0,0,.35);
  --c-red: #C9564C;
  --c-navy: #5B85B8;
  --c-moss: #7C9B6F;
  --c-ochre: #C79A4A;
  --c-plum: #A87399;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

.app, .auth {
  height: 100%;
  height: 100dvh;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--t-md);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── 공통 버튼 ─────────────────────────── */
.btn {
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-solid {
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
}

.btn-quiet {
  border-color: var(--rule);
  color: var(--ink);
}

.btn-quiet:hover { background: var(--shade); }

.btn-danger {
  color: var(--seal);
  border-color: var(--rule);
  width: 100%;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
}

.icon-btn:hover { background: var(--shade); color: var(--ink); }

/* ── 로그인 ───────────────────────────── */
.auth {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 32px 28px;
}

.auth-title {
  font-family: var(--serif);
  font-size: var(--t-2xl);
  font-weight: 700;
  margin: 0;
  letter-spacing: .04em;
}

.auth-sub {
  color: var(--ink-soft);
  font-size: var(--t-sm);
  margin: 6px 0 24px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-size: var(--t-sm);
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  resize: vertical;
}

.auth-msg,
.sheet-msg {
  min-height: 20px;
  margin: 4px 0 12px;
  font-size: var(--t-sm);
  color: var(--seal);
}

.auth-actions {
  display: flex;
  gap: 10px;
}

.auth-actions .btn { flex: 1; }

/* ── 상단 바 ──────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.title {
  font-family: var(--serif);
  font-size: var(--t-xl);
  font-weight: 700;
  margin: 0 8px;
  letter-spacing: .02em;
  white-space: nowrap;
}

.seg {
  display: flex;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg-btn {
  min-width: 46px;
  height: var(--tap);
  border: 0;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
}

.seg-btn[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
}

.offline {
  flex: none;
  margin: 0;
  padding: 8px 14px;
  font-size: var(--t-sm);
  background: var(--seal);
  color: #fff;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ── 월간 ─────────────────────────────── */
.month {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.weekdays {
  flex: none;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--rule);
}

.wd {
  padding: 8px 0;
  text-align: center;
  font-size: var(--t-sm);
  color: var(--ink-soft);
}

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

.month-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.day {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 4px 6px;
  border-right: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
  background: none;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.day:nth-child(7n) { border-right: 0; }
.day.outside { color: var(--ink-soft); opacity: .45; }
.day:hover { background: var(--shade); }

.daynum {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: var(--t-md);
  line-height: 1;
}

.day.sun .daynum { color: var(--seal); }
.day.sat .daynum { color: var(--sat); }

.day.today .daynum {
  color: #fff;
  background: var(--seal);
  border-radius: 4px;
  font-weight: 700;
}

.chips {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.chip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  border: 0;
  border-radius: 5px;
  background: var(--rule-soft);
  background: color-mix(in srgb, var(--chip) 16%, transparent);
  color: var(--ink);
  font-size: var(--t-xs);
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.chip-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chip);
}

.chip-time {
  flex: none;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.allday {
  background: var(--chip);
  color: #fff;
}

.chip.allday .chip-dot { display: none; }

.more {
  flex: none;
  font-size: var(--t-xs);
  color: var(--ink-soft);
  padding-left: 6px;
}

/* ── 주간 ─────────────────────────────── */
.week {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.week-head {
  flex: none;
  display: flex;
  border-bottom: 1px solid var(--rule);
}

.gutter {
  flex: none;
  width: var(--gutter);
}

.week-days {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.wcol-head {
  padding: 6px 0 8px;
  text-align: center;
  border-left: 1px solid var(--rule-soft);
}

.wcol-head .wname {
  font-size: var(--t-xs);
  color: var(--ink-soft);
}

.wcol-head.sun .wname { color: var(--seal); }
.wcol-head.sat .wname { color: var(--sat); }

.wcol-head .wnum {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 2px;
  font-family: var(--serif);
  font-size: var(--t-md);
}

.wcol-head.today .wnum {
  background: var(--seal);
  color: #fff;
  border-radius: 4px;
  font-weight: 700;
}

.week-allday {
  flex: none;
  display: flex;
  min-height: 0;
  border-bottom: 1px solid var(--rule);
}

.week-allday:empty { display: none; }

.allday-track {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 4px;
}

.allday-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.week-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hours {
  flex: none;
  width: var(--gutter);
}

.hour-label {
  height: var(--slot);
  padding-right: 8px;
  text-align: right;
  font-size: var(--t-xs);
  color: var(--ink-soft);
  transform: translateY(-7px);
  font-variant-numeric: tabular-nums;
}

.week-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  position: relative;
}

.wcol {
  position: relative;
  border-left: 1px solid var(--rule-soft);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--rule-soft) 0 1px,
    transparent 1px var(--slot)
  );
}

.block {
  position: absolute;
  left: 2px;
  right: 2px;
  padding: 3px 6px;
  border: 0;
  border-left: 3px solid var(--chip);
  border-radius: 5px;
  background: var(--card);
  background: color-mix(in srgb, var(--chip) 18%, var(--card));
  color: var(--ink);
  font-size: var(--t-xs);
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.block b {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.block span { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.nowline {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1.5px solid var(--seal);
  pointer-events: none;
  z-index: 2;
}

.nowline::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--seal);
}

/* ── 추가 버튼 ────────────────────────── */
.fab {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--seal);
  color: #fff;
  box-shadow: 0 4px 16px var(--shade);
  cursor: pointer;
}

.fab svg { width: 26px; height: 26px; stroke-width: 2; }

/* ── 편집 시트 ────────────────────────── */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 20;
}

.sheet {
  position: fixed;
  z-index: 21;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-top: 1px solid var(--rule);
  border-radius: 18px 18px 0 0;
  animation: rise .22s ease;
}

@keyframes rise {
  from { transform: translateY(16px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
}

.sheet-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
}

.sheet-title {
  font-family: var(--serif);
  font-size: var(--t-lg);
  font-weight: 700;
  margin: 0;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 20px calc(28px + env(safe-area-inset-bottom));
}

.title-input {
  width: 100%;
  min-height: 52px;
  padding: 8px 0;
  margin-bottom: 8px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  font-family: var(--serif);
  font-size: var(--t-xl);
}

.title-input:focus { outline: none; border-bottom-color: var(--seal); }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}

.row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
}

.row.two .field { margin-bottom: 0; }

.row-label {
  font-size: var(--t-sm);
  color: var(--ink-soft);
}

.toggle {
  justify-content: space-between;
  min-height: var(--tap);
  cursor: pointer;
}

.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.switch {
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 14px;
  background: var(--rule);
  position: relative;
  transition: background .15s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--card);
  transition: transform .15s;
}

.toggle input:checked ~ .switch { background: var(--seal); }
.toggle input:checked ~ .switch::after { transform: translateX(18px); }
.toggle input:focus-visible ~ .switch { outline: 2px solid var(--seal); outline-offset: 2px; }

.colors {
  display: flex;
  gap: 10px;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--chip);
  cursor: pointer;
  padding: 0;
}

.swatch[aria-checked="true"] {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--card);
}


/* ── 반복 설정 ────────────────────────── */
select {
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: pointer;
}

.days {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.daypick {
  width: 38px;
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: none;
  color: var(--ink-soft);
  font-size: var(--t-sm);
  cursor: pointer;
  padding: 0;
}

.daypick[aria-pressed="true"] {
  background: var(--seal);
  border-color: var(--seal);
  color: #fff;
  font-weight: 600;
}

.with-suffix {
  display: flex;
  align-items: center;
  gap: 8px;
}

.with-suffix input {
  width: 76px;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
}

.with-suffix span {
  font-size: var(--t-sm);
  color: var(--ink-soft);
  white-space: nowrap;
}

.hint {
  margin: 2px 0 0;
  font-size: var(--t-xs);
  color: var(--ink-soft);
}

.chip-rep {
  flex: none;
  font-size: 9px;
  line-height: 1;
  opacity: .6;
  font-style: normal;
}

.block-rep {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 9px;
  line-height: 1;
  opacity: .55;
  font-style: normal;
}

/* ── 선택 대화상자 ────────────────────── */
.ask {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.4);
}

.ask-box {
  width: min(340px, 100%);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 22px 20px 18px;
}

.ask-msg {
  margin: 0 0 18px;
  font-size: var(--t-md);
  line-height: 1.55;
}

.ask-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ask-actions .btn { width: 100%; }

/* ── 태블릿 가로 · PC: 시트를 옆 패널로 ──── */
@media (min-width: 900px) {
  :root { --slot: 56px; --gutter: 64px; }

  .sheet {
    top: 0;
    left: auto;
    width: 400px;
    max-height: none;
    border-radius: 0;
    border-top: 0;
    border-left: 1px solid var(--rule);
    animation: slide .22s ease;
  }

  @keyframes slide {
    from { transform: translateX(24px); opacity: 0; }
  }

  .scrim { background: rgba(0,0,0,.18); }
  .daynum { width: 32px; height: 32px; font-size: var(--t-lg); }
  .chip { font-size: var(--t-sm); padding: 4px 8px; }
  #add-top { display: none; }
}

/* 포인터가 있는 환경에서만 hover 반응 */
@media (hover: none) {
  .day:hover, .icon-btn:hover, .btn-quiet:hover { background: none; }
}

/* ── 모바일 세로 ──────────────────────── */
@media (max-width: 619px) {
  :root { --slot: 46px; --gutter: 42px; --tap: 42px; }

  .topbar {
    flex-wrap: wrap;
    row-gap: 4px;
    padding: 6px 8px;
  }

  .topbar-left {
    flex: 1 1 100%;
    justify-content: flex-start;
  }

  .topbar-right {
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  .title {
    font-size: var(--t-lg);
    margin: 0 4px;
    flex: 1;
  }

  .fab { display: none; }

  .wd { font-size: var(--t-xs); padding: 6px 0; }
  .day { padding: 3px 2px 4px; }
  .daynum { width: 26px; height: 26px; font-size: var(--t-sm); }
  .chip { padding: 2px 4px; gap: 4px; border-radius: 4px; }
  .chip-time { display: none; }
  .wcol-head .wnum { width: 26px; height: 26px; font-size: var(--t-sm); }
  .hour-label { font-size: 10px; padding-right: 5px; }
  .block { font-size: 10px; padding: 2px 4px; border-left-width: 2px; }
  .block span { display: none; }

  .sheet-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
  .title-input { font-size: var(--t-lg); min-height: 46px; }
  .row.two { grid-template-columns: 1fr; gap: 10px; }
  .row.two .field { margin-bottom: 0; }
  .auth-card { padding: 26px 20px; }
}

/* ── 좁은 폭 세로 태블릿 ──────────────── */
@media (min-width: 620px) and (max-width: 899px) {
  .fab { display: none; }
  .sheet { max-height: 82vh; }
}

/* ── 큰 화면 ──────────────────────────── */
@media (min-width: 1400px) {
  :root { --slot: 62px; }
  .chip { padding: 5px 9px; }
}
