@font-face {
  font-family: "Karl";
  src: url("./assets/fonts/Karl%20Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Karl";
  src: url("./assets/fonts/Karl%20Medium.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Karl";
  src: url("./assets/fonts/Karl%20Bold%20Typeface.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Karl Display";
  src: url("./assets/fonts/Karl%20Ultra%20Black.woff2") format("woff2");
  font-style: normal;
  font-weight: 900;
  font-display: swap;
}

:root {
  --bg: #fff9ef;
  --ink: #111111;
  --subtle: #4a4a4a;
  --panel-1: #fff4da;
  --panel-2: #ffe4ec;
  --panel-3: #d9f7ff;
  --line: #141414;
  --accent-a: #ff5a36;
  --accent-b: #00a5cf;
  --accent-c: #31b44b;
  --accent-d: #ffcf2f;
  --status-bg: #fff5c2;
  --font-ui: "Karl", "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  --font-display: "Karl Display", "Karl", "Bookman Old Style", "Palatino Linotype", Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at 8% 14%, #ffd26f 0, #ffd26f 13%, transparent 13.2%),
    radial-gradient(circle at 94% 18%, #ff8fab 0, #ff8fab 10%, transparent 10.2%),
    radial-gradient(circle at 88% 82%, #72dfff 0, #72dfff 14%, transparent 14.2%),
    linear-gradient(180deg, #fff9ef 0%, #ffeedd 100%);
}

header {
  max-width: 1500px;
  margin: 0 auto;
  padding: 22px 24px 10px;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2rem, 3.5vw, 2.6rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

header p {
  margin: 10px 0 0;
  font-size: 1.02rem;
  color: #262626;
  max-width: 760px;
}

.byline {
  font-size: 0.94rem;
  color: #3a3a3a;
}

.byline a {
  color: #264577;
  font-weight: 700;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.14em;
}

.byline a:hover {
  color: #163152;
}

h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.45rem;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

main {
  max-width: 1500px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(760px, 1fr);
  gap: 16px;
  padding: 12px 24px 28px;
}

.panel {
  border: 3px solid var(--line);
  border-radius: 26px;
  box-shadow: 8px 8px 0 #111111;
  padding: 16px;
}

.controls {
  background: var(--panel-1);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview {
  background: var(--panel-2);
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 340px)) minmax(320px, 1fr);
  gap: 12px;
  align-items: start;
}

.row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

label {
  font-size: 0.78rem;
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: #2f2f2f;
  min-height: 2.2em;
  display: flex;
  align-items: flex-end;
  line-height: 1.1;
}

input[type="file"],
input[type="number"],
input[type="color"],
select,
button {
  border: 2px solid var(--line);
  border-radius: 13px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
}

input[type="file"],
input[type="number"],
select,
button {
  height: 40px;
  padding: 0 11px;
}

select {
  appearance: none;
}

input[type="number"] {
  appearance: auto;
  -webkit-appearance: auto;
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 8px 0 0;
  accent-color: var(--accent-a);
}

input[type="range"] {
  width: 100%;
  margin: 8px 0 2px;
  accent-color: var(--accent-b);
}

input[type="file"] {
  display: flex;
  align-items: center;
  padding: 0 10px 0 8px;
}

input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
  margin: 0 10px 0 0;
  padding: 8px 13px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--accent-d);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

button {
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.07s ease, box-shadow 0.12s ease, background-color 0.12s ease;
  box-shadow: 0 2px 0 #111;
}

button:hover:enabled {
  transform: translateY(-1px);
  background: #fff4d8;
}

button:active:enabled {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #111;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#openInBambuBtn {
  background: #31b44b;
  border-color: #163d1f;
  color: #071b0b;
}

#openInBambuBtn:hover:enabled {
  background: #3bcf58;
}

#openInBambuBtn:active:enabled {
  background: #2aa142;
}

#openInBambuBtn:disabled {
  background: #9bc8a4;
  color: #1f4127;
}

.status {
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--status-bg);
  color: #1c3a63;
  font-size: 0.9rem;
  font-weight: 500;
}

.hint {
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: #ffffff;
  color: #2a2a2a;
  font-size: 0.84rem;
  line-height: 1.35;
}

.unit-hint {
  font-size: 0.78rem;
  color: #3f3f3f;
  font-weight: 500;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compact-actions {
  margin-top: 4px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-width: 520px;
  width: 100%;
}

.compact-actions button {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  white-space: nowrap;
  font-size: 0.95rem;
}

.color-actions-row {
  margin-top: -2px;
}

.advanced-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.advanced-options[hidden] {
  display: none !important;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 2px solid var(--line);
  border-radius: 13px;
  font-size: 0.88rem;
  font-weight: 700;
  background: #fff;
}

.picker-wrap {
  position: relative;
  width: 46px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--line);
  overflow: hidden;
  cursor: pointer;
}

.swatch-preview {
  display: block;
  width: 100%;
  height: 100%;
}

.swatch-picker {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.swatch-hex {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.76rem;
  color: #303030;
}

.stem-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#stemPaletteIndex {
  flex: 1;
  min-width: 0;
  width: 100%;
}

.stem-preview {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid var(--line);
  background: #e7edf5;
  flex: 0 0 auto;
}

.canvas-wrap,
.viewer-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.canvas-wrap h3,
.viewer-wrap h3 {
  min-height: 2.2em;
  display: flex;
  align-items: flex-end;
  margin-bottom: 4px;
}

canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: conic-gradient(from 90deg, #ffffff 25%, #edf0f6 0 50%, #ffffff 0 75%, #edf0f6 0);
  background-size: 16px 16px;
}

#viewer {
  min-height: 430px;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: var(--panel-3);
}

.layer-exports {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 1240px) {
  main {
    grid-template-columns: 1fr;
  }

  .preview {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .viewer-wrap {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .row {
    grid-template-columns: 1fr;
  }

  .preview {
    grid-template-columns: 1fr;
  }
}
