/* Code Christmas Tree — 전체 스타일 (빌드 도구 없음) */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #02030a; }
body { font-family: 'Gowun Batang', serif; color: #fff6e0; }
canvas { display: block; position: fixed; inset: 0; cursor: grab; touch-action: none; }
canvas.dragging { cursor: grabbing; }
canvas.hovering { cursor: zoom-in; }
canvas.pointing { cursor: pointer; }

/* ---------- 상단: 제목 + 무늬 이름 ---------- */
#top {
  position: fixed; left: 0; right: 0;
  top: calc(env(safe-area-inset-top) + clamp(10px, 2.5vh, 28px));
  text-align: center; pointer-events: none;
}
#title {
  font-family: 'Dancing Script', 'Gowun Batang', cursive;   /* 한글 제목은 Gowun Batang으로 */
  font-size: clamp(26px, min(8vw, 8vh), 64px); line-height: 1.15;
  color: #ffe9a8; text-shadow: 0 0 18px rgba(255, 200, 80, .7);
  opacity: 0; transition: opacity 2s; padding: 0 12px;
}
#patternName {
  margin-top: 4px; font-size: clamp(11px, min(2.8vw, 2.2vh), 15px);
  letter-spacing: .3em; color: #cfe8ff; opacity: 0; transition: opacity .8s;
}
#patternName.show { opacity: .85; }

/* ---------- 하단: 글귀 + 도구 ---------- */
#bottom {
  position: fixed; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + clamp(10px, 2vh, 20px));
  display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 1.6vh, 16px);
  pointer-events: none; padding: 0 12px;
}
#message {
  width: min(100%, 640px); text-align: center; min-height: 1.6em;
  font-size: clamp(15px, min(3.8vw, 3.2vh), 24px); line-height: 1.6;
  text-shadow: 0 0 12px rgba(255, 210, 120, .6); white-space: pre-line;
}
#message .cursor { display: inline-block; width: 2px; height: 1em; background: #ffe9a8;
  vertical-align: -0.15em; margin-left: 3px; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

#toolbar { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; pointer-events: auto; max-width: 100%; }
button {
  font-family: inherit; font-size: clamp(12px, 3.3vw, 14px);
  min-height: 36px; padding: 6px clamp(10px, 3vw, 16px);
  background: rgba(255, 255, 255, .08); color: #ffe9a8;
  border: 1px solid rgba(255, 220, 140, .35); border-radius: 999px;
  cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: background .2s, transform .1s; white-space: nowrap;
}
button:hover { background: rgba(255, 220, 140, .2); }
button:active { transform: scale(.96); }

/* ---------- 글귀 편집 패널 ---------- */
.panel {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 120px);
  width: min(92vw, 440px); max-height: 60vh; overflow: auto;
  padding: 16px; border-radius: 14px; z-index: 6;
  background: rgba(10, 14, 30, .92); border: 1px solid rgba(255, 220, 140, .3);
  font-size: 13px; display: none;
}
.panel.open { display: block; }
.panel label { display: block; margin: 8px 0 4px; color: #ffe9a8; }
.panel input, .panel textarea {
  width: 100%; background: rgba(255, 255, 255, .06); color: #fff;
  border: 1px solid rgba(255, 255, 255, .15); border-radius: 8px;
  padding: 8px; font-family: inherit; font-size: 16px; /* 16px 미만이면 iOS가 확대함 */
  resize: vertical;
}
.panel .hint { color: #a9a39a; font-size: 12px; margin-top: 6px; line-height: 1.5; }
.panel .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* ---------- 사진 확대 보기 ---------- */
#viewer {
  position: fixed; inset: 0; z-index: 10; display: none;
  align-items: center; justify-content: center; cursor: zoom-out;
  background: rgba(2, 3, 10, 0); transition: background .5s;
}
#viewer.open { display: flex; }
#viewer.show { background: rgba(2, 3, 10, .8); }
#card {
  background: #fdfaf3; border-radius: 4px; position: relative;
  box-shadow: 0 0 60px rgba(255, 210, 120, .35);
  transform-origin: 50% 50%; will-change: transform;
}
#card img { display: block; }
#cardCap {
  position: absolute; left: 0; right: 0; text-align: center; color: #3a2f24;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 10px;
}
#viewerHint {
  position: fixed; left: 0; right: 0; text-align: center;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  font-size: 13px; color: #cbbfa8; opacity: 0; transition: opacity .5s; pointer-events: none;
}
#viewer.show #viewerHint { opacity: .8; }
#fileInput { display: none; }

