:root {
  --cts-panel-gap: 16px;
  --cts-border-radius: 14px;
  --cts-panel-bg: rgba(20, 20, 20, 0.8);
  --cts-panel-border: rgba(255, 255, 255, 0.08);
  --cts-focus-ring: 0 0 0 2px var(--accent-secondary), 0 0 12px var(--accent-secondary);
  --cts-header-offset: 72px;
  --cts-accent: var(--accent-secondary, #00ff00);
}

/* Light Theme Overrides */
body[data-theme="light"] {
  --bg-dark: #ffffff;
  --bg-medium: #f5f5f5;
  --bg-light: #e0e0e0;
  --text-primary: #000000;
  --text-secondary: #666666;
  --border: #cccccc;
  --cts-panel-border: rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .cts-panel {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body[data-theme="light"] .cts-stage-card {
  border-color: rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.8);
}

body[data-theme="light"] .cts-stage-card[data-selected="true"] {
  background: rgba(0, 255, 0, 0.15);
  border-color: var(--accent-secondary);
}

body[data-theme="light"] .cts-button {
  border-color: rgba(0, 0, 0, 0.3);
  background: rgba(255, 255, 255, 0.9);
}

body[data-theme="light"] .cts-button:hover {
  background: rgba(200, 200, 200, 0.5);
  border-color: var(--accent-secondary);
}

body[data-theme="light"] .cts-add-stage-title {
  color: var(--accent-secondary);
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.3);
}

body[data-theme="light"] .cts-stage-menu__item {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.3);
  color: #000000;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body[data-theme="light"] .cts-stage-menu__item:hover {
  background: rgba(230, 255, 230, 1);
  border-color: var(--accent-secondary);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .cts-stage-icon {
  color: var(--accent-secondary);
}

body[data-theme="light"] .cts-form-field input,
body[data-theme="light"] .cts-form-field select,
body[data-theme="light"] .cts-form-field textarea {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.3);
  color: #000000;
}

body[data-theme="light"] .cts-form-field input:focus-visible,
body[data-theme="light"] .cts-form-field select:focus-visible,
body[data-theme="light"] .cts-form-field textarea:focus-visible {
  background: rgba(255, 255, 255, 1);
  border-color: var(--accent-secondary);
}

body[data-theme="light"] .cts-table thead {
  background: rgba(0, 255, 0, 0.1);
}

body[data-theme="light"] .cts-table th,
body[data-theme="light"] .cts-table td {
  border-bottom-color: rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .cts-results-view {
  background: rgba(255, 255, 255, 0.6);
}

html {
  scroll-behavior: smooth;
}

.cts-app {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--font-sans);
  transition: background 240ms ease, color 240ms ease;
  overflow-x: hidden;
}

.cts-app::before,
.cts-app::after {
  content: none;
}

.cts-header,
.cts-footer {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-medium);
  border-bottom: 1px solid var(--cts-panel-border);
  position: relative;
  z-index: 5;
  color: var(--text-primary);
}

.cts-footer {
  border-bottom: none;
  border-top: 1px solid var(--cts-panel-border);
  justify-content: flex-start;
}

.cts-mobile-nav {
  display: none;
  width: 100%;
  gap: 8px;
  margin-top: 8px;
}

.cts-mobile-nav__item {
  flex: 1 1 auto;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  padding: 8px 12px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.cts-header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted, rgba(255, 255, 255, 0.7));
}

.cts-header__title {
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  color: var(--text-primary);
  text-transform: none;
  letter-spacing: 0.01em;
}

.cts-header__divider {
  opacity: 0.65;
}

.cts-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cts-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
  pointer-events: auto;
}

.cts-button:hover {
  border-color: var(--cts-accent);
  background: rgba(255, 255, 255, 0.1);
}

.cts-button:focus-visible {
  outline: none;
  box-shadow: var(--cts-focus-ring);
}

.cts-button--primary {
  border-color: var(--cts-accent);
  background: var(--cts-accent);
  color: #000;
  font-weight: 600;
}

.cts-stage {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(360px, 1fr) minmax(360px, 1.2fr);
  gap: var(--cts-panel-gap);
  padding: 16px 24px;
  box-sizing: border-box;
  max-width: 1440px;
  margin: 0 auto;
  position: relative;
  z-index: 5;
}

.cts-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-medium);
  border: 1px solid var(--cts-panel-border);
  border-radius: var(--cts-border-radius);
  padding: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  min-height: 0;
  scroll-margin-top: var(--cts-header-offset);
  color: var(--text-primary);
}

.cts-panel__header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cts-panel__header h2 {
  font-size: 1.25rem;
  margin: 0;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-primary);
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.cts-panel__help {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
  opacity: 0.8;
}

.cts-help-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  margin: 8px 0 0 0;
  opacity: 0.7;
}

.cts-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cts-panel__body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cts-stage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 6px;
  max-height: 60vh;
}

.cts-stage-card {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease;
}

.cts-stage-card[data-selected="true"] {
  border-color: var(--cts-accent);
  background: rgba(0, 255, 0, 0.15);
  transform: translateX(4px);
  box-shadow: 0 0 0 2px var(--cts-accent);
}

.cts-stage-card:hover:not([data-selected="true"]) {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(2px);
}

.cts-stage-card:focus-visible {
  outline: none;
  box-shadow: var(--cts-focus-ring);
}

.cts-stage-card__title {
  font-weight: 600;
  font-size: 0.9rem;
}

