:root {
  --wall: #e9e4da;
  --wall-ink: #2b2722;
  --muted: #6f675c;
  --mat: #fbfaf7;
  --frame: #1d1a17;
  --film: #151413;
  --film-ink: #8a8378;
  --paper: #ffffff;
  --accent: #b5482f;
  --serif: "Iowan Old Style", "Apple Garamond", "Nanum Myeongjo", "Batang", Georgia, serif;
  --sans: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--wall);
  color: var(--wall-ink);
  font-family: var(--sans);
  line-height: 1.5;
}

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

/* 머리말 */
.top {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  align-items: end;
  justify-content: space-between;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 1.25rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
  letter-spacing: .08em;
}

h1 {
  margin: .2rem 0 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -.01em;
}

#year-label { color: var(--accent); }

.count {
  margin: .3rem 0 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}
.count strong { font-weight: 600; }

.tools { display: grid; gap: .5rem; justify-items: end; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: flex-end; }

.btn, .view-btn {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0 1rem;
  border: 1px solid var(--wall-ink);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
  font-size: .92rem;
  white-space: nowrap;
  transition: background-color .15s, color .15s;
}
.btn:hover { background: rgba(43, 39, 34, .07); }
.btn.primary { background: var(--wall-ink); color: var(--mat); }
.btn.primary:hover { background: #000; }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
label.btn:focus-within, .btn:focus-visible, .view-btn:focus-visible, .cell:focus-visible,
.bar:focus-visible, .menu > :focus-visible, .menu label:focus-within, .field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .92rem;
  color: var(--muted);
}
.field select {
  min-height: 2.5rem;
  padding: 0 .6rem;
  border: 1px solid var(--wall-ink);
  border-radius: 2px;
  background: transparent;
  color: var(--wall-ink);
  cursor: pointer;
}

.views { display: inline-flex; }
.view-btn { border-radius: 0; }
.view-btn + .view-btn { border-left: 0; }
.view-btn[aria-pressed="true"] { background: var(--wall-ink); color: var(--mat); }

/* 더보기 메뉴 */
.more { position: relative; }
.more summary { list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 5;
  display: grid;
  min-width: 12rem;
  padding: .35rem;
  background: var(--paper);
  box-shadow: 0 12px 30px rgba(30, 20, 10, .22);
}
.menu > button, .menu > label {
  display: block;
  padding: .65rem .8rem;
  border: 0;
  background: none;
  text-align: left;
  font-size: .92rem;
  cursor: pointer;
}
.menu > button:hover, .menu > label:hover { background: var(--wall); }
.menu > button:disabled { opacity: .4; cursor: not-allowed; background: none; }
.menu .danger { color: var(--accent); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

/* 달마다 넣은 사진 수 */
.bars {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  margin-bottom: .75rem;
}
.bar {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: .72rem;
  color: var(--muted);
}
.bar-track {
  position: relative;
  width: 100%;
  height: 34px;
  background: rgba(43, 39, 34, .07);
}
.bar-track::after { /* 한 달 목표선(8장) */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--target) * 100%);
  border-top: 1px dashed rgba(43, 39, 34, .45);
}
.bar-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--h) * 100%);
  background: var(--wall-ink);
  transition: height .3s;
}
.bar.full .bar-fill { background: var(--accent); }
.bar-n { font-variant-numeric: tabular-nums; color: var(--wall-ink); font-weight: 600; }
.bar.empty .bar-n { color: var(--muted); font-weight: 400; }
.bar:hover .bar-track { background: rgba(43, 39, 34, .13); }

.notice {
  min-height: 1.5rem;
  margin: 0 0 .75rem;
  color: var(--accent);
  font-size: .92rem;
}

.privacy {
  max-width: 40rem;
  margin: 2rem auto 0;
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
}
.privacy strong { font-weight: 600; color: var(--wall-ink); }

/* 액자: 검은 틀 + 흰 매트 */
.frame {
  padding: clamp(10px, 1.6vw, 18px);
  background: var(--frame);
  box-shadow: 0 1px 0 #000, 0 24px 50px -20px rgba(30, 20, 10, .55);
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 10), 1fr);
  gap: clamp(4px, 1vw, 12px);
  padding: clamp(14px, 4vw, 48px);
  background: var(--mat);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), inset 0 2px 8px rgba(0, 0, 0, .08);
}

/* 칸 한 개 = 앞면(폴라로이드)과 뒷면(필름)을 가진 카드 */
.cell {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 0.82;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 600px;
}