/* 가로로 눕힌 휴대폰 등 세로 공간이 아주 좁을 때 */
@media (max-height: 480px) {
  #patternName { display: none; }
  #message { font-size: 14px; min-height: 1.4em; }
  button { min-height: 30px; padding: 4px 10px; }
  .panel { bottom: 70px; max-height: 70vh; }
}

/* =====================================================================
 *  Phase 3 — 사용자 화면 (로그인 · 내 트리 · 공유 보기)
 * ===================================================================== */
[hidden] { display: none !important; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* 모드가 정해지기 전에는 도구 막대를 감춰서 깜빡임 방지 */
body[data-mode="boot"] #toolbar { visibility: hidden; }

a { color: #ffe9a8; }
a.button {
  display: inline-flex; align-items: center; text-decoration: none;
  font-size: clamp(12px, 3.3vw, 14px); min-height: 36px; padding: 6px clamp(10px, 3vw, 16px);
  background: rgba(255, 255, 255, .08); color: #ffe9a8;
  border: 1px solid rgba(255, 220, 140, .35); border-radius: 999px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); white-space: nowrap;
}
a.button:hover { background: rgba(255, 220, 140, .2); }
button.primary { background: rgba(255, 214, 120, .22); border-color: rgba(255, 220, 140, .6); }
button.primary:hover { background: rgba(255, 214, 120, .34); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid #ffe9a8; outline-offset: 2px;
}
button.icon { min-height: 32px; width: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* 공유 보기: "OOO님의 트리" */
#owner {
  margin-top: 2px; font-size: clamp(13px, min(3.4vw, 2.4vh), 17px);
  color: #ffe9a8; opacity: .9; letter-spacing: .05em; text-shadow: 0 0 10px rgba(255, 200, 80, .5);
}

#notice {
  font-size: 13px; color: #cbbfa8; text-align: center; line-height: 1.5;
  text-shadow: 0 0 8px rgba(0, 0, 0, .8);
}

