:root {
  --bg: #0b1210;
  --bg-2: #121a17;
  --surface: rgba(24, 34, 30, 0.88);
  --surface-strong: #1a2521;
  --line: rgba(164, 196, 180, 0.14);
  --text: #e7f0ea;
  --muted: #8fa39a;
  --accent: #5fd4a4;
  --accent-dim: rgba(95, 212, 164, 0.16);
  --green: #49d18a;
  --amber: #e2b44c;
  --red: #e86b6b;
  --danger: #ff8f8f;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  --tap: 52px;
  --font-display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-body: "Manrope", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 55% at 15% -10%, rgba(95, 212, 164, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 8%, rgba(56, 120, 98, 0.22), transparent 50%),
    linear-gradient(180deg, #0e1714 0%, var(--bg) 42%, #0a100e 100%);
  z-index: 0;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

.app {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(36px, env(safe-area-inset-bottom));
}

.top {
  padding: 6px 2px 12px;
  animation: rise 520ms ease both;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 11vw, 3.4rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
}

.module-title {
  margin: 8px 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
  max-width: 28ch;
}

.races {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
  animation: rise 620ms ease both;
}

.race {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 2px;
  backdrop-filter: blur(10px);
}

.race-name {
  grid-column: 1;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}

.race-date {
  grid-column: 1;
  font-size: 0.78rem;
  color: var(--muted);
}

.race-days {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}

.race-unit {
  display: none;
}

.form-panel,
.result-panel,
.history-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 18px;
  margin-bottom: 16px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  animation: rise 700ms ease both;
}

.hidden {
  display: none !important;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.field.full {
  margin-bottom: 12px;
}

.field > span,
.slider-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.field em {
  font-style: normal;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.8;
}

.slider-label strong {
  font-family: var(--font-display);
  font-size: 1.45rem;
  color: var(--text);
  min-width: 1.4ch;
  text-align: right;
}

input[type="number"],
textarea {
  width: 100%;
  min-height: var(--tap);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 10, 0.55);
  padding: 12px 14px;
  font-size: 1.15rem;
  font-weight: 600;
  outline: none;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

textarea {
  min-height: 84px;
  resize: vertical;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.4;
}

input[type="number"]:focus,
textarea:focus {
  border-color: rgba(95, 212, 164, 0.55);
  background: rgba(8, 12, 10, 0.78);
}

input[type="range"] {
  width: 100%;
  height: 44px;
  appearance: none;
  background: transparent;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(95, 212, 164, 0.18), rgba(95, 212, 164, 0.55));
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(95, 212, 164, 0.18), rgba(95, 212, 164, 0.55));
}

input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--accent);
}

.range-ends {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: -4px;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  width: 100%;
  min-height: var(--tap);
  border-radius: 16px;
  border: 1px solid transparent;
  padding: 14px 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: transform 140ms ease, background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.primary-btn {
  background: var(--accent);
  color: #062118;
  font-size: 1.05rem;
  margin-top: 4px;
}

.primary-btn:active,
.secondary-btn:active,
.ghost-btn:active,
.chart-tab:active {
  transform: scale(0.985);
}

.secondary-btn {
  background: var(--accent-dim);
  border-color: rgba(95, 212, 164, 0.28);
  color: var(--accent);
}

.ghost-btn {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  margin-top: 12px;
}

.ghost-btn.danger {
  color: var(--danger);
  border-color: rgba(232, 107, 107, 0.28);
}

.result-panel {
  text-align: center;
  overflow: hidden;
}

.score-ring {
  --level: var(--green);
  width: 180px;
  height: 180px;
  margin: 4px auto 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(11, 18, 16, 0.92) 58%, transparent 59%),
    conic-gradient(var(--level) calc(var(--pct, 0) * 1%), rgba(255, 255, 255, 0.08) 0);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  animation: pop 480ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.score-ring[data-level="green"] { --level: var(--green); }
.score-ring[data-level="amber"] { --level: var(--amber); }
.score-ring[data-level="red"] { --level: var(--red); }

.score-inner {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: var(--surface-strong);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.score-label {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.score-value {
  font-family: var(--font-display);
  font-size: 4rem;
  font-weight: 800;
  line-height: 0.9;
}

.score-max {
  font-size: 0.85rem;
  color: var(--muted);
}

.traffic {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  background: rgba(8, 12, 10, 0.45);
  border: 1px solid var(--line);
  animation: rise 560ms ease both;
}

.traffic-light {
  width: 18px;
  height: 18px;
  margin-top: 4px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(73, 209, 138, 0.12);
  animation: pulse 1.8s ease-in-out infinite;
}

.traffic[data-level="amber"] .traffic-light {
  background: var(--amber);
  box-shadow: 0 0 0 6px rgba(226, 180, 76, 0.14);
}

.traffic[data-level="red"] .traffic-light {
  background: var(--red);
  box-shadow: 0 0 0 6px rgba(232, 107, 107, 0.14);
}

.traffic-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.traffic-copy {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sample-flag {
  margin: 0;
  font-size: 0.75rem;
  color: var(--amber);
  font-weight: 600;
}

.sample-flag.hidden {
  display: none;
}

.chart-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.chart-tab {
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 10, 0.35);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.chart-tab.active {
  background: var(--accent-dim);
  border-color: rgba(95, 212, 164, 0.35);
  color: var(--accent);
}

.chart-wrap {
  width: 100%;
  border-radius: 14px;
  background: rgba(8, 12, 10, 0.4);
  border: 1px solid var(--line);
  padding: 10px 8px 4px;
  margin-bottom: 14px;
}

#trend-chart {
  width: 100%;
  height: auto;
  display: block;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 12px;
  border-radius: 14px;
  background: rgba(8, 12, 10, 0.38);
  border: 1px solid transparent;
}

.history-item.today {
  border-color: rgba(95, 212, 164, 0.28);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
}

.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-date {
  font-weight: 700;
  font-size: 0.92rem;
}

.history-stats {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-score {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
}

.actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.footer {
  padding: 8px 4px 20px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
}

.footer p {
  margin: 0 0 4px;
}

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

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.85; }
}

@media (max-width: 360px) {
  .field-row {
    grid-template-columns: 1fr;
  }

  .race-days {
    font-size: 1.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
