:root {
  color-scheme: light;
  --ink: #1b1b1f;
  --muted: #62646d;
  --line: #d8dbe3;
  --paper: #ffffff;
  --panel: #f7f8fa;
  --canvas: #111113;
  --accent: #0e8f8f;
  --accent-strong: #0a6969;
  --warn: #d69d00;
  --shadow: 0 18px 60px rgba(14, 18, 25, 0.22);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: #e6e8ed;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.download-link {
  min-height: 36px;
  border: 1px solid #cfd3dc;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  text-decoration: none;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

button:hover,
.download-link:hover {
  border-color: #9da5b5;
  background: #f8f9fb;
}

button:active,
.download-link:active {
  transform: translateY(1px);
}

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

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

.primary-button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px;
  border-bottom: 1px solid #d4d8e1;
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  min-width: 430px;
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 6px 18px rgba(26, 33, 46, 0.16);
  flex: 0 0 auto;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.15;
  margin: 0;
  letter-spacing: 0;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin: 3px 0 0;
}

.follow-button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #111;
  border-radius: 7px;
  background: #111;
  color: #fff;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.follow-button:hover {
  border-color: #27313f;
  background: #27313f;
}

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

.transport {
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.route-toggle {
  font-weight: 650;
}

.route-toggle.is-on {
  border-color: rgba(14, 143, 90, 0.42);
  background: #eaf8f1;
  color: #0b7b4c;
}

.route-toggle.is-on:hover {
  border-color: rgba(14, 143, 90, 0.72);
  background: #ddf3e8;
}

.route-toggle.is-off {
  border-color: #cfd3dc;
  background: #f1f3f6;
  color: #62646d;
}

.help-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
  border-color: rgba(14, 143, 143, 0.42);
  border-radius: 50%;
  background: #eef8f8;
  color: var(--accent-strong);
  font-weight: 800;
}

.help-button:hover {
  border-color: rgba(14, 143, 143, 0.72);
  background: #e2f3f3;
}

.download-type {
  width: 174px;
  min-height: 36px;
  display: grid;
  grid-template-columns: auto minmax(96px, 1fr);
  align-items: center;
  gap: 8px;
}

.download-type span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.download-type select {
  height: 36px;
}

.timeline {
  width: min(48vw, 620px);
  min-width: 300px;
  display: grid;
  grid-template-columns: 86px minmax(200px, 1fr);
  align-items: center;
  gap: 10px;
  padding: 0 10px;
}

.timeline span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

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

input[type="number"],
input[type="text"],
input[type="color"],
select {
  width: 100%;
  height: 36px;
  border: 1px solid #cfd3dc;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

input[type="color"] {
  padding: 4px;
}

#durationRangeInput {
  height: auto;
  border: 0;
  padding: 0;
  background: transparent;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.stage-panel {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  padding: 16px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    var(--canvas);
  background-size: 32px 32px;
}

#stageCanvas {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #0d0d0f;
  cursor: crosshair;
}

.stage-badge {
  position: absolute;
  left: 28px;
  top: 28px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(18, 18, 20, 0.74);
  color: #fff;
  padding: 0 11px;
  font-size: 13px;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

#activeBadgeDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 12px currentColor;
}

.control-panel {
  min-height: 0;
  overflow: auto;
  border-left: 1px solid #d4d8e1;
  background: var(--panel);
  padding: 16px;
}

.control-section {
  padding: 0 0 18px;
  margin: 0 0 18px;
  border-bottom: 1px solid #d8dbe3;
  display: grid;
  gap: 12px;
}

.control-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-heading h2 {
  margin: 0;
  font-size: 13px;
  color: #34363c;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

label > span,
.range-line span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

output {
  color: #30333a;
  font-variant-numeric: tabular-nums;
}

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

.piece-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.toggle-line {
  min-height: 36px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid #cfd3dc;
  border-radius: 7px;
  background: #fff;
  color: #30333a;
}

.toggle-line input {
  accent-color: var(--accent);
}

.edit-toggle {
  justify-content: flex-start;
}

.piece-tabs {
  display: grid;
  grid-template-columns: repeat(var(--piece-count, 3), minmax(0, 1fr));
  gap: 8px;
}

.piece-tab {
  min-width: 0;
  border-color: transparent;
  background: #e7eaf0;
  color: #30333a;
  padding: 0 8px;
}

.piece-tab.is-active {
  border-color: var(--tab-color);
  background: #fff;
  box-shadow: inset 0 -3px 0 var(--tab-color);
}

.piece-tab span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tab-color);
  flex: 0 0 auto;
}

.pause-controls {
  display: grid;
  gap: 12px;
}

.pause-controls[hidden] {
  display: none;
}

.range-line {
  gap: 8px;
}

.help-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.help-dialog::backdrop {
  background: rgba(10, 12, 16, 0.46);
  backdrop-filter: blur(3px);
}

.help-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e2e5ec;
}

.help-dialog h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.help-close-button {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 50%;
  font-weight: 700;
}

.help-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px 18px 18px 34px;
  color: #30333a;
  font-size: 13px;
  line-height: 1.45;
}

.help-list li::marker {
  color: var(--accent-strong);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 330px;
  }

  .timeline {
    min-width: 280px;
    width: 38vw;
  }
}

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

  .app-shell {
    height: auto;
    min-height: 100%;
    grid-template-rows: auto auto;
  }

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

  .brand {
    min-width: 0;
  }

  .transport {
    flex-wrap: wrap;
  }

  .timeline {
    width: 100%;
    min-width: 0;
    grid-template-columns: 86px minmax(160px, 1fr);
    order: 5;
    flex: 1 0 100%;
    padding: 0;
  }

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

  .stage-panel {
    height: 62vh;
    min-height: 420px;
  }

  .control-panel {
    border-left: 0;
    border-top: 1px solid #d4d8e1;
  }
}
