:root {
  --ink: #13201f;
  --muted: #5a6e6b;
  --paper: #eef3f1;
  --panel: rgba(255, 255, 255, 0.72);
  --teal: #1f6f68;
  --teal-deep: #0f2f2c;
  --band-outer: rgba(31, 111, 104, 0.16);
  --band-inner: rgba(31, 111, 104, 0.32);
  --median: #c26a2b;
  --line: rgba(19, 32, 31, 0.12);
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Sora", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-ui);
  background: var(--paper);
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 16px
    calc(20px + env(safe-area-inset-bottom));
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(31, 111, 104, 0.22), transparent 55%),
    radial-gradient(700px 420px at 110% 10%, rgba(194, 106, 43, 0.12), transparent 50%),
    linear-gradient(165deg, #f7faf8 0%, #e7efec 48%, #dfeae7 100%);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  animation: rise 0.5s ease-out both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--teal-deep);
}

.mark {
  width: 14px;
  height: 36px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--teal), var(--median));
  box-shadow: 0 8px 18px rgba(31, 111, 104, 0.28);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.controls {
  display: grid;
  gap: 10px;
  animation: rise 0.55s ease-out 0.05s both;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid rgba(19, 32, 31, 0.08);
  border-radius: calc(var(--radius) + 2px);
  backdrop-filter: blur(10px);
}

.seg button,
.ghost,
.primary {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.seg button {
  padding: 0.7rem 0.5rem;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.seg button.active {
  background: var(--teal-deep);
  color: #f4faf8;
  box-shadow: 0 8px 16px rgba(15, 47, 44, 0.22);
}

.seg button:active {
  transform: scale(0.98);
}

.offset-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
}

.window {
  margin: 0;
  text-align: center;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 500;
}

.ghost {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(19, 32, 31, 0.08);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
}

.status {
  margin: 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.2em;
  transition: opacity 0.25s ease;
}

.status.error {
  color: #9b2c2c;
}

.charts {
  display: grid;
  gap: 14px;
  animation: rise 0.6s ease-out 0.1s both;
}

.chart-panel {
  display: grid;
  gap: 8px;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 4px;
}

.chart-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 560;
  color: var(--teal-deep);
}

.chart-head .unit {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.chart-wrap {
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(19, 32, 31, 0.08);
  overflow: hidden;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: min(38dvh, 340px);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--muted);
  animation: rise 0.65s ease-out 0.14s both;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 3px;
}

.legend .wide {
  background: var(--band-outer);
}

.legend .mid {
  background: var(--band-inner);
}

.legend .median {
  height: 3px;
  background: var(--median);
  border-radius: 2px;
}

dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(92vw, 400px);
  background: #f8fbfa;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(15, 47, 44, 0.28);
}

dialog::backdrop {
  background: rgba(15, 47, 44, 0.45);
  backdrop-filter: blur(2px);
}

dialog form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

dialog h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

dialog label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

dialog input {
  font: inherit;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(19, 32, 31, 0.14);
  background: #fff;
  color: var(--ink);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions .ghost,
.dialog-actions .primary {
  width: auto;
  height: auto;
  padding: 0.65rem 1rem;
}

.primary {
  border-radius: 10px;
  background: var(--teal-deep);
  color: #f4faf8;
  font-weight: 600;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 720px) {
  .chart-wrap canvas {
    height: min(42dvh, 380px);
  }
}