.cts-stage-card__meta {
  font-size: 0.7rem;
  opacity: 0.7;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.cts-stage-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cts-stage-card__controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cts-icon-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 120ms ease;
}

.cts-icon-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

.cts-icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cts-add-stage-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px solid var(--cts-panel-border);
}

.cts-add-stage-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cts-accent);
  font-weight: 700;
  margin: 0 0 12px 0;
}

.cts-stage-menu-static {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cts-stage-menu {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  border: 2px solid var(--cts-accent);
  padding: 12px;
  animation: fade-in 160ms ease;
}

.cts-stage-menu::before {
  content: "Choose stage type:";
  grid-column: 1 / -1;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 4px;
}

.cts-stage-menu__item {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  color: inherit;
  padding: 10px 12px;
  font-size: 0.8rem;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 100ms ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cts-stage-icon {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--cts-accent);
}

.cts-stage-menu__item:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--cts-accent);
  transform: translateY(-2px);
}

.cts-stage-menu__item:active {
  transform: translateY(0);
}

.cts-form {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-right: 6px;
}

.cts-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cts-form-field label {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
}

.cts-form-field input,
.cts-form-field select,
.cts-form-field textarea {
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 10, 10, 0.72);
  padding: 10px 12px;
  color: inherit;
  font-size: 0.9rem;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.cts-form-field input:hover,
.cts-form-field select:hover,
.cts-form-field textarea:hover {
  border-color: var(--cts-accent);
}

.cts-form-field input:focus-visible,
.cts-form-field select:focus-visible,
.cts-form-field textarea:focus-visible {
  outline: none;
  box-shadow: var(--cts-focus-ring);
  border-color: var(--cts-accent);
  background: rgba(0, 0, 0, 0.85);
}

.cts-form__placeholder {
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
  padding: 48px 12px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 12px;
}

.cts-tabs {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.cts-tab {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 120ms ease;
}

.cts-tab[aria-selected="true"] {
  background: var(--cts-accent);
  color: #000;
  font-weight: 600;
}

.cts-tab:focus-visible {
  outline: none;
  box-shadow: var(--cts-focus-ring);
}

.cts-results-view {
  flex: 1;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(12, 12, 12, 0.8);
  position: relative;
  display: none;
  padding: 18px;
  box-sizing: border-box;
}

.cts-results-view[data-visible="true"] {
  display: block;
}

.cts-results-heading {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted, rgba(255, 255, 255, 0.7));
  margin-bottom: 14px;
}

.cts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.cts-table thead {
  background: rgba(255, 255, 255, 0.06);
}

.cts-table th,
.cts-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.cts-cell--numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cts-results-placeholder {
  padding: 32px;
  text-align: center;
  opacity: 0.6;
  font-size: 0.85rem;
}

.cts-dilution-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cts-dilution-list li {
  display: flex;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.06);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.cts-math-ledger {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: var(--font-mono, 'Fira Mono', monospace);
  font-size: 0.8rem;
}

.cts-math-ledger li {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cts-warning-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.cts-warning-strip span {
  background: rgba(255, 99, 71, 0.2);
  border: 1px solid rgba(255, 99, 71, 0.45);
  color: #ff9a7a;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
}

.cts-status {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}

.cts-modal-root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 5, 5, 0.9);
  z-index: 100;
}

.cts-modal-root[hidden] {
  display: none !important;
}

.cts-modal {
  width: min(640px, calc(100vw - 48px));
  max-height: 80vh;
  overflow: auto;
  background: rgba(20, 20, 20, 0.92);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.cts-template-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 16px 0;
}

.cts-template-card {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 16px;
  background: rgba(10, 10, 10, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cts-template-card p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  opacity: 0.8;
}

.cts-template-card h4 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}


.cts-template-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cts-template-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.cts-export-textarea {
  width: 100%;
  margin: 16px 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.6);
  color: inherit;
  padding: 12px;
  font-family: var(--font-mono, 'Fira Mono', monospace);
  font-size: 0.85rem;
  resize: vertical;
}

.cts-export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.cts-import-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cts-import-label input {
  border: 1px dashed rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: inherit;
}

.cts-noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  z-index: 200;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1220px) {
  .cts-stage {
    grid-template-columns: minmax(280px, 1fr) minmax(320px, 1fr);
    grid-auto-rows: auto;
  }
  .cts-panel {
    min-height: 240px;
  }
  .cts-panel--results {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  :root {
    --cts-header-offset: 112px;
  }
  .cts-header,
  .cts-footer {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .cts-header__actions {
    justify-content: center;
    flex-wrap: wrap;
  }
  .cts-header__brand {
    justify-content: center;
  }
  .cts-mobile-nav {
    display: flex;
  }
  .cts-stage {
    display: flex;
    flex-direction: column;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    gap: 12px;
  }
  .cts-panel {
    padding: 14px;
    min-height: auto;
  }
  .cts-panel__actions {
    justify-content: center;
  }
  .cts-stage-list {
    max-height: none;
  }
  .cts-stage-card {
    flex-direction: column;
  }
  .cts-stage-card__controls {
    flex-direction: row;
    justify-content: flex-end;
  }
  .cts-stage-card__meta {
    align-items: flex-start;
  }
  .cts-stage-menu {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
  .cts-tabs {
    width: 100%;
    justify-content: center;
  }
  .cts-results-view {
    padding: 14px;
  }
  .cts-table th,
  .cts-table td {
    padding: 8px 6px;
  }
  .cts-export-actions {
    flex-direction: column;
  }
}
/* Removed overly aggressive color overrides - let simulatte-core.css handle theming */
