:root {
  color-scheme: light;
  --page: #f1f2f4;
  --surface: #ffffff;
  --surface-soft: #f7f8f9;
  --ink: #17191d;
  --ink-soft: #555b65;
  --line: #d9dde2;
  --line-strong: #b5bbc4;
  --accent: #d94f35;
  --accent-strong: #a93421;
  --accent-soft: #fff0eb;
  --success: #17765c;
  --warning: #9d5a16;
  --danger: #b52e3a;
  --focus: #1969d2;
  --radius-panel: 14px;
  --radius-control: 10px;
  --header-height: 72px;
  --z-sticky: 20;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="range"] {
  cursor: pointer;
}

button {
  color: inherit;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 50%;
  z-index: 50;
  padding: 9px 13px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
  transform: translate(-50%, -160%);
}

.skip-link:focus {
  transform: translate(-50%, 0);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--header-height);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.header-inner {
  width: min(1440px, 100%);
  height: 100%;
  margin: 0 auto;
  padding: 0 24px 0 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.app-brand div {
  min-width: 0;
  display: grid;
}

.app-brand strong {
  font-size: 0.98rem;
  line-height: 1.25;
}

.app-brand span:last-child {
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.74rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.status-chip {
  min-height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--success);
}

.status-chip[data-state="paused"] .status-dot {
  background: var(--warning);
}

.status-chip[data-state="error"] .status-dot {
  background: var(--danger);
}

.language-control select {
  height: 38px;
  min-width: 84px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
}

.workspace {
  width: min(1440px, 100%);
  height: calc(100dvh - var(--header-height));
  min-height: 540px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}

.control-panel {
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 30px 26px 34px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  scrollbar-width: thin;
}

.editor-intro h1,
.editor-intro p {
  margin: 0;
}

.editor-intro h1 {
  max-width: 14ch;
  font-size: clamp(1.65rem, 2.4vw, 2.15rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.editor-intro p {
  max-width: 34ch;
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 0.84rem;
  text-wrap: pretty;
}

.text-form {
  margin-top: 27px;
}

.field-heading,
.control-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.field-heading label,
.control-label label,
.editor-section legend {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
}

.field-heading output,
.control-label output {
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.text-entry {
  margin-top: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

#text-input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
}

#text-input::placeholder {
  color: #656b74;
  font-weight: 500;
}

#text-input[aria-invalid="true"] {
  border-color: var(--danger);
  background: #fff7f7;
}

.primary-button,
.secondary-button,
.download-button,
.preset-row button,
.palette-button,
.segmented-control button {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
}

.primary-button {
  min-width: 64px;
  padding: 0 14px;
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 800;
}

.primary-button:hover {
  background: #30343a;
}

.field-help {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 0.72rem;
  line-height: 1.45;
}

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

.preset-row button {
  min-width: 0;
  min-height: 34px;
  padding: 4px 6px;
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 750;
}

.preset-row button:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.editor-section {
  min-width: 0;
  margin: 25px 0 0;
  padding: 24px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.editor-section legend {
  width: 100%;
  margin: 0 0 13px;
  padding: 0;
}

.palette-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.palette-button {
  min-width: 0;
  min-height: 62px;
  padding: 8px 3px 6px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
  color: var(--ink-soft);
  font-size: 0.66rem;
  font-weight: 750;
  line-height: 1.2;
}

.palette-button:hover {
  border-color: var(--ink-soft);
}

.palette-button.selected {
  border-color: var(--ink);
  background: var(--surface-soft);
  color: var(--ink);
}

.palette-swatch {
  width: 33px;
  height: 17px;
  display: flex;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 5px;
  background: #111315;
}

.palette-swatch i {
  width: 11px;
  height: 100%;
  display: block;
}

.palette-signal i:nth-child(1) { background: #ff7657; }
.palette-signal i:nth-child(2) { background: #ffd166; }
.palette-signal i:nth-child(3) { background: #fff4dc; }
.palette-tide i:nth-child(1) { background: #55c8ff; }
.palette-tide i:nth-child(2) { background: #62e6c7; }
.palette-tide i:nth-child(3) { background: #d8fbff; }
.palette-orchid i:nth-child(1) { background: #c99cff; }
.palette-orchid i:nth-child(2) { background: #ff8fc7; }
.palette-orchid i:nth-child(3) { background: #f8e9ff; }
.palette-ember i:nth-child(1) { background: #ff9f45; }
.palette-ember i:nth-child(2) { background: #f35136; }
.palette-ember i:nth-child(3) { background: #ffe0b8; }
.palette-mono i:nth-child(1) { background: #f6f7f8; }
.palette-mono i:nth-child(2) { background: #aeb5bd; }
.palette-mono i:nth-child(3) { background: #ffffff; }

.tuning-section {
  display: grid;
  gap: 16px;
}

.tuning-section legend {
  margin-bottom: -1px;
}

.control-row {
  display: grid;
  gap: 7px;
}

input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--ink);
}

.segmented-control {
  padding: 3px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.segmented-control button {
  min-height: 36px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.segmented-control button.selected {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.editor-actions {
  margin-top: 25px;
  padding-top: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  border-top: 1px solid var(--line);
}

.secondary-button,
.download-button {
  min-height: 40px;
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.secondary-button:hover {
  border-color: var(--ink);
}

.secondary-button[aria-pressed="true"] {
  border-color: var(--warning);
  background: #fff8ec;
  color: #74400e;
}

.download-button {
  grid-column: 1 / -1;
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #fff;
}

.download-button:hover {
  background: var(--accent-strong);
}

.local-note {
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: 0.7rem;
  line-height: 1.45;
  text-wrap: pretty;
}

.stage-panel {
  min-width: 0;
  min-height: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  background: var(--page);
}

.stage-toolbar {
  min-height: 48px;
  padding: 0 2px 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.stage-label {
  display: block;
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 750;
}

.stage-toolbar h2 {
  max-width: 32ch;
  margin: 2px 0 0;
  overflow: hidden;
  font-size: 1.05rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#particle-count {
  color: var(--ink-soft);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  white-space: nowrap;
}

.canvas-frame {
  position: relative;
  flex: 1;
  min-height: 420px;
  overflow: hidden;
  border-radius: var(--radius-panel);
  background: #101217;
}

#particle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#particle-canvas:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -7px;
}

.canvas-hint {
  position: absolute;
  right: 14px;
  bottom: 13px;
  left: 14px;
  z-index: 1;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(16, 18, 23, 0.82);
  color: #e8ebef;
  font-size: 0.72rem;
  font-weight: 650;
  text-align: center;
  pointer-events: none;
}

.noscript {
  position: fixed;
  right: 20px;
  bottom: 20px;
  left: 20px;
  z-index: 40;
  padding: 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-control);
  background: #fff7f7;
  color: #751b24;
  text-align: center;
}

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

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

  .header-inner {
    padding-right: 16px;
    padding-left: 96px;
  }

  .workspace {
    height: auto;
    min-height: calc(100dvh - var(--header-height));
    grid-template-columns: 1fr;
  }

  .control-panel {
    overflow: visible;
    padding: 30px max(20px, calc((100vw - 680px) / 2)) 48px;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .editor-intro h1 {
    max-width: 19ch;
  }

  .stage-panel {
    order: -1;
    min-height: 58svh;
    padding: 16px;
  }

  .canvas-frame {
    height: 50svh;
    min-height: 360px;
    flex: none;
  }
}

@media (max-width: 560px) {
  :root {
    --header-height: 64px;
  }

  .header-inner {
    gap: 10px;
    padding-right: 10px;
    padding-left: 91px;
  }

  .brand-mark,
  .app-brand span:last-child {
    display: none;
  }

  .app-brand strong {
    font-size: 0.9rem;
    white-space: nowrap;
  }

  .header-actions {
    gap: 6px;
  }

  .status-chip {
    width: 38px;
    min-height: 38px;
    padding: 0;
    justify-content: center;
  }

  #status-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .language-control select {
    width: 66px;
    min-width: 66px;
    padding-left: 8px;
  }

  .stage-panel {
    min-height: 52svh;
    padding: 12px;
  }

  .stage-toolbar {
    min-height: 45px;
    padding-bottom: 10px;
  }

  .canvas-frame {
    height: 43svh;
    min-height: 320px;
  }

  .canvas-hint {
    right: 10px;
    bottom: 10px;
    left: 10px;
    font-size: 0.67rem;
  }

  .control-panel {
    padding: 27px 18px 42px;
  }

  .editor-intro h1 {
    font-size: 1.7rem;
  }
}

@media (max-width: 380px) {
  .app-brand {
    display: none;
  }

  .header-inner {
    justify-content: flex-end;
  }

  .palette-button {
    font-size: 0.61rem;
  }

  .palette-swatch {
    width: 28px;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  :root {
    --header-height: 58px;
  }

  body {
    overflow: hidden;
  }

  .app-header {
    position: relative;
  }

  .header-inner {
    padding-left: 100px;
  }

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

  .app-brand span:last-child {
    display: none;
  }

  .workspace {
    height: calc(100dvh - var(--header-height));
    min-height: 0;
    grid-template-columns: minmax(280px, 34vw) minmax(0, 1fr);
  }

  .control-panel {
    order: 0;
    overflow-y: auto;
    padding: 22px 20px 28px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .editor-intro h1 {
    font-size: 1.5rem;
  }

  .editor-intro p {
    display: none;
  }

  .text-form {
    margin-top: 18px;
  }

  .stage-panel {
    order: 0;
    min-height: 0;
    padding: 12px;
  }

  .stage-toolbar {
    min-height: 39px;
    padding-bottom: 8px;
  }

  .canvas-frame {
    height: auto;
    min-height: 0;
    flex: 1;
  }
}

@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;
  }
}

@media (forced-colors: active) {
  .status-dot,
  .palette-swatch i {
    forced-color-adjust: none;
  }

  .canvas-frame {
    border: 1px solid CanvasText;
  }

  .primary-button,
  .download-button {
    border: 1px solid ButtonText;
  }
}
