:root {
  color-scheme: dark;
  --ink: #e9e5da;
  --ink-soft: #b8b4aa;
  --ink-faint: #7e837a;
  --bg: #0c1713;
  --bg-raised: #121f1a;
  --panel: #17251f;
  --panel-soft: #1c2c25;
  --line: rgba(220, 219, 203, 0.13);
  --line-strong: rgba(220, 219, 203, 0.22);
  --accent: #d5b477;
  --accent-deep: #b68e51;
  --accent-ink: #251d12;
  --danger: #e8a29a;
  --radius: 18px;
  --font: "LXGW WenKai", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 4%, rgba(76, 111, 82, 0.24), transparent 34rem),
    radial-gradient(circle at 88% 84%, rgba(165, 123, 68, 0.16), transparent 34rem),
    var(--bg);
}

button,
select,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  color: inherit;
  background: none;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 8px 14px;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 8px;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  min-height: 72px;
  padding: 12px clamp(18px, 3.4vw, 44px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 23, 19, 0.84);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}

.brand img {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.brand-copy {
  display: grid;
  line-height: 1.08;
}

.brand-copy strong {
  font-size: 19px;
  letter-spacing: 0.3px;
}

.brand-copy small {
  margin-top: 4px;
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button {
  min-height: 40px;
  padding: 9px 17px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.button--primary {
  color: var(--accent-ink);
  background: var(--accent);
  box-shadow: 0 10px 30px -16px rgba(213, 180, 119, 0.9);
}

.button--primary:hover {
  background: #e2c48b;
}

.button--wide {
  min-width: 130px;
}

.studio {
  width: min(1580px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 2.4vw, 34px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: clamp(18px, 2.2vw, 30px);
  align-items: start;
}

.stage {
  min-width: 0;
  padding: clamp(16px, 2.1vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.035), transparent 42%),
    rgba(18, 31, 26, 0.84);
  box-shadow: 0 30px 80px -48px rgba(0, 0, 0, 0.88);
}

.stage-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.resolution-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: rgba(0, 0, 0, 0.16);
  font-size: 11px;
  letter-spacing: 0.6px;
}

.live-dot,
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(213, 180, 119, 0.1);
}

.canvas-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 13px;
  background: #0a1511;
  box-shadow:
    0 34px 80px -40px rgba(0, 0, 0, 0.9),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.artwork,
.artwork svg {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
}

.artwork svg {
  height: auto;
}

.canvas-badge {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.canvas-badge span {
  padding: 4px 8px;
  color: rgba(255, 255, 255, 0.84);
  background: rgba(7, 14, 12, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 9px;
  letter-spacing: 0.8px;
}

.stage-foot {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.export-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-faint);
  font-size: 12px;
  line-height: 1.5;
}

.export-group {
  display: flex;
  align-items: center;
  gap: 9px;
}

.select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-faint);
  font-size: 11px;
}

.select-wrap select {
  min-height: 40px;
  padding: 0 30px 0 12px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.controls {
  position: sticky;
  top: 92px;
  max-height: calc(100vh - 112px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(213, 180, 119, 0.35) transparent;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23, 37, 31, 0.9);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 30px 80px -52px rgba(0, 0, 0, 0.95);
}

.controls-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.controls h2 {
  margin: 0;
  font-size: 22px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: transparent;
  cursor: pointer;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  display: block;
  margin: auto;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.icon-button:disabled {
  opacity: 0.3;
  cursor: default;
}

.icon-button:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
}

.icon-button:disabled:hover {
  color: var(--ink-soft);
  background: transparent;
}

[hidden] {
  display: none !important;
}

.control-section {
  padding: 19px 0;
  border-bottom: 1px solid var(--line);
}

.section-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-label h3 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.5px;
}

.section-label span {
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 1.3px;
  text-transform: uppercase;
}

.presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.presets--swatches {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.gradient-theme {
  position: relative;
  aspect-ratio: 1.45;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--theme-gradient);
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.gradient-theme::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
}

.gradient-theme:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.gradient-theme.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(213, 180, 119, 0.15);
}

.palette-row {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 5px;
  margin-bottom: 8px;
}

.color-cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--cell-color);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.color-cell:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.48);
}

.color-cell.is-anchor {
  border-color: #fff1c8;
  box-shadow:
    0 0 0 3px rgba(255, 221, 145, 0.42),
    0 0 25px rgba(255, 207, 105, 0.5);
}

.color-cell.is-active {
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px var(--accent),
    0 0 28px rgba(213, 180, 119, 0.45);
}

.color-cell.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 0;
  height: 0;
  border-right: 5px solid transparent;
  border-left: 5px solid transparent;
  border-top: 7px solid var(--accent);
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

.color-popover {
  margin-top: 11px;
  padding: 11px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #14231d;
  box-shadow: 0 18px 34px -24px rgba(0, 0, 0, 0.9);
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 10px;
}

.popover-close {
  width: 22px;
  height: 22px;
  color: var(--ink-faint);
  border-radius: 50%;
  cursor: pointer;
}

.popover-close:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.popover-color {
  display: grid;
  grid-template-columns: 38px 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--ink-faint);
  font-size: 10px;
}

.popover-color input {
  width: 34px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.popover-color input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.popover-color input::-webkit-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
}

.popover-color input::-moz-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
}

.popover-color code {
  color: var(--ink-soft);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
}

.anchor-checkbox {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  color: var(--ink-soft);
  font-size: 10px;
  cursor: pointer;
}

.anchor-checkbox input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.generate-gradient {
  width: 100%;
  min-height: 40px;
  margin-top: 11px;
  color: var(--accent-ink);
  border-radius: 10px;
  background: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  transition: background 150ms ease, transform 150ms ease;
}

.generate-gradient:hover {
  background: #e2c48b;
  transform: translateY(-1px);
}

.mini-note {
  margin: 9px 0 0;
  color: var(--ink-faint);
  font-size: 9.5px;
  line-height: 1.55;
}

.range-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 43px;
  align-items: center;
  gap: 10px;
  min-height: 35px;
  color: var(--ink-soft);
  font-size: 11px;
}

.range-row output {
  color: var(--ink);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(213, 180, 119, 0.46);
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
}

.reset-default {
  width: 100%;
  margin-top: 12px;
  padding: 9px 12px;
  color: var(--ink-faint);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 10px;
}

.reset-default:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.035);
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 22px;
  max-width: min(480px, calc(100vw - 36px));
  padding: 11px 16px;
  color: var(--ink);
  background: rgba(23, 37, 31, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  font-size: 12px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  color: #2b1511;
  background: var(--danger);
}

@media (max-width: 1080px) {
  .studio {
    grid-template-columns: minmax(0, 1fr) 340px;
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
  }

  .studio {
    display: block;
  }

  .controls {
    position: static;
    max-height: none;
    margin-top: 18px;
  }

  .stage-foot {
    align-items: flex-start;
    flex-direction: column;
  }

  .export-group {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 10px 14px;
    align-items: center;
  }

  .brand-copy small {
    display: none;
  }

  .topbar-actions {
    gap: 7px;
  }

  .button {
    padding-inline: 13px;
    font-size: 12px;
  }

  .studio {
    padding: 12px;
  }

  .stage {
    padding: 13px;
  }

  .stage-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .canvas-badge span:nth-child(2) {
    display: none;
  }

  .export-summary {
    font-size: 11px;
  }

  .export-group {
    align-items: stretch;
    flex-direction: column;
  }

  .select-wrap {
    justify-content: space-between;
  }

  .controls {
    padding: 18px;
  }
}

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