:root {
  --bg: #f1eadb;
  --panel: rgba(252, 248, 239, 0.88);
  --panel-strong: rgba(255, 253, 247, 0.96);
  --ink: #1f2f2a;
  --muted: #5e6d66;
  --line: rgba(31, 47, 42, 0.12);
  --accent: #d95f43;
  --accent-deep: #b4462f;
  --accent-soft: rgba(217, 95, 67, 0.14);
  --green: #1f5e4d;
  --green-soft: rgba(31, 94, 77, 0.12);
  --danger: #9e2f2f;
  --shadow: 0 20px 60px rgba(39, 48, 44, 0.14);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Trebuchet MS', 'Gill Sans', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(217, 95, 67, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(31, 94, 77, 0.18), transparent 28%),
    linear-gradient(135deg, #f7f0e3 0%, #efe5d0 100%);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(31, 47, 42, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 47, 42, 0.03) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: radial-gradient(circle at center, black 40%, transparent 90%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

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

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

#app {
  padding: 24px;
}

.app-build-badge {
  color: rgba(31, 47, 42, 0.5);
  font-family: 'Courier New', monospace;
  font-size: 0.66rem;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-align: center;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sidebar,
.editor,
.cockpit {
  padding: 22px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.panel-head h2,
.panel-head h3,
.step-card__header h3,
.option-card__header h4,
.status-card h3 {
  margin: 4px 0 0;
  font-family: 'Palatino Linotype', 'Book Antiqua', serif;
  font-weight: 700;
}

.program-name-input {
  width: 100%;
  font-size: 2rem;
  font-family: 'Palatino Linotype', 'Book Antiqua', serif;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0;
}

.program-name-input:focus {
  outline: none;
  border-color: var(--accent);
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.summary-chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 700;
}

.stacked-actions,
.composer-actions,
.control-grid,
.mini-actions,
.pill-group,
.step-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.pill-button {
  min-height: 44px;
  border-radius: 999px;
  padding: 0 16px;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent) 0%, #f08e58 100%);
  color: white;
}

.secondary-button {
  background: var(--green-soft);
  color: var(--green);
}

.ghost-button,
.pill-button {
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border: 1px solid var(--line);
}

.pill-button.is-active {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.danger-button,
.danger-text {
  color: var(--danger);
}

.danger-button {
  background: rgba(158, 47, 47, 0.12);
}

.program-list,
.step-list {
  display: grid;
  gap: 12px;
}

.program-list {
  margin-top: 14px;
}

.sidebar-footer-actions {
  margin-top: 26px;
}

.program-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid transparent;
}

.program-row.is-active {
  background: var(--panel-strong);
  border-color: rgba(217, 95, 67, 0.4);
}

.program-row__select {
  flex: 1;
  min-height: 52px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  background: transparent;
  text-align: left;
  color: inherit;
  font-weight: 700;
  display: grid;
  gap: 4px;
}

.program-row__summary {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.step-card,
.option-card,
.status-card,
.preview-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
}

.step-card {
  padding: 18px;
}

.step-card.is-collapsed {
  padding: 14px 16px;
}

.step-card__summary-button {
  width: 100%;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.step-card__drag-handle {
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.step-card__summary-main {
  display: grid;
  gap: 4px;
}

.step-card__summary-main strong {
  font-size: 1.05rem;
  font-family: 'Palatino Linotype', 'Book Antiqua', serif;
}

.step-card__summary-tag {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.step-card__header,
.option-card__header,
.preview-card__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.step-card__summary,
.option-card__meta {
  margin: 8px 0 0;
  color: var(--muted);
}

.step-card__collapsed-footer {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.step-card__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.step-card__chips span {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 700;
}

.step-card__toolbar {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.step-card__options {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.option-card {
  padding: 16px;
}

.option-card__heading {
  min-width: 0;
}

.option-card__heading h4 {
  line-height: 1.35;
}

.field-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-select {
  display: grid;
  gap: 6px;
}

.field-select span,
.field-range span {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.field-select select {
  min-height: 46px;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: white;
  padding: 0 12px;
  color: var(--ink);
}

.field-range {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.82);
}

.field-range__row,
.field-range__limits {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-range__row strong {
  font-size: 0.92rem;
  color: var(--ink);
}

.field-range__track {
  position: relative;
}

.field-range__limits small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

.field-range__limits--three-up {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-range__input {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  touch-action: pan-x;
}

.field-range--placement .field-range__track::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 18px;
  border-radius: 999px;
  background: rgba(67, 91, 78, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.field-range__input--placement {
  position: relative;
  z-index: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 18px;
  background: transparent;
}

.field-range__input--placement::-webkit-slider-runnable-track {
  height: 18px;
  background: transparent;
}

.field-range__input--placement::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: 0;
  border-radius: 50%;
  border: 2px solid white;
  background: var(--accent);
  box-shadow: 0 4px 14px rgba(217, 95, 67, 0.28);
}

.field-range__input--placement::-moz-range-track {
  height: 18px;
  background: transparent;
}

.field-range__input--placement::-moz-range-progress {
  background: transparent;
}

.field-range__input--placement::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid white;
  background: var(--accent);
  box-shadow: 0 4px 14px rgba(217, 95, 67, 0.28);
}

.status-card {
  padding: 18px;
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-weight: 700;
  margin-bottom: 10px;
}

.status-pill--disconnected,
.status-pill--connecting,
.status-pill--initial,
.status-pill--connected-1,
.status-pill--connected-2,
.status-pill--connected-3,
.status-pill--connected-3a,
.status-pill--connected-3b,
.status-pill--stop-requested {
  background: rgba(31, 47, 42, 0.08);
  color: var(--ink);
}

.status-pill--standby {
  background: rgba(31, 94, 77, 0.12);
  color: var(--green);
}

.status-pill--shooting,
.status-pill--shooting-restart {
  background: rgba(217, 95, 67, 0.14);
  color: var(--accent-deep);
}

.status-pill--pause {
  background: rgba(221, 168, 77, 0.18);
  color: #8a5e09;
}

.status-pill--countdown {
  background: rgba(217, 95, 67, 0.14);
  color: var(--accent-deep);
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.stats-grid div {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: rgba(31, 94, 77, 0.08);
  display: grid;
  gap: 8px;
}

.stats-grid span {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats-grid strong {
  font-size: 2rem;
  font-family: 'Palatino Linotype', 'Book Antiqua', serif;
}

.preview-card {
  padding: 16px;
}

.preview-card pre {
  margin: 12px 0 0;
  padding: 16px;
  border-radius: var(--radius-md);
  background: #18231f;
  color: #f4efe6;
  overflow: auto;
  min-height: 180px;
  white-space: pre-wrap;
}

.error-banner {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(158, 47, 47, 0.12);
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  #app {
    padding: 14px;
  }

  .sidebar,
  .editor,
  .cockpit {
    padding: 18px;
  }

  .program-name-input {
    font-size: 1.7rem;
  }

  .step-card__header,
  .option-card__header,
  .panel-head,
  .step-card__toolbar,
  .preview-card__head,
  .step-card__collapsed-footer {
    flex-direction: column;
  }

  .step-card__summary-button {
    grid-template-columns: 20px minmax(0, 1fr);
  }

  .step-card__summary-tag {
    grid-column: 2;
    justify-self: start;
  }

  .program-detail-head {
    flex-direction: row;
    align-items: center;
  }
}

.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding-bottom: 220px;
}

.program-list-screen,
.program-detail-screen,
.editor-screen {
  padding: 14px;
}

.top-actions {
  margin: 12px 0;
}

.program-detail-head {
  align-items: center;
}

.program-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.summary-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.program-name-row .program-name-input {
  flex: 1;
  min-width: 0;
}

.program-settings-card {
  margin: 14px 0;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
}

.program-settings-card h3 {
  margin: 4px 0 6px;
  font-family: 'Palatino Linotype', 'Book Antiqua', serif;
}

.composer-actions--bottom {
  margin-top: 10px;
  justify-content: center;
}

.compact-step-list {
  gap: 8px;
}

.compact-step-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-strong);
}

.compact-step-row.is-view {
  grid-template-columns: minmax(0, 1fr) auto;
}

.compact-step-row.is-touch-dragging {
  outline: 2px dashed rgba(217, 95, 67, 0.5);
}

.compact-step-row__handle,
.compact-step-row__main {
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
}

.compact-step-row__handle {
  font-size: 1.05rem;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  -webkit-user-drag: element;
}

.compact-step-row__handle:active {
  cursor: grabbing;
}

.compact-step-row__meta {
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 700;
  font-size: 0.82rem;
}

.compact-step-row__main {
  display: grid;
  gap: 2px;
}

.compact-step-row__title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.compact-step-row__title-text {
  display: grid;
  gap: 2px;
}

.compact-step-row__main strong {
  font-size: 0.95rem;
}

.compact-step-row__summary {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: normal;
}

.touch-drag-ghost {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0.92;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.compact-step-row__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compact-step-row__actions .field-select span {
  font-size: 0.7rem;
}

.compact-step-row__actions .field-select span:empty {
  display: none;
}

.compact-step-row__actions .field-select select {
  min-height: 36px;
  padding: 0 8px;
}

.controller-dock {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(980px, calc(100vw - 16px));
  bottom: 0;
  z-index: 30;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  display: grid;
  gap: 10px;
  max-height: min(48vh, 360px);
  overflow: auto;
}

.controller-dock__connect {
  display: flex;
}

.controller-dock__connect button {
  width: 100%;
}

.control-grid--dock {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.editor-screen {
  min-height: calc(100vh - 32px);
}

.editor-screen--ball {
  padding-left: 8px;
  padding-right: 8px;
}

.ball-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.ball-editor-head__actions {
  display: flex;
  gap: 8px;
}

.step-card__toolbar--editor {
  margin-top: 0;
}

.ball-editor-footer {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.option-card__footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.controller-dock__footer {
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
  .app-shell {
    padding-bottom: 260px;
  }

  .compact-step-row {
    grid-template-columns: 20px minmax(0, 1fr);
  }

  .compact-step-row__actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .control-grid--dock {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controller-dock {
    width: calc(100vw - 8px);
    max-height: min(56vh, 420px);
    padding-left: 12px;
    padding-right: 12px;
  }

  .ball-editor-head {
    align-items: center;
  }

  .ball-editor-head__actions {
    width: 100%;
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .ball-editor-head__actions button {
    flex: 1 1 0;
  }

  .ball-editor-footer {
    align-items: stretch;
  }

  .program-settings-card,
  .program-name-row {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-chip-group {
    justify-content: flex-start;
  }
}
