:root {
  color-scheme: light;
  --bg: #edf1f4;
  --ink: #20242a;
  --muted: #66707a;
  --line: #d3dbe2;
  --panel: #ffffff;
  --accent: #0b7d7b;
  --accent-dark: #075f5e;
  --danger: #b93638;
  --button: #f6f8fa;
  --shadow: 0 18px 45px rgba(30, 40, 50, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 260px;
  height: 100vh;
}

.app-shell.compact {
  grid-template-columns: 300px minmax(0, 1fr);
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  /* 패널 자체 스크롤 없음 — 제품 목록이 독립 스크롤 */
  overflow: hidden;
  padding: 22px 22px 0;
  gap: 18px;
}

/* 제품 섹션: 남은 공간 전부 + 내부 스크롤 */
.product-section {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  /* 하단 패딩은 제품 목록 안쪽에서 처리 */
}

.product-section .section-title-row {
  flex-shrink: 0;
  padding-bottom: 8px;
}

.product-section .product-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding-bottom: 22px; /* 마지막 아이템 아래 여백 */
}

.details-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 27% 27%, rgba(255, 255, 255, 0.9) 0 12%, transparent 13%),
    radial-gradient(circle at 70% 27%, rgba(255, 255, 255, 0.9) 0 12%, transparent 13%),
    radial-gradient(circle at 27% 70%, rgba(255, 255, 255, 0.9) 0 12%, transparent 13%),
    radial-gradient(circle at 70% 70%, rgba(255, 255, 255, 0.9) 0 12%, transparent 13%),
    #d92929;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.15;
}

.brand p,
.compact-help p,
.selection-box p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

h2 {
  margin-bottom: 10px;
  color: #323941;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.control-group {
  min-width: 0;
}

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

.rotation,
.tool-button,
.icon-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button);
  color: var(--ink);
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease,
    color 0.15s ease;
}

.rotation:hover,
.tool-button:hover,
.icon-button:hover,
.product-card:hover {
  transform: translateY(-1px);
}

.rotation.active,
.transform-mode.active,
.tool-button.active,
.icon-button:active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.tool-stack {
  display: grid;
  gap: 8px;
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.size-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.size-grid input {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: var(--ink);
  font-weight: 800;
}

.base-colors {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.base-swatch {
  aspect-ratio: 1;
  min-width: 0;
  border: 2px solid #ffffff;
  border-radius: 8px;
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--line), inset 0 -6px 0 rgba(0, 0, 0, 0.12);
}

.base-swatch.active {
  box-shadow:
    0 0 0 3px var(--accent),
    inset 0 -6px 0 rgba(0, 0, 0, 0.12);
}

.range-row {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.range-row input {
  width: 100%;
  accent-color: var(--accent);
}

.tool-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.tool-button span {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}

.transform-modes {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.rotation-pad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

/* ── 베타 뱃지 ── */
.beta-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  background: #e84040;
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 4px;
  position: relative;
  top: -2px;
}

/* 사이드바 언어 선택기: 데스크톱에서 숨김 */
.sidebar-lang-select { display: none; }

/* ── 장식장 설정 토글 (모바일용) ── */
.cabinet-toggle {
  display: none; /* 데스크톱에서 숨김 */
}
.desktop-only-h2 { display: block; }
.cabinet-body { display: contents; } /* 데스크톱: 그냥 흘려보냄 */

/* ── 커뮤니티 버튼 (topbar) ── */
.community-link {
  background: var(--accent);
  color: #fff !important;
  text-decoration: none;
  border-radius: 7px;
}
.community-link:hover { background: var(--accent-dark); }

.axis-label {
  margin: 10px 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rotation-pad .tool-button {
  min-height: 38px;
  font-size: 13px;
}

.transform-mode {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button);
  color: var(--ink);
  font-weight: 750;
}

.product-list {
  display: grid;
  gap: 8px;
}

.product-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 78px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: var(--ink);
  text-align: left;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}

.product-card:hover {
  border-color: rgba(11, 125, 123, 0.42);
  background: #eef8f7;
}

.product-thumb {
  display: block;
  width: 72px;
  height: 58px;
  overflow: hidden;
  border-radius: 7px;
  background: #e8eef2;
}

.product-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #ffffff;
}

.product-card strong,
.product-card small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-card strong {
  font-size: 14px;
}

.product-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

/* ── 프리로드 상태 점 ── */
.preload-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.3s;
}
.product-card { position: relative; }

.preload-loading {
  background: #f59e0b;
  animation: pulse-dot 1s infinite;
}
.preload-cached {
  background: #22c55e;
}
.preload-error {
  background: #ef4444;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.empty-text {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tool-button.danger,
.icon-button.danger {
  color: var(--danger);
}

.tool-button.danger:hover,
.icon-button.danger:hover {
  border-color: rgba(185, 54, 56, 0.4);
  background: #fff5f5;
}

.stage-area {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
}

.topbar {
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  min-height: 66px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
}

.topbar strong {
  display: block;
  font-size: 15px;
}

.topbar span {
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.language-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button);
  font-size: 12px;
  font-weight: 800;
}

.language-select select {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title-row h2 {
  margin-bottom: 0;
}

.text-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--button);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.quick-controls {
  display: grid;
  gap: 8px;
  min-width: 280px;
}

