/* 🛋️ 내 방 가구 배치 시뮬레이터 — 따뜻한 종이 도면 UI */

:root {
  --bg: #f3ece1;
  --bg-2: #ece2d3;
  --card: #fffdf9;
  --ink: #33291f;
  --ink-2: #5d4f40;
  --muted: #8a7965;
  --line: #e6dbca;
  --line-2: #d8cab5;
  --accent: #b4552f;
  --accent-dark: #96421f;
  --accent-soft: #f7e3d8;
  --ok: #3f7b5c;
  --warn: #c0271b;
  --shadow: 0 10px 30px rgba(72, 52, 32, .10);
  --shadow-lg: 0 18px 44px rgba(72, 52, 32, .16);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(90% 55% at 50% -8%, #fffaf1 0%, rgba(255, 250, 241, 0) 62%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: radial-gradient(rgba(120, 96, 64, .07) 1px, transparent 1px);
  background-size: 14px 14px;
  opacity: .55;
}

.app {
  position: relative; z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 14px 34px;
}

/* ── 헤더 ── */
.hero { padding: 6px 4px 16px; }

.kicker {
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--accent);
}

.hero h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.22;
  letter-spacing: -.02em;
  font-weight: 800;
}

.hero h1 .emoji { font-size: 22px; margin-right: 2px; }

.hero .sub {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  max-width: 46em;
}

/* ── 레이아웃 ── */
main { display: block; }

.col-stage { margin-bottom: 14px; }
.col-panel > * + * { margin-top: 10px; }

/* ── 도면 스테이지 ── */
.stage {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fbf7ef;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#plan {
  display: block;
  width: 100%;
  height: 404px;
  touch-action: none;
  cursor: grab;
}

#plan.dragging { cursor: grabbing; }

.tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 249, .82);
}

.tools-label {
  margin-right: auto;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tools-label b { color: var(--ink-2); font-weight: 700; }

.tools button {
  width: 40px; height: 38px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.tools button:active { background: var(--accent-soft); color: var(--accent-dark); }
.tools button:disabled { opacity: .3; }

.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 9px 2px 0;
  font-size: 12px;
  color: var(--ink-2);
}

.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(63, 123, 92, .14);
  flex: 0 0 auto;
}

.status.bad .dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(192, 39, 27, .14); }
.status .right { margin-left: auto; color: var(--muted); font-size: 11.5px; }

.tip {
  margin: 7px 2px 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

.tip b { color: var(--ink-2); font-weight: 600; }

/* ── 카드 ── */
.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  padding: 14px;
  box-shadow: 0 2px 10px rgba(80, 58, 34, .045);
}

.card h2 {
  display: flex; align-items: center; gap: 7px;
  margin: 0 0 11px;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.card h2 .num {
  display: grid; place-items: center;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
  flex: 0 0 auto;
}

.chip-dim {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0;
}

/* ── 칩 · 버튼 ── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 11px; }

.chips button {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: #fffefa;
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.chips button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.chips button:active { transform: scale(.97); }

.btn {
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: #fffefa;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn:active { transform: scale(.985); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 12px; border-radius: 10px; }
.btn.ghost { background: #fdf8f0; }
.btn.ghost:active { background: var(--accent-soft); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(180, 85, 47, .24);
}
.btn.primary:active { background: var(--accent-dark); }
.btn.danger { color: var(--warn); }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.size-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}

.size-row label,
.custom-body label {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.unit {
  display: flex; align-items: center; gap: 4px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

input[type="number"],
input[type="text"] {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: #fffefa;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  -webkit-appearance: none;
  appearance: none;
}

input:focus-visible, select:focus-visible, .btn:focus-visible,
.chips button:focus-visible, .libtab:focus-visible, .libitem:focus-visible,
.op .x:focus-visible, .op .hinge:focus-visible, .tools button:focus-visible {
  outline: 2px solid rgba(180, 85, 47, .55);
  outline-offset: 1px;
}

.unit input { min-width: 0; }

.opts {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px dashed var(--line);
}

.switch {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px;
  color: var(--ink-2);
  cursor: pointer;
}

.switch input {
  width: 17px; height: 17px;
  accent-color: var(--accent);
}

/* ── 문·창문 목록 ── */
.openings { display: grid; gap: 8px; margin-top: 9px; }
.openings:empty { display: none; }

.op {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 7px 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fdfaf4;
}

.op .ico { font-size: 16px; }

.op select {
  width: 100%;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: #fffefa;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  -webkit-appearance: none;
  appearance: none;
}

.op .x {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.op .fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 7px;
  align-items: end;
}

.op .fields label {
  display: block;
  min-width: 0;
  font-size: 10.5px;
  color: var(--muted);
}

.op .fields label span { display: block; margin-bottom: 3px; }

.op .fields input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  font-size: 13px;
  text-align: center;
}

