/* =====================================================================
   테마 토큰
   - 기본: 브라우저/OS 설정(prefers-color-scheme)을 따름
   - 사용자가 토글로 선택하면 html[data-theme="light|dark"] 가 우선
   ===================================================================== */
:root {
  --radius: 14px;
  color-scheme: light;
  --bg: #f5f6fa;
  --card: #ffffff;
  --surface: #f9fafb;
  --hover: #f3f4f6;
  --input-bg: #ffffff;
  --text: #1f2937;
  --text-strong: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-dashed: #d1d5db;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --success-soft: #ecfdf5;
  --success-border: #a7f3d0;
  --warn: #f59e0b;
  --sun: #dc2626;
  --sat: #2563eb;
  --excluded-bg: #fee2e2;
  --excluded-text: #991b1b;
  --stripe-a: #f3f4f6;
  --stripe-b: #e5e7eb;
  --cnt-bg: rgba(255, 255, 255, .85);
  --emoji-shadow: rgba(255, 255, 255, .9);
  --overlay-alpha: .38;
  --backdrop: rgba(17, 24, 39, .5);
  --toast-bg: #111827;
  --toast-text: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1117;
    --card: #181b24;
    --surface: #1f2330;        /* 칩, 행, 미니 배경 */
    --hover: #262b3a;
    --input-bg: #11141c;
    --text: #e5e7eb;
    --text-strong: #f9fafb;
    --muted: #9ca3af;
    --border: #2a2f3d;
    --border-dashed: #3a4052;
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-soft: #2a2f4a;
    --primary-text: #ffffff;
    --danger: #f87171;
    --success: #22c55e;
    --success-soft: #0f2a1d;
    --success-border: #1f6e42;
    --warn: #f59e0b;
    --sun: #f87171;
    --sat: #60a5fa;
    --excluded-bg: #3a1c1f;
    --excluded-text: #fca5a5;
    --stripe-a: #1c2029;
    --stripe-b: #262b38;
    --cnt-bg: rgba(24, 27, 36, .85);
    --emoji-shadow: rgba(0, 0, 0, .8);
    --overlay-alpha: .42;
    --backdrop: rgba(0, 0, 0, .65);
    --toast-bg: #f3f4f6;
    --toast-text: #111827;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
  }
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --card: #181b24;
  --surface: #1f2330;        /* 칩, 행, 미니 배경 */
  --hover: #262b3a;
  --input-bg: #11141c;
  --text: #e5e7eb;
  --text-strong: #f9fafb;
  --muted: #9ca3af;
  --border: #2a2f3d;
  --border-dashed: #3a4052;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-soft: #2a2f4a;
  --primary-text: #ffffff;
  --danger: #f87171;
  --success: #22c55e;
  --success-soft: #0f2a1d;
  --success-border: #1f6e42;
  --warn: #f59e0b;
  --sun: #f87171;
  --sat: #60a5fa;
  --excluded-bg: #3a1c1f;
  --excluded-text: #fca5a5;
  --stripe-a: #1c2029;
  --stripe-b: #262b38;
  --cnt-bg: rgba(24, 27, 36, .85);
  --emoji-shadow: rgba(0, 0, 0, .8);
  --overlay-alpha: .42;
  --backdrop: rgba(0, 0, 0, .65);
  --toast-bg: #f3f4f6;
  --toast-text: #111827;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; color: var(--text-strong); }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; color: var(--text-strong); }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); font-size: .9rem; }
[hidden] { display: none !important; }

/* ---------- 레이아웃 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1.25rem;
  background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text-strong); }
.topbar-right { display: flex; gap: .4rem; align-items: center; }
/* 상단 버튼(요약 위치·피드백·그룹 나가기·테마)은 크기와 글자를 하나로 맞춘다 */
.topbar-right .btn, .topbar-right .btn.small, .topbar-right .btn.icon {
  font: inherit; font-size: .85rem; font-weight: 600; line-height: 1.25;
  padding: .4rem .7rem; border-radius: 8px;
}
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.hero { text-align: center; padding: 1.5rem 0 2rem; }
.hero h1 { font-size: 2rem; line-height: 1.25; }
.home-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.25rem; }
/* 한 열 배치가 기본 골격이고, 넓은 화면에서는 data-layout 으로 오른쪽 사이드바(기본)를 적용한다 */
.group-grid { display: grid; grid-template-columns: 1fr; gap: 1.25rem; margin-top: 1.25rem; }
/* 요약 위치를 바꿀 때: 캘린더는 줄어들거나 늘어나고, 요약은 옆에서 들어오거나 아래로 내려간다.
   (배치 자체는 그리드가 즉시 바꾸고, 그 위에 짧은 움직임만 얹는다) */
