/* 멍코스 UI 톤: 점 격자 크림 바탕 · 2px 잉크 테두리 · 둥근 카드 · Jua 제목 · 라임 선택 상태 */
:root {
  --bg: #F5F2E9;
  --dot: #E2DDCF;
  --card: #FFFFFF;
  --sunk: #EFEBE0;
  --ink: #17171A;
  --muted: #4A4740;
  --hair: #D8D3C6;
  --line: #17171A;
  --pass: #D9F25E;   /* 선택·강조 */
  --orange: #FF8D52;
  --blue: #9DB7FF;
  --lilac: #BEAEFF;
  --pink: #FFBDE2;
  --mint: #86DDBD;
  --accent: var(--ink);
  --face: #FF8D52;
  --fur: #5B7CFF;
  --radius: 22px;
  --f-display: "Jua", "Gothic A1", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --f-body: "Gothic A1", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-family: var(--f-body);
  color: var(--ink);
  color-scheme: light;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.3px, transparent 1.3px);
  background-size: 18px 18px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
small { color: var(--muted); font-size: 12px; }
:focus-visible { outline: 3px solid var(--fur); outline-offset: 2px; }

/* ---------- 상단 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand .logo { width: 38px; height: 38px; flex: none; }
.brand .name { font-family: var(--f-display); font-size: 26px; line-height: 1; white-space: nowrap; }
.brand small { font-weight: 700; margin-left: 4px; font-size: 13px; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 800; padding: 6px 12px; border-radius: 99px; background: var(--card); border: 2px solid var(--line); color: var(--ink); white-space: nowrap; }
.pill .short { display: none; }
.pill svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 480px; gap: 24px; padding: 0 24px 28px; align-items: start; }

/* ---------- 사진 자르기 */
.crop-stage { position: relative; user-select: none; }
.drop { display: grid; place-items: center; gap: 6px; min-height: 220px; border: 2px dashed var(--line); border-radius: 22px; text-align: center; padding: 18px; cursor: pointer; background: var(--sunk); font-size: 14px; font-weight: 700; line-height: 1.6; transition: background .15s; }
.drop small { font-weight: 600; }
.drop-dog { width: 84px; height: 84px; }
.drop:hover, .drop.over { background: #F3FAD6; }
.drop.over { border-style: solid; }
.crop-stage.has-image .drop { display: none; }
.crop-img { display: none; width: 100%; border-radius: 18px; border: 2px solid var(--line); }
.crop-stage.has-image .crop-img { display: block; }
.crop-box { position: absolute; display: none; border: 2.5px solid; border-radius: 6px; cursor: move; touch-action: none; }
.crop-stage.has-image .crop-box { display: block; }
.crop-box.face { border-color: var(--face); background: rgba(255,141,82,.10); }
.crop-box.fur { border-color: var(--fur); background: rgba(91,124,255,.10); }
.crop-box.active { background: rgba(255,255,255,.16); }
.crop-box .tag { position: absolute; left: -2px; top: -24px; font-size: 11px; font-weight: 800; color: var(--ink); padding: 3px 8px; border-radius: 8px 8px 0 0; }
.crop-box.face .tag { background: var(--face); }
.crop-box.fur .tag { background: var(--fur); color: #fff; }
.crop-box .handle { position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2.5px solid currentColor; cursor: nwse-resize; }
.crop-box .handle::before { content: ""; position: absolute; inset: -10px; }        /* 터치용 넓은 판정 영역 */
.crop-box.face .handle { color: var(--face); }
.crop-box.fur .handle { color: var(--fur); }
.crop-box .rot { position: absolute; left: 50%; top: -34px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; background: #fff; border: 2.5px solid var(--face); cursor: grab; }
.crop-box .rot::before { content: ""; position: absolute; inset: -10px; }
.crop-box .rot::after { content: ""; position: absolute; left: 50%; top: 15px; width: 2px; height: 16px; margin-left: -1px; background: var(--face); }
.crop-box.face::after { content: attr(data-deg); position: absolute; right: -2px; top: -24px; font-size: 11px; font-weight: 800; color: var(--ink); background: #fff; border: 1.5px solid var(--face); padding: 1px 7px; border-radius: 99px; opacity: 0; transition: opacity .15s; pointer-events: none; }
.crop-box.face.active::after, .crop-box.face:not([data-deg="0°"])::after { opacity: 1; }
.guide.eyes { position: absolute; left: 12%; right: 12%; top: 42%; border-top: 2px dashed rgba(255,255,255,.95); pointer-events: none; }
.guide.nose { position: absolute; left: 50%; top: 70%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; border: 2.5px solid #fff; pointer-events: none; }
.help { margin-top: 14px; font-size: 13.5px; line-height: 1.8; background: var(--sunk); border-radius: 18px; padding: 12px 14px; }
.help small { display: inline-block; line-height: 1.6; margin-top: 2px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--line); margin-right: 6px; vertical-align: -1px; }
.dot.face { background: var(--face); }
.dot.fur { background: var(--fur); }
.link { display: inline-flex; margin-top: 8px; border: 2px solid var(--line); background: var(--card); color: var(--ink); padding: 6px 14px; border-radius: 99px; font-size: 13px; font-weight: 800; }
.link:hover { background: var(--pass); }

/* ---------- 칩 · 버튼 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 99px; border: 2px solid var(--line); background: var(--card); font-size: 13.5px; font-weight: 800; white-space: nowrap; transition: transform .12s, background .15s; }
.chip:hover { background: var(--sunk); }
.chip:active { transform: translateY(1px); }
.chip.active, #actions .chip.active { background: var(--pass); color: var(--ink); border-color: var(--line); }
.chip.primary { background: var(--ink); color: #fff; border-color: var(--ink); box-shadow: 0 4px 0 var(--pass); }
.chip.primary:hover { background: #2B2B30; }

/* 자동 회전 토글 */
.switch { display: inline-flex; gap: 8px; align-items: center; font-size: 13.5px; font-weight: 800; cursor: pointer; white-space: nowrap; }
.switch input { -webkit-appearance: none; appearance: none; margin: 0; flex: none; width: 46px; height: 28px; border-radius: 99px; border: 2px solid var(--line); background: #E4E0D5; position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; left: 2px; top: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--line); box-sizing: border-box; transition: transform .15s; }
.switch input:checked { background: var(--ink); }
.switch input:checked::after { transform: translateX(18px); }

/* ---------- 3D 뷰어 */
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; position: sticky; top: 16px; }
.viewer { position: relative; height: calc(100vh - 176px); max-height: 760px; min-height: 380px; border-radius: 28px; overflow: hidden; border: 2px solid var(--line);
  background-color: #EEEAFF; background-image: radial-gradient(#DAD3FA 1.4px, transparent 1.4px); background-size: 16px 16px; }
.viewer canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
.pet-hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); font-size: 13px; font-weight: 800; color: var(--ink); background: var(--pink); border: 2px solid var(--line); padding: 7px 14px; border-radius: 99px; pointer-events: none; z-index: 1; transition: opacity .6s; white-space: nowrap; }
.pet-hint.gone { opacity: 0; }

.toolbar { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.view-ctrl { display: flex; align-items: center; gap: 8px; padding-left: 10px; border-left: 2px dashed var(--hair); }
.tri { font-size: 12px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.export { display: flex; gap: 8px; margin-left: auto; }

/* ---------- 꾸미기 패널 + 오른쪽 탭 */
.custom { display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 8px; position: sticky; top: 16px; height: calc(100vh - 96px); max-height: 832px; min-height: 480px; }
.panel-box { position: relative; z-index: 1; background: var(--card); border: 2px solid var(--line); border-radius: 28px; padding: 22px 20px; overflow-y: auto; min-width: 0; scrollbar-width: thin; }
.pane-title { margin: 0 0 18px; font-family: var(--f-display); font-weight: 400; font-size: 24px; line-height: 1.2; }
.field + .field { margin-top: 22px; }
.sec-title { margin: 0 0 10px; font-size: 13px; font-weight: 800; color: var(--muted); }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.options.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opt { min-height: 48px; padding: 10px 14px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); font-size: 14px; font-weight: 700; text-align: center; transition: background .15s, transform .12s; }
.opt:hover { background: var(--sunk); }
.opt.active { background: var(--pass); color: var(--ink); font-weight: 800; box-shadow: 0 3px 0 var(--line); transform: translateY(-2px); }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.opt.card { display: flex; flex-direction: column; gap: 6px; padding: 0; border: 0; background: none; min-height: 0; box-shadow: none; transform: none; }
.opt.card .thumb { position: relative; display: block; aspect-ratio: 1; border-radius: 18px; background: var(--sunk); border: 2px solid var(--line); overflow: hidden; transition: background .15s, transform .12s, box-shadow .12s; }
.opt.card .thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; opacity: 0; transition: opacity .2s; }
.opt.card .thumb.ready img { opacity: 1; }
.opt.card .thumb:not(.ready)::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.75) 50%, transparent 70%); background-size: 200% 100%; animation: shimmer 1.1s infinite; }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.opt.card:hover .thumb { background: #E8E3D6; }
.opt.card.active { background: none; }
.opt.card.active .thumb { background: var(--pass); box-shadow: 0 4px 0 var(--line); transform: translateY(-3px); }
.card-label { font-size: 12.5px; font-weight: 700; line-height: 1.3; }
.opt.card.active .card-label { font-weight: 800; }

/* 슬라이더 */
.sliders { display: flex; flex-direction: column; gap: 18px; }
.slider { display: grid; grid-template-columns: 88px minmax(0, 1fr); align-items: center; gap: 12px; font-size: 14px; font-weight: 700; }
.slider input { -webkit-appearance: none; appearance: none; width: 100%; height: 14px; margin: 0; border-radius: 99px; border: 2px solid var(--line);
  background: linear-gradient(90deg, var(--orange) var(--p, 50%), var(--sunk) var(--p, 50%)); }
.slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2.5px solid var(--line); box-shadow: 0 2px 0 var(--line); cursor: grab; }
.slider input::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2.5px solid var(--line); cursor: grab; }
.note { display: block; margin-top: 20px; font-weight: 600; }

