:root {
  --panel-bg: rgba(248, 251, 246, 0.76);
  --panel-line: rgba(35, 77, 116, 0.18);
  --ink: #16344e;
  --muted: rgba(22, 52, 78, 0.62);
  --accent: #5547b5;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #f3ecd9;
}

body {
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: #f3ecd9;
}

canvas {
  display: block;
}

#controls {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 5;
  box-sizing: border-box;
  width: min(372px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: 0 24px 70px rgba(36, 74, 104, 0.18);
  backdrop-filter: blur(18px) saturate(1.25);
  transition: width 180ms ease, padding 180ms ease;
}

.panel-title,
.button-row,
.swatches {
  display: flex;
  align-items: center;
}

.panel-title {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-title strong {
  display: block;
  font-size: 19px;
  line-height: 1.1;
  letter-spacing: 0;
}

.panel-title span,
.field span,
.color-field span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.panel-body {
  display: block;
}

#controls.is-collapsed {
  width: 184px;
  padding: 12px 14px;
}

#controls.is-collapsed .panel-title {
  margin-bottom: 0;
}

#controls.is-collapsed .panel-body {
  display: none;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px 16px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.field b {
  color: var(--ink);
  font-weight: 650;
}

input,
button {
  font: inherit;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.swatches {
  justify-content: space-between;
  gap: 9px;
  margin: 16px 0 14px;
}

.color-field {
  display: grid;
  gap: 6px;
  flex: 1 1 0;
  min-width: 0;
}

.color-field input {
  width: 100%;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(35, 77, 116, 0.18);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.button-row {
  gap: 9px;
}

button {
  flex: 1;
  height: 35px;
  border: 1px solid rgba(35, 77, 116, 0.2);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.icon-button {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

button:hover {
  border-color: rgba(239, 107, 55, 0.58);
  background: rgba(239, 107, 55, 0.12);
}

@media (max-width: 720px) {
  #controls {
    top: auto;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    max-height: 52vh;
    padding: 14px;
  }

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