@keyframes cal-shrink { from { transform: scaleX(1.04); } to { transform: none; } }
@keyframes cal-grow   { from { transform: scaleX(.96);  } to { transform: none; } }
@keyframes side-in-right { from { opacity: 0; transform: translateX(2.5rem); } to { opacity: 1; transform: none; } }
@keyframes side-in-below { from { opacity: 0; transform: translateY(1.5rem); } to { opacity: 1; transform: none; } }
.group-grid.to-side .calendar-card { animation: cal-shrink .3s cubic-bezier(.4, 0, .2, 1); transform-origin: left center; }
.group-grid.to-side .side { animation: side-in-right .34s cubic-bezier(.2, .8, .2, 1); }
.group-grid.to-stack .calendar-card { animation: cal-grow .3s cubic-bezier(.4, 0, .2, 1); transform-origin: left center; }
.group-grid.to-stack .side { animation: side-in-below .34s cubic-bezier(.2, .8, .2, 1); }
@media (prefers-reduced-motion: reduce) {
  .group-grid.to-side .calendar-card, .group-grid.to-side .side,
  .group-grid.to-stack .calendar-card, .group-grid.to-stack .side { animation: none; }
}
.side { display: flex; flex-direction: column; gap: 1.25rem; }
.side > .side-top { display: none; }   /* 오버레이로 열렸을 때만 보이는 머리글 */

@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
  /* 헤더의 📊 요약 버튼으로 덮어 띄우기 */
  /* 아래에서 올라오는 시트 (닫으면 다시 내려간다) */
  .side.as-modal {
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 88vh; overflow: auto;
    padding: .9rem calc(.9rem + env(safe-area-inset-right)) calc(.9rem + env(safe-area-inset-bottom)) .9rem;
    background: var(--bg); border: 1px solid var(--border); border-bottom: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, .35);
    transform: translateY(100%); opacity: .4;
    transition: transform .34s cubic-bezier(.16, 1, .3, 1), opacity .34s ease;
    will-change: transform;
  }
  .side.as-modal.open { transform: none; opacity: 1; }
  /* 시트 안에서는 머리글이 함께 스크롤된다 (고정하지 않는다) */
  .side.as-modal > .side-top { display: flex; align-items: center; justify-content: space-between; }
  .side.as-modal { gap: .8rem; }   /* 머리글과 첫 카드 사이가 너무 벌어지지 않게 */
  .side-overlay {
    position: fixed; inset: 0; z-index: 49; background: var(--backdrop);
    opacity: 0; transition: opacity .28s ease;
  }
  .side-overlay.open { opacity: 1; }
  @media (prefers-reduced-motion: reduce) {
    .side.as-modal { transition: none; transform: none; }
    .side-overlay { transition: none; opacity: 1; }
  }
}

/* 넓은 화면에서는 헤더 버튼으로 두 가지 배치를 고른다 */
@media (min-width: 901px) {
  .side-overlay { display: none; }
  /* 아래로 몰기: 카드를 나란히 배치. 각 카드는 자기 높이만 차지한다(겹치지 않음) */
  [data-layout="stack"] .side {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    align-items: start; grid-auto-rows: min-content; gap: 1.25rem;
  }
  [data-layout="stack"] .side > section { margin: 0; }
  /* 오른쪽 사이드바: 스크롤해도 따라온다 */
  [data-layout="side"] .group-grid { grid-template-columns: minmax(0, 1fr) 340px; }
  [data-layout="side"] .side { position: sticky; top: 4.75rem; max-height: calc(100vh - 6rem); overflow: auto; padding-right: .2rem; }
}

/* ---------- 메인 메뉴 ---------- */
/* 메뉴와 각 화면의 가로 크기를 맞춰 열고 닫을 때 폭이 흔들리지 않게 한다 */
.home-menu, .home-view { max-width: 640px; margin-left: auto; margin-right: auto; }
.home-menu { display: flex; flex-direction: column; gap: .75rem; margin-top: 1.25rem; }
.menu-card {
  font: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: .25rem;
  padding: 1.15rem 1.15rem 1.15rem 1.5rem; border-radius: 14px; border: 1px solid var(--border); background: var(--card); color: var(--text);
  transition: transform .08s, box-shadow .15s, border-color .15s;
}
.menu-card:hover { border-color: var(--primary); box-shadow: 0 6px 20px rgba(0, 0, 0, .08); }
.menu-card:active { transform: translateY(1px); }
.menu-card .ico { font-size: 1.6rem; line-height: 1.2; }
.menu-card .tt { font-weight: 700; font-size: 1.05rem; color: var(--text-strong); }
.menu-card .ds { font-size: .85rem; color: var(--muted); }

