:root {
  /* 브이월드(www.vworld.kr) 실제 디자인 시스템의 색상값을 기준으로 함 (라이트 기본값) */
  --color-primary: rgb(74, 99, 225);
  --color-primary-tint05: rgba(74, 99, 225, 0.05);
  --color-primary-tint10: rgba(74, 99, 225, 0.1);
  --color-primary-tint20: rgba(74, 99, 225, 0.2);
  --color-primary-dark: rgb(56, 78, 190);

  --color-wh: #fff;
  --color-border-tint: rgba(0, 0, 0, 0.1);

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --border: #dde3ec;
  --text: #1c2733;
  --text-muted: #6b7684;
  --text-faint: #9aa4b1;

  --radius-min: 4px;
  --radius-max: 8px;
  --shadow-min: 0 2px 4px var(--color-border-tint);
  --shadow-max: 0 0 8px var(--color-border-tint);
}

/* 실제 적용할 다크 여부는 JS가 시스템/라이트/다크 설정을 계산해 html.dark 로 반영한다 */
html.dark {
  --color-primary-tint05: rgba(74, 99, 225, 0.14);
  --color-primary-tint10: rgba(74, 99, 225, 0.22);
  --color-primary-tint20: rgba(74, 99, 225, 0.32);

  --color-border-tint: rgba(255, 255, 255, 0.12);

  --bg: #14171c;
  --surface: #1b1f26;
  --surface-alt: #20242c;
  --border: #2a2f38;
  --text: #e8eaed;
  --text-muted: #9aa3ad;
  --text-faint: #6b7280;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", -apple-system, BlinkMacSystemFont, sans-serif;
  transition: background-color 0.15s ease, color 0.15s ease;
}

body {
  display: flex;
  flex-direction: column;
}

a {
  text-decoration: none;
}

/* 헤더 아래: 좌측 아이콘 레일 + 본문 */

.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.side-rail {
  flex: none;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
  background: var(--surface-alt);
  border-right: 1px solid var(--color-border-tint);
}

.rail-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 52px;
  padding: 8px 0;
  border: none;
  border-radius: var(--radius-min);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.rail-btn:hover {
  background: var(--color-primary-tint05);
  color: var(--color-primary);
}

.rail-btn.active {
  background: var(--color-primary-tint10);
  color: var(--color-primary);
}

.rail-btn svg {
  width: 20px;
  height: 20px;
}

.rail-label {
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.rail-shortcut {
  margin-top: 16px;
  text-decoration: none;
}

.left-panel {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  /* 갤러리 카드(min 240px) + .gallery-view 좌우 padding(24px*2)이 잘리지 않는 최소 너비 */
  min-width: 320px;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.pane-resizer {
  flex: none;
  width: 6px;
  margin: 0 -3px;
  position: relative;
  z-index: 1;
  cursor: col-resize;
  background: transparent;
}

.pane-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: var(--border);
  transition: background-color 0.15s ease;
}

.pane-resizer:hover::after,
.pane-resizer.dragging::after {
  left: 0;
  width: 100%;
  transform: none;
  background: var(--color-primary);
}

body.pane-resizing {
  cursor: col-resize;
  user-select: none;
}

/* 헤더 (브이월드 gnb 스타일) */

.app-header {
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-bottom: 1px solid var(--color-border-tint);
  box-shadow: var(--shadow-min);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
  padding: 0 24px;
  border-bottom: 1px solid var(--color-border-tint);
}

.brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.brand-name {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
}

.brand-name:hover {
  opacity: 0.75;
}

.brand-logo {
  display: block;
  height: 26px;
  width: auto;
}

.brand-name span {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-muted);
}

nav.gnb {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 28px;
  min-width: 0;
}

nav.gnb .menu {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

nav.gnb .menu:hover {
  color: var(--color-primary);
}

/* 테마 버튼: 클릭할 때마다 시스템 → 라이트 → 다크 순환 */

.theme-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.theme-btn:hover {
  border-color: var(--color-primary-tint20);
  color: var(--color-primary);
}

.bt {
  height: 32px;
  padding: 0 16px;
  border-radius: var(--radius-min);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, background-color 0.15s ease;
}

.bt.bg.primary {
  background: var(--color-primary);
  color: var(--color-wh);
}

.bt.bg.primary:hover {
  background: var(--color-primary-dark);
}

.bt.bd {
  background: var(--surface);
  color: var(--color-primary);
  border-color: var(--color-primary-tint20);
}

.bt.bd:hover {
  background: var(--color-primary-tint05);
}


/* 갤러리 */

.gallery-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--color-primary-tint20) transparent;
}

.gallery-view::-webkit-scrollbar {
  width: 10px;
}

.gallery-view::-webkit-scrollbar-track {
  background: transparent;
}

.gallery-view::-webkit-scrollbar-thumb {
  background-color: var(--color-primary-tint20);
  border-radius: 100px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.gallery-view::-webkit-scrollbar-thumb:hover {
  background-color: rgba(74, 99, 225, 0.45);
}

html.dark .gallery-view::-webkit-scrollbar-thumb:hover {
  background-color: rgba(74, 99, 225, 0.55);
}

.gallery-view[hidden],
.pane[hidden] {
  display: none;
}

.gallery-toolbar h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.gallery-count {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  margin-left: 2px;
  border-radius: 100px;
  background: var(--color-primary-tint10);
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 700;
  vertical-align: middle;
}

.gallery-toolbar p {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.gallery-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-max);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.gallery-card:hover {
  border-color: var(--color-primary-tint20);
  box-shadow: var(--shadow-min);
}

.gallery-thumb {
  height: 110px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--color-primary-tint20), var(--color-primary-tint05));
}

.gallery-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 14px;
}

.gallery-card-title {
  font-size: 14px;
  font-weight: 700;
}

.gallery-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.gallery-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 100px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.run-btn-inline {
  height: 26px;
  padding: 0 12px;
  font-size: 12px;
}

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

#preview-pane {
  min-width: 240px;
}

.pane-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.pane-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-hint {
  font-weight: 400;
  color: var(--text-faint);
}

.editor-host {
  flex: 1;
  min-height: 0;
}

.preview-host {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  background: #fff;
}

@media (max-width: 900px) {
  .side-rail {
    width: 48px;
  }

  .rail-label {
    display: none;
  }

  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .app-shell {
    flex-direction: column;
  }

  .left-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-basis: auto !important;
  }

  .pane-resizer {
    display: none;
  }
}