.card {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.3, .7, .2, 1);
  transition-delay: var(--delay, 0s);
}
.cell.filled .card { transform: rotateY(180deg); }
.no-anim .card { transition: none; }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.back {
  display: grid;
  place-items: center;
  background: var(--film);
  color: var(--film-ink);
  font-family: var(--serif);
  font-size: clamp(.5rem, 1.1vw, .8rem);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.cell:hover .back { color: var(--mat); }

.front {
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  padding: 7% 7% 0;
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}
.front img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #ddd;
}
.front .stamp {
  flex: 1;
  display: grid;
  place-items: center;
  font-size: clamp(.4rem, .8vw, .62rem);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

/* 자리 바꾸기 */
.grid.swapping .cell { cursor: crosshair; }
.grid.swapping .cell:hover .card { outline: 2px dashed var(--accent); outline-offset: 2px; }
.cell.picked .card { outline: 3px solid var(--accent); outline-offset: 3px; transform: rotateY(180deg) scale(.94); }

/* 월별 보기 */
.months { display: grid; gap: 2.5rem; }
.month { scroll-margin-top: 1rem; }
.month h2 {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  margin: 0 0 .9rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid rgba(43, 39, 34, .25);
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.4rem;
}
.month h2 small { font-family: var(--sans); font-size: .85rem; color: var(--muted); }
.month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}
.month-grid .front .stamp { font-size: .72rem; }
.month-grid .memo {
  margin: .3rem 0 0;
  font-size: .8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty-state {
  padding: 4rem 1rem;
  text-align: center;
  color: var(--muted);
}

/* 사진 놓기 안내 */
.drop-hint {
  position: fixed;
  inset: 1rem;
  display: grid;
  place-items: center;
  border: 2px dashed var(--wall-ink);
  background: rgba(233, 228, 218, .92);
  font-family: var(--serif);
  font-size: 1.6rem;
  pointer-events: none;
  z-index: 10;
}

/* 대화 상자 공통 */
dialog { color: var(--wall-ink); }
dialog::backdrop { background: rgba(20, 16, 12, .6); }

/* 한 장 자세히 */
.detail {
  width: min(92vw, 760px);
  padding: 0;
  border: 0;
  background: var(--paper);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
.detail form {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
}
.crop-wrap {
  display: grid;
  align-content: center;
  gap: .5rem;
  padding: 1.25rem;
  background: var(--film);
}
.crop {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  outline-offset: 3px;
}
.crop.dragging { cursor: grabbing; }
.crop:focus-visible { outline: 2px solid var(--accent); }
.crop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.crop-hint { margin: 0; text-align: center; font-size: .8rem; color: var(--film-ink); }
.detail-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
}
.detail-no {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.3rem;
}
.detail label, .sheet legend { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); }
.detail input {
  min-height: 2.5rem;
  padding: 0 .6rem;
  border: 1px solid #cfc8bc;
  border-radius: 2px;
  background: #fff;
  color: var(--wall-ink);
}
.detail input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.detail-actions { display: flex; gap: .4rem; margin-top: auto; }
.spacer { flex: 1; }

/* 저장·공유 */
.sheet {
  width: min(92vw, 420px);
  padding: 1.5rem;
  border: 0;
  background: var(--paper);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
.sheet h2 { margin: 0 0 1rem; font-family: var(--serif); font-weight: 500; font-size: 1.4rem; }
.sheet fieldset { display: grid; gap: .25rem; margin: 0; padding: 0; border: 0; }
.sheet legend { margin-bottom: .4rem; }
.sheet fieldset label {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 2.75rem;
  padding: 0 .75rem;
  border: 1px solid #e2ddd3;
  cursor: pointer;
}
.sheet fieldset label:has(input:checked) { border-color: var(--wall-ink); background: var(--wall); }
.sheet input[type=radio] { accent-color: var(--wall-ink); width: 1.1rem; height: 1.1rem; }
.sheet-note { margin: 1rem 0 1.25rem; font-size: .82rem; color: var(--muted); }

/* 1년 돌려보기 */
.show {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #0e0d0c;
  color: var(--mat);
}
.show[open] { display: grid; grid-template-rows: 1fr auto auto; }
.show::backdrop { background: #0e0d0c; }
.show-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem 0;
  cursor: pointer;
}
.show-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  opacity: 0;
  transform: scale(.985);
  transition: opacity .5s, transform .8s;
}
.show-stage img.in { opacity: 1; transform: none; }
.show-caption { padding: 1rem 1.25rem 0; text-align: center; }
.show-date { margin: 0; font-family: var(--serif); font-size: 1.3rem; }
.show-memo { margin: .25rem 0 0; min-height: 1.5em; color: #c9c2b6; }
.show-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .75rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
.show-controls button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: 1px solid rgba(251, 250, 247, .35);
  border-radius: 2px;
  background: none;
  color: var(--mat);
  font-size: 1.1rem;
  cursor: pointer;
}
.show-controls button:hover { background: rgba(251, 250, 247, .1); }
.show-controls button:focus-visible { outline: 2px solid var(--mat); outline-offset: 2px; }
.show-count { min-width: 5rem; text-align: center; font-variant-numeric: tabular-nums; color: #c9c2b6; font-size: .9rem; }

@media (max-width: 640px) {
  .top { padding-top: 1.75rem; }
  .tools, .row { justify-items: start; justify-content: flex-start; }
  .btn, .view-btn { padding: 0 .8rem; }
  .menu { right: auto; left: 0; }
  .bar-m { font-size: .62rem; }
  .detail form { grid-template-columns: 1fr; }
  .crop-wrap { padding: .75rem; }
  .crop { width: min(100%, 52vh); justify-self: center; }
  .front .stamp { display: none; }
  .front { padding-bottom: 12%; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .bar-fill, .show-stage img { transition: none; }
}
