/* 뀨알이가? 팬카페 배너와 첼시 블루를 맞췄다. 왕관은 채팅의 금색을 쓴다. */
:root {
  --blue: #034694;
  --blue-deep: #123767;
  --masthead-blue: #1e5099;
  --blue-soft: #e7effb;
  --paper: #f4f7fc;
  --card: #ffffff;
  --line: #cddcf0;
  --ink: #0a1730;
  --muted: #506483;
  --gold: #e0a106;
  --chat-ground: #f0f4fb;
  --chat-row: #ffffff;
  --chat-edge: #d9e3f2;
  --chat-ink: #172640;
  --chat-time: #566986;

  --display: "Black Han Sans", "Apple SD Gothic Neo", sans-serif;
  --sans: "IBM Plex Sans KR", system-ui, "Apple SD Gothic Neo", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --radius: 14px;

  /* 공구 단추는 전부 이 높이다. 달 넘기기·보기 토글·밝기 세 덩이가 한 줄에 서므로
     하나라도 어긋나면 바로 눈에 띈다. */
  --control: 44px;
  --on-blue: #fff;
  --sunday: #a93632;
  --sunday-on-blue: #ffd9d5;
  --text-shadow: rgba(0, 0, 0, .7);
  --backdrop: rgba(1, 20, 48, .64);
  --media-ground: #080f1d;
  --media-shade: rgba(8, 15, 29, .58);

  /* 테두리 없는 단추의 호버 바탕.
     불투명한 색(--card)을 깔면 라이트에서는 연파랑 머리말 위에 흰 판이 떠서 멀겋고,
     다크에서는 바탕보다 어두워져 구멍처럼 패인다. 비치는 덧칠이라야 어느 바닥
     위에서도 같은 세기로 눌린 느낌이 난다. */
  --ghost-hover: rgba(3, 70, 148, .12);
  --ghost-press: rgba(3, 70, 148, .2);
  --scroll-thumb: rgba(10, 23, 48, .2);
  --scroll-thumb-hover: rgba(10, 23, 48, .36);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue: #90b8f2;
    --blue-deep: #123767;
    --blue-soft: #152b4d;
    --paper: #091425;
    --card: #111f36;
    --line: #2b4264;
    --ink: #e8eefa;
    --muted: #a9bbd8;
    --gold: #f0bb3c;
    --chat-ground: #0d182b;
    --chat-row: #162540;
    --chat-edge: #2d4263;
    --chat-ink: #e8eefa;
    --chat-time: #a5b7d4;
    --sunday: #ff9d96;
    --ghost-hover: rgba(255, 255, 255, .11);
    --ghost-press: rgba(255, 255, 255, .18);
    --scroll-thumb: rgba(232, 238, 250, .2);
    --scroll-thumb-hover: rgba(232, 238, 250, .38);
  }
}
:root[data-theme="dark"] {
  --blue: #90b8f2;
  --blue-deep: #123767;
  --blue-soft: #152b4d;
  --paper: #091425;
  --card: #111f36;
  --line: #2b4264;
  --ink: #e8eefa;
  --muted: #a9bbd8;
  --gold: #f0bb3c;
  --chat-ground: #0d182b;
  --chat-row: #162540;
  --chat-edge: #2d4263;
  --chat-ink: #e8eefa;
  --chat-time: #a5b7d4;
  --sunday: #ff9d96;
  --ghost-hover: rgba(255, 255, 255, .11);
  --ghost-press: rgba(255, 255, 255, .18);
  --scroll-thumb: rgba(232, 238, 250, .2);
  --scroll-thumb-hover: rgba(232, 238, 250, .38);
}

* { box-sizing: border-box; }

/* 스크롤바. 맥은 평소 숨기지만 윈도우·"항상 보이기" 설정에서는 굵은 회색 띠가
   그대로 드러나 첼시 블루 위에서 혼자 논다. 페이지와 채팅에 같은 결을 입힌다.
   scrollbar-color 를 아는 브라우저가 먼저 먹고, 못 알아듣는 사파리는 아래 ::-webkit 이 받는다. */
html, .chat-lines {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb); border-radius: 999px;
  border: 3px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit; color: inherit; cursor: pointer;
  background: none; border: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

/* ── 머리 ──────────────────────────────────────────────────────── */

