/* 팔레트 스튜디오 — 무채색 크롬 + 단일 민트 액센트. 색 견본이 주인공. */

/* ============ 토큰 ============ */
:root,
[data-theme="dark"] {
  --bg: #0e0f12;
  --surface: #16181d;
  --surface-2: #1d2026;
  --ink: #e9eaed;
  --muted: #8b9099;
  --line: #2a2e36;
  --accent: #2dd4bf;
  --accent-ink: #06302b;
  --pass: #34d399;
  --fail: #fb7185;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #efefea;
  --ink: #1a1b1e;
  --muted: #6b7079;
  --line: #e2e2dc;
  --accent: #0d9488;
  --accent-ink: #ffffff;
  --pass: #059669;
  --fail: #e11d48;
  --shadow: 0 12px 40px rgba(20, 20, 20, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Pretendard", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.18s ease, color 0.18s ease;
}

.num, .mono { font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

kbd {
  font-family: "Space Grotesk", monospace;
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
}

/* ============ 헤더 / 툴바 ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background:
    linear-gradient(135deg, #fb7185 0 33%, transparent 33%),
    linear-gradient(135deg, transparent 33%, #f59e0b 33% 66%, transparent 66%),
    linear-gradient(135deg, transparent 66%, var(--accent) 66%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.brand-name {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600; font-size: 16px; letter-spacing: -0.01em;
}

.toolbar {
  display: flex; align-items: center; gap: 8px;
  flex: 1 1 auto; min-width: 0; flex-wrap: wrap;
}
.toolbar-spacer { flex: 1 1 auto; }

.base-field {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 0 10px; height: 36px;
}
.base-dot {
  width: 16px; height: 16px; border-radius: 4px;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
}
.base-input {
  background: none; border: none; color: var(--ink);
  font-family: "Space Grotesk", monospace; font-size: 14px;
  font-variant-numeric: tabular-nums;
  width: 8.5ch; text-transform: lowercase;
}
.base-input:focus { outline: none; }

.select, .btn, .icon-btn {
  height: 36px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 0.14s ease, border-color 0.14s ease, transform 0.06s ease;
}
.select { padding: 0 10px; }
.btn { padding: 0 14px; }
.btn:hover, .select:hover, .icon-btn:hover { background: var(--surface-2); }
.btn:active, .icon-btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.ghost { background: transparent; }

.icon-btn {
  width: 36px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.icon-btn.ghost { background: transparent; border-color: transparent; }
.icon-btn.ghost:hover { background: var(--surface-2); }

/* ============ 레이아웃 ============ */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  padding: 18px 20px 40px;
  max-width: 1320px; margin: 0 auto;
}
.side { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.panel-title { margin: 0; font-family: "Space Grotesk", sans-serif; font-size: 15px; font-weight: 600; }
.panel-note { color: var(--muted); font-size: 11.5px; }

/* ============ 팔레트 스트립 ============ */
.strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.col {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--surface-2);
}
.swatch {
  position: relative; height: 150px;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 10px; cursor: default;
  transition: background 0.16s ease;
}
.swatch-actions { display: flex; gap: 6px; }
.swatch-btn {
  width: 28px; height: 28px; border-radius: 7px;
  border: 1px solid rgba(0,0,0,0.18);
  background: rgba(255,255,255,0.85); color: #111;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; line-height: 1;
  transition: transform 0.08s ease, background 0.12s ease;
}
.swatch-btn:hover { transform: scale(1.06); }
.swatch-btn.on { background: #111; color: #fff; }
.swatch-role {
  font-family: "Space Grotesk", sans-serif;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(0,0,0,0.28); color: #fff;
}
.col-body { padding: 10px; display: flex; flex-direction: column; gap: 2px; }

.fmt-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 5px 7px; border-radius: 7px;
  cursor: pointer; transition: background 0.12s ease;
}
.fmt-row:hover { background: var(--surface); }
.fmt-key {
  font-family: "Space Grotesk", sans-serif; font-size: 10px; font-weight: 600;
  letter-spacing: 0.06em; color: var(--muted); width: 42px; flex: none;
}
.fmt-val {
  font-family: "Space Grotesk", monospace; font-size: 12px;
  font-variant-numeric: tabular-nums;
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fmt-copy { color: var(--muted); font-size: 12px; flex: none; }
.fmt-row.copied .fmt-copy { color: var(--pass); }
.fmt-row.copied .fmt-key { color: var(--pass); }

.scale-strip { display: flex; height: 22px; border-radius: 6px; overflow: hidden; margin-top: 8px; }
.scale-cell { flex: 1; position: relative; cursor: pointer; }
.scale-cell::after {
  content: attr(data-stop);
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-family: "Space Grotesk", monospace; opacity: 0;
  transition: opacity 0.12s ease;
}
.scale-cell:hover::after { opacity: 1; }
/* Touch: swatches (28px), the 22px scale strip, and 36px toolbar controls all sit
   under the 44px tap minimum — enlarge on phones so thumbs can hit them. */
@media (pointer: coarse) {
  .swatch-btn { width: 44px; height: 44px; }
  .scale-strip { height: 44px; }
  .btn, .select, .icon-btn, .base-field { min-height: 44px; }
}

.hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.hint b { color: var(--ink); font-weight: 600; }

/* ============ 대비 매트릭스 ============ */
.contrast-list { display: flex; flex-direction: column; gap: 8px; }
.contrast-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 12px; padding: 10px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--surface-2);
}
.cr-sample {
  width: 64px; height: 44px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px; flex: none;
  border: 1px solid rgba(128,128,128,0.25);
}
.cr-meta { min-width: 0; }
.cr-pair {
  font-family: "Space Grotesk", monospace; font-size: 11px;
  color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cr-ratio {
  font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 22px;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.cr-badges { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; max-width: 116px; }
.badge {
  font-family: "Space Grotesk", sans-serif; font-size: 10px; font-weight: 600;
  padding: 3px 7px; border-radius: 6px; white-space: nowrap;
  border: 1px solid transparent;
}
.badge.pass {
  color: var(--pass); background: color-mix(in srgb, var(--pass) 14%, transparent);
  border-color: color-mix(in srgb, var(--pass) 35%, transparent);
}
.badge.fail {
  color: var(--fail); background: color-mix(in srgb, var(--fail) 12%, transparent);
  border-color: color-mix(in srgb, var(--fail) 30%, transparent);
}

/* ============ 미리보기 ============ */
.preview-card { border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.pv-inner { padding: 18px; }
.pv-badge {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  padding: 3px 9px; border-radius: 999px; margin-bottom: 12px;
}
.pv-heading { font-family: "Space Grotesk", sans-serif; font-size: 19px; font-weight: 700; margin: 0 0 8px; }
.pv-body { font-size: 13px; margin: 0 0 14px; }
.pv-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.pv-btn {
  border: none; border-radius: 8px; padding: 9px 16px;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.pv-btn.ghost { background: transparent; }
.pv-link { font-size: 13px; font-weight: 600; text-decoration: none; }
.pv-link:hover { text-decoration: underline; }

/* ============ 모달 ============ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade 0.16s ease;
}
.modal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
  width: min(560px, 100%); max-height: 86vh; display: flex; flex-direction: column;
  animation: pop 0.16s ease;
}
.modal-head, .drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-title, .drawer-title { margin: 0; font-family: "Space Grotesk", sans-serif; font-size: 16px; font-weight: 600; }

.tabs { display: flex; gap: 6px; padding: 14px 18px 0; }
.tab {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 8px; padding: 7px 13px; font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.12s ease;
}
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.code-block {
  margin: 14px 18px; padding: 14px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: "Space Grotesk", monospace; font-size: 12.5px; line-height: 1.6;
  overflow: auto; max-height: 44vh; white-space: pre; color: var(--ink);
}
.modal-actions { padding: 0 18px 18px; display: flex; justify-content: flex-end; }

/* ============ 보관함 서랍 ============ */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 45;
  width: min(360px, 90vw); background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: slidein 0.18s ease;
}
.saved-list { padding: 14px; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.saved-item {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer;
  transition: border-color 0.12s ease;
}
.saved-item:hover { border-color: var(--accent); }
.saved-swatches { display: flex; height: 40px; }
.saved-swatches span { flex: 1; }
.saved-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; font-size: 12px;
}
.saved-name { font-weight: 600; }
.saved-del {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px;
  padding: 2px 6px; border-radius: 6px;
}
.saved-del:hover { color: var(--fail); background: var(--surface-2); }
.empty { color: var(--muted); text-align: center; padding: 30px 16px; font-size: 13px; }

/* ============ 토스트 ============ */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 애니메이션 ============ */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
@keyframes slidein { from { transform: translateX(100%); } to { transform: translateX(0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============ 반응형 ============ */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .side { flex-direction: column; }
}
@media (max-width: 720px) {
  .strip { grid-template-columns: 1fr; }
  .col { flex-direction: row; }
  .swatch { height: auto; min-height: 96px; width: 120px; flex: none; }
  .col-body { flex: 1 1 auto; }
  .toolbar-spacer { display: none; }
  .toolbar { gap: 6px; }
}
@media (max-width: 480px) {
  .col { flex-direction: column; }
  .swatch { width: auto; height: 110px; }
  .cr-badges { max-width: 92px; }
}
[hidden] { display: none !important; }

/* 언어 스위처 (라이트/다크 테마 대응) */
.i18n-switch {
  --i18n-switch-bg: rgba(128,128,128,.14);
  --i18n-switch-border: rgba(128,128,128,.3);
  --i18n-switch-active-bg: rgba(45,212,191,.22);
  --i18n-switch-active-fg: #14b8a6;
  --i18n-switch-menu-border: rgba(128,128,128,.3);
}
[data-theme="dark"] .i18n-switch { --i18n-switch-fg: rgba(255,255,255,.9); --i18n-switch-menu-bg: #16181d; }
[data-theme="light"] .i18n-switch { --i18n-switch-fg: rgba(20,20,25,.92); --i18n-switch-menu-bg: #ffffff; }
