:root {
  --bg: #0d1017;
  --bg-2: #141925;
  --panel: #161c28;
  --panel-2: #1d2533;
  --line: #283143;
  --text: #e7ecf3;
  --muted: #8b97ab;
  --accent: #6c8cff;
  --accent-2: #9b6cff;
  --ok: #36d399;
  --bad: #f87272;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Noto Sans KR", "Noto Sans", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 80% -10%, #1b2336 0%, var(--bg) 55%);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}
.logo {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}
.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.brand p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}
.ai-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}
.ai-status .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.ai-status.on .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(54, 211, 153, 0.15);
}
.ai-status.off .dot {
  background: var(--bad);
}

/* ---- layout ---- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  min-height: 0;
}

.panel {
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
}
.group h2 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}
.group h2 small {
  text-transform: none;
  letter-spacing: 0;
  color: var(--accent);
  font-weight: 600;
}

.row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
#sizeSwap {
  margin-bottom: 3px;
}
label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.field {
  margin-bottom: 10px;
}
input[type="text"],
input[type="number"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 140, 255, 0.18);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}
.chips button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: 0.15s;
}
.chips button:hover {
  border-color: var(--accent);
  color: #fff;
}

/* color palette combobox */
.combo {
  position: relative;
  margin-top: 10px;
}
.combo-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
}
.combo-btn:hover {
  border-color: var(--accent);
}
.combo-caret {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}
.sw {
  display: inline-flex;
  flex: none;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.sw i {
  width: 16px;
  height: 16px;
  display: block;
}
.combo-list {
  margin-top: 6px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
}
.combo-list[hidden] {
  display: none;
}
.combo-opt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text);
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  text-align: left;
}
.combo-opt:hover {
  background: var(--panel);
}
.combo-opt.active {
  background: var(--accent);
  color: #fff;
}

.colors {
  align-items: center;
}
.colors label {
  align-items: center;
  flex-direction: row;
  gap: 8px;
}
input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.swap {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 15px;
}
.swap:hover {
  border-color: var(--accent);
}

.toggle {
  display: inline-flex;
  margin-top: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}
.toggle button,
.seg button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.toggle button.active,
.seg button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-ai {
  width: 100%;
  background: linear-gradient(135deg, rgba(155, 108, 255, 0.18), rgba(108, 140, 255, 0.18));
  border: 1px solid var(--accent-2);
  color: #d9d2ff;
  padding: 11px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  transition: 0.15s;
}
.btn-ai:hover {
  background: linear-gradient(135deg, rgba(155, 108, 255, 0.3), rgba(108, 140, 255, 0.3));
}
.btn-ai:disabled {
  opacity: 0.5;
  cursor: default;
}
.hint {
  font-size: 11.5px;
  color: var(--muted);
  margin: 8px 0 0;
  min-height: 14px;
}

.btn-primary {
  margin-top: auto;
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  padding: 13px;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 0.1s;
}
.btn-primary:active {
  transform: translateY(1px);
}

/* ---- results ---- */
.results {
  padding: 18px 22px;
  overflow-y: auto;
}
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.head-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.cols-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cols-label {
  color: var(--muted);
  font-size: 12px;
}
.results-head #count {
  color: var(--muted);
  font-size: 13px;
}
.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.card .thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: repeating-conic-gradient(#1a2030 0% 25%, #161c28 0% 50%) 50% / 18px 18px;
}
.card .thumb svg {
  position: absolute;
  inset: 14px;
  width: calc(100% - 28px);
  height: calc(100% - 28px);
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.card .cap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.tag.ai {
  color: #d9d2ff;
  border-color: var(--accent-2);
}
.tag.rule {
  color: var(--muted);
}

/* ---- modal ---- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
}
.modal[hidden] {
  display: none;
}
.modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 14, 0.72);
  backdrop-filter: blur(3px);
}
.modal-card {
  position: relative;
  width: min(80vw, 760px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.preview {
  display: grid;
  place-items: center;
  background: repeating-conic-gradient(#1a2030 0% 25%, #161c28 0% 50%) 50% / 22px 22px;
  border-radius: 12px;
  padding: 22px;
  max-height: 62vh;
}
.preview svg {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions .meta {
  font-size: 12.5px;
  color: var(--muted);
}
.modal-actions .spacer {
  flex: 1;
}
.modal-actions button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
}
.modal-actions button:hover {
  border-color: var(--accent);
}
.modal-actions button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  font-weight: 600;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 60px 0;
  font-size: 14px;
  grid-column: 1 / -1;
}

/* ---- top-right, mode, language ---- */
.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.toggle.lang button {
  padding: 7px 11px;
  font-size: 12px;
}

/* ---- logo upload ---- */
.btn-upload {
  width: 100%;
  background: var(--panel-2);
  border: 1px dashed var(--line);
  color: var(--text);
  padding: 11px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
}
.btn-upload:hover {
  border-color: var(--accent);
}
.logo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.logo-row[hidden] {
  display: none;
}
.logo-row button {
  background: none;
  border: none;
  color: var(--bad);
  cursor: pointer;
  font-size: 13px;
}

/* candidate-count pills */
.count-control {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.pills {
  display: inline-flex;
  gap: 6px;
}
.pills button {
  min-width: 34px;
  height: 30px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
}
.pills button:hover {
  border-color: var(--accent);
  color: var(--text);
}
.pills button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---- designer editor ---- */
.editor {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.editor[hidden] {
  display: none;
}
.editor-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.editor-top .etitle {
  font-weight: 700;
}
.editor-top .etitle small {
  color: var(--muted);
  font-weight: 400;
  margin-left: 6px;
}
.editor-top .espacer {
  flex: 1;
}
.editor-top button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.editor-top button:hover {
  border-color: var(--accent);
}
.editor-top button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  font-weight: 600;
}
.editor-body {
  flex: 1;
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 0;
}
.editor-props {
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
}
.prop-block h3 {
  margin: 0 0 9px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}
.el-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.el-list button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
}
.el-list button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.ctl {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}
.ctl-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.editor-canvas {
  display: grid;
  place-items: center;
  padding: 24px;
  background: repeating-conic-gradient(#1a2030 0% 25%, #161c28 0% 50%) 50% / 22px 22px;
  overflow: auto;
}
.editor-canvas svg {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  touch-action: none;
}
.editor-canvas svg text,
.editor-canvas svg image {
  cursor: move;
}
.editor-canvas svg .sel-outline {
  pointer-events: none;
}

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 10px;
  z-index: 80;
  box-shadow: var(--shadow);
  font-size: 13.5px;
}
.toast[hidden] {
  display: none;
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}