/* 책갈피 탭: 패널 옆 세로 알약, 선택은 라임 */
.rail { display: flex; flex-direction: column; gap: 6px; padding-top: 22px; }
.rail-item { min-height: 46px; padding: 8px 6px; border: 2px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); font-size: 14px; font-weight: 700; text-align: center; transition: background .15s, transform .12s; }
.rail-item:hover { background: var(--sunk); transform: translateX(-2px); }
.rail-item.active { background: var(--pass); font-weight: 800; box-shadow: -3px 3px 0 var(--line); transform: translateX(-3px); }

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

/* ============================================================ 폰 (세로)
   한 화면 고정: 위 머리줄 · 가운데 강아지 · 아래 꾸미기 시트. 페이지·패널 모두 스크롤 없음 */
.short { display: none; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.pane-title { display: flex; align-items: baseline; gap: 10px; }
.pane-title .sel { font-family: var(--f-body); font-size: 14px; font-weight: 800; color: var(--muted); }
.pane-title .credits-link { margin: 0 0 0 auto; font-family: var(--f-body); }

@media (max-width: 880px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  .long { display: none !important; }
  .short { display: inline; }

  .top { flex: none; min-height: 52px; padding: calc(6px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px)); }
  .brand { gap: 6px; }
  .brand .logo { width: 30px; height: 30px; }
  .brand .name { font-size: 21px; }
  .brand small { display: none; }

  .layout { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 0 max(12px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); }

  /* 강아지: 남는 높이를 모두 */
  .stage { position: relative; flex: 1; min-height: 0; top: auto; gap: 0; }
  .viewer { height: 100%; min-height: 0; max-height: none; border-radius: 24px; }
  .pet-hint { bottom: 52px; font-size: 12px; padding: 4px 11px; }

  /* 동작·회전은 강아지 화면 위에 얹기 */
  .toolbar { position: absolute; inset: 0; z-index: 2; pointer-events: none; background: none; border: 0; border-radius: 0; padding: 8px; display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; flex-wrap: nowrap; }
  .toolbar > * { pointer-events: auto; }
  .chips { flex-wrap: nowrap; gap: 4px; min-width: 0; }
  .chip { min-height: 34px; padding: 0 11px; font-size: 12.5px; }
  #actions .chip { background: rgba(255,255,255,.88); }
  #actions .chip.active { background: var(--pass); }
  .view-ctrl { flex: none; flex-direction: column; align-items: flex-end; gap: 6px; padding: 0; border: 0; }
  .switch { gap: 5px; font-size: 12px; background: rgba(255,255,255,.88); border: 2px solid var(--line); border-radius: 99px; padding: 3px 4px 3px 9px; flex-direction: row-reverse; }
  .switch input { width: 38px; height: 24px; }
  .switch input::after { width: 16px; height: 16px; }
  .switch input:checked::after { transform: translateX(14px); }
  #resetView { width: 34px; padding: 0; background: rgba(255,255,255,.88); }
  .tri { display: none; }
  /* 위아래가 아닌 오른쪽 위 구석으로 */
  .view-ctrl { position: absolute; top: 8px; right: 8px; flex-direction: row; }

  /* 내보내기는 머리줄 오른쪽 */
  .export { position: fixed; z-index: 30; margin: 0; gap: 6px; top: calc(9px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); }
  .export .chip { min-height: 34px; padding: 0 13px; font-size: 13px; }
  .export .primary { box-shadow: 0 3px 0 var(--pass); }

  /* 꾸미기 시트: 탭 한 줄 + 높이 고정 패널 */
  .custom { position: static; flex: none; display: flex; flex-direction: column; height: auto; max-height: none; min-height: 0; gap: 6px; }
  .rail { order: -1; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; padding: 0; overflow: visible; }
  .rail-item { min-width: 0; min-height: 38px; padding: 0; border-radius: 12px; font-size: 13.5px; white-space: nowrap; }
  .rail-item:hover { transform: none; }
  .rail-item.active { box-shadow: 0 3px 0 var(--line); transform: translateY(-2px); }

  .panel-box { --ph: clamp(196px, 31dvh, 272px); height: var(--ph); overflow: hidden; border-radius: 22px; padding: 10px 12px 12px; display: flex; flex-direction: column; }
  .pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .pane[hidden] { display: none; }
  .pane-title { flex: none; margin: 0 0 8px; font-size: 17px; line-height: 1.25; white-space: nowrap; }
  .pane-title .sel { font-size: 13px; }
  .pane-title .credits-link { font-size: 11.5px; }
  .field + .field { margin-top: 10px; }
  .sec-title { display: none; }
  #cardsPane { justify-content: flex-start; }
  #cardsPane > .field:first-of-type { flex: 0 1 auto; min-height: 0; }

  /* 카드: 이름은 제목 옆에만, 칸 수는 항목 수에 맞춰 한두 줄 */
  .card-label { display: none; }
  .cards { --cols: 5; --rows: 1; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 6px; }
  .cards.n-17 { --cols: 6; --rows: 3; }
  .cards.n-9 { --cols: 5; --rows: 2; }
  .cards.n-3 { --cols: 3; }
  .cards.n-4 { --cols: 4; }
  /* 패널 높이에 맞춰 썸네일 크기 제한 → 넘치지 않게 */
  .opt.card .thumb { border-radius: 12px; max-height: calc((var(--ph) - 52px - (var(--rows) - 1) * 6px) / var(--rows)); width: 100%; margin: 0 auto; }
  .cards.n-3 .opt.card .thumb, .cards.n-4 .opt.card .thumb { max-height: calc(var(--ph) - 112px); }
  .opt.card.active .thumb { box-shadow: 0 3px 0 var(--line); transform: translateY(-2px); }

  /* 슬라이더: 촘촘하게 */
  .sliders { gap: 4px; }
  #cardsPane > .sliders:nth-child(2) { flex: 1; min-height: 0; gap: 0; justify-content: space-evenly; }
  #cardsPane .pane-title.bare { display: none; }
  .slider { grid-template-columns: 74px minmax(0, 1fr); gap: 10px; font-size: 13.5px; min-height: 34px; }
  .slider span { white-space: nowrap; }
  .slider input { height: 12px; }
  .slider input::-webkit-slider-thumb { width: 24px; height: 24px; }

  /* 사진 탭 */
  /* 사진을 올리면 박스 맞추기 쉽게 시트를 키움 */
  .panel-box:has(.crop-stage.has-image) { --ph: clamp(250px, 44dvh, 400px); }
  .crop-stage { flex: 1; min-height: 0; display: flex; justify-content: center; }
  .drop { flex: 1; min-height: 0; border-radius: 16px; padding: 10px; gap: 4px; font-size: 14px; }
  .drop-dog { width: 56px; height: 56px; }
  .crop-img { width: auto; max-width: 100%; max-height: 100%; height: auto; object-fit: contain; border-radius: 12px; align-self: center; }
  #photoPane:has(.crop-stage.has-image) .pane-title { display: none; }
  .crop-box .tag { font-size: 10px; top: -20px; padding: 2px 6px; }
  .help { flex: none; margin-top: 8px; padding: 0; background: none; display: flex; align-items: center; gap: 10px; font-size: 13px; line-height: 1; white-space: nowrap; }
  .help[hidden] { display: none; }
  .legend { display: inline-flex; align-items: center; }
  .help-btns { margin-left: auto; display: inline-flex; gap: 6px; }
  .link { margin: 0; padding: 0 12px; min-height: 32px; align-items: center; font-size: 12.5px; }
}

@media (max-width: 359px) {
  .brand .name { font-size: 18px; }
  .brand .logo { width: 26px; height: 26px; }
  .export .chip { padding: 0 10px; font-size: 12px; }
  .rail-item { font-size: 12.5px; border-radius: 10px; }
  .chip { padding: 0 9px; font-size: 12px; }
  .help { gap: 6px; }
  .link { padding: 0 9px; }
}

/* 버튼 hover가 없는 기기에서는 눌림만 */
@media (hover: none) {
  .chip:hover, .opt:hover, .rail-item:hover { background: var(--card); }
  .chip.primary:hover { background: var(--ink); }
  .rail-item.active:hover, .opt.active:hover, .chip.active:hover, #actions .chip.active:hover { background: var(--pass); }
  .opt.card:hover .thumb { background: var(--sunk); }
  .opt.card.active:hover .thumb { background: var(--pass); }
}

.credits-link { display: inline-block; margin-top: 16px; font-size: 12px; color: inherit; opacity: .6; }
.credits-link:hover { opacity: 1; }
