:root {
  color-scheme: light;
  --ink: #1f2633;
  --muted: #697282;
  --paper: #f7f4eb;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(31, 38, 51, 0.15);
  --accent: #db4f54;
  --shadow: 0 20px 60px rgba(31, 38, 51, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background:
    linear-gradient(90deg, rgba(31, 38, 51, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(31, 38, 51, 0.045) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
  width: min(1180px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  margin: 16px auto;
}

.topbar,
.tool-row,
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 34%, #f2c84b 0 18%, transparent 19%),
    conic-gradient(from 20deg, #db4f54, #f2c84b, #3fa66b, #3e78c9, #db4f54);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.68), 0 8px 20px rgba(31, 38, 51, 0.14);
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.45rem);
  line-height: 1.02;
  letter-spacing: 0;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
}

.actions,
.color-palette,
.segmented {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mood-palette {
  flex: 1 1 680px;
  flex-wrap: wrap;
  gap: 10px;
}

.icon-button,
.swatch,
.segment,
.mood-swatch {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease, background 140ms ease;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  box-shadow: 0 8px 24px rgba(31, 38, 51, 0.08);
}

.icon-button:hover,
.swatch:hover,
.segment:hover,
.mood-swatch:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(31, 38, 51, 0.12);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
  transform: none;
  box-shadow: none;
}

.icon-button.primary {
  color: #fff;
  border-color: transparent;
  background: var(--ink);
}

.icon {
  transform: translateY(-1px);
  font-size: 1.5rem;
  line-height: 1;
}

.tool-row {
  flex-wrap: wrap;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
  backdrop-filter: blur(14px);
}

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--swatch);
}

.swatch.active {
  outline: 3px solid rgba(31, 38, 51, 0.2);
  outline-offset: 3px;
}

.mood-swatch {
  display: grid;
  grid-template-columns: 42px minmax(44px, auto);
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 6px 10px 6px 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  white-space: nowrap;
}

.mood-swatch.active {
  border-color: rgba(31, 38, 51, 0.32);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 26px rgba(31, 38, 51, 0.13);
}

.swatch-dot {
  display: block;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(31, 38, 51, 0.12);
}

.mood-swatch.active .swatch-dot {
  outline: 3px solid rgba(31, 38, 51, 0.18);
  outline-offset: 3px;
}

.mood-text {
  display: grid;
  gap: 1px;
  text-align: left;
  line-height: 1.05;
}

.mood-text strong {
  font-size: 0.95rem;
  letter-spacing: 0;
}

.mood-text small {
  color: var(--muted);
  font-size: 0.76rem;
}

.segmented {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  flex-wrap: wrap;
}

.segment {
  min-width: 64px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.segment.active {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 8px 18px rgba(31, 38, 51, 0.16);
}

.density-control {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  white-space: nowrap;
}

input[type="range"] {
  width: 156px;
  accent-color: var(--ink);
}

.stage-wrap {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgba(31, 38, 51, 0.18);
  border-radius: 8px;
  background:
    radial-gradient(circle at 25% 28%, rgba(242, 200, 75, 0.16), transparent 26%),
    radial-gradient(circle at 72% 68%, rgba(62, 120, 201, 0.13), transparent 28%),
    rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  touch-action: none;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#particleCanvas {
  pointer-events: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  pointer-events: none;
  color: rgba(31, 38, 51, 0.58);
}

.empty-state strong {
  color: rgba(31, 38, 51, 0.78);
  font-size: clamp(1.2rem, 3.6vw, 2.2rem);
  letter-spacing: 0;
}

.empty-state.hidden {
  display: none;
}

.statusbar {
  color: var(--muted);
  font-size: 0.92rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.line {
  background: #3e78c9;
}

.dot.circle {
  background: #3fa66b;
}

.dot.triangle {
  background: #db4f54;
}

@media (max-width: 720px) {
  body {
    overflow: auto;
  }

  .app-shell {
    width: min(100vw - 20px, 640px);
    height: auto;
    min-height: calc(100vh - 20px);
    margin: 10px auto;
    grid-template-rows: auto auto 62vh auto;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .actions {
    flex-shrink: 0;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .tool-row {
    align-items: flex-start;
  }

  .density-control {
    width: 100%;
  }

  input[type="range"] {
    flex: 1;
    width: auto;
  }
}
