:root {
  --paper: #f3eee4;
  --card: #fbf8f2;
  --ink: #1f2a37;
  --ink-60: rgba(31, 42, 55, 0.6);
  --ink-40: rgba(31, 42, 55, 0.4);
  --line: rgba(31, 42, 55, 0.12);
  --accent: #c6603f;
  --accent-soft: rgba(198, 96, 63, 0.12);
  --r: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 55, 0.06), 0 12px 32px -18px rgba(31, 42, 55, 0.35);
}

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

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, system-ui, sans-serif;
  font-feature-settings: 'tnum';
  -webkit-text-size-adjust: 100%;
}

body {
  background-image:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.7), transparent 45%),
    radial-gradient(circle at 82% 88%, rgba(198, 96, 63, 0.05), transparent 40%);
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

#app { max-width: 1180px; margin: 0 auto; padding: 28px 20px 48px; }

.eyebrow {
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
}

/* ── 홈 ─────────────────────────────────────────────── */
.home-head { text-align: center; padding: 32px 0 30px; }
.home-head h1 { font-size: clamp(30px, 6vw, 42px); font-weight: 700; letter-spacing: -0.02em; margin: 10px 0 12px; }
.lede { color: var(--ink-60); line-height: 1.65; font-size: 15px; }

.card-list { list-style: none; display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px; text-align: left; width: 100%; box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex; flex-direction: column; gap: 14px;
}
.card:hover { transform: translateY(-3px); border-color: rgba(198, 96, 63, 0.35); }

.card-mystery {
  height: 128px; border-radius: 10px; display: grid; place-items: center;
  background:
    repeating-linear-gradient(45deg, rgba(31,42,55,.035) 0 6px, transparent 6px 12px),
    var(--paper);
  border: 1px dashed var(--line);
}
.card-mystery svg { width: 74px; height: 74px; opacity: 0.5; }
.card-mystery path, .card-mystery circle, .card-mystery polygon {
  fill: none; stroke: var(--ink); stroke-width: 1.4; stroke-linejoin: round;
}
.card-q { font-size: 26px; font-weight: 700; color: var(--ink-40); letter-spacing: 0.1em; }

.card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h3 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.card p { font-size: 13px; color: var(--ink-60); line-height: 1.55; }

.chip {
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
}
.chip--ghost { background: rgba(31, 42, 55, 0.06); color: var(--ink-60); }

.home-foot { margin-top: 34px; text-align: center; font-size: 12.5px; color: var(--ink-40); line-height: 1.8; }
.copy { font-size: 11.5px; }

/* ── 작업대 ─────────────────────────────────────────── */
.studio { display: flex; gap: 24px; align-items: flex-start; }
.board { flex: 1; min-width: 0; display: grid; place-items: center; }

.paper {
  position: relative; width: 100%; max-width: 520px; aspect-ratio: 210 / 297;
  background: #fffdf8; border-radius: 6px; box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden;
}
.sheet-mount, .paper canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.paper canvas { touch-action: none; cursor: crosshair; }
.sheet-mount svg { width: 100%; height: 100%; display: block; }