.op .hinge {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: #fffefa;
  color: var(--ink-2);
  font: inherit;
  font-size: 11.5px;
  white-space: nowrap;
  cursor: pointer;
}

.note {
  margin: 9px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

/* ── 가구 라이브러리 ── */
.libcats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.libtab {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: #fffefa;
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.libtab.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.libgrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.libitem {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 1px 8px;
  align-items: center;
  min-height: 54px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 11px;
  background: #fffefa;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.libitem:active { background: var(--accent-soft); }

.libitem .e { grid-row: 1 / 3; font-size: 18px; }
.libitem .n {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.libitem .s { font-size: 10.5px; color: var(--muted); }

.custom { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.custom summary {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  list-style: none;
}
.custom summary::-webkit-details-marker { display: none; }
.custom summary::before { content: "＋ "; color: var(--accent); }
.custom[open] summary::before { content: "－ "; }

.custom-body { display: grid; gap: 8px; margin-top: 10px; }
.custom-list { display: grid; gap: 6px; }
.custom-list:empty { display: none; }

.custom-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fdfaf4;
  font-size: 12px;
}
.custom-row b { font-weight: 600; }
.custom-row span { color: var(--muted); font-size: 11px; }
.custom-row button {
  margin-left: auto;
  width: 28px; height: 28px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

/* ── 진단 ── */
.diag { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.diag li {
  display: flex; gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  background: #fdf6f4;
  border: 1px solid #f0d8d2;
  font-size: 12px;
  line-height: 1.45;
  color: #7d2b22;
}

.diag li.ok {
  background: #f2f8f3;
  border-color: #d8e9dd;
  color: #2f6249;
}

.diag li .ic { flex: 0 0 auto; }

/* ── 액션 · 도움말 ── */
.actions { display: grid; gap: 8px; }

.help {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 253, 249, .72);
  padding: 12px 14px;
  font-size: 12px;
  color: var(--ink-2);
}

.help summary { font-weight: 700; cursor: pointer; list-style: none; }
.help summary::-webkit-details-marker { display: none; }
.help summary::before { content: "？ "; color: var(--accent); }
.help ul { margin: 10px 0 0; padding-left: 17px; display: grid; gap: 7px; }
.help li { line-height: 1.55; }
.help b { color: var(--ink); }

.foot {
  margin: 14px 0 0;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: .02em;
  color: #a2937f;
}

/* ── 모달 · 토스트 ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(38, 28, 18, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal[hidden] { display: none; }

.modal-card {
  width: min(560px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 16px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.modal-card h3 { margin: 2px 0 12px; font-size: 15px; }
.modal-card img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.modal-card p { margin: 11px 0 13px; font-size: 12px; line-height: 1.55; color: var(--muted); }
.modal-card p b { color: var(--ink); }
.modal-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(51, 41, 31, .94);
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 데스크톱 ── */
@media (min-width: 880px) {
  .app { padding: 26px 22px 44px; }
  .hero { padding-bottom: 20px; }
  .hero h1 { font-size: 30px; }
  .hero .sub { font-size: 13.5px; }

  main {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr);
    gap: 20px;
    align-items: start;
  }

  .col-stage {
    position: sticky;
    top: 18px;
    margin-bottom: 0;
  }

  #plan { height: 540px; }
  .col-panel > * + * { margin-top: 12px; }
  .libgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tools button { width: 46px; height: 42px; }
}

@media (min-width: 1180px) {
  #plan { height: 580px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
