:root {
  --bg: #f8fafc;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-muted: rgba(248, 250, 252, 0.96);
  --panel-border: rgba(15, 23, 42, 0.08);
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, 0.1);
  --accent-strong: #115e59;
  --warn: #b91c1c;
  --grid: rgba(15, 23, 42, 0.06);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.08), transparent 28%),
    linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

code {
  font-family: "SFMono-Regular", "Menlo", monospace;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 28px auto 28px;
}

.hero {
  margin-bottom: 10px;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

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

.hero h1 {
  margin: 0;
  max-width: 18ch;
  font-size: clamp(1.3rem, 1.7vw, 2rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.hero-copy {
  max-width: 72ch;
  color: var(--muted);
  line-height: 1.45;
  margin: 6px 0 0;
  font-size: 0.88rem;
}

.hero-upload {
  flex: 0 0 min(360px, 34vw);
}

.hero-upload-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.workspace {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
}

.panel {
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls-panel {
  grid-column: span 12;
  display: grid;
  grid-template-columns: minmax(200px, 1.1fr) minmax(0, 2fr) minmax(240px, 1fr);
  gap: 12px;
  align-items: start;
  background: var(--panel-muted);
}

.utility-hidden {
  display: none;
}

.stats-panel {
  grid-column: span 12;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.plot-panel {
  grid-column: span 12;
  padding: 18px;
}

.dropzone {
  min-height: 76px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px dashed rgba(15, 118, 110, 0.28);
  background: rgba(15, 118, 110, 0.04);
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.dropzone.drag-active {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
}

.dropzone-title,
.dropzone-subtitle,
.hint,
.status,
.plot-header p {
  margin: 0;
}

.dropzone-title {
  font-size: 0.98rem;
  font-weight: 600;
}

.dropzone-subtitle,
.hint,
.status,
.plot-header p {
  margin-top: 6px;
  color: var(--muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 0;
  align-content: flex-start;
}

button {
  padding: 8px 11px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

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

.small-button {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.icon-button {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  font-size: 0;
  line-height: 0;
  font-weight: 600;
  background: var(--accent) !important;
  color: #fff !important;
  border-color: transparent !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.icon-button::before {
  content: "+";
  color: #fff;
  display: block;
  font-size: 1.15rem;
  line-height: 1;
  transform: translateY(-1px);
}

.danger-icon-button {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  border-color: transparent;
  background: #b91c1c;
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  line-height: 1;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

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

.selection-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 0;
}

.selection-grid label {
  display: grid;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--muted);
}

.selection-grid input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 12px;
  background: white;
  color: var(--ink);
}

.hint {
  margin-top: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  grid-column: 1 / -1;
}

.status {
  margin-top: -4px;
  min-height: 1.5em;
  font-size: 0.9rem;
  grid-column: 1 / -1;
}

.hero-status {
  margin-top: 8px;
  margin-bottom: 10px;
}

.status.error {
  color: var(--warn);
}

.stat-card {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--panel-muted);
  border: 1px solid rgba(15, 23, 42, 0.06);
}

.stat-card.accent {
  background: var(--accent-soft);
}

.stat-label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-card strong {
  display: block;
  font-size: 0.9rem;
  line-height: 1.3;
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.plot-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.plot-header h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
}

.plot-header p {
  font-size: 0.9rem;
}

.scale-readout {
  color: var(--muted);
  font-size: 0.84rem;
}

.analysis-panel {
  grid-column: span 12;
  background: var(--panel-muted);
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.analysis-card {
  padding: 14px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  min-width: 0;
}

.analysis-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.analysis-card h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.analysis-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.analysis-summary {
  min-height: 1.4em;
}

.analysis-buckets,
.analysis-pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.analysis-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.05);
  color: var(--ink);
  font-size: 0.8rem;
}

.analysis-code {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: #f8fafc;
  color: #0f172a;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}

.diff-table {
  margin-top: 12px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-radius: 14px;
  overflow: hidden;
}

.diff-table-head,
.diff-table-row {
  display: grid;
  grid-template-columns: 48px repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 8px 10px;
  font-size: 0.8rem;
}

.diff-table-head {
  background: rgba(15, 23, 42, 0.05);
  color: var(--muted);
  font-weight: 600;
}

.diff-table-row {
  border-top: 1px solid rgba(15, 23, 42, 0.05);
}

.diff-table-row.status-exact {
  background: rgba(15, 118, 110, 0.03);
}

.diff-table-row.status-close {
  background: rgba(242, 177, 52, 0.08);
}

.diff-table-row.status-mismatch,
.diff-table-row.status-missing {
  background: rgba(185, 28, 28, 0.04);
}

.burst-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.burst-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: rgba(248, 250, 252, 0.96);
  cursor: pointer;
}

.burst-row-copy {
  display: grid;
  gap: 4px;
}

.burst-row-copy strong,
.burst-row-copy span {
  display: block;
}

.burst-row-copy span {
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quantize-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 10px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.quantize-estimate {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.quantize-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.quantize-input-wrap input {
  width: 68px;
  padding: 5px 7px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.toggle-button {
  padding: 6px 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.toggle-button.active {
  background: var(--accent);
  color: white;
}

.compare-panel {
  grid-column: span 12;
  background: var(--panel-muted);
}

.compare-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 14px;
}

.compare-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compare-actions button:not(.icon-button) {
  background: var(--panel);
}

.compare-actions button:not(.icon-button),
.analysis-card select {
  background: var(--panel);
}

.analysis-card select {
  min-width: 0;
  max-width: 160px;
  padding: 7px 10px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 12px;
  color: var(--ink);
}

.compare-header h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
}

.compare-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.workspace-list {
  display: grid;
  gap: 14px;
}

.workspace-card {
  --workspace-color: var(--accent);
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-left: 8px solid var(--workspace-color);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  transition: box-shadow 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.workspace-card:hover {
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.workspace-card.active {
  background: color-mix(in srgb, var(--workspace-color) 10%, rgba(255, 255, 255, 0.82));
  border-color: color-mix(in srgb, var(--workspace-color) 45%, rgba(15, 23, 42, 0.08));
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.workspace-card-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.workspace-card-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.workspace-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--workspace-color);
}

.workspace-card h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.workspace-title-input {
  min-width: 0;
  width: min(220px, 100%);
  padding: 6px 8px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 10px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
}

.workspace-title-edit-button {
  min-width: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 999px;
  font-size: 0.92rem;
  line-height: 1;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.03);
  border-color: rgba(15, 23, 42, 0.05);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.workspace-title-edit-button:hover {
  background: rgba(15, 23, 42, 0.07);
  color: var(--ink);
}

.workspace-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.workspace-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.workspace-card-actions button {
  padding: 7px 10px;
  font-size: 0.84rem;
}

.export-menu {
  position: relative;
}

.export-menu summary {
  list-style: none;
}

.export-menu summary::-webkit-details-marker {
  display: none;
}

.export-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.84rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.export-menu-toggle::after {
  content: "▾";
  font-size: 0.72rem;
  color: var(--muted);
}

.export-menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 148px;
  padding: 6px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
  display: grid;
  gap: 4px;
}

.export-menu-list button {
  width: 100%;
  text-align: left;
  background: transparent;
  box-shadow: none;
  border-color: transparent;
}

.export-menu-list button:hover {
  background: rgba(15, 23, 42, 0.04);
}

.workspace-align-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 4px;
  padding: 0 14px 0 2px;
  margin-right: 6px;
  border-right: 1px solid rgba(15, 23, 42, 0.9);
}

.workspace-align-label,
.workspace-align-value {
  font-size: 0.84rem;
  color: var(--muted);
  white-space: nowrap;
}

.workspace-align-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.workspace-align-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.workspace-align-nudge {
  min-width: 34px;
  padding: 7px 8px;
}

.workspace-align-input {
  width: 84px;
  padding: 7px 8px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 10px;
  background: white;
  color: var(--ink);
  font: inherit;
}

.workspace-align-unit {
  font-size: 0.84rem;
  color: var(--muted);
}

.workspace-preview {
  height: 80px;
  cursor: default;
}

canvas {
  width: 100%;
  display: block;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98));
  border: 1px solid rgba(15, 23, 42, 0.08);
}

@media (max-width: 1000px) {
  .controls-panel,
  .stats-panel,
  .plot-panel,
  .analysis-panel {
    grid-column: span 12;
  }

  .hero-row {
    flex-direction: column;
  }

  .hero-upload {
    width: 100%;
    flex-basis: auto;
  }

  .controls-panel {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 20px, 1320px);
    margin-top: 10px;
  }

  .panel {
    border-radius: 16px;
    padding: 14px;
  }

  .selection-grid,
  .stats-panel {
    grid-template-columns: 1fr;
  }

  .workspace-card-header,
  .compare-header,
  .plot-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .compare-actions {
    justify-content: flex-start;
  }

  .detail-header-actions {
    justify-content: flex-start;
  }

  .analysis-card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .site-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .workspace-align-group {
    margin-left: 0;
    margin-right: 0;
    padding: 0 0 10px;
    border-right: 0;
    border-bottom: 1px solid rgba(15, 23, 42, 0.9);
    flex-wrap: wrap;
  }
}

.site-footer {
  padding: 18px 4px 0;
  color: var(--muted);
  font-size: 0.92rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

.site-footer p {
  margin: 0;
}

.footer-copy {
  display: grid;
  gap: 4px;
}

.footer-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.site-footer a {
  color: var(--accent-strong);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.footer-repo-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.footer-repo-link svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
  flex: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.36);
  backdrop-filter: blur(4px);
  z-index: 1000;
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-modal {
  width: min(420px, calc(100vw - 32px));
  padding: 18px;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
}

.confirm-modal h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.confirm-modal p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