/* 도면 선 스타일 — 화면 */
.sheet .st { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.sheet .st--cut { stroke-width: 0.55; }
.sheet .st--mountain { stroke-width: 0.5; stroke-dasharray: 3 2; }
.sheet .st--valley { stroke-width: 0.5; stroke-dasharray: 1.2 1.8; }
.sheet .st-guide { fill: none; stroke-width: 0.4; stroke-dasharray: 1 1.6; }
.sheet .st-hole { fill: none; stroke-width: 0.3; }

.sheet--screen .is-idle, .sheet--screen .is-idle .st-guide, .sheet--screen .is-idle .st-hole { stroke: rgba(31, 42, 55, 0.11); }
.sheet--screen .is-aux { stroke: rgba(31, 42, 55, 0.08); }
.sheet--screen .is-done, .sheet--screen .is-done .st-guide, .sheet--screen .is-done .st-hole { stroke: rgba(31, 42, 55, 0.3); }
.sheet--screen .is-active, .sheet--screen .is-active .st-guide, .sheet--screen .is-active .st-hole {
  stroke: var(--accent); stroke-width: 0.75;
  animation: pulse 1.9s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* 패널 */
.panel {
  width: 296px; flex: none; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.back { font-size: 13px; color: var(--ink-60); align-self: flex-start; }
.back:hover { color: var(--accent); }
.panel-head { display: flex; gap: 6px; flex-wrap: wrap; }
.target { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.target-sub { font-size: 12.5px; color: var(--ink-40); }

.meter { height: 6px; border-radius: 99px; background: rgba(31, 42, 55, 0.08); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.12s linear; }
.meter-label { font-size: 12px; color: var(--ink-40); }
.meter-label span { color: var(--ink); font-weight: 600; }

.steps { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.steps li {
  width: 9px; height: 9px; border-radius: 3px; background: rgba(31, 42, 55, 0.1);
}
.steps li.done { background: var(--accent); }
.steps li.now { background: var(--ink); }

.panel-foot { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; }

.btn { border-radius: 10px; padding: 10px 14px; font-size: 13.5px; font-weight: 600; transition: 0.16s; }
.btn--ghost { border: 1px solid var(--line); color: var(--ink-60); flex: 1; }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn--solid { background: var(--ink); color: #fbf8f2; }
.btn--solid:hover { background: var(--accent); }

/* ── 완성 화면 ──────────────────────────────────────── */
.result { display: flex; gap: 30px; align-items: center; flex-wrap: wrap; padding-top: 8px; }
.reveal {
  flex: 1 1 320px; min-height: 380px; display: grid; place-items: center;
  border-radius: var(--r); border: 1px solid var(--line);
  background: radial-gradient(circle at 50% 42%, #fffdf8, var(--paper) 70%);
  box-shadow: var(--shadow); overflow: hidden;
}
.result-body { flex: 1 1 300px; display: flex; flex-direction: column; gap: 10px; }
.result-body h2 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.rv-size { font-size: 13px; color: var(--ink-60); }

.score { display: flex; align-items: baseline; gap: 14px; margin: 8px 0 2px; }
.score-grade {
  font-size: 40px; font-weight: 700; color: var(--accent); line-height: 1;
  font-family: 'Pretendard Variable', sans-serif;
}
.score-num b { font-size: 26px; font-weight: 700; }
.score-num span { font-size: 13px; color: var(--ink-40); margin-left: 2px; }

.rv-detail { list-style: none; display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--ink-60); }
.rv-detail li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding-bottom: 4px; }
.rv-detail b { font-weight: 600; color: var(--ink); }

.rv-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.rv-actions .btn--solid { flex: 1 1 100%; }
.rv-tips { list-style: none; font-size: 12.5px; color: var(--ink-40); line-height: 1.7; margin-top: 6px; }
.rv-tips li::before { content: '· '; }

/* ── 3D 조립 ───────────────────────────────────────── */
.scene { width: 100%; height: 380px; perspective: 900px; position: relative; }
.pivot {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0;
  transform-style: preserve-3d; transition: transform 1.2s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.solid, .half, .face { position: absolute; transform-style: preserve-3d; }
.half { transition: transform 1s cubic-bezier(0.34, 1.1, 0.4, 1); }
.face {
  transition: transform 0.85s cubic-bezier(0.34, 1.2, 0.4, 1);
  backface-visibility: visible;
}
.face--paper {
  background: linear-gradient(150deg, #fffdf7, #ece3d2);
  border: 1px solid rgba(31, 42, 55, 0.16);
  box-shadow: inset 0 0 22px rgba(31, 42, 55, 0.06);
}
.face--leather {
  background: linear-gradient(150deg, #a06a45, #6f452b);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.face--leather.is-pocket { background: linear-gradient(150deg, #8d5c3c, #5e3a24); }
.face--glass {
  background: linear-gradient(150deg, rgba(255, 252, 240, 0.94), rgba(240, 226, 200, 0.78));
  box-shadow: inset 0 0 20px rgba(198, 96, 63, 0.18);
}
.stitch-row {
  position: absolute; left: 6px; right: 6px; bottom: 5px; height: 0;
  border-top: 1.5px dashed rgba(255, 240, 220, 0.65);
}
.stitch-row--l { left: 5px; top: 12px; bottom: 12px; right: auto; width: 0; height: auto; border-top: 0; border-left: 1.5px dashed rgba(255, 240, 220, 0.55); }
.stitch-row--r { right: 5px; top: 12px; bottom: 12px; left: auto; width: 0; height: auto; border-top: 0; border-left: 1.5px dashed rgba(255, 240, 220, 0.55); }

/* ── 반응형 ────────────────────────────────────────── */
@media (max-width: 860px) {
  /* 세로 배치에서는 align-items 가 가로 정렬이 된다.
     flex-start 를 그대로 두면 .paper 의 width:100% 가 기준을 잃어 폭이 0 이 된다. */
  .studio { flex-direction: column; align-items: stretch; gap: 12px; }
  #app { padding: 14px 16px 28px; }

  /* 그리는 동안 목표와 진행률이 늘 보이도록 패널을 위로 올리고 납작하게 만든다.
     도면까지 한 화면에 들어와야 해서 여백을 아낀다. */
  .panel { order: 1; width: 100%; padding: 12px 14px; gap: 6px; }
  .board { order: 2; }
  .steps { display: none; }
  .panel-foot { padding-top: 2px; }
  .btn { padding: 7px 12px; font-size: 13px; }
  .paper { max-width: min(100%, 300px); }

  .scene { height: 300px; }
  .reveal { min-height: 300px; }
  .result { gap: 20px; }
}

/* ── 인쇄 ──────────────────────────────────────────── */
.print-root { display: none; }

@page { size: A4 portrait; margin: 0; }

@media print {
  body { background: #fff; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block; }
  .print-page {
    width: 210mm; height: 297mm; page-break-after: always; break-after: page;
    position: relative; overflow: hidden; background: #fff;
  }
  .print-sheet svg { width: 210mm; height: 297mm; display: block; }

  .sheet--print .st { fill: none; stroke: #000; stroke-linejoin: round; stroke-linecap: round; }
  .sheet--print .st--cut { stroke-width: 0.4; }
  .sheet--print .st--mountain { stroke-width: 0.3; stroke-dasharray: 3 2; }
  .sheet--print .st--valley { stroke-width: 0.3; stroke-dasharray: 1.2 1.8; }
  .sheet--print .st-hole { fill: #000; stroke: none; }
  .scalebar path { stroke: #000; stroke-width: 0.3; fill: none; }
  .scalebar text { font-size: 3px; fill: #000; font-family: sans-serif; }

  .print-guide { padding: 22mm 20mm; color: #111; font-size: 10.5pt; line-height: 1.7; }
  .print-guide h1 { font-size: 20pt; margin-bottom: 2mm; }
  .print-guide h2 { font-size: 11pt; margin: 8mm 0 2mm; padding-bottom: 1mm; border-bottom: 0.3mm solid #ddd; }
  .pg-sub { color: #666; margin-bottom: 6mm; }
  .pg-meta { display: grid; grid-template-columns: 18mm 1fr; gap: 1mm 3mm; }
  .pg-meta dt { color: #666; }
  .pg-legend, .pg-steps { padding-left: 5mm; }
  .pg-legend { list-style: none; padding-left: 0; }
  .pg-legend li { display: flex; align-items: center; gap: 3mm; margin-bottom: 1.5mm; }
  .lg { width: 14mm; height: 0; border-top: 0.4mm solid #000; flex: none; }
  .lg--mountain { border-top-style: dashed; }
  .lg--valley { border-top-style: dotted; }
  .lg--stitch { border-top: 0; height: 1.2mm; background:
    radial-gradient(circle, #000 40%, transparent 42%) 0 0 / 3mm 1.2mm repeat-x; }
  .pg-steps li { margin-bottom: 2mm; }
  .pg-foot { position: absolute; bottom: 14mm; left: 20mm; color: #999; font-size: 8pt; }
}