.home-view { margin-top: 1.25rem; }   /* 가로 크기는 위에서 .home-menu 와 함께 지정 */
.view-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
/* 이름을 입력하면 아래 칸이 열리는 영역 */
.reveal {
  display: grid; grid-template-rows: 0fr; opacity: 0;
  transition: grid-template-rows .22s ease, opacity .22s ease, margin-top .22s ease;
  margin-top: -.9rem;   /* 접혔을 때 폼 간격까지 상쇄해 완전히 사라지게 */
}
.reveal > * { overflow: hidden; min-height: 0; }
.reveal.open { grid-template-rows: 1fr; opacity: 1; margin-top: 0; }
.reveal > .stack { display: flex; flex-direction: column; gap: .9rem; }

/* 각 단계 내부도 폼과 같은 간격(.9rem)으로 띄운다 */
.step { display: flex; flex-direction: column; gap: .9rem; }
.step > p { margin: 0; }
.step-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.step-actions .btn { min-width: 6rem; }
.check { flex-direction: row !important; align-items: center; gap: .5rem; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--primary); }
.summary-box { display: flex; flex-direction: column; gap: .3rem; padding: .7rem .8rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); font-weight: 400; }
.summary-box > div { display: flex; gap: .6rem; font-size: .88rem; }
.summary-box .k { color: var(--muted); min-width: 3.4rem; }
.warn-text { color: var(--warn); font-weight: 600; }
.summary-box .v { color: var(--text-strong); font-weight: 600; word-break: break-all; }

