:root {
  --bg: #0c0d10;
  --bg-soft: #12141a;
  --panel: #16181f;
  --panel-2: #1c1f28;
  --line: #262a35;
  --line-soft: #1f232d;
  --text: #e8e9ee;
  --muted: #8a8f9e;
  --muted-2: #666b79;
  --accent: #f0b429;
  --accent-soft: #3a2f13;
  --good: #55c58a;
  --bad: #e5675f;
  --blue: #6aa8ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(240, 180, 41, 0.07), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(106, 168, 255, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* --------------------------------- topbar -------------------------------- */
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(12, 13, 16, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.tagline { color: var(--muted); font-size: 12px; letter-spacing: 0.02em; }

.statusbar { display: flex; gap: 8px; align-items: center; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}
.pill-ok { color: var(--good); border-color: rgba(85, 197, 138, 0.3); background: rgba(85, 197, 138, 0.07); }
.pill-warn { color: var(--accent); border-color: rgba(240, 180, 41, 0.3); background: rgba(240, 180, 41, 0.07); }
.pill-bad { color: var(--bad); border-color: rgba(229, 103, 95, 0.3); background: rgba(229, 103, 95, 0.07); }
.pill-muted { color: var(--muted); }

/* --------------------------------- layout -------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr) 340px;
  gap: 14px;
  padding: 14px;
  align-items: start;
  max-width: 1720px;
  margin: 0 auto;
}

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.018), transparent 140px), var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar { padding: 14px; position: sticky; top: 72px; max-height: calc(100vh - 86px); overflow: auto; }
.assistant { padding: 14px; position: sticky; top: 72px; max-height: calc(100vh - 86px); overflow: auto; }

.viewer { min-height: calc(100vh - 86px); display: flex; flex-direction: column; overflow: hidden; }

/* --------------------------------- blocks -------------------------------- */
.block { padding: 4px 2px 14px; border-bottom: 1px solid var(--line-soft); margin-bottom: 14px; }
.block:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.block h2, .block-head h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 650;
}
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.block-head h2 { margin-bottom: 10px; }

/* --------------------------------- upload -------------------------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 118px;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--line);
  background: rgba(255, 255, 255, 0.015);
  cursor: pointer;
  text-align: center;
  padding: 14px;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { display: block; font-weight: 600; }
.dropzone span { color: var(--muted); font-size: 12px; }
.dropzone img { max-width: 100%; max-height: 160px; border-radius: 6px; object-fit: contain; }
.meta { margin-top: 8px; font-size: 12px; }

/* --------------------------------- fields -------------------------------- */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.field-row label { color: var(--muted); font-size: 12.5px; }
.field-row input, .field-row select {
  width: 96px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  outline: none;
}
.field-row input:focus, .field-row select:focus { border-color: var(--accent); }
.field-label { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
textarea, .search {
  width: 100%;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  padding: 9px 10px;
  outline: none;
  resize: vertical;
}
textarea:focus, .search:focus { border-color: var(--accent); }

/* --------------------------------- buttons -------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 560;
  transition: transform 0.06s, background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
}
.btn:hover { background: #232735; border-color: #313747; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #171207; }
.btn-primary:hover { background: #ffc94a; border-color: #ffc94a; }
.btn-accent { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-accent:hover { background: var(--accent-soft); }

/* --------------------------------- palette -------------------------------- */
.filament-list { display: flex; flex-direction: column; gap: 6px; }
.filament-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) 58px;
  gap: 9px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line-soft);
}
.swatch {
  width: 16px; height: 16px; border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.filament-name { min-width: 0; }
.filament-name .n { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filament-name .s { display: block; color: var(--muted-2); font-size: 10.5px; }
.filament-row input.layers {
  width: 58px; padding: 4px 6px; text-align: right;
  border-radius: 6px; border: 1px solid var(--line); background: var(--bg);
}
.hint { color: var(--muted-2); font-size: 11px; margin: 8px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }

/* --------------------------------- viewer -------------------------------- */
.viewer-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 6px 11px; border-radius: 8px; cursor: pointer; font-size: 12.5px;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--line); }

.metrics { display: flex; gap: 6px; flex-wrap: wrap; }
.metric {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 4px 9px; border-radius: 8px; background: rgba(255,255,255,0.03);
  border: 1px solid var(--line-soft); font-size: 11.5px;
}
.metric b { font-variant-numeric: tabular-nums; font-weight: 650; }
.metric .k { color: var(--muted-2); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; }
.metric.good b { color: var(--good); }
.metric.warn b { color: var(--accent); }
.metric.bad b { color: var(--bad); }