/* 입력 공통 */
.card input, .panel.edit input {
  width: 100%; background: rgba(255, 255, 255, .06); color: #fff;
  border: 1px solid rgba(255, 255, 255, .18); border-radius: 8px;
  padding: 8px 10px; font-family: inherit; font-size: 16px; /* 16px 미만이면 iOS가 확대함 */
}
.card input[aria-invalid="true"], .panel.edit input[aria-invalid="true"] { border-color: rgba(255, 140, 140, .8); }
.sub { color: #a9a39a; font-size: 12px; }
.msg { font-size: 12.5px; line-height: 1.5; color: #cfe8ff; }
.msg:empty { display: none; }
.msg.error, .msg.bad { color: #ffb3b3; }
.msg.good { color: #b9f5c9; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
.row.center { justify-content: center; }
.row.spread { justify-content: space-between; align-items: center; }
.inline { display: flex; gap: 8px; align-items: stretch; }
.inline input { flex: 1; min-width: 0; }
.fields { display: flex; gap: 10px; }
.fields .field { flex: 1; min-width: 0; }
.fields .field.pin { flex: 0 0 38%; }
.card .field.email, .card .field.rc-code, #rcStep2 .fields { margin-top: 8px; }
.card .hint.top { margin: 0 0 8px; }
.card .hint b { color: #ffe9a8; }
.fields .field.email-wide { flex: 1.7; }
.row-gap { display: inline-flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
button.ghost { background: transparent; border-color: transparent; color: #ffe9a8; text-decoration: underline; text-underline-offset: 3px; padding-left: 4px; padding-right: 4px; }
button.ghost:hover { background: rgba(255, 255, 255, .06); }
.card .warn {
  margin-top: 8px; padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.55;
  color: #ffe2b0; background: rgba(255, 180, 80, .1); border: 1px solid rgba(255, 190, 100, .28);
}
.card .warn b { color: #fff1c9; font-weight: 700; }
.hint { color: #a9a39a; font-size: 12px; margin-top: 8px; line-height: 1.55; }

/* ---------- 로그인 카드 ---------- */
.card {
  pointer-events: auto; width: min(100%, 420px); text-align: left;
  padding: 14px 16px; border-radius: 14px; font-size: 13px;
  background: rgba(10, 14, 30, .86); border: 1px solid rgba(255, 220, 140, .3);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.card h1 { font-size: 16px; font-weight: 700; color: #ffe9a8; margin-bottom: 8px; }
.card label { display: block; margin-bottom: 4px; color: #ffe9a8; }
.card .msg { margin-top: 6px; }
.card .confirm {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: rgba(255, 214, 120, .1); border: 1px solid rgba(255, 220, 140, .35); line-height: 1.55;
}
.card .confirm .row { margin-top: 8px; }

/* ---------- 내 트리 편집 패널 ---------- */
.panel.edit {
  width: min(94vw, 480px); max-height: min(64vh, 620px);
  padding: 0; overflow: hidden; flex-direction: column;
}
.panel.edit:not([hidden]) { display: flex; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 6px; }
.panel-head h2 { font-size: 15px; color: #ffe9a8; flex: 1; }
.save-state { font-size: 12px; color: #a9a39a; }
.save-state.bad { color: #ffb3b3; }
.tabs { display: flex; gap: 4px; padding: 4px 10px 0; border-bottom: 1px solid rgba(255, 220, 140, .18); overflow-x: auto; flex-shrink: 0; }
.tabs [role="tab"] {
  border: 0; border-radius: 8px 8px 0 0; background: transparent; min-height: 34px;
  backdrop-filter: none; -webkit-backdrop-filter: none; color: #cbbfa8; padding: 6px 12px;
}
.tabs [role="tab"][aria-selected="true"] { color: #ffe9a8; background: rgba(255, 220, 140, .14); box-shadow: inset 0 -2px 0 #ffd678; }
.pane { padding: 6px 14px 14px; overflow-y: auto; overscroll-behavior: contain; }
.pane fieldset { border: 0; margin-top: 10px; }
.pane legend { color: #ffe9a8; margin-bottom: 6px; }
.panel .pane label.check { display: flex; align-items: center; gap: 8px; color: #fff6e0; margin: 10px 0 0; cursor: pointer; }
.panel.edit label.check input { width: 18px; height: 18px; accent-color: #ffd678; }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.choices button { border-radius: 10px; white-space: normal; }
.choices button[aria-pressed="true"] { background: rgba(255, 214, 120, .3); border-color: #ffd678; color: #fff; }
.counter { color: #a9a39a; font-size: 12px; float: right; }
.list-head { font-size: 13px; font-weight: 400; color: #ffe9a8; margin: 14px 0 6px; }
.list-head .counter { float: none; margin-left: 4px; }
.items { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.items li {
  display: flex; gap: 8px; align-items: center; padding: 6px 6px 6px 10px; border-radius: 8px;
  background: rgba(255, 255, 255, .05);
}
.items li .text { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.5; }
.items li button, .grid li button { min-height: 30px; padding: 2px 10px; font-size: 12px; }
.grid { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.grid li { background: #fdfaf3; border-radius: 4px; padding: 5px 5px 4px; color: #3a2f24; display: flex; flex-direction: column; gap: 4px; }
.grid img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #ddd; }
.grid .cap { font-size: 11px; text-align: center; min-height: 1.4em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid li button { color: #7a2a2a; border-color: rgba(122, 42, 42, .35); background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
button.confirming, .grid li button.confirming { background: #c94b4b; border-color: #c94b4b; color: #fff; }
.empty { color: #a9a39a; font-size: 12.5px; padding: 8px 0; }
#shareOpen { font-size: 12.5px; }

/* ---------- 로딩 · 오류 · 알림 ---------- */
#screen {
  position: fixed; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center;
  background: rgba(2, 3, 10, .45); padding: 24px;
}
.screen-box {
  text-align: center; padding: 18px 22px; border-radius: 14px; max-width: 360px;
  background: rgba(10, 14, 30, .88); border: 1px solid rgba(255, 220, 140, .3); line-height: 1.6;
}
#screen.loading { background: transparent; pointer-events: none; }
#screen.loading .screen-box { background: transparent; border-color: transparent; text-shadow: 0 0 10px rgba(0, 0, 0, .9); }
#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); z-index: 20;
  transform: translate(-50%, -8px); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  width: max-content; max-width: min(92vw, 420px); padding: 9px 16px; border-radius: 18px; font-size: 13.5px; text-align: center;
  background: rgba(10, 14, 30, .94); border: 1px solid rgba(255, 220, 140, .45); color: #fff6e0; line-height: 1.5;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { border-color: rgba(255, 140, 140, .7); }

@media (max-width: 380px) {
  .fields:not(.three) { flex-direction: column; gap: 8px; }
  .fields .field.pin { flex: 1; }
}
@media (max-height: 480px) {
  .card { padding: 10px 12px; }
  .card h1, .card .hint { display: none; }
  .panel.edit { bottom: 56px; max-height: calc(100vh - 70px); }
  #owner { font-size: 12px; }
}

/* =====================================================================
 *  트리 목록 서랍 (담은 트리 · 최근 본 트리)
 * ===================================================================== */
/* 왼쪽 위 [☰ 목록] · 오른쪽 위 [English/한국어] 버튼과 제목이 겹치지 않게 */
#title { padding: 0 84px; }
.side-toggle {
  position: fixed; z-index: 7;
  top: calc(env(safe-area-inset-top) + 10px); left: calc(env(safe-area-inset-left) + 10px);
  min-height: 34px; padding: 4px 12px;
}
body.lib-open .side-toggle { visibility: hidden; }
/* 화면 언어 전환 (오른쪽 위) */
.lang-toggle {
  position: fixed; z-index: 7;
  top: calc(env(safe-area-inset-top) + 10px); right: calc(env(safe-area-inset-right) + 10px);
  min-height: 34px; padding: 4px 12px; font-size: 13px;
}
body[data-mode="boot"] .lang-toggle { visibility: hidden; }
@media (max-width: 700px) { body.lib-open .lang-toggle { visibility: hidden; } }   /* 좁은 화면: 펼친 목록 가장자리에 걸치지 않게 */
#library {
  position: fixed; z-index: 7; top: 0; bottom: 0; left: 0; width: min(86vw, 320px);
  display: flex; flex-direction: column; font-size: 13px;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: rgba(8, 11, 24, .95); border-right: 1px solid rgba(255, 220, 140, .25);
  box-shadow: 8px 0 30px rgba(0, 0, 0, .45);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transform: translateX(-105%); transition: transform .28s ease, visibility .28s;
  visibility: hidden;
}
#library.open { transform: none; visibility: visible; }
@media (prefers-reduced-motion: reduce) { #library { transition: none; } }
.lib-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 4px 16px; }
.lib-head h2 { flex: 1; font-size: 15px; color: #ffe9a8; }
.lib-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 12px 16px 16px; }
.lib-body section + section { margin-top: 6px; }
.lib-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.lib-list li { display: flex; align-items: center; gap: 4px; border-radius: 8px; background: rgba(255, 255, 255, .04); }
.lib-list a {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px;
  padding: 7px 10px; border-radius: 8px; text-decoration: none; color: #fff6e0;
}
.lib-list a:hover { background: rgba(255, 220, 140, .1); }
.lib-list a[aria-current="page"] { background: rgba(255, 214, 120, .16); box-shadow: inset 3px 0 0 #ffd678; }
.lib-list .who, .lib-list .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-list .who { color: #ffe9a8; }
.lib-list .meta { color: #a9a39a; font-size: 12px; }
.lib-list button.icon { flex-shrink: 0; margin-right: 4px; min-height: 30px; width: 30px; backdrop-filter: none; -webkit-backdrop-filter: none; }
#library .row { margin-top: 8px; }
#library .hint { margin-top: 14px; }
.lib-list.mine li { flex-wrap: wrap; }
.lib-list .actions { display: flex; gap: 2px; margin-right: 4px; }
.lib-list .actions button.icon { margin-right: 0; width: 28px; min-height: 28px; font-size: 13px; }
.lib-list .actions button.icon:disabled { opacity: .3; }
.lib-list li.editing { padding: 6px; gap: 6px; }
.lib-list li.editing input {
  flex: 1; min-width: 0; font-family: inherit; font-size: 16px; color: #fff;
  background: rgba(255, 255, 255, .08); border: 1px solid #ffd678; border-radius: 6px; padding: 5px 8px;
}
#libMine .hint { margin-top: 6px; }
.lib-account {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 12px; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, .04);
}
.lib-account .sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #cbbfa8; }
.lib-account button { flex-shrink: 0; }
button#btnSave[aria-pressed="true"] { background: rgba(255, 214, 120, .28); border-color: #ffd678; }

/* =====================================================================
 *  장식 · 사진 캡션 고치기 · 사진 여러 장 삭제
 * ===================================================================== */
canvas.placing { cursor: copy; }
button.danger { color: #ffc2c2; border-color: rgba(255, 140, 140, .45); }
.pane .hint.top { margin: 4px 0 8px; }
.pane .hint b { color: #ffe9a8; font-weight: 400; }
.decor-kinds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.decor-kinds button {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  border-radius: 10px; min-height: 52px; padding: 4px 2px; white-space: normal; line-height: 1.2;
}
.decor-kinds button .ico { font-size: 20px; line-height: 1.1; }
.decor-kinds button[aria-pressed="true"] { background: rgba(255, 214, 120, .3); border-color: #ffd678; color: #fff; }
.decor-colors { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.decor-colors button {
  width: 32px; min-height: 32px; height: 32px; padding: 0; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .25); background: var(--swatch); backdrop-filter: none; -webkit-backdrop-filter: none;
}
.decor-colors button:hover { background: var(--swatch); filter: brightness(1.15); }
.decor-colors button[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px #ffd678; }
.decor-actions { margin-top: 10px; }
.decor-actions .counter { float: none; }

/* 장식 탭: 트리가 보이도록 패널을 옆으로 (넓은 화면 · 가로 화면) */
@media (min-width: 900px) {
  .panel.edit.decor-mode {
    left: auto; right: calc(env(safe-area-inset-right) + 16px); transform: none;
    top: calc(env(safe-area-inset-top) + 64px); bottom: auto; width: 340px; max-height: calc(100vh - 160px);
  }
}
@media (max-height: 480px) and (min-width: 600px) {
  .panel.edit.decor-mode {
    left: auto; right: calc(env(safe-area-inset-right) + 8px); transform: none;
    top: 8px; bottom: 54px; width: 330px; max-height: none;
  }
}
/* 좁은 세로 화면: 장식 탭은 패널을 낮게 → 트리는 패널 위 공간에 맞춰 줄어듦 */
@media (max-width: 899px) and (min-height: 481px) {
  .panel.edit.decor-mode { max-height: min(42vh, 330px); bottom: calc(env(safe-area-inset-bottom) + 64px); }
  .panel.edit.decor-mode .hint.top { font-size: 11.5px; }
  .panel.edit.decor-mode .decor-kinds button { min-height: 44px; }
  .panel.edit.decor-mode .decor-kinds button .ico { font-size: 17px; }
}

/* 사진 카드: 선택 상자 + 캡션 입력 */
.grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.grid li { position: relative; }
.grid li.selected { box-shadow: 0 0 0 3px #ffd678; }
.panel.edit .grid input.cap-input {
  font-size: 16px; color: #3a2f24; background: #fff; border: 1px solid rgba(58, 47, 36, .25);
  border-radius: 4px; padding: 3px 6px; width: 100%; min-width: 0; text-align: center;
}
.panel.edit .grid input.cap-input:focus-visible { outline: 2px solid #c8963c; outline-offset: 0; }
.panel.edit .grid input.cap-input.saved { border-color: #3fbf7f; }
.panel.edit .grid input.cap-input.bad { border-color: #c94b4b; }
.panel.edit .grid input.pick {
  position: absolute; top: 9px; left: 9px; width: 22px; height: 22px; padding: 0; accent-color: #c8963c; cursor: pointer;
}
.photo-tools { margin: 0 0 8px; }
.photo-tools label.check { margin: 0 !important; }