#masthead { background: var(--masthead-blue); }
.banner-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(100%, 1080px) minmax(0, 1fr);
}
.banner-band::before,
.banner-band::after {
  content: "";
  background-repeat: repeat-x;
  background-size: 144px 100%;
}
.banner-band::before {
  background-image: url("banner-stripes.png");
  background-position: right top;
}
.banner-band::after {
  background-image: url("banner-stripes-right.png");
  background-position: left top;
}
#banner {
  display: block;
  width: 100%;
  height: auto;
}
.archive-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  margin-bottom: 12px;
}
.controls {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  display: flex;
  align-items: center;
  /* 보기 토글과 밝기 단추는 하는 일이 전혀 달라서 붙여 두면 한 덩이로 읽힌다. */
  gap: 16px;
}
.switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
}
.switch button, #theme {
  display: grid;
  place-items: center;
  color: var(--muted);
}
.switch button {
  /* 테두리(1)와 안쪽 여백(3)을 빼야 알약 바깥 높이가 --control 과 같아진다. */
  width: calc(var(--control) - 8px);
  height: calc(var(--control) - 8px);
  border-radius: 999px;
}
.switch button[aria-pressed="true"] {
  background: var(--blue-soft);
  color: var(--blue);
}
.switch button:hover, #theme:hover { color: var(--blue); }
#theme {
  width: var(--control);
  height: var(--control);
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
}
.controls svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.controls svg[hidden] { display: none; }

@media (max-width: 619px) {
  :root { --control: 38px; }
  .archive-toolbar { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .archive-toolbar .controls { grid-column: 2; gap: 8px; }
  .archive-toolbar .month-head { grid-column: 1; justify-content: start; gap: 4px; }
  .archive-toolbar .month-head h2 { min-width: 0; font-size: 1.05rem; white-space: nowrap; }
  /* 폭만 줄인다. 높이를 따로 주면 옆 단추들과 밑줄이 어긋난다. */
  .archive-toolbar .month-head button { flex: 0 0 30px; width: 30px; }
}

/* ── 본문 ──────────────────────────────────────────────────────── */

main { max-width: 1080px; margin-inline: auto; padding: 18px 16px 56px; }

#empty { color: var(--muted); padding: 32px 0; text-align: center; }
#empty[hidden], #month[hidden], #feed[hidden], #day[hidden] { display: none; }

/* ── 달력 ──────────────────────────────────────────────────────── */

.month-head {
  grid-column: 2;
  grid-row: 1;
  display: flex; align-items: center; justify-content: center; gap: 14px;
}
.month-head[hidden] { display: none; }
.month-head h2 {
  margin: 0; font-family: var(--display); font-weight: 400;
  font-size: 1.35rem; min-width: 7.5em; text-align: center;
}
.month-head button {
  width: var(--control); height: var(--control); border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  font-size: 1.1rem; color: var(--muted);
  display: grid; place-items: center;
}
.month-head button:hover { border-color: var(--blue); color: var(--blue); }
.month-head button:disabled { opacity: .35; cursor: default; }

.weekdays, .grid { list-style: none; margin: 0; padding: 0; }
.weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  text-align: center; color: var(--muted);
  font-size: .72rem; font-weight: 600; padding-bottom: 5px;
}
.weekdays li:first-child { color: var(--sunday); }

.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
@media (min-width: 620px) { .grid { gap: 8px; } }

.cell {
  position: relative; aspect-ratio: 3 / 4;
  border-radius: 9px; overflow: hidden;
  background: var(--card); border: 1px solid var(--line);
}
.cell.blank { background: none; border: 0; }
.cell .num {
  position: absolute; inset: 4px auto auto 6px; z-index: 2;
  font: 500 .74rem/1 var(--mono); color: var(--muted);
}
/* 썸네일 위에 덮개를 깔지 않는다 — 사진을 가린다. 날짜는 글자 그림자로만 띄운다. */
.cell.has .num { color: var(--on-blue); text-shadow: 0 1px 2px var(--text-shadow), 0 0 6px var(--text-shadow); }
.cell.sun .num { color: var(--sunday); }
.cell.has.sun .num { color: var(--sunday-on-blue); }

.cell button.open {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; padding: 0;
}
.cell img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.cell button.replay-art, .row .thumb.replay-art, #still-pending {
  background: linear-gradient(rgb(8 15 29 / 24%), rgb(8 15 29 / 64%)),
              url("banner.png") 40% center / auto 100% no-repeat var(--blue-deep);
}
.cell .pending-label {
  position: absolute; inset: auto 2px 4px;
  padding: 3px 0; border-radius: 4px;
  color: #fff; background: rgb(8 15 29 / 82%);
  text-align: center; white-space: nowrap;
  font-size: clamp(.625rem, 2.1vw, .75rem);
  font-weight: 600; line-height: 1.2;
}
.cell.has.no-img { background: var(--blue-deep); }
.cell.has:hover { border-color: var(--blue); }

/* ── 목록 ──────────────────────────────────────────────────────── */

