:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --text: #eef1f5;
  --muted: #9aa4b2;
  --grid-border: #000;
  --inactive: #3a3a3a;
  --cell-size: 18px;
  --bar-height: 44px;

  --slider-base: #00509D;
  --slider-fill: #00296B;
  --slider-thumb: #ffc300;
  --line-color: #00509D;
  --marker-color: #ffc300;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
}

/* ---------------- HOME ---------------- */

.home-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background:
    radial-gradient(circle at top, rgba(0,80,157,0.18), transparent 35%),
    var(--bg);
}

.home-container {
  display: flex;
  flex-direction: column;   /* THIS is the key */
  align-items: center;
}

.home-wrap {
  width: min(1200px, 100%);
}

.home-title {
  margin: 0 0 8px 0;
  text-align: center;
  font-size: 28px;
  font-weight: 700;
}

.home-subtitle {
  text-align: center;
  color: var(--muted);
  margin-bottom: 24px;
  font-size: 15px;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 20px;
  justify-content: center;
}

.home-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  overflow: hidden;
  border: 2px solid #3f4652;
  background: #13161c;
  cursor: pointer;
  transition: border-color 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  padding: 0;
}

.home-card:hover {
  border-color: #9cc4ff;
  box-shadow: 0 16px 36px rgba(0,80,157,0.24);
  filter: brightness(1.08);
}

.home-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
  transform: scale(1);
  transition: transform 0.28s ease, filter 0.22s ease, opacity 0.14s linear;
}

.home-card:hover .home-card-img {
  transform: scale(1.06);
  filter: brightness(1.08);
}

/* ---------------- DASHBOARD ---------------- */

.dashboard-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  height: var(--bar-height);
  padding: 0 14px;
  border-bottom: 1px solid #22252b;
  display: flex;
  align-items: center;
  gap: 12px;
}

header h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}

.meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #003F88;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background-color 0.18s ease, transform 0.18s ease;
  font-size: 13px;
}

.back-btn:hover {
  background: #00509D;
  transform: translateX(-1px);
}

.back-arrow {
  font-size: 16px;
  line-height: 1;
}

.bar {
  height: var(--bar-height);
  padding: 0 14px;
  border-bottom: 1px solid #22252b;
  display: flex;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  background: #121419;
}

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 25% 35% 40%;
  min-height: 0;
}

.panel {
  border-right: 1px solid #22252b;
  background: var(--panel);
  overflow: auto;
}

.panel:last-child {
  border-right: none;
}

/* Bars inside panels */
.frame-head {
  height: var(--bar-height);
  padding: 0 12px;
  border-bottom: 1px solid #22252b;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.chart-head {
  height: var(--bar-height);
  padding: 0 14px;
  border-bottom: 1px solid #22252b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.chart-head span:nth-child(2) {
  margin: 0 auto;
}

.layer-bar {
  height: var(--bar-height);
  padding: 0 14px;
  border-bottom: 1px solid #22252b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  gap: 12px;
}

.layer-bar .legend {
  margin: 0 auto;
}

/* Left image */
.frame-img {
  display: block;
  width: calc(100% - 32px);
  max-width: calc(100% - 32px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #0d0e10;
  margin: 16px auto;
  border: 1px solid #2a2d34;
  border-radius: 12px;
}

/* Slider */
#frameSlider {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right,
    var(--slider-fill) 0%,
    var(--slider-fill) var(--val,0%),
    var(--slider-base) var(--val,0%),
    var(--slider-base) 100%);
  outline: none;
  flex: 1;
}

#frameSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--slider-thumb);
  cursor: pointer;
  border: none;
}

#frameSlider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--slider-thumb);
  cursor: pointer;
  border: none;
}

/* Chart */
.chart-wrap {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.chart-box {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  height: 100%;
  padding: 12px 12px 0 12px;
}

#chart {
  width: 100%;
  max-width: 620px;
  height: auto;
  overflow: visible;
}

.line {
  fill: none;
  stroke: var(--line-color);
  stroke-width: 3;
}

.marker {
  stroke: #fff;
  stroke-width: 1.5;
  fill: var(--marker-color);
}

/* Filter grids */
.grids {
  padding: 8px;
  display: grid;
  gap: 8px;
  border-bottom: 1px solid #22252b;
}

.grid-card {
  background: #111317;
  border: 1px solid #22252b;
  border-radius: 12px;
  overflow: hidden;
}

.grid-head {
  padding: 6px 8px;
  border-bottom: 1px solid #22252b;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 2px;
  padding: 6px;
}

.cell {
  border: 1px solid var(--grid-border);
  aspect-ratio: 1 / 1;
  background: #1b1f26;
  width: var(--cell-size);
  height: var(--cell-size);
  transition: transform 0.15s ease, background 0.15s ease;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  overflow: hidden;
}

.cell:hover {
  transform: scale(1.15);
  z-index: 2;
}

/* Legend */
.legend {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.legend.hidden {
  display: none;
}

.swatch {
  width: 14px;
  height: 14px;
  border: 1px solid #000;
  border-radius: 4px;
}

.swatch.red { background: rgba(255,0,0,1); }
.swatch.blue { background: rgba(0,64,255,1); }
.swatch.grey { background: var(--inactive); }

/* Selectors */
#transformSelect,
#layerSelect,
#vizModeSelect {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: #003F88;
  color: #fff;
  border: none;
  padding: 6px 28px 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'><path fill='white' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
  transition: background-color 0.2s ease;
}

#transformSelect:hover,
#layerSelect:hover,
#vizModeSelect:hover {
  background-color: #00509D;
}

/* Popup */
.popup {
  position: fixed;
  background: rgba(20,22,28,0.95);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #333;
  font-size: 12px;
  pointer-events: none;
  max-width: 300px;
  line-height: 1.4;
  z-index: 9999;
  display: none;
}

.popup strong {
  color: #ffd166;
}

.popup-fmap-wrap {
  margin: 10px auto 0 auto;
  width: 160px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0f13;
  border: 1px solid #2a2d34;
  border-radius: 6px;
  overflow: hidden;
}

.popup-fmap {
  width: 160px;
  height: 160px;
  object-fit: fill;
  image-rendering: pixelated;
  display: block;
}

.popup-fmap-missing {
  width: 160px;
  height: 160px;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 12px;
  text-align: center;
  padding: 8px;
}

/* Details */
.details {
  padding: 12px;
  background: #111317;
  border-top: 1px solid #22252b;
  min-height: 200px;
}

.details-bar {
  height: var(--bar-height);
  padding: 0 14px;
  border-bottom: 1px solid #22252b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.details-bar .details-msg {
  margin: 0 auto;
}

.details-bar select {
  background-color: #003F88;
  color: #fff;
  border: none;
  padding: 6px 28px 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.details-bar select:hover {
  background-color: #00509D;
}

.details-bar .close {
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  transition: color 0.2s ease;
}

.details-bar .close:hover {
  color: #ff4d4d;
}

.placeholder {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin: 20px 0;
}

@media (max-width: 1200px) {
  .home-grid {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
  }
}

@media (max-width: 900px) {
  .home-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

.home-credit {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.home-credit a {
  color: #9cc4ff;
  text-decoration: none;
}

.home-credit a:hover {
  text-decoration: underline;
}