:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --page-bg-top: #f8fbff;
  --page-glow-left: rgba(37, 99, 235, 0.16);
  --page-glow-right: rgba(14, 165, 233, 0.12);
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --surface-soft: #f8fbff;
  --surface-subtle: #f7faff;
  --drop-bg: linear-gradient(180deg, #fbfdff 0%, #f4f8ff 100%);
  --drop-bg-hover: linear-gradient(180deg, #f7fbff 0%, #eaf2ff 100%);
  --kpi-bg: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  --primary-gradient: linear-gradient(135deg, var(--primary) 0%, #3b82f6 100%);
  --primary-gradient-hover: linear-gradient(135deg, var(--primary-strong) 0%, var(--primary) 100%);
  --text: #162033;
  --muted: #5b6780;
  --border: #dbe3f0;
  --border-strong: #c7d4e8;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #e8f0ff;
  --success-bg: #ecfdf3;
  --success-text: #0f7a42;
  --error-bg: #fff1f2;
  --error-text: #be123c;
  --shadow: 0 18px 48px rgba(20, 32, 62, 0.10);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101827;
  --page-bg-top: #0c1320;
  --page-glow-left: rgba(45, 212, 191, 0.11);
  --page-glow-right: rgba(96, 165, 250, 0.13);
  --panel: rgba(22, 31, 47, 0.9);
  --panel-solid: #172033;
  --surface-soft: #111c2d;
  --surface-subtle: #1b2940;
  --drop-bg: linear-gradient(180deg, #172236 0%, #111c2d 100%);
  --drop-bg-hover: linear-gradient(180deg, #1d2b43 0%, #16243a 100%);
  --kpi-bg: linear-gradient(180deg, #1b2940 0%, #121d2f 100%);
  --text: #eef4ff;
  --muted: #a8b5ca;
  --border: #2d3d56;
  --border-strong: #40536f;
  --primary: #60a5fa;
  --primary-strong: #93c5fd;
  --primary-soft: rgba(96, 165, 250, 0.16);
  --success-bg: #0f2b21;
  --success-text: #86efac;
  --error-bg: #35151e;
  --error-text: #fda4af;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #101827;
    --page-bg-top: #0c1320;
    --page-glow-left: rgba(45, 212, 191, 0.11);
    --page-glow-right: rgba(96, 165, 250, 0.13);
    --panel: rgba(22, 31, 47, 0.9);
    --panel-solid: #172033;
    --surface-soft: #111c2d;
    --surface-subtle: #1b2940;
    --drop-bg: linear-gradient(180deg, #172236 0%, #111c2d 100%);
    --drop-bg-hover: linear-gradient(180deg, #1d2b43 0%, #16243a 100%);
    --kpi-bg: linear-gradient(180deg, #1b2940 0%, #121d2f 100%);
    --text: #eef4ff;
    --muted: #a8b5ca;
    --border: #2d3d56;
    --border-strong: #40536f;
    --primary: #60a5fa;
    --primary-strong: #93c5fd;
    --primary-soft: rgba(96, 165, 250, 0.16);
    --success-bg: #0f2b21;
    --success-text: #86efac;
    --error-bg: #35151e;
    --error-text: #fda4af;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, var(--page-glow-left), transparent 28%),
    radial-gradient(circle at top right, var(--page-glow-right), transparent 22%),
    linear-gradient(180deg, var(--page-bg-top) 0%, var(--bg) 100%);
}

.page-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 20px 56px;
}

.card,
.card-lite {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow);
}

.card {
  border-radius: var(--radius-xl);
  padding: 28px;
  margin-bottom: 24px;
}

.card-lite {
  border-radius: var(--radius-lg);
  padding: 20px;
}

.hero {
  padding: 34px 42px;
}

.hero-copy {
  max-width: 760px;
}

.hero-main {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hero-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: 36px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2.7rem, 5vw, 4.6rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.25rem;
  margin-bottom: 6px;
}

.hero-text,
.section-head p,
.controls-card p {
  color: var(--muted);
  margin: 12px 0 0;
  line-height: 1.7;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
  justify-content: flex-end;
  margin-left: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.summary-label {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.summary-value {
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.5;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-head.compact {
  margin-bottom: 14px;
}

.theme-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.theme-toolbar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 260px;
}

.theme-toggle {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-soft);
  width: 260px;
}

.theme-option {
  appearance: none;
  min-width: 68px;
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.theme-option:hover {
  color: var(--text);
}

.theme-option.is-selected {
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.10);
}

.upload-form {
  display: grid;
  gap: 24px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.4fr) minmax(240px, 1fr);
  gap: 18px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label {
  font-weight: 700;
  font-size: 0.95rem;
}

input[type="text"],
select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--panel-solid);
  color: var(--text);
  font-size: 0.98rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 24px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 18px;
  background: var(--drop-bg);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--drop-bg-hover);
  transform: translateY(-1px);
}

.drop-title {
  font-size: 1rem;
  font-weight: 800;
}

.drop-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
}

input[type="file"] {
  display: none;
}

.file-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.94rem;
}

#fileName {
  font-weight: 700;
}

#fileSize {
  color: var(--muted);
}

.hint {
  color: var(--muted);
  line-height: 1.6;
}

code {
  background: var(--primary-soft);
  color: var(--primary-strong);
  padding: 0.18rem 0.42rem;
  border-radius: 8px;
  font-size: 0.92em;
}

.action-groups {
  display: grid;
  gap: 18px;
}

.action-block {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
}

.action-title {
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text);
}

.button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 0.97rem;
  font-weight: 700;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease, opacity 0.14s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.26);
}

.btn-primary:hover {
  background: var(--primary-gradient-hover);
}

.btn-secondary {
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
  background: var(--surface-soft);
}

.status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--panel-solid);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
  font-weight: 700;
  margin-bottom: 24px;
}

.status-card.status-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: rgba(15, 122, 66, 0.18);
}

.status-card.status-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: rgba(190, 18, 60, 0.18);
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--primary);
  animation: spin 0.85s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

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

.kpi-card {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--kpi-bg);
}

.kpi-label {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.5;
}

.preview-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.preview-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.55;
}

.preview-list li:last-child {
  border-bottom: none;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel-solid);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--surface-soft);
}

tbody tr:last-child td {
  border-bottom: none;
}

.plot-frame {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--kpi-bg);
}

#plotImage {
  display: block;
  width: 100%;
  max-width: 100%;
  border-radius: 12px;
  background: var(--panel-solid);
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .section-head,
  .hero-top {
    display: flex;
    flex-direction: column;
  }

  .theme-toolbar {
    align-items: flex-start;
  }

  .hero-badges {
    justify-content: flex-start;
  }

  .summary-grid,
  .control-grid,
  .info-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 18px 14px 36px;
  }

  .card {
    padding: 20px;
    border-radius: 20px;
  }

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

  .theme-toggle {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .btn {
    width: 100%;
  }
}