.recent-row { display: flex; align-items: stretch; gap: .4rem; margin-bottom: .35rem; }
.recent-row > a { flex: 1; min-width: 0; margin-bottom: 0; }
/* 두 버튼은 같은 크기의 정사각형에 가깝게, 이모지는 가운데 정렬 */
.recent-share, .recent-del {
  flex: 0 0 auto; width: 2.6rem; padding: 0; margin: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 1rem; line-height: 1; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--muted);
}
.recent-del:hover { color: var(--sun); border-color: var(--sun); }
.recent-share:hover { color: var(--text-strong); border-color: var(--primary); }
/* ---------- 폼 ---------- */
form { display: flex; flex-direction: column; gap: .9rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 600; }
input[type="text"], input[type="date"], input[type="datetime-local"], input[type="password"] {
  font: inherit; font-weight: 400; padding: .6rem .75rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--input-bg); color: var(--text);
}
input::placeholder { color: var(--muted); opacity: .8; }
input:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.field { display: flex; flex-direction: column; gap: .4rem; font-size: .9rem; font-weight: 600; }
.field-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; font-weight: 400; }
textarea {
  font: inherit; font-weight: 400; padding: .6rem .75rem; resize: vertical; min-height: 110px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--input-bg); color: var(--text);
}
textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
.code-input { text-transform: uppercase; letter-spacing: .25em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .65rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); transition: background .15s, transform .05s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.small { padding: .4rem .7rem; font-size: .85rem; }
.btn-label { margin-left: .25rem; }   /* 이모지와 글자 사이 간격 */
.btn.icon { font-size: 1.05rem; padding: .3rem .55rem; line-height: 1; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- 요일 단위 제외 토글 ---------- */
.weekday-toggles { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; font-weight: 400; }
.weekday-toggles .lbl { font-size: .8rem; color: var(--muted); margin-right: .15rem; }
.wd-btn {
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  width: 2.2rem; height: 2.2rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .15s, color .15s, border-color .15s;
}
.wd-btn:hover { background: var(--hover); }
.wd-btn.sun { color: var(--sun); } .wd-btn.sat { color: var(--sat); }
.wd-btn.active { background: var(--excluded-bg); color: var(--excluded-text); border-color: var(--excluded-text); text-decoration: line-through; }

/* ---------- 미니 캘린더(제외일 선택) ---------- */
.mini-calendar { display: flex; flex-direction: column; gap: .75rem; max-height: 320px; overflow: auto; padding: .25rem; border: 1px dashed var(--border-dashed); border-radius: 10px; font-weight: 400; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.mini-month .month-title { font-weight: 700; font-size: .85rem; margin: .25rem .25rem .35rem; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.mini-grid .dow { text-align: center; font-size: .7rem; color: var(--muted); }
.mini-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; font-size: .8rem; cursor: pointer; user-select: none; border: 1px solid var(--border);
}
.mini-cell:hover { background: var(--primary-soft); }

/* 제외일: 생성 화면과 그룹 화면을 같은 모양(사선 + 취소선)으로 통일 */
.mini-cell.excluded, .mini-cell.excluded:hover {
  background: repeating-linear-gradient(135deg, var(--stripe-a) 0 6px, var(--stripe-b) 6px 12px);
  color: var(--excluded-text); border-color: var(--excluded-text); text-decoration: line-through;
}
.mini-cell.sun { color: var(--sun); }
.mini-cell.sat { color: var(--sat); }

/* ---------- 그룹 헤더 ---------- */
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.notice {
  margin: .35rem 0 0; padding: .45rem .6rem; border-radius: 8px; font-size: .85rem;
  background: var(--warn-soft, var(--surface)); border: 1px solid var(--border); color: var(--text);
}
.group-desc {
  margin: .25rem 0 .35rem; font-size: .9rem; line-height: 1.5; color: var(--text);
  white-space: pre-wrap; word-break: break-word; max-width: 60ch;
}
.group-desc a { color: var(--primary); text-decoration: underline; word-break: break-all; }
.share-box { display: flex; align-items: center; gap: .75rem; }
.share-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
/* 이 두 버튼은 그룹 화면에서 가장 많이 쓰는 조작이라 크게 잡는다.
   안에 든 내용(글자 vs 이모지)이 달라도 높이가 어긋나지 않도록 높이를 고정한다. */
.share-actions .btn.small,
.share-actions .me-chip {
  display: inline-flex; align-items: center; justify-content: center;
  height: 3.1rem; padding: 0 1.1rem; font-size: 1rem; font-weight: 600;
  border-radius: 10px; line-height: 1;
}
/* 프로필 칩은 외곽선 컬러만 참여자 색을 유지한다 */
.share-actions .me-chip { gap: .45rem; }
.share-actions .me-chip .avatar { font-size: 1.35rem; line-height: 1; }
.share-actions .me-chip .name { font-size: 1rem; }
.share-actions .me-chip .edit { font-size: .85rem; }

/* ---------- 캘린더 ---------- */
.calendar-card { min-width: 0; }
.calendar-toolbar { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar-actions { display: flex; align-items: center; gap: .75rem; }
.me-chip { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem .35rem .45rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.me-chip:hover { background: var(--hover); }
.me-chip .avatar { font-size: 1.25rem; }
.me-chip .name { font-weight: 700; }
.me-chip .edit { color: var(--muted); font-size: .8rem; }

.calendar { display: flex; flex-direction: column; gap: 1.5rem; user-select: none; -webkit-user-select: none; touch-action: pan-y; }
/* 월 블록마다 테두리를 둘러 달 사이 경계를 만든다 */
.month { border: 1px solid var(--border); border-radius: 12px; padding: .75rem .8rem .8rem; }
.month .month-title {
  font-weight: 700; font-size: 1.05rem; color: var(--text-strong);
  margin: -.15rem 0 .55rem; padding-bottom: .45rem; border-bottom: 1px solid var(--border);
}
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.grid .dow { text-align: center; font-size: .75rem; color: var(--muted); padding-bottom: .15rem; }
.grid .dow.sun { color: var(--sun); } .grid .dow.sat { color: var(--sat); }
.cell {
  position: relative; min-height: 78px; border-radius: 10px;   /* 이모지 6개까지 안 잘리게 */
  border: 1px solid var(--border); background: var(--card); padding: .35rem .4rem;
  display: flex; flex-direction: column; gap: .2rem; cursor: pointer; overflow: hidden;
  transition: transform .06s, box-shadow .1s;
}
.cell:hover { box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 55%, transparent) inset; }
/* 기간 밖 날짜: 숫자는 보여주되 고를 수 없는 날임을 알 수 있게 */
.cell.out, .cell.out:hover, .mini-cell.out, .mini-cell.out:hover {
  cursor: not-allowed; box-shadow: none; opacity: .22;
  color: var(--muted); background: transparent; border-style: dashed;
}
.cell.out .day { color: var(--muted); }
.cell.disabled {
  cursor: not-allowed; color: var(--muted);
  background: repeating-linear-gradient(135deg, var(--stripe-a) 0 6px, var(--stripe-b) 6px 12px);
}
.cell.disabled:hover { box-shadow: none; }
.cell.disabled .day > span:first-child { text-decoration: line-through; }
.cell.disabled .day .cnt { background: none; color: var(--excluded-text); }
.cell.mine { box-shadow: 0 0 0 2px var(--primary) inset; }
.cell.mine:hover { box-shadow: 0 0 0 3px var(--primary) inset; }
.cell .day { font-size: .8rem; font-weight: 700; display: flex; justify-content: space-between; align-items: center; z-index: 1; }
.cell .day .cnt { font-size: .7rem; font-weight: 700; background: var(--cnt-bg); border-radius: 999px; padding: 0 .35rem; color: var(--text); }
.cell.sun .day { color: var(--sun); } .cell.sat .day { color: var(--sat); }
.cell .emojis { display: flex; flex-wrap: wrap; gap: 2px; font-size: 1rem; line-height: 1.05; z-index: 1; }
.cell .emojis span { filter: drop-shadow(0 1px 1px var(--emoji-shadow)); }
.cell .colors { position: absolute; inset: 0; opacity: var(--overlay-alpha); pointer-events: none; }
.cell.today .day::before { content: "오늘"; font-size: .6rem; color: var(--primary); margin-right: .2rem; }
.cell.all { box-shadow: 0 0 0 2px var(--success) inset; }
.cell.all.mine { box-shadow: 0 0 0 2px var(--success) inset, 0 0 0 4px var(--primary) inset; }
.cell.dragging { box-shadow: 0 0 0 2px var(--warn) inset !important; }
/* 날짜 코멘트 */
/* 코멘트 있음 표시는 오른쪽 아래 모서리 */
.cell .note-mark { position: absolute; right: .28rem; bottom: .15rem; font-size: .72rem; z-index: 1; line-height: 1; }
/* 이어가기 통합 모달 */
.cont-or { display: flex; align-items: center; gap: .6rem; margin: .25rem 0; color: var(--muted); font-size: .8rem; }
.cont-or::before, .cont-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
#modal-continue .modal-actions { justify-content: flex-end; }
#modal-continue form { gap: .5rem; }

/* 이 기기에서 표현할 수 없는 이모지 대체 표시 */
.emoji-missing { opacity: .75; cursor: help; }

/* 참여자 PIN */
.pin-input { letter-spacing: .5em; text-align: center; font-size: 1.15rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pin-people { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .75rem; max-height: 180px; overflow: auto; }
.pin-person {
  font: inherit; font-size: .9rem; cursor: pointer; display: flex; align-items: center; gap: .35rem;
  padding: .35rem .6rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.pin-person:hover { border-color: var(--primary); }
.pin-person.on { border-color: var(--primary); color: var(--primary); font-weight: 700; }

/* 언어 선택 */
.lang-list { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.lang-item {
  font: inherit; font-size: .95rem; cursor: pointer; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem .75rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.lang-item:hover { background: var(--hover); border-color: var(--primary); }
.lang-item.on { border-color: var(--primary); color: var(--primary); font-weight: 700; }

/* 목록 더 보기 버튼 */
.more-btn {
  width: 100%; margin-top: .45rem; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
  padding: .35rem; border-radius: 8px; border: 1px dashed var(--border-dashed);
  background: transparent; color: var(--muted);
}
.more-btn:hover { color: var(--primary); border-color: var(--primary); }

/* 접히는 요약 카드 (기본 닫힘) */
.fold > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  font-size: 1.05rem; font-weight: 700; color: var(--text-strong);
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: '▾'; margin-left: auto; color: var(--muted); font-size: .9rem; transition: transform .15s; }
.fold[open] > summary::after { transform: rotate(180deg); }
.fold > summary + * { margin-top: .75rem; }

/* 캘린더 셀 마우스오버 팝업 */
.cell-pop {
  position: fixed; z-index: 60; max-width: 280px;   /* 코멘트 링크를 누를 수 있어야 해서 마우스를 받는다 */
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28); padding: .5rem .6rem; font-size: .82rem;
}
.cell-pop .pop-head { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; margin-bottom: .35rem; }
.cell-pop .pop-head strong { color: var(--text-strong); }
.cell-pop .pop-row { display: flex; align-items: baseline; gap: .35rem; padding: .1rem 0; }
.cell-pop .pop-row .who { font-size: 1rem; }
.cell-pop .pop-row .nm { font-weight: 600; white-space: nowrap; }
.cell-pop .pop-row .note { color: var(--muted); word-break: break-word; }
.cell-pop a, .note-row .txt a { color: var(--accent); text-decoration: underline; word-break: break-all; }
.cell-pop a:hover, .note-row .txt a:hover { text-decoration: none; }
.cell-pop .pop-empty { color: var(--muted); }

/* 날짜 코멘트 모아 보기 */
.notes-list { display: flex; flex-direction: column; gap: .5rem; }
/* 가장 많이 겹친 날짜 · 날짜별 참여자와 같은 크기·여백 */
.note-row {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem; cursor: pointer;
  padding: .5rem .65rem; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--border); border-left: 5px solid var(--border);   /* 참여자별 목록과 같은 두께 */
}
.note-row:hover { background: var(--hover); }
.note-row .date { font-weight: 700; white-space: nowrap; }
.note-row .mid { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: .35rem; }
.note-row .who { font-size: 1rem; }
.note-row .txt { min-width: 0; word-break: break-word; color: var(--text); font-size: .85rem; }
.note-row .note-edit { flex: 0 0 auto; }
.note-row .note-edit {
  font: inherit; font-size: .95rem; line-height: 1; cursor: pointer;
  min-width: 1.9rem; min-height: 1.7rem; padding: .25rem .45rem;
  border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--muted);
}
.note-row .note-edit:hover { color: var(--primary); border-color: var(--primary); }

/* 요약에서 날짜를 눌러 이동했을 때 잠깐 강조 */
.cell.focus { animation: cellFocus 1.1s ease-in-out 2; }
@keyframes cellFocus {
  0%, 100% { box-shadow: 0 0 0 3px var(--warn) inset; }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--warn) 45%, transparent) inset; }
}
.best-row[data-date], .date-row[data-date], .chip[data-date] { cursor: pointer; }
.best-row[data-date]:hover, .date-row[data-date]:hover { background: var(--hover); }
.chip[data-date]:hover { filter: brightness(1.1); }
@media (max-width: 600px) {
  .cell { min-height: 82px; padding: .3rem .28rem; }
  .cell .emojis { font-size: .88rem; }
}

