:root {
  --blue: #6B97E0;
  --ink: #7A4433;
  --paper: #F2EEE3;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--blue);
  color: var(--ink);
  font-family: 'Pretendard', -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  display: none;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.screen.active { display: flex; }

/* ---------- standby ---------- */
#screen-standby { position: relative; overflow: hidden; text-align: center; gap: 10px; }

.script { font-family: 'Berkshire Swash', serif; }
.serif { font-family: 'Lora', serif; font-size: 15px; }
.small { font-size: clamp(26px, 8vw, 40px); }
.title { font-weight: 400; font-size: clamp(48px, 15vw, 84px); line-height: 1; margin-bottom: 6px; }
.date { font-size: 20px; margin-bottom: 20px; }
.hint { font-size: 13px; opacity: 0.75; }
.credit {
  position: absolute; left: 0; right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  font-family: 'Lora', serif; font-size: 12px; opacity: 0.7;
}

.stars { position: absolute; width: 110px; height: 110px; color: var(--ink); }
.stars.left { top: max(24px, env(safe-area-inset-top)); left: 8px; }
.stars.right { top: max(70px, calc(env(safe-area-inset-top) + 46px)); right: 8px; }

/* ---------- buttons ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 24px;
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  width: 100%;
  max-width: 420px;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.big { padding: 20px 24px; font-size: 19px; }
.btn.ghost { background: transparent; color: inherit; border: 1.5px solid currentColor; opacity: 0.8; }
.row { display: flex; gap: 10px; width: 100%; max-width: 420px; }
.row .btn { flex: 1; }

/* ---------- capture ---------- */
#screen-capture { background: #111; color: #fff; justify-content: flex-start; }

.viewfinder {
  position: relative;
  width: min(100%, 520px, calc((100dvh - 230px) * 500 / 560));
  aspect-ratio: 500 / 560; /* same shape as one photo cell */
  overflow: hidden;
  border-radius: 12px;
  background: #000;
}
#camera-feed { width: 100%; height: 100%; object-fit: cover; display: block; }

.wb-tint { position: absolute; inset: 0; mix-blend-mode: multiply; pointer-events: none; transition: background-color 0.4s; }

.countdown {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 120px; font-weight: 800;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.hidden { display: none; }

.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.active { animation: flash 0.4s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.shot-badge {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 12px; border-radius: 999px; font-size: 14px;
}

.thumbs { display: flex; gap: 8px; width: min(100%, 520px); }
.thumb {
  flex: 1; aspect-ratio: 500 / 560;
  border-radius: 6px; background: #2a2a2a; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- result ---------- */
#composite {
  width: auto;
  height: min(52dvh, calc(100vw * 1.5 - 48px));
  max-width: 100%;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.frame-picker { display: flex; gap: 8px; }
.chip {
  border: 1.5px solid var(--ink);
  background: transparent; color: var(--ink);
  border-radius: 999px; padding: 8px 16px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--ink); color: var(--paper); }

.memo-row { display: flex; gap: 8px; width: 100%; max-width: 420px; }
.memo-row .chip { flex: none; }
.memo {
  flex: 1; min-width: 0;
  padding: 12px 16px;
  border: 0; border-radius: 12px;
  font: inherit; font-size: 16px; /* 16px stops iOS zoom-on-focus */
  background: var(--paper); color: var(--ink);
}

.qr-box {
  display: flex; align-items: center; gap: 14px;
  width: 100%; max-width: 420px;
  padding: 12px; border-radius: 16px;
  background: var(--paper);
}
.qr-code {
  flex: none; width: 132px; height: 132px;
  border-radius: 8px; background: #fff;
  display: flex; align-items: center; justify-content: center;
}
.qr-code svg { width: 100%; height: 100%; display: block; }
.qr-text { display: none; font-size: 15px; font-weight: 600; line-height: 1.45; }
.qr-text .chip { margin-top: 6px; }
.qr-box[data-state="ready"] .qr-ready,
.qr-box[data-state="loading"] .qr-loading,
.qr-box[data-state="error"] .qr-error { display: block; }
.qr-box:not([data-state="ready"]) .qr-code { opacity: 0.35; pointer-events: none; }

/* ---------- mission ---------- */
.mission-card {
  position: relative;
  width: 100%; max-width: 420px;
  padding: 36px 24px;
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transform: rotate(-1.5deg);
  text-align: center;
}
#mission-text { font-size: clamp(22px, 6vw, 28px); font-weight: 700; line-height: 1.4; word-break: keep-all; white-space: pre-line; }
.mission-star { position: absolute; top: -22px; right: -14px; width: 48px; height: 48px; color: var(--ink); background: none; }
.mission-intro { font-family: 'Lora', 'Pretendard', serif; font-size: clamp(17px, 4.6vw, 21px); line-height: 1.55; text-align: center; margin-bottom: 8px; word-break: keep-all; }
.mission-verse { font-family: 'Lora', 'Pretendard', serif; font-size: 14px; opacity: 0.8; margin-top: 4px; }
#shooter { flex: none; width: 100%; max-width: 420px; }

/* ---------- desktop ---------- */
#screen-desk { padding: 0; gap: 0; justify-content: flex-start; align-items: stretch; height: 100dvh; }
.menubar {
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: rgba(242, 238, 227, 0.75);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.menubar .script { font-size: 22px; }
.desk-count { font-size: 14px; opacity: 0.75; }
.spacer { flex: 1; }
.draw-notice { font-size: 14px; font-weight: 700; }
.draw-notice[hidden], .menubar .chip[hidden] { display: none; }

.desk {
  position: relative; flex: 1; overflow: hidden;
  background: radial-gradient(ellipse at 30% 20%, #8DB0EA, var(--blue) 60%, #5A86D2);
}
/* field.jpg: photo by Chris Barbalis on Unsplash (unsplash.com/photos/doicC_ATzkQ), Unsplash License */
.desk[data-wall="field"] { background: #4E9E2C url(field.jpg) center / cover no-repeat; }
.desk-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  text-align: center; color: #fff; font-size: 18px; line-height: 1.6;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.desk-empty[hidden] { display: none; }

.icon {
  position: absolute; width: 140px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: none; border: 0; padding: 6px; border-radius: 10px;
  cursor: pointer; font: inherit;
  transition: transform 0.15s, background 0.15s;
}
.icon img {
  width: 72px; aspect-ratio: 2 / 3; object-fit: cover;
  border: 4px solid #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.icon span {
  color: #fff; font-size: 13px; font-weight: 700; line-height: 1.3;
  text-align: center; word-break: break-all;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}
.icon:active { transform: scale(0.95); }
.icon.pick { background: rgba(255, 255, 255, 0.3); transform: scale(1.12); }
.icon span em { font-style: normal; }
.icon.pick span em {
  background: #2F64D6; border-radius: 5px; padding: 1px 5px; text-shadow: none;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.icon.new { animation: pop 0.6s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(20, 30, 60, 0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.viewer[hidden] { display: none; }
.viewer-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  width: 100%; max-width: 420px; max-height: 100%;
  padding: 16px; border-radius: 18px;
  background: var(--paper);
}
.viewer-badge { font-size: 34px; }
.viewer-badge[hidden] { display: none; }
#viewer-img { max-width: 100%; max-height: 52dvh; border-radius: 4px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); }
.viewer-caption { white-space: pre-line; text-align: center; font-size: 15px; font-weight: 600; line-height: 1.5; }
.viewer-qr { width: 96px; }
.viewer-qr:empty { display: none; }
.viewer-qr svg { width: 100%; height: auto; display: block; }

/* ---------- 30s decorating ---------- */
.stage { position: relative; line-height: 0; touch-action: none; }
.stage #composite { display: block; }
.stk { position: absolute; inset: 0; overflow: hidden; border-radius: 6px; }
.st { position: absolute; transform-origin: center; cursor: grab; }
.st img { width: 100%; height: 100%; display: block; pointer-events: none; }
.st.sel { outline: 2px dashed rgba(255, 255, 255, 0.95); outline-offset: 4px; }
.st .h {
  position: absolute; width: 28px; height: 28px; border-radius: 50%;
  background: #fff; color: #111; font-size: 15px; font-weight: 800; line-height: 1;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.st.sel .h { display: flex; }
.st .h-del { left: -14px; top: -14px; }
.st .h-top { right: -14px; top: -14px; }
.st .h-siz { right: -14px; bottom: -14px; cursor: nwse-resize; }

.deco-bar, .deco-tools { display: none; width: 100%; max-width: 520px; }
#screen-result.decorating .deco-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; }
#screen-result.decorating .deco-tools { display: flex; flex-direction: column; gap: 10px; }
#screen-result.decorating .qr-box,
#screen-result.decorating .row { display: none; }
#deco-sec { font-size: 20px; }
.deco-track { width: 100%; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.4); overflow: hidden; }
.deco-fill { height: 100%; background: var(--ink); transition: width 1s linear; }

.pal { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pal button {
  flex: none; width: 56px; height: 56px; padding: 6px;
  border: 0; border-radius: 12px; background: var(--paper); cursor: pointer;
}
.pal img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ts-styles { display: flex; gap: 6px; overflow-x: auto; }
.ts-styles .chip { flex: none; padding: 6px 12px; font-size: 13px; }
