/* ════════════════════════════════════════════════════════════
   모두의 우편함 — 공통 디자인 시스템
   BESPOKE 부서 맞춤형 조직문화 프로그램 (한국수자원공사)

   원칙
     · 파랑(K-water Blue)은 면이 아니라 잉크로 쓴다
     · 주황(K-water Orange)은 항공우편 띠 · 소인 · 공감 숫자 세 곳에만
     · 모서리 2px, 카드보다 괘선
     · 읽는 문장은 15px 이상, weight 300 금지 (부장급 이상 참가자)
     · 이모지 없음
   ════════════════════════════════════════════════════════════ */

:root {
  --paper:   #FAF6EF;
  --paper-2: #F3ECE1;
  --surface: #FFFDF9;
  --ink:     #10202F;
  --ink-2:   #33455A;
  --muted:   #5C6875;
  --rule:    #D6CBBA;
  --rule-2:  #E7DED0;

  --blue:    #005596;   /* K-water Blue */
  --blue-2:  #003D6E;
  --seal:    #C96518;   /* K-water Orange 를 인쇄 잉크로 누른 값 */
  --ok:      #1F7A4D;
  --warn:    #B0451B;

  --logo-plate: transparent;
  --grain: .05;

  --f-title:  "Hahmlet", "Nanum Myeongjo", serif;
  --f-body:   "IBM Plex Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --f-letter: "Gowun Batang", "Nanum Myeongjo", serif;   /* 편지 본문 전용 */
  --f-reg:    "IBM Plex Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0D141C; --paper-2: #121A24; --surface: #16202B;
    --ink: #F0EAE0; --ink-2: #C6CFD9; --muted: #9DAAB7;
    --rule: #33404E; --rule-2: #232F3B;
    --blue: #7BC0EC; --blue-2: #A6D6F4; --seal: #F6A051;
    --ok: #5FC38E; --warn: #F0885A;
    --logo-plate: #FFFFFF; --grain: .07;
  }
}
:root[data-theme="dark"] {
  --paper: #0D141C; --paper-2: #121A24; --surface: #16202B;
  --ink: #F0EAE0; --ink-2: #C6CFD9; --muted: #9DAAB7;
  --rule: #33404E; --rule-2: #232F3B;
  --blue: #7BC0EC; --blue-2: #A6D6F4; --seal: #F6A051;
  --ok: #5FC38E; --warn: #F0885A;
  --logo-plate: #FFFFFF; --grain: .07;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

/* ── 종이 결 ── */
.grain {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  opacity: var(--grain);
  background-image: 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='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── 항공우편 띠 ── */
.airmail {
  height: 6px; flex: none;
  background: repeating-linear-gradient(-45deg,
    var(--blue) 0 10px, var(--paper) 10px 20px,
    var(--seal) 20px 30px, var(--paper) 30px 40px);
}

/* ── 브랜드바 ── */
.brandbar {
  flex: none; display: flex; align-items: center; gap: 11px;
  padding: 9px 22px; border-bottom: 1px solid var(--rule-2); background: var(--paper);
}
.bb-logo {
  display: block; height: 30px; width: auto;
  background: var(--logo-plate); border-radius: 2px; padding: 2px 4px;
}
.bb-div { width: 1px; align-self: stretch; background: var(--rule); flex: none; }
.bb-name {
  font-family: var(--f-title); font-weight: 600; font-size: 15px;
  letter-spacing: -.015em; color: var(--ink);
  display: flex; align-items: center; gap: 9px; min-width: 0;
}
.bb-bespoke {
  font-family: var(--f-reg); font-size: 10px; font-weight: 600;
  letter-spacing: .16em; color: var(--seal); flex: none;
}
@media (max-width: 400px) {
  .brandbar { padding-left: 18px; padding-right: 18px; gap: 9px; }
  .bb-logo { height: 26px; }
  .bb-name { font-size: 14px; gap: 7px; }
}

/* ── 작은 라벨 (레지스터) ── */
.reg {
  font-family: var(--f-reg); font-size: 11.5px; font-weight: 600;
  letter-spacing: .16em; color: var(--ink-2);
}
.kicker { display: flex; align-items: center; gap: 13px; margin: 0 0 22px; }
.kicker::after { content: ""; height: 1px; flex: 1; background: var(--rule); }

/* ── 제목 ── */
h1, h2, h3 { font-family: var(--f-title); font-weight: 600; letter-spacing: -.028em; margin: 0; text-wrap: balance; }
.h-hero { font-size: clamp(46px, 12vw, 74px); line-height: 1.1; letter-spacing: -.035em; }
.h-page { font-size: clamp(25px, 6vw, 33px); line-height: 1.38; }
.h-q     { font-size: clamp(25px, 6.6vw, 29px); line-height: 1.42; letter-spacing: -.03em; }
.lede { font-size: 16.5px; color: var(--muted); line-height: 1.95; margin: 24px 0 0; text-wrap: pretty; }
.sub  { font-size: 15px; color: var(--muted); line-height: 1.85; margin: 11px 0 0; }

/* ── 버튼 ── */
.btn {
  font-family: var(--f-body); font-size: 14.5px; font-weight: 500;
  border: 1px solid var(--rule); border-radius: 2px;
  background: transparent; color: var(--ink-2);
  padding: 11px 16px; min-height: 46px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .15s, color .15s, background .15s;
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn[disabled]:hover { border-color: var(--rule); color: var(--muted); }

.btn-solid {
  background: var(--blue); border-color: var(--blue); color: var(--paper);
  font-weight: 600; font-size: 17px; padding: 16px 26px; min-height: 56px;
}
.btn-solid:hover { background: var(--blue-2); border-color: var(--blue-2); color: var(--paper); }
.btn-solid[disabled], .btn-solid[disabled]:hover {
  background: transparent; border-color: var(--rule); color: var(--muted);
}
:root[data-theme="dark"] .btn-solid { color: #0D141C; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-solid { color: #0D141C; }
}

.btn-warn { border-color: var(--seal); color: var(--seal); }
.btn-warn:hover { border-color: var(--seal); color: var(--seal); background: color-mix(in srgb, var(--seal) 8%, transparent); }
.btn-seal { background: var(--seal); border-color: var(--seal); color: var(--paper); font-weight: 600; }
:root[data-theme="dark"] .btn-seal { color: #0D141C; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-seal { color: #0D141C; } }
.btn-go { background: var(--ok); border-color: var(--ok); color: #FFF9F2; font-weight: 600; }
.btn-sm { font-size: 13.5px; padding: 8px 12px; min-height: 40px; }
.btn-wide { width: 100%; }
.btn-ghost { font-size: 15.5px; padding: 14px 20px; min-height: 52px; width: 100%; }

.link {
  background: none; border: 0; padding: 8px 0; min-height: 36px;
  font-family: var(--f-body); font-size: 13.5px; color: var(--blue); cursor: pointer;
}
.link:hover { text-decoration: underline; }
.rowbtns { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 15px; }

/* ── 카드 · 괘선 ── */
.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 2px;
  padding: 20px 22px 22px; margin-bottom: 16px;
}
.card-k {
  font-family: var(--f-reg); font-size: 11px; font-weight: 600; letter-spacing: .14em;
  color: var(--muted); margin: 0 0 14px; display: flex; align-items: baseline; gap: 11px;
}
.card-k::after { content: ""; height: 1px; flex: 1; background: var(--rule-2); align-self: center; }

/* ── 입력 ── */
.f { display: flex; flex-direction: column; gap: 7px; }
.f label {
  font-family: var(--f-reg); font-size: 11px; font-weight: 600;
  letter-spacing: .14em; color: var(--ink-2);
}
.f input, .f select, .f textarea {
  font-family: var(--f-body); font-size: 16px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule); border-radius: 2px;
  padding: 12px 14px; min-height: 50px;
}
.f input:focus, .f select:focus, .f textarea:focus {
  outline: none; border-color: var(--blue); background: var(--surface);
}
.f .hint { font-size: 13px; color: var(--muted); line-height: 1.7; }
.fgrid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .fgrid { grid-template-columns: 1fr 1fr; } }
.f-full { grid-column: 1 / -1; }

/* ── 편지 ── */
.letter-body {
  font-family: var(--f-letter); font-size: 17px; line-height: 2.05;
  color: var(--ink); margin: 0;
}
.sheet textarea {
  display: block; width: 100%; min-height: 272px; resize: none; overflow: hidden;
  font-family: var(--f-letter); font-size: 17px; line-height: 34px; color: var(--ink);
  background-color: var(--surface);
  background-image: linear-gradient(var(--rule-2) 1px, transparent 1px);
  background-size: 100% 34px; background-position: 0 47px; background-attachment: local;
  border: 1px solid var(--rule); border-radius: 1px; padding: 14px 16px 18px;
  transition: border-color .15s, box-shadow .15s;
}
.sheet textarea::placeholder { color: var(--rule); }
.sheet textarea:focus { outline: none; border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }

/* ── 진행률 ── */
.bar { height: 7px; background: var(--rule-2); border-radius: 4px; overflow: hidden; margin: 7px 0 9px; }
.bar i { display: block; height: 100%; background: var(--blue); border-radius: 4px; transition: width .3s; }
.bar.full i { background: var(--ok); }
.prog-k { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 15px; color: var(--ink-2); }
.prog-k b { font-family: var(--f-reg); font-weight: 600; color: var(--blue); }
.prog-d { font-size: 13.5px; color: var(--muted); margin: 0 0 18px; line-height: 1.7; }
.prog-d b { color: var(--seal); font-weight: 600; }

/* ── 모달 ── */
.back {
  position: fixed; inset: 0; z-index: 100; background: rgba(10,18,26,.64);
  display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 540px; margin: auto;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 2px;
  box-shadow: 0 40px 90px -45px rgba(0,0,0,.65);
}
.modal.lg { max-width: 720px; }
.m-top { padding: 22px 24px 16px; border-bottom: 1px solid var(--rule-2); }
.m-k { font-family: var(--f-reg); font-size: 11px; font-weight: 600; letter-spacing: .16em; color: var(--seal); display: block; margin-bottom: 6px; }
.m-t { font-size: 22px; line-height: 1.4; }
.m-d { font-size: 14.5px; color: var(--muted); margin: 8px 0 0; line-height: 1.8; }
.m-d b { color: var(--seal); font-weight: 600; }
.m-in { padding: 20px 24px 22px; }
.m-acts { display: flex; gap: 10px; padding: 0 24px 22px; flex-wrap: wrap; }
.m-acts .btn { flex: 1; min-width: 120px; }

.warnbox { margin-top: 16px; padding: 14px 16px; border: 1px solid var(--seal); border-left-width: 2px; border-radius: 2px; font-size: 14.5px; line-height: 1.75; }
.warnbox b { color: var(--seal); font-weight: 600; }
.okbox { margin-top: 16px; padding: 14px 16px; border: 1px solid var(--ok); border-left-width: 2px; border-radius: 2px; font-size: 14.5px; line-height: 1.75; }
.okbox b { color: var(--ok); font-weight: 600; }

/* ── 알림 띠 ── */
.alert {
  position: relative; z-index: 3; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 22px; font-size: 14.5px; font-weight: 500;
}
.alert-off { background: var(--warn); color: #FFF9F2; }
.alert-off .btn { border-color: #FFF9F2; color: #FFF9F2; }
.alert-seal { background: color-mix(in srgb, var(--seal) 14%, var(--paper)); border-bottom: 1px solid var(--rule-2); }
.alert-blue { background: color-mix(in srgb, var(--blue) 12%, var(--paper)); border-bottom: 1px solid var(--rule-2); }
.alert .sp { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; animation: mp-pulse 1.2s infinite; }
.alert small { font-weight: 400; opacity: .9; font-size: 13.5px; }
.alert .btn { margin-left: auto; }
@keyframes mp-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ── 안내 토스트 ── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 92px; z-index: 200;
  background: var(--ink); color: var(--paper); border-radius: 2px;
  padding: 13px 20px; font-size: 14.5px; max-width: 88vw; text-align: center;
}
:root[data-theme="dark"] .toast { background: var(--surface); color: var(--ink); border: 1px solid var(--rule); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast { background: var(--surface); color: var(--ink); border: 1px solid var(--rule); }
}

/* ── 소인 ── */
.stamp { color: var(--seal); flex: none; }
.stamp svg { display: block; }

/* ── 봉투 열림 연출 ── */
.opening {
  position: fixed; inset: 0; z-index: 150; background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 30px;
}
.env3d { position: relative; width: 250px; height: 166px; perspective: 950px; }
.e-back, .e-front, .e-flap { position: absolute; background: var(--paper-2); border: 1px solid var(--rule); }
.e-back { inset: 0; border-radius: 2px; z-index: 1; }
.e-paper {
  position: absolute; left: 15px; right: 15px; top: 17px; height: 136px; z-index: 2;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 1px;
  padding: 16px 17px; overflow: hidden;
  animation: mp-paper .72s .46s cubic-bezier(.2,.9,.28,1) both;
}
.e-paper i { display: block; height: 1px; background: var(--rule-2); margin-bottom: 15px; }
.e-front { inset: 0; border-radius: 2px; z-index: 3; clip-path: polygon(0 28%, 50% 74%, 100% 28%, 100% 100%, 0 100%); }
.e-flap {
  left: -1px; right: -1px; top: 0; height: 68%; z-index: 4;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center; backface-visibility: hidden;
  animation: mp-flap .5s cubic-bezier(.4,.05,.25,1) both;
}
.e-stamp { position: absolute; right: 13px; bottom: 13px; z-index: 5; color: var(--seal); }
.opening-n {
  font-family: var(--f-reg); font-size: 12px; font-weight: 600; letter-spacing: .2em;
  color: var(--muted); margin: 0; animation: mp-fade .45s .84s both;
}
@keyframes mp-flap { from { transform: rotateX(0deg); } to { transform: rotateX(-168deg); } }
@keyframes mp-paper { from { transform: translateY(0) scale(1); } to { transform: translateY(-70px) scale(1.04); } }
@keyframes mp-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .e-flap { transform: rotateX(-168deg); }
  .e-paper { transform: translateY(-70px); }
  .alert .sp { opacity: .7; }
}

/* ════════════════════════════════════════════════════════════
   참가자 화면 — 폰이 주 사용처
   ════════════════════════════════════════════════════════════ */
.phone {
  position: relative; min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; background: var(--paper);
}
.app-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 22px; border-bottom: 1px solid var(--rule-2);
}
.room-label { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.room-tag { font-family: var(--f-reg); font-size: 10.5px; font-weight: 600; letter-spacing: .14em; color: var(--seal); }
.room-name {
  font-family: var(--f-title); font-weight: 600; font-size: 16px; letter-spacing: -.015em;
  color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.timer { text-align: right; flex: none; }
.timer .k { display: block; font-family: var(--f-reg); font-size: 9.5px; font-weight: 600; letter-spacing: .14em; color: var(--muted); }
.timer .v {
  display: block; font-family: var(--f-reg); font-size: 20px; font-weight: 600;
  letter-spacing: .06em; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.timer.low .v { color: var(--seal); }

.screen { flex: 1; padding: 26px 22px 26px; display: none; flex-direction: column; }
.screen.on { display: flex; }
.spacer { flex: 1; min-height: 22px; }
.stagemark {
  font-family: var(--f-reg); font-size: 11px; font-weight: 600; letter-spacing: .16em;
  color: var(--blue); margin: 0 0 12px; display: flex; align-items: center; gap: 11px;
}
.stagemark::after { content: ""; height: 1px; flex: 1; background: var(--rule-2); }

.bottombar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 22px; border-top: 1px solid var(--rule-2); background: var(--paper-2);
}
.bb-l { font-size: 14px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-l b { color: var(--ink-2); font-weight: 600; }
.bb-r { font-family: var(--f-reg); font-size: 14px; font-weight: 600; letter-spacing: .08em; color: var(--seal); flex: none; }
.bb-out { font-size: 13px; color: var(--muted); background: none; border: 0; flex: none;
  padding: 6px 2px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.bb-out:hover { color: var(--seal); }

@media (min-width: 720px) {
  .phone { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--rule-2); border-right: 1px solid var(--rule-2); }
}

/* ── 저장 표시 ── */
.saved {
  font-family: var(--f-reg); font-size: 12px; letter-spacing: .04em; color: var(--muted);
  display: flex; align-items: center; gap: 7px;
}
.saved i { width: 6px; height: 6px; border-radius: 50%; background: var(--rule); flex: none; }
.saved.ok i { background: var(--blue); }
.saved.wait i { background: var(--seal); }

/* ── 4칸 답장 · 응원 ── */
.fld { margin-top: 15px; }
.fld-k { display: flex; align-items: baseline; gap: 9px; margin-bottom: 7px; }
.fld-k b { font-family: var(--f-reg); font-size: 11px; font-weight: 600; letter-spacing: .13em; color: var(--blue); }
.fld-k span { font-size: 13.5px; color: var(--muted); }
.fld textarea {
  display: block; width: 100%; min-height: 76px; resize: none; overflow: hidden;
  font-family: var(--f-letter); font-size: 16.5px; line-height: 1.95; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 1px; padding: 12px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.fld textarea::placeholder { color: var(--rule); }
.fld textarea:focus { outline: none; border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.fld.ro textarea { background: var(--paper-2); color: var(--ink-2); }

.sect-k { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 4px; }
.sect-k b { font-family: var(--f-reg); font-size: 11px; font-weight: 600; letter-spacing: .14em; color: var(--blue); }
.sect-k span { font-size: 13px; color: var(--muted); }
.sect-k::after { content: ""; height: 1px; flex: 1; background: var(--rule-2); }

.ch { display: flex; gap: 12px; align-items: flex-start; padding: 13px 0; border-bottom: 1px solid var(--rule-2); }
.ch:last-child { border-bottom: 0; }
.ch-w {
  font-family: var(--f-reg); font-size: 10.5px; font-weight: 600; letter-spacing: .05em;
  color: var(--muted); flex: none; width: 66px; padding-top: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ch-t { flex: 1; min-width: 0; font-family: var(--f-letter); font-size: 16px; line-height: 1.85; color: var(--ink); }
.ch-t.wait { color: var(--rule); }