.quick-mode,
.quick-rotate {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.quick-rotate {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.mini-button {
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--button);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.icon-button {
  min-width: 82px;
  min-height: 38px;
  padding: 0 12px;
}

.viewport {
  position: relative;
  min-height: 0;
  outline: none;
  background: #dce4ea;
}

.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.selection-box {
  display: grid;
  gap: 9px;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.selection-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.selection-row span:first-child {
  color: var(--muted);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: #37404a;
  font-weight: 700;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ── 태블릿 ── */
@media (max-width: 980px) {
  body { overflow: auto; }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(60vh, 1fr);
    min-height: 100vh;
    height: auto;
  }

  .panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand { grid-column: 1 / -1; }
  .details-panel { border-left: 0; border-top: 1px solid var(--line); }
}

/* ── 모바일 ── */
@media (max-width: 620px) {
  body { overflow: hidden; }

  /* 전체 레이아웃: 뷰어 위 + 하단 서랍 */
  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh; /* fallback */
    overflow: hidden;
  }

  /* 사이드 패널을 하단 서랍으로 */
  .tools-panel {
    order: 2;
    flex: 0 0 50dvh;
    flex: 0 0 50vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 내부 섹션이 스크롤 처리 */
    border-right: 0;
    border-top: 2px solid var(--accent);
    background: var(--panel);
    /* 데스크톱 패딩 덮어쓰기 */
    padding: 0;
    gap: 0;
  }

  /* 드래그 핸들 힌트 */
  .tools-panel::before {
    content: "";
    display: block;
    flex-shrink: 0;
    width: 36px;
    height: 4px;
    background: var(--line);
    border-radius: 2px;
    margin: 8px auto 4px;
  }

  /* 브랜드 + 설정: 스크롤 없이 고정 */
  .tools-panel > .brand {
    flex-shrink: 0;
    padding: 6px 14px 6px;
  }
  .tools-panel > .cabinet-group {
    flex-shrink: 0;
    padding: 0;
  }

  /* 브랜드 가로 컴팩트 */
  .brand { flex-direction: row; align-items: center; }
  .brand-mark { width: 28px; height: 28px; flex: 0 0 28px; }
  h1 { font-size: 15px; }

  /* 장식장 설정 토글 버튼 (모바일) */
  .cabinet-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 14px;
    background: var(--bg);
    border: none;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
  }
  .cabinet-toggle-arrow { transition: transform 0.2s; font-size: 10px; }
  .cabinet-toggle[aria-expanded="true"] .cabinet-toggle-arrow { transform: rotate(180deg); }

  /* cabinet-body 접힘/펼침 */
  .cabinet-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 14px 10px;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease, padding 0.25s ease;
    padding-top: 0;
    padding-bottom: 0;
  }
  .cabinet-body.open {
    max-height: 400px;
    padding: 10px 14px;
  }

  .desktop-only-h2 { display: none; }

  /* 장식판 크기 인풋 */
  .size-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .size-grid input { min-height: 36px; font-size: 14px; }

  /* 색상 스와치 */
  .base-colors { grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 0; }
  .base-swatch { border-radius: 6px; }

  /* 제품 섹션: 남은 공간 + 가로 스크롤 */
  .tools-panel > .product-section {
    flex: 1 1 0;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 14px 14px;
    gap: 0;
  }
  .tools-panel > .product-section .section-title-row {
    flex-shrink: 0;
    padding-bottom: 6px;
  }
  .tools-panel > .product-section .product-list {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    gap: 8px;
    padding-bottom: 4px;
  }
  .product-list::-webkit-scrollbar { height: 3px; }
  .product-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

  .product-card {
    flex: 0 0 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    gap: 5px;
  }
  .product-thumb { width: 72px; height: 58px; }
  .product-card strong { font-size: 11px; white-space: normal; text-align: center; line-height: 1.3; }
  .product-card small { display: none; }

  /* 뷰어 */
  .stage-area {
    order: 1;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .viewport { flex: 1; min-height: 0; }

  /* 상단 툴바: 2줄 */
  .topbar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 10px 5px;
    flex-shrink: 0;
  }

  /* 줄 1: 상태 + 이동/회전/크기 + 커뮤니티/전체삭제 */
  .topbar-row1 {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
  }

  .topbar > div:first-child {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }
  .topbar strong { font-size: 11px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar span { font-size: 10px; color: var(--muted); }

  /* 이동/회전/크기 */
  .quick-controls { gap: 4px; }
  .quick-mode { gap: 2px; }
  .transform-mode { min-height: 30px; font-size: 11px; padding: 0 8px; }

  /* 언어 선택 topbar에서 숨김 → 사이드바로 이동 */
  .topbar-actions { gap: 4px; flex-wrap: nowrap; }
  .topbar-actions .language-select { display: none; }
  .icon-button { min-width: 46px; min-height: 30px; font-size: 11px; padding: 0 6px; }

  /* 줄 2: 회전 버튼 6개 */
  .quick-rotate {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 3px;
  }
  .mini-button { min-height: 26px; font-size: 10px; padding: 0 2px; }

  /* 사이드바 언어 선택기 (모바일 전용 표시) */
  .sidebar-lang-select { display: flex; margin-left: auto; }
  .sidebar-lang-select select {
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 4px 6px;
    font-size: 12px;
    background: var(--bg);
    color: var(--ink);
    outline: none;
  }

}