#feed { display: grid; gap: 10px; }
/* 행에 담긴 말이 줄어서 넓은 화면에서는 한 줄이 휑하다. 두 칸으로 접는다. */
/* 두 칸은 880px 부터. 그보다 좁으면 한 행이 날짜와 칩을 겨우 붙여 놓은 꼴이 된다. */
@media (min-width: 880px) {
  #feed { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  /* 두 칸이 되면 한 행이 절반 폭이다. 썸네일을 vw 로 잡으면 글자 자리를 다 먹는다. */
  .row { grid-template-columns: 132px minmax(0, 1fr) auto auto; }
}
@media (min-width: 1000px) { .row { grid-template-columns: 164px minmax(0, 1fr) auto auto; } }
/* 목록 행은 "그날이 있었다"는 사실만 전한다 — 짤 한 장, 날짜, 채팅 유무.
   무슨 말을 했는지는 열어 봐야 할 일이라 여기 미리 흘리지 않는다. */
.row {
  display: grid; width: 100%; align-items: center;
  grid-template-columns: clamp(96px, 26vw, 168px) minmax(0, 1fr) auto auto;
  gap: clamp(10px, 2.2vw, 18px);
  padding: 10px clamp(10px, 1.6vw, 16px) 10px 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); text-align: start;
  transition: border-color .12s ease, background-color .12s ease;
}
.row:hover { border-color: var(--blue); background: var(--blue-soft); }
@media (prefers-reduced-motion: reduce) { .row { transition: none; } }

.row .thumb {
  display: grid; place-items: center; overflow: hidden;
  background: var(--blue-deep); border-radius: 10px; aspect-ratio: 16 / 9;
}
.row .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row .thumb .none { color: var(--on-blue); font-size: .68rem; }
.row .thumb.replay-art .none {
  padding: 2px 5px; background: rgb(8 15 29 / 78%);
  border-radius: 4px; text-align: center;
}

.row .side { display: grid; gap: 1px; min-width: 0; }
/* 날짜는 절대 쪼개지면 안 된다 — 좁은 칸에서 "11 / 월 / 12 / 일" 로 흩어진다. */
.row .d {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(1rem, 3vw, 1.35rem); line-height: 1.15;
  letter-spacing: .01em; white-space: nowrap;
}
.row .wd { color: var(--muted); font-size: .76rem; font-weight: 500; white-space: nowrap; }
.row .wd.sun { color: var(--sunday); }

/* 채팅이 남았는지 아닌지. 남은 날은 금색, 없는 날은 조용히 비워 둔다. */
.row .mark {
  font: 500 .74rem/1 var(--mono); white-space: nowrap;
  padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: transparent;
}
.row .mark.yes { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }

@media (max-width: 420px) {
  .row { gap: 10px; padding: 8px; }
  .row .mark { padding: 5px 8px; font-size: .68rem; }
}
.row-arrow { color: var(--blue); font-size: 1.45rem; line-height: 1; }

/* ── 하루 보기 ─────────────────────────────────────────────────── */

#day {
  position: fixed; inset: 0; z-index: 50;
  background: var(--backdrop);
  display: grid; align-items: end; justify-items: center;
  backdrop-filter: blur(3px);
}
@media (min-width: 760px) { #day { align-items: center; justify-items: center; padding: 24px; } }

/* 높이를 미리 못박는다. 채팅이 길어져도 시트는 안 늘어나고 안쪽만 구른다. */
.sheet {
  position: relative; background: var(--paper);
  width: 100%; max-width: 940px;
  height: 90dvh;
  border-radius: 18px 18px 0 0; overflow: hidden;
  display: flex; flex-direction: column; min-height: 0;
  animation: up .2s ease both;
}
/* 가로 화면에서는 영상이 제 몫을 하도록 시트를 넓고 낮게 잡는다.
   높이를 키울수록 16:9 영상 위아래로 흐린 여백만 늘어난다. */
@media (min-width: 760px) { .sheet { border-radius: 18px; height: min(620px, 88dvh); max-width: min(1120px, 94vw); } }
@keyframes up { from { transform: translateY(14px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#still {
  margin: 0; width: 100%; flex: 0 0 auto;
  height: min(56.25vw, 32dvh); background: var(--media-ground);
}
#still :is(img, video) { display: block; width: 100%; height: 100%; object-fit: contain; }
#still[hidden], #still [hidden] { display: none; }
#still-pending {
  position: relative; height: 100%;
  display: grid; align-items: end; justify-items: center;
  padding: clamp(12px, 3vw, 26px);
}
#still-pending span {
  color: #fff; background: rgb(8 15 29 / 82%);
  border: 1px solid rgb(255 255 255 / 40%);
  border-radius: 999px; padding: 7px 14px;
  font-size: clamp(.85rem, 2.5vw, 1rem); font-weight: 600;
}

.talk {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; flex: 1;
  border-top: 1px solid var(--line);
}
@media (min-width: 880px), (min-width: 560px) and (orientation: landscape) {
  .sheet-body { flex-direction: row; }
  #still { width: 60%; height: auto; min-height: 0; position: relative; overflow: hidden; }
  /* 가로 화면에서 영상 비율을 유지하고, 남는 면에는 포스터 색을 잇는다. */
  #still::before {
    content: ""; position: absolute; inset: -20px;
    background: linear-gradient(var(--media-shade), var(--media-shade)), var(--still-poster, none) center / cover;
    filter: blur(16px);
  }
  #still :is(img, video) { position: absolute; inset: 0; }
  .talk { border-top: 0; }
  #still:not([hidden]) + .talk { border-left: 1px solid var(--line); }
}

