:root{
  --bg: #0b101a;
  --panel: #111827;
  --panel-2: #151f32;
  --text: #eef2ff;
  --muted: #9fb0ca;
  --line: #24324a;
  --accent: #73b2ff;
  --accent-soft: rgba(115,178,255,.16);
  --accent-strong: rgba(115,178,255,.3);
  --accent-border: rgba(115,178,255,.42);
  --success: #4dd3a7;
  --warn: #f1b36b;
  --shadow: 0 20px 50px rgba(5,10,20,.55);
  --radius: 18px;
}

body[data-theme="light"]{
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #eef2f8;
  --text: #1b2333;
  --muted: #51607a;
  --line: #d6deeb;
  --accent: #3f6ff5;
  --accent-soft: rgba(63,111,245,.14);
  --accent-strong: rgba(63,111,245,.24);
  --accent-border: rgba(63,111,245,.38);
  --success: #1ba37d;
  --warn: #d88a2c;
  --shadow: 0 12px 32px rgba(18,25,38,.14);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(115,178,255,.18), transparent 55%),
    radial-gradient(900px 600px at 95% 10%, rgba(77,211,167,.12), transparent 60%),
    var(--bg);
  color:var(--text);
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
body[data-theme="light"]{
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(63,111,245,.12), transparent 55%),
    radial-gradient(900px 600px at 95% 10%, rgba(77,211,167,.16), transparent 60%),
    var(--bg);
}