/* 캘린더 위(빠른 선택 아래)에 위치하고, 스크롤해도 상단 바 아래에 고정된다 */
.legend {
  display: flex; flex-wrap: wrap; gap: .5rem;
  position: sticky; top: 3.35rem; z-index: 12;
  margin: 0 0 .75rem; padding: .5rem 0;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.legend .item { display: flex; align-items: center; gap: .35rem; font-size: .85rem; padding: .2rem .55rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; }
.legend .item.me { border-color: var(--primary); }

/* ---------- 요약 패널 ---------- */
.best-dates { display: flex; flex-direction: column; gap: .5rem; }
.best-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .65rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.best-row.all { background: var(--success-soft); border-color: var(--success-border); }
.best-row .date { font-weight: 700; }
.row-note { font-size: .78rem; opacity: .9; }   /* 목록에서 코멘트 있음 표시 */
.best-row .who { display: flex; gap: 2px; font-size: 1rem; }
/* 개수 배지: 겹친 날짜 · 날짜별 참여자 · 참여자별 선택 날짜 모두 같은 모양 */
.best-row .count, .user-row > summary.head > .muted {
  font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap;
  padding: .05rem .45rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card);
}

.by-user { display: flex; flex-direction: column; gap: .6rem; }
.user-row { border: 1px solid var(--border); border-radius: 10px; padding: .55rem .65rem; border-left-width: 5px; }
.user-row > summary.head { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.user-row > summary.head::-webkit-details-marker { display: none; }
.user-row > summary.head::after { content: '▾'; color: var(--muted); font-size: .8rem; transition: transform .15s; }
.user-row[open] > summary.head::after { transform: rotate(180deg); }
.user-row .head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
/* 닉네임 길이에 상관없이 일수·화살표가 항상 오른쪽 같은 자리에 오도록 */
.user-row .head .nm { font-weight: 700; display: flex; align-items: center; gap: .35rem; flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.user-row > summary.head > .muted { flex: 0 0 auto; text-align: center; }
.user-row .head .nm .you { font-size: .7rem; color: var(--primary); border: 1px solid var(--primary); border-radius: 999px; padding: 0 .35rem; }
.user-row .dates { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.chip { font-size: .75rem; padding: .1rem .45rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); }

.by-date { display: flex; flex-direction: column; gap: .5rem; }   /* TOP 5 와 같은 간격 */
.date-row { display: flex; align-items: center; gap: .5rem; font-size: .9rem; padding: .25rem .3rem; border-radius: 6px; }
.date-row:hover { background: var(--surface); }
.date-row .d { width: 6.2rem; font-variant-numeric: tabular-nums; color: var(--text); }
.date-row .who { display: flex; gap: 2px; font-size: 1rem; }   /* 가장 많이 겹친 날짜와 동일 */
.sort-btn {
  font: inherit; font-size: .75rem; font-weight: 600; cursor: pointer; vertical-align: middle;
  padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
}
.sort-btn:hover { color: var(--primary); border-color: var(--primary); }
.empty { color: var(--muted); font-size: .9rem; text-align: center; padding: .5rem; }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
/* 모달 위에 겹치는 확인·선택 모달 */
#modal-confirm, #modal-choice, #modal-lang, #modal-pin { z-index: 60; }
.modal-backdrop { position: absolute; inset: 0; background: var(--backdrop); }
/* 그룹에 처음 들어올 때(참여·비밀번호)만 뒤 내용을 흐리게 가린다.
   그 밖의 모달은 뒤 화면이 보이는 편이 맥락을 알기 쉽다. */
.modal.blur-back > .modal-backdrop {
  backdrop-filter: blur(10px) saturate(.85); -webkit-backdrop-filter: blur(10px) saturate(.85);
}
/* 안내만 있는 화면(그룹 없음 등) — 가운데 정렬하고 여백을 넉넉히 */
.notice-card {
  text-align: center; max-width: 30rem; margin: 3rem auto;
  padding: 2.5rem 1.75rem; display: flex; flex-direction: column; align-items: center; gap: 1.25rem;
}
.notice-card h1 { margin: 0; font-size: 1.35rem; line-height: 1.5; }
.notice-card p { margin: 0; line-height: 1.7; }
.notice-card .btn { margin-top: .5rem; }
@media (max-width: 720px) {
  .notice-card { margin: 1.5rem auto; padding: 2rem 1.25rem; gap: 1rem; }
}
.modal-body { position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.cont-foot { margin-top: 1.1rem; }   /* 위쪽 '핀번호로 접속' 버튼과 붙지 않게 */
.emoji-preview { display: inline-block; font-size: 1.4rem; vertical-align: middle; margin-left: .3rem; }
.emoji-search { width: 100%; font-weight: 400; }
.emoji-groups { display: flex; gap: .3rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: thin; }
.chip-btn { font: inherit; font-size: .8rem; font-weight: 600; white-space: nowrap; cursor: pointer; padding: .3rem .6rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.chip-btn:hover { background: var(--hover); }
.chip-btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--text-strong); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; max-height: 260px; overflow: auto; padding: .25rem; border: 1px solid var(--border); border-radius: 10px; }
.emoji-btn { font-size: 1.4rem; aspect-ratio: 1; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.emoji-btn:hover { background: var(--primary-soft); }
.emoji-btn.selected { background: var(--primary-soft); border-color: var(--primary); }
.emoji-btn.taken { opacity: .25; cursor: not-allowed; position: relative; }
.emoji-btn.taken::after { content: "✕"; position: absolute; font-size: .7rem; color: var(--danger); right: 3px; top: 1px; opacity: 1; }

/* ---------- 기타 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  display: flex; align-items: center; gap: .6rem;
  background: var(--toast-bg); color: var(--toast-text);
  padding: .55rem .7rem .55rem 1rem; border-radius: 999px; font-size: .9rem;
  z-index: 100; box-shadow: var(--shadow);
}
.toast-btn {
  font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer; white-space: nowrap;
  padding: .25rem .7rem; border-radius: 999px; border: 1px solid currentColor;
  background: transparent; color: inherit;
}
.toast-btn:active { transform: translateY(1px); }
.recent { margin-top: 1.25rem; }
.recent h3 { font-size: .9rem; margin: 0 0 .4rem; color: var(--muted); }
.recent a { display: flex; justify-content: space-between; align-items: center; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--border); font-size: .9rem; }
.recent a:hover { background: var(--surface); }
.recent code { font-family: ui-monospace, Menlo, monospace; color: var(--muted); }

/* =====================================================================
   모바일 대응
   ===================================================================== */
* { -webkit-tap-highlight-color: transparent; }
button, .btn, .wd-btn, .emoji-btn, .chip-btn, .mini-cell, .cell { touch-action: manipulation; }
.calendar { touch-action: pan-y; }

@media (max-width: 768px) {
  .container { padding: 1rem .75rem 2.5rem; }
  .topbar { padding: .6rem .75rem; }
  .brand { font-size: 1rem; }
  .card { padding: 1rem; border-radius: 12px; }
  .hero { padding: .5rem 0 1.25rem; }
  .hero h1 { font-size: 1.5rem; }
  .hero p { font-size: .9rem; }
  h1 { font-size: 1.3rem; }

  .group-head { flex-direction: column; align-items: stretch; gap: .75rem; }
  .share-box { justify-content: space-between; }
  .share-actions { justify-content: stretch; gap: .5rem; }
  .share-actions .btn.small,
  .share-actions .me-chip { flex: 1; height: 3.3rem; padding: 0 .8rem; font-size: 1.05rem; }
  .recent-share, .recent-del { width: 3rem; font-size: 1.1rem; }

  .legend { top: 3rem; }
  .calendar-toolbar { flex-direction: column; align-items: stretch; gap: .5rem; }
  .toolbar-actions { justify-content: space-between; }
  .toolbar-actions .hint { display: none; }
  .me-chip { justify-content: center; }

  .grid { gap: 4px; }
  .cell { min-height: 82px; padding: .28rem .3rem; border-radius: 8px; gap: .12rem; }
  .cell .day { font-size: .78rem; }
  .cell .day .cnt { font-size: .66rem; padding: 0 .28rem; }
  .cell .emojis { font-size: .88rem; gap: 2px; }
  .cell.today .day::before { display: none; }
  .month { padding: .6rem .55rem .65rem; border-radius: 10px; }
  .month .month-title { font-size: .95rem; }

  .date-row { font-size: .85rem; }
  .date-row .d { width: 5.4rem; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-body { max-width: none; max-height: 94vh; border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); max-height: 38vh; }
  .emoji-btn { font-size: 1.3rem; }
  .modal-actions .btn { flex: 1; }

  .mini-calendar { max-height: 260px; }
  .wd-btn { width: 2.4rem; height: 2.4rem; }
  .toast { bottom: calc(1rem + env(safe-area-inset-bottom)); max-width: 92vw; text-align: center; }
}
@media (max-width: 420px) {
  .row { grid-template-columns: 1fr; }
  .cell { min-height: 80px; }
  .cell .emojis { font-size: .82rem; }
  .topbar-right .btn.small { padding: .35rem .5rem; font-size: .8rem; }
  .btn-label { display: none; }   /* 좁은 화면에서는 아이콘만 */
}

/* ---------- 가능 날짜 빠른 선택(전체/요일) ---------- */
.avail-toggles {
  display: flex; gap: .3rem; align-items: center; margin-bottom: 1rem;
  flex-wrap: nowrap; overflow-x: auto; padding-bottom: .15rem;   /* 한 주가 한 줄에 다 들어가도록 */
}
.avail-toggles .lbl { flex: 0 0 auto; }
.avail-toggles .wd-btn { flex: 0 0 auto; width: 2.05rem; height: 2.05rem; }
.avail-toggles .wd-btn.wide { width: auto; padding: 0 .6rem; }
.avail-toggles .lbl { font-size: .8rem; color: var(--muted); margin-right: .15rem; }
.wd-btn.wide { width: auto; padding: 0 .7rem; }
.wd-btn.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.wd-btn.on.sun, .wd-btn.on.sat { color: var(--primary-text); }
.wd-btn:disabled { opacity: .35; cursor: default; }
.wd-btn:disabled:hover { background: var(--surface); }

/* 범례 = 참여자별 보기 토글 */
.legend .item { font: inherit; font-size: .85rem; color: var(--text); cursor: pointer; transition: opacity .15s, background .15s; }
.legend .item:hover { background: var(--hover); }
.legend .item.off { opacity: .45; text-decoration: line-through; }
.legend .item.off .swatch { background: var(--border) !important; }
.legend .toggle-all { font-weight: 700; }
.legend .legend-note { align-self: center; }

/* 기기 이어하기 코드 */
.handoff-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.7rem; font-weight: 700;
  letter-spacing: .3em; text-align: center; padding: .7rem .5rem .7rem .8rem; user-select: all;
  border: 1px dashed var(--border-dashed); border-radius: 10px; background: var(--surface); color: var(--text-strong);
  margin-bottom: 1.1rem;   /* 아래 버튼과 붙지 않게 */
}