.talk-head {
  flex: 0 0 auto; display: grid; gap: 8px;
  padding: 8px 12px; background: var(--blue-soft);
  border-bottom: 1px solid var(--line);
}
.talk-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#day-date { margin: 0; font-size: clamp(.95rem, 3vw, 1.12rem); font-weight: 700; }
/* 네 단추는 성격이 둘로 갈린다. 재생은 화면을 바꾸는 토글이고, 나머지 셋은 파일을
   꺼내 가는 일이다. 테두리를 두르는 대신 "재생 — 사이 띄움 — 저장 셋" 의 거리만으로
   묶음을 드러낸다. 머리말이 이미 색면이라 선을 더하면 지저분해진다. */
.talk-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.talk-actions[hidden], .talk-actions [hidden], #export-status[hidden] { display: none; }
.save-group { display: flex; gap: 2px; }

.act, #close {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; flex: 0 0 36px;
  background: none; border: 0; color: var(--muted);
  border-radius: 10px; padding: 0; text-decoration: none;
  transition: background-color .12s ease, color .12s ease;
}
.act svg {
  width: 19px; height: 19px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.act svg.solid { fill: currentColor; stroke: none; }
.act:hover, #close:hover { background: var(--ghost-hover); color: var(--blue); }
.act:active, #close:active { background: var(--ghost-press); }
.act:focus-visible, #close:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.act:disabled { opacity: .45; cursor: wait; }
#close { border-radius: 50%; font-size: .9rem; }
#replay[aria-pressed="true"] { background: var(--ghost-hover); color: var(--blue); }
@media (prefers-reduced-motion: reduce) { .act, #close { transition: none; } }
#export-status { margin: 0; color: var(--muted); font-size: .74rem; }
/* 채팅이 없는 날. 자리를 억지로 채우지 않는다 — 시트 자체가 짤 높이로 줄어든다. */
.chat-empty {
  display: grid; place-content: center; gap: 4px;
  min-height: 0; flex: 1; padding: 28px 16px; text-align: center; background: var(--chat-ground);
}
.chat-empty[hidden], .chat-lines[hidden] { display: none; }
.chat-empty p { margin: 0; color: var(--muted); font-size: .84rem; }

.chat-lines {
  list-style: none; margin: 0; padding: 10px 10px 16px;
  display: flex; flex-direction: column; gap: 5px;
  flex: 1; min-height: 0; overflow-y: auto;
  background: var(--chat-ground);
  overscroll-behavior: contain;
}

.chat-lines li {
  background: var(--chat-row);
  border: 1px solid var(--chat-edge);
  border-radius: 10px; padding: 7px 11px 8px;
  display: grid; grid-template-columns: auto auto 1fr; gap: 2px 8px;
  align-items: center;
  animation: pop .16s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .chat-lines li { animation: none; } }

.chat-lines .tm {
  font: 500 .7rem/1 var(--mono); color: var(--chat-time);
  font-variant-numeric: tabular-nums;
}
.chat-lines .who {
  display: flex; align-items: center; gap: 5px;
  font-size: .78rem; font-weight: 600; color: var(--gold);
  white-space: nowrap;
}
.chat-lines .who svg { width: 14px; height: 14px; display: block; }
.chat-lines .tx {
  grid-column: 1 / -1; min-width: 0; word-break: break-word;
  font-size: .93rem; color: var(--chat-ink); line-height: 1.5;
}
@media (min-width: 420px) {
  .chat-lines li { grid-template-columns: auto auto minmax(0, 1fr); }
  .chat-lines .tx { grid-column: 3; }
}
.chat-lines .tx img { width: 27px; height: 27px; object-fit: contain; vertical-align: -8px; }
.chat-lines .ph {
  display: inline-block; background: var(--blue-soft); color: var(--blue);
  border-radius: 5px; padding: 0 6px; font-size: .76rem; font-weight: 500;
}