.page-shell{
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 16px;
  display:flex;
  flex-direction:column;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.hero{
  display:grid;
  gap:24px;
  grid-template-columns: minmax(0, 1.2fr) minmax(240px, .7fr);
  align-items:center;
  margin-bottom: 0;
}
.hero__copy h1{
  margin: 10px 0 12px;
  font-size: 34px;
}
.eyebrow{
  text-transform: uppercase;
  letter-spacing: .2em;
  font-size: 11px;
  color: var(--muted);
}
.lead{
  color: var(--muted);
  line-height: 1.6;
}
.hero__chips{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top:16px;
}
.chip{
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
}
.hero__stats{
  display:grid;
  gap:14px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,0));
  box-shadow: var(--shadow);
}
.hero--compact .hero__copy h1{
  font-size: 26px;
}
.hero--compact .lead{
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hero--compact .hero__chips{
  display:none;
}
.hero--compact .hero__stats{
  padding: 14px;
}
.stat{
  display:flex;
  justify-content:space-between;
  align-items:center;
  font-size: 13px;
}
.stat__label{ color: var(--muted); }
.stat__value{ font-weight: 600; }

.panel{
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 14px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.analysis-layout{
  display:grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 18px;
  height: 100%;
  min-height: 0;
}

.control-panel{
  display:flex;
  flex-direction:column;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
}

.control-section{
  background: var(--panel-2);
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 16px;
  display:flex;
  flex-direction:column;
  gap: 12px;
}

.section-title{
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .18em;
  color: var(--muted);
  margin-bottom: 4px;
}

.control{
  display:flex;
  flex-direction:column;
  gap: 6px;
  font-size: 13px;
}
.control input[type="range"],
.control select,
.control input[type="file"]{
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--text);
}
.control input[type="file"]{
  padding: 8px;
}
.control input[type="range"]{
  padding: 4px;
}

.control--toggle{
  flex-direction:row;
  align-items:center;
  gap: 10px;
}
.control--toggle input{
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.helper{
  font-size: 12px;
  color: var(--muted);
}

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

.btn{
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  background: transparent;
  color: var(--text);
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: all .2s ease;
}
.btn:hover{ background: var(--accent-soft); }
.btn:disabled{
  opacity: .55;
  cursor: not-allowed;
}
.btn--primary{
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn--primary:hover{ filter: brightness(1.05); }
.btn--ghost{
  background: rgba(255,255,255,.04);
}

.file-switcher{
  display:flex;
  flex-direction:column;
  gap: 12px;
}
.file-switcher__header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  font-size: 12px;
  color: var(--muted);
}

.file-grid{
  display:grid;
  gap: 8px;
  max-height: 150px;
  overflow:auto;
  padding-right: 4px;
}
.file-item{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(0,0,0,.12);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.file-item span{
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}
.file-item.active{
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.advanced{ display:none; }
.advanced.is-active{ display:flex; }
.advanced-grid{
  display:flex;
  flex-direction:column;
  gap: 12px;
}
.advanced-control{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap: 6px;
}
.control-reset{
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
}

.analysis-panel{
  display:flex;
  flex-direction:column;
  gap: 14px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

.analysis-card{
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,0));
  padding: 14px;
  display:flex;
  flex-direction:column;
  min-height: 0;
}
.analysis-card--preview{
  flex: 0 0 auto;
}
.analysis-card--histogram,
.analysis-card--results{
  flex: 0 0 auto;
}

.analysis-card__header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.analysis-card__header h2{
  margin: 0 0 6px;
  font-size: 18px;
}
.muted{ color: var(--muted); font-size: 13px; }

.preview-block{
  background: var(--panel-2);
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 12px;
  flex: 1;
  display:flex;
  flex-direction:column;
  gap: 10px;
}
.preview-block h3{
  margin-top: 0;
  font-size: 14px;
}
.preview-block--stacked{
  min-height: 0;
}
.preview-stack{
  position: relative;
  flex: none;
  height: clamp(240px, 46vh, 520px);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.2);
  overflow: hidden;
}
.preview-stack .preview-canvas{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border: none;
  background: transparent;
  border-radius: 0;
  display: block;
}
canvas:not(.preview-canvas){
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.2);
}

.legend{
  display:flex;
  align-items:center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.legend__dot{
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  display:inline-block;
}

.chart-wrap{
  position: relative;
}
.chart-tooltip{
  position:absolute;
  pointer-events:none;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--text);
  opacity:0;
  transform: translate(-50%, -120%);
  transition: opacity .2s ease;
}
.chart-tooltip.is-visible{ opacity: 1; }

.results-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.result-card{
  background: var(--panel-2);
  border-radius: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  display:flex;
  flex-direction:column;
  gap: 6px;
}
.result-label{ font-size: 12px; color: var(--muted); }
.result-value{ font-size: 18px; font-weight: 600; }
.result-note{ font-size: 11px; color: var(--muted); }

.results-table-wrap{
  overflow: hidden;
  max-height: none;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.results-table{
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.results-table th,
.results-table td{
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.results-table th{
  text-align:left;
  color: var(--muted);
  background: rgba(0,0,0,.2);
  position: sticky;
  top: 0;
}
.results-table-wrap .helper{
  padding: 8px 10px 10px;
  margin: 0;
}

.footer{
  padding: 24px;
  text-align:center;
  color: var(--muted);
}

.preview-controls{
  display:flex;
  flex-wrap:wrap;
  gap: 10px;
  align-items:center;
}
.mini-control{
  display:flex;
  flex-direction:column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
.mini-control input,
.mini-control select{
  width: 120px;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 4px 8px;
  background: rgba(255,255,255,.04);
  color: var(--text);
}

@media (max-width: 960px){
  html, body{
    height: auto;
  }
  body{
    overflow: visible;
  }
  .page-shell,
  .panel{
    flex: none;
    overflow: visible;
  }
  .analysis-layout,
  .analysis-panel{
    height: auto;
  }
  .control-panel,
  .analysis-panel{
    overflow: visible;
  }
  .preview-stack{
    height: auto;
    aspect-ratio: 3 / 2;
  }
  .analysis-layout{
    grid-template-columns: 1fr;
  }
  .hero{
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px){
  .analysis-card__header{
    flex-direction:column;
    align-items:flex-start;
  }
  .button-row{
    flex-direction:column;
    align-items:stretch;
  }
}
