:root{
  --bg: #ffeea9;
  --card: #fff5cc;
  --text: #5D4037;
  --muted: #8D6E63;
  --accent: #FBC02D;
  --border: rgba(0,0,0,0.12);
  --shadow: 0 4px 10px rgba(0,0,0,0.10);
}

*{ box-sizing: border-box; }

body{
  font-family: 'Arial', sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

/* 페이지 레이아웃 */
.container{
  max-width: 1100px;
  margin: 0 auto;
  padding: 78px 20px 44px; /* 좌상단 고정 back-button과 겹치지 않게 상단 여백 확보 */
}

/* 대시보드로 돌아가기: 좌측 상단 고정 */
.back-button{
  position: fixed;
  top: 18px;
  left: 20px;
  z-index: 1000;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 10px 15px;
  background: #fff;
  text-decoration: none;
  border-radius: 20px;
  border: 1px solid #ddd;
  font-weight: bold;
  color: var(--text);
}

/* 타이틀 */
.page-title{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;              /* 제목과 부제 사이 간격 */
  margin-bottom: 24px;  /* 카드와의 여백 */
  line-height: 1.2;
}

/* 부제 스타일 */
.page-title .subtitle{
  font-size: 14px;
  font-weight: 700;
  color: #8D6E63;       /* 기존 muted 톤과 통일 */
  letter-spacing: -0.2px;
}

/* 모바일에서 부제가 너무 답답하지 않게 */
@media (max-width: 480px){
  .page-title{
    font-size: 24px;    /* h1 자체 크기 살짝 축소 */
  }

  .page-title .subtitle{
    font-size: 13px;
  }
}

/* 카드(단계 박스) */
.card{
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
  border: 1px solid var(--border);

  /* 추가(안전): 내부 요소가 폭을 밀어도 카드가 페이지 밖으로 나가지 않게 */
  max-width: 100%;
  min-width: 0;
}

/* 단계 공통 */
.hidden{ display: none !important; }

.step-title{
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 900;
}

.step-desc{
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.45;
}

.msg{
  margin-top: 10px;
  color: #7a4a22;
  font-weight: 700;
  white-space: pre-line;
}

/* 버튼 공통 */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  padding: 11px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
  user-select: none;
  border: 2px solid transparent;
}

.btn.primary{
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 8px rgba(0,0,0,0.10);
}

.btn.secondary{
  background: #fff;
  color: var(--text);
  border: 2px solid rgba(0,0,0,0.15);
}

.btn:disabled{
  opacity: .55;
  cursor: not-allowed;
}

.row-actions{
  display:flex;
  gap:10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* ---------- PIN UI ---------- */
.pin-box{
  display:flex;
  flex-direction:column;
  gap: 12px;
}

/* dot이 '지우기'와 붙지 않게 여백 추가 */
.pin-dots{
  display:flex;
  gap: 10px;
  justify-content: center;
  margin: 12px 0 6px; /* 핵심: 아래로 살짝 내려서 버튼과 분리 */
}

.dot{
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.18);
  background: #fff;
}
.dot.filled{
  background: var(--accent);
  border-color: var(--accent);
}

