:root {
  --bg: #f3f3f3;
  --panel: #ffffff;
  --ink: #111111;
  --accent: #111111;
  --line: #d0d0d0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  position: relative;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.app-header p {
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
  padding-right: 12.5rem;
}

.repo-hint {
  position: absolute;
  top: 50%;
  right: 2.9rem;
  transform: translateY(-50%);
  font-size: 0.78rem;
  color: #111111;
  border-bottom: 1px dashed #666666;
  padding-bottom: 1px;
}

.github-link {
  position: absolute;
  top: 50%;
  right: 0.8rem;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #111111;
  border: 1px solid #111111;
  border-radius: 6px;
  background: #ffffff;
  text-decoration: none;
}

.github-link:hover {
  background: #f3f3f3;
}

.github-link svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.viewer-layout {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.left-column {
  min-height: 0;
  height: 100%;
  display: block;
}

.controls {
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.controls h2,
.controls h3 {
  margin: 0 0 0.5rem;
  color: var(--accent);
}

.controls h2 {
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
}

.controls-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: -2px;
  margin-bottom: 0.45rem;
}

.controls-head h2 {
  margin-bottom: 0;
}

.controls h3 {
  margin-top: 0;
  font-size: 1rem;
}

.workflow-progress {
  margin-bottom: 0.8rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e7e7e7;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: #111111;
  transition: width 180ms ease-out;
}

.workflow-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0.75rem;
  margin-bottom: 0.7rem;
  box-shadow: 0 1px 0 rgba(35, 46, 53, 0.04);
}

.workflow-step.pending {
  border-color: #c43d3d;
  background: #fff5f5;
}

.workflow-step.in-progress {
  border-color: #c9a227;
  background: #fffbea;
  box-shadow: 0 0 0 1px #c9a227;
}

.workflow-step.complete {
  border-color: #3f8a4c;
  background: #f1faf3;
}

.step-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 0.35rem;
}

.step-kicker {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5c5c5c;
}

.workflow-step h3 {
  margin-top: 0;
  margin-bottom: 0.2rem;
}

.step-state {
  margin-top: 1px;
  padding: 0.16rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid #c43d3d;
  background: #ffe6e6;
  color: #7f1f1f;
  white-space: nowrap;
}

.step-state.in-progress {
  border-color: #c9a227;
  background: #fff3c4;
  color: #6b5200;
}

.step-state.complete {
  border-color: #3f8a4c;
  background: #ddf1e1;
  color: #1f5c2a;
}

.small {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  color: #4d4d4d;
}

.status {
  margin: 0.6rem 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid #cfcfcf;
  background: #f7f7f7;
  border-radius: 6px;
  font-size: 0.85rem;
}

label,
select,
button,
input {
  width: 100%;
}

.hidden {
  display: none !important;
}

select,
button,
input[type="file"] {
  margin-top: 0.3rem;
}

button {
  margin-top: 0.8rem;
  padding: 0.6rem;
  border: 1px solid #111111;
  border-radius: 7px;
  background: #111111;
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: #2a2a2a;
}

.secondary-btn {
  background: #ffffff;
  color: #111111;
  border: 1px solid #111111;
}

.secondary-btn:hover {
  background: #f2f2f2;
}

.formula-help {
  margin-top: 0.55rem;
  border: 1px solid #d8d2c6;
  border-radius: 6px;
  background: #fafafa;
  padding: 0.45rem 0.55rem;
}

.formula-help summary {
  cursor: pointer;
  font-size: 0.83rem;
  color: #222222;
  font-weight: 600;
}

.formula-help[open] {
  background: #fff;
}

.formula-help .small {
  margin-top: 0.5rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.alias-list {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.45rem;
}

.preset-band-group {
  margin-top: 0.35rem;
}

.alias-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem;
  background: #fff;
}

.alias-row small {
  display: block;
  margin-bottom: 0.25rem;
  color: #4d4d4d;
  word-break: break-word;
}

.canvases {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.75fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.canvases article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.canvases h2 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  color: #111111;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-head h2 {
  margin: 0 0 0.6rem;
}

.icon-btn {
  width: auto;
  margin-top: 0;
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

.map-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 500;
  width: 220px;
  margin: 0;
  padding: 0.45rem;
  border: 1px solid #cfcfcf;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(2px);
}

.map-controls label {
  display: block;
  margin-bottom: 0.15rem;
  font-size: 0.75rem;
  color: #333333;
}

.map-controls select {
  margin-top: 0.15rem;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid #c8c8c8;
  border-radius: 5px;
  background: #ffffff;
}

.map-controls select:last-child {
  margin-bottom: 0;
}

.map-controls input[type="file"] {
  margin-top: 0.2rem;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
}

.map-controls input[type="range"] {
  margin-top: 0.2rem;
  margin-bottom: 0;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
}

.map-controls input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #111111;
}

.map-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #111111;
  margin-top: -4px;
}

.map-controls input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: #111111;
}

.map-controls input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #111111;
}

.map-stage {
  position: relative;
}

.map-mini-btn {
  margin-top: 0.2rem;
  margin-bottom: 0;
  padding: 0.35rem 0.45rem;
  font-size: 0.72rem;
}

.measure-control {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #111111;
  border-radius: 6px;
  box-shadow: none;
}

.measure-control button {
  width: auto;
  margin: 0;
  padding: 0.22rem 0.45rem;
  font-size: 0.72rem;
  line-height: 1.2;
  border-radius: 5px;
}

.measure-toggle {
  background: #ffffff;
  color: #111111;
  border: 1px solid #111111;
}

.measure-toggle.active {
  background: #111111;
  color: #ffffff;
}

.measure-clear {
  background: #ffffff;
  color: #111111;
  border: 1px solid #111111;
}

.measure-readout {
  grid-column: 1 / -1;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  background: #ffffff;
  padding: 0.18rem 0.35rem;
  font-size: 0.72rem;
  color: #111111;
}

.map-stage .status {
  margin-top: 0.55rem;
  margin-bottom: 0;
}

.map-container {
  width: 100%;
  min-height: 420px;
  height: calc(100vh - 260px);
  border: 1px solid #cfcfcf;
  border-radius: 6px;
  overflow: hidden;
  background: #f2f2f2;
}

.pixel-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0.6rem;
}

.pixel-values-list {
  margin-bottom: 0.45rem;
}

.pixel-values-list .small {
  margin-bottom: 0.35rem;
}

.pixel-panel h3 {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  color: #111111;
}

.pixel-panel {
  height: 100%;
}

.hidden-canvases {
  display: none;
}

#pixelTrendCanvas {
  width: 100%;
  height: auto;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  background: #ffffff;
}

canvas {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 210px);
  border: 1px solid #cfcfcf;
  border-radius: 6px;
  background: #f8f8f8;
  image-rendering: pixelated;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .viewer-layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .left-column {
    display: block;
    height: auto;
  }

  .controls {
    height: auto;
    overflow: visible;
  }

  .canvases {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  canvas {
    max-height: 420px;
  }

  .map-container {
    height: 420px;
    min-height: 420px;
  }

}