.canvas-wrap {
  position: relative; flex: 1; min-height: 340px; display: flex;
  align-items: center; justify-content: center; padding: 18px;
  background:
    linear-gradient(45deg, #14161c 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(-45deg, #14161c 25%, transparent 25%) 0 11px / 22px 22px,
    linear-gradient(45deg, transparent 75%, #14161c 75%) 11px -11px / 22px 22px,
    linear-gradient(-45deg, transparent 75%, #14161c 75%) -11px 0 / 22px 22px,
    #101217;
}
.canvas-wrap img { max-width: 100%; max-height: calc(100vh - 250px); border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,0.45); }
.empty { text-align: center; color: var(--muted); }
.empty-mark { font-size: 42px; font-weight: 800; letter-spacing: 0.1em; color: #22262f; }
.empty p { max-width: 360px; margin: 10px auto 0; font-size: 13px; }
.small-empty p { font-size: 12.5px; }
.canvas-legend {
  position: absolute; right: 18px; bottom: 16px; background: rgba(10,11,14,0.8);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 11px; color: var(--muted);
}

.viewer-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--line-soft);
}
.foot-info { color: var(--muted); font-size: 12px; }
.foot-actions { display: flex; align-items: center; gap: 10px; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------- assistant ------------------------------ */
.assistant-log { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

.iter-card {
  border: 1px solid var(--line-soft); border-radius: 11px; padding: 11px;
  background: rgba(255,255,255,0.018);
}
.iter-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.iter-title { font-size: 12px; font-weight: 650; letter-spacing: 0.02em; }
.iter-title .best { color: var(--accent); }
.iter-sub { color: var(--muted-2); font-size: 10.5px; margin-top: 1px; }
.iter-metrics { display: flex; gap: 5px; flex-wrap: wrap; margin: 8px 0; }
.chip {
  font-size: 10.5px; padding: 2px 7px; border-radius: 999px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--line-soft); color: var(--muted);
}
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.iter-stack { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.stack-dot {
  width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.25);
  title: attr(data-label);
}
.iter-text { color: #c6c9d2; font-size: 12px; }
.iter-changes { margin: 7px 0 0; padding-left: 16px; color: var(--muted); font-size: 11.5px; }
.iter-changes li { margin: 2px 0; }

.export-card {
  margin-top: 14px; padding: 12px; border-radius: 11px;
  border: 1px solid rgba(240, 180, 41, 0.28); background: rgba(240, 180, 41, 0.06);
}
.export-card h3 { margin: 0 0 8px; font-size: 13px; color: var(--accent); }
.export-summary { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.export-summary b { color: var(--text); }

/* --------------------------------- dialog -------------------------------- */
.dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 80px));
  border-radius: 16px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); padding: 16px;
  box-shadow: 0 40px 120px rgba(0,0,0,0.7);
}
.dialog::backdrop { background: rgba(4, 5, 8, 0.66); backdrop-filter: blur(4px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dialog-head h2 { margin: 0; font-size: 15px; }
.palette-list {
  margin-top: 10px; max-height: 430px; overflow: auto;
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
}
.pal-item {
  display: grid; grid-template-columns: 18px 16px minmax(0,1fr) auto;
  align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--line-soft); background: rgba(255,255,255,0.015);
  cursor: pointer;
}
.pal-item:hover { border-color: #343a4a; }
.pal-item.checked { border-color: rgba(240,180,41,0.45); background: rgba(240,180,41,0.06); }
.pal-item .n { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-item .s { color: var(--muted-2); font-size: 10.5px; }
.pal-item .td { color: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.dialog-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }

/* --------------------------------- toast --------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #23262f; border: 1px solid #343a4a; color: var(--text);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  z-index: 100; max-width: min(560px, calc(100vw - 32px)); font-size: 13px;
}
.toast.error { border-color: rgba(229,103,95,0.5); color: #ffb4ae; }

/* --------------------------------- responsive ----------------------------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 290px minmax(0, 1fr); }
  .assistant { grid-column: 1 / -1; position: static; max-height: none; }
  .sidebar { position: static; max-height: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .topbar { padding: 0 12px; }
  .tagline { display: none; }
  .statusbar .pill:nth-child(3) { display: none; }
  .viewer { min-height: 0; }
  .canvas-wrap img { max-height: 60vh; }
  .palette-list { grid-template-columns: 1fr; }
}


/* --------------------------------- tiling -------------------------------- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  user-select: none;
}
.switch input { accent-color: var(--accent); width: 14px; height: 14px; }

.select-wide { width: 150px !important; }
.pair { display: inline-flex; align-items: center; gap: 6px; }
.pair input { width: 68px !important; }
.times { color: var(--muted-2); }

.tiling-summary {
  margin: 8px 0 2px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-soft);
  background: rgba(240, 180, 41, 0.05);
  color: #cfd2db;
  font-size: 11.5px;
  line-height: 1.55;
}
.tiling-summary b { color: var(--accent); }
#tiling-fields[hidden] { display: none; }
#frame-style-row[hidden], #frame-width-row[hidden],
#frame-raise-row[hidden], #frame-filament-row[hidden] { display: none; }

.link { color: var(--accent); text-decoration: none; font-size: 11.5px; }
.link:hover { text-decoration: underline; }

.field-row input:disabled { color: var(--muted); background: #101218; border-color: var(--line-soft); cursor: not-allowed; }