/* 삭제 버튼 줄: dot 아래에 충분히 떨어지게 */
.pin-actions{
  display:flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

/* 숫자패드 */
.pin-pad{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.key{
  padding: 14px 0;
  border-radius: 14px;
  background: #fff;
  border: 2px solid rgba(0,0,0,0.12);
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}
.key:active{ transform: translateY(1px); }

/* ---------- BG grid ---------- */
.bg-grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.bg-card{
  border-radius: 16px;
  border: 2px solid rgba(0,0,0,0.12);
  background: #fff;
  padding: 10px;
  cursor:pointer;
  text-align:left;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.bg-card:hover{
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.12);
}

.bg-card img{
  width: 100%;
  display:block;
  border-radius: 12px;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: #f2f2f2;
}

.bg-cap{
  margin-top: 8px;
  font-weight: 900;
  color: var(--text);
  font-size: 15px;
}

.bg-card.selected{
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(251,192,45,0.25);
}

/* ---------- Camera ---------- */
.camera-frame{
  border-radius: 16px;
  border: 2px solid rgba(0,0,0,0.12);
  background:#000;
  overflow:hidden;
}

#camera{
  width:100%;
  display:block;
  aspect-ratio: 4/3;
  object-fit: cover;
}

/* ---------- Loading ---------- */
.center{ text-align:center; }

.spinner{
  width: 58px;
  height: 58px;
  border: 6px solid rgba(0,0,0,0.10);
  border-top: 6px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 18px auto 10px;
}
@keyframes spin{ to { transform: rotate(360deg); } }

/* ---------- Result ---------- */
/* 핵심: flex 컨텍스트에서 이미지/캔버스가 고유폭 때문에 안 줄어들어 튀어나오는 문제 해결 */
.result-wrap{
  background:#fff;
  border: 2px dashed rgba(0,0,0,0.18);
  border-radius: 16px;
  padding: 12px;

  display:flex;
  align-items:center;
  justify-content:center;

  /* 추가: 절대 바깥으로 못 나가게 */
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;

  /* 추가: flex 수축 허용(매우 중요) */
  min-width: 0;
}

/* 결과/프린트 미리보기 이미지 공통 (inline style(px)도 이기도록 !important 사용) */
#result-image,
#print-image,
#print-preview,
#frame-preview,
#framed-image,
.result-wrap > img{
  display:block;

  /* 추가 핵심 */
  min-width: 0;
  flex: 0 1 100%;

  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;

  border-radius: 12px;
  object-fit: contain;
  box-sizing: border-box;
}

/* 만약 미리보기가 canvas라면 */
.result-wrap canvas,
.print-wrap canvas,
.print-preview canvas,
#frame-canvas{
  display:block;

  /* 추가 핵심 */
  min-width: 0;
  flex: 0 1 100%;

  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;

  box-sizing: border-box;
}

/* 반응형 */
@media (max-width: 920px){
  .bg-grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px){
  .bg-grid{ grid-template-columns: 1fr; }
  .btn{ width: 100%; }
  .back-button{ left: 14px; top: 14px; }
  .container{ padding: 72px 14px 36px; }
}

/* ===============================
   PIN 오류/잠금 UX
   =============================== */

/* 흔들림 애니메이션 */
@keyframes pinShake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-10px); }
  40%  { transform: translateX(10px); }
  60%  { transform: translateX(-8px); }
  80%  { transform: translateX(8px); }
  100% { transform: translateX(0); }
}

.pin-dots.shake {
  animation: pinShake 0.35s ease-in-out;
}

/* 1초 잠금 상태: 키패드/버튼 색 변경 + 비활성 느낌 */
.pin-pad.locked .key {
  background: #ffe7e7;
  border-color: rgba(200, 0, 0, 0.25);
  color: #8a2d2d;
}

.pin-pad.locked {
  opacity: 0.75;
  pointer-events: none; /* 클릭 차단 */
}

/* confirm/지우기/전체삭제도 잠금 */
.pin-actions.locked,
#pin-confirm.locked {
  opacity: 0.65;
  pointer-events: none;
}

/* confirm 버튼이 버튼 태그일 경우를 대비 */
#pin-confirm[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
}

/* ===== Print preview: 박스 밖으로 절대 안 나가게 강제 ===== */
.print-wrap,
.print-preview{
  max-width: 100%;
  overflow: hidden;          /* 넘치는 부분은 잘라냄 */
  box-sizing: border-box;
  min-width: 0;              /* flex 컨텍스트 대비 */
}

.print-wrap img,
.print-preview img{
  display: block;

  min-width: 0;
  flex: 0 1 100%;

  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;

  object-fit: contain;
  box-sizing: border-box;
}
