:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-strong: #eef2f6;
  --ink: #191b1f;
  --muted: #626a73;
  --line: #dfe5ec;
  --onepace: #e85d46;
  --other: #188f83;
  --gold: #e2b43d;
  --blue: #3a72b8;
  --danger: #b63f3f;
  --shadow: 0 14px 35px rgba(25, 27, 31, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(58, 114, 184, 0.12), transparent 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.icon-sprite {
  display: none;
}

.app-shell {
  width: min(100%, 680px);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 14px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px 16px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(25, 27, 31, 0.1);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-mark svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.topbar h1,
.tool-panel h2,
.route-hero h2,
.summary-band h2 {
  margin: 0;
  font-size: 1.22rem;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.screen {
  display: none;
}

.screen.is-active {
  display: grid;
  gap: 14px;
}

.summary-band,
.route-hero,
.tool-panel,
.source-note {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.summary-band {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 18px;
}

.summary-copy {
  min-width: 0;
}

.verdict {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.minute-wheel {
  display: grid;
  width: 112px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--onepace) 0deg, var(--onepace) var(--share-angle, 0deg), var(--other) var(--share-angle, 0deg), var(--other) 360deg);
  box-shadow: inset 0 0 0 1px rgba(25, 27, 31, 0.08);
}

.wheel-core {
  display: grid;
  width: 74px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  text-align: center;
}

.wheel-core span {
  font-size: 1.15rem;
  font-weight: 900;
}

.wheel-core small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.05rem;
  line-height: 1.1;
}

.pace-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 10px;
  align-items: stretch;
}

.pace-number,
.pace-facts p {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.pace-number {
  display: grid;
  align-content: center;
  min-height: 122px;
  padding: 14px;
}

.pace-number strong {
  font-size: 2rem;
  line-height: 1;
}

.pace-number span,
.pace-facts span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.pace-facts {
  display: grid;
  gap: 7px;
}

.pace-facts p {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
}

.pace-facts strong {
  font-size: 1rem;
}

.tool-panel {
  padding: 14px;
}

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

.comparison-bars {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.bar-label span {
  color: var(--muted);
  font-weight: 800;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.bar-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 180ms ease;
}

#onepace-bar {
  background: var(--onepace);
}

#other-bar {
  background: var(--other);
}

.soft-callout {
  margin: 13px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(226, 180, 61, 0.4);
  border-radius: var(--radius);
  background: rgba(226, 180, 61, 0.12);
  line-height: 1.35;
}

.week-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
  align-items: end;
  min-height: 132px;
}

.day-stack {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 7px;
  min-width: 0;
}

.day-bars {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 2px;
  height: 92px;
  padding: 6px 3px;
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.day-bars span {
  width: 45%;
  min-height: 3px;
  border-radius: 999px 999px 0 0;
}

.day-bars .one {
  background: var(--onepace);
}

.day-bars .other {
  background: var(--other);
}

.day-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list,
.series-list,
.arc-list {
  display: grid;
  gap: 9px;
}

.empty-state {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  line-height: 1.35;
}

.session-card,
.series-card,
.arc-card {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.session-main,
.series-main,
.arc-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.session-main div,
.series-main div,
.arc-main div {
  min-width: 0;
}

.session-title,
.series-title,
.arc-title {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 900;
}

.session-meta,
.series-meta,
.arc-meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.3;
}

.session-minutes,
.series-minutes {
  flex: 0 0 auto;
  font-weight: 900;
  text-align: right;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.tag.onepace {
  border-color: rgba(232, 93, 70, 0.35);
  background: rgba(232, 93, 70, 0.12);
  color: #9e3527;
}

.tag.other {
  border-color: rgba(24, 143, 131, 0.35);
  background: rgba(24, 143, 131, 0.12);
  color: #0f625a;
}

.tag.missing {
  border-color: rgba(182, 63, 63, 0.35);
  background: rgba(182, 63, 63, 0.1);
  color: #8d3030;
}

.tag.dub {
  border-color: rgba(58, 114, 184, 0.35);
  background: rgba(58, 114, 184, 0.1);
  color: #2b568a;
}

.stacked-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.field-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.duration-card {
  display: grid;
  gap: 10px;
  padding: 11px;
  border: 1px solid rgba(232, 93, 70, 0.25);
  border-radius: var(--radius);
  background: rgba(232, 93, 70, 0.07);
}

.duration-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.duration-card-head div {
  display: grid;
  gap: 3px;
}

.duration-card-head strong {
  font-size: 0.98rem;
}

.duration-card-head span,
.duration-mini-grid span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.duration-card-head > span {
  flex: 0 0 auto;
  color: #9e3527;
}

.duration-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.duration-mini-grid p {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.duration-mini-grid strong {
  font-size: 0.95rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 46px;
  padding: 0 12px;
}

textarea {
  min-height: 128px;
  padding: 11px 12px;
  line-height: 1.4;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(58, 114, 184, 0.18);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quick-row,
.data-actions,
.series-actions,
.arc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.ghost-button,
.danger-button,
.icon-button,
.chip-button,
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 850;
}

.primary-button {
  width: 100%;
  background: var(--ink);
  color: white;
}

.compact-primary {
  width: auto;
  padding: 0 12px;
}

.ghost-button,
.chip-button,
.segmented button {
  background: var(--surface-strong);
  color: var(--ink);
}

.danger-button {
  background: rgba(182, 63, 63, 0.1);
  color: var(--danger);
}

.icon-button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  background: var(--surface-strong);
  color: var(--ink);
}

.chip-button {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.9rem;
}

.primary-button svg,
.ghost-button svg,
.danger-button svg,
.icon-button svg,
.bottom-nav svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.route-hero {
  display: grid;
  grid-template-columns: 1fr 116px;
  gap: 12px;
  align-items: center;
  padding: 16px;
}

.route-hero p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.38;
}

.route-visual {
  width: 116px;
  height: auto;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-visual .route-sea {
  stroke: rgba(24, 143, 131, 0.55);
  stroke-width: 6;
}

.route-visual .route-line {
  stroke: var(--onepace);
  stroke-width: 5;
}

.route-visual circle {
  fill: var(--surface);
  stroke: var(--ink);
  stroke-width: 4;
}

.route-notes {
  display: grid;
  gap: 10px;
}

.route-notes div {
  display: grid;
  gap: 4px;
}

.route-notes span {
  color: var(--muted);
  line-height: 1.35;
}

.route-controls {
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.segmented button {
  min-height: 36px;
  border-radius: 6px;
}

.segmented button.is-selected {
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(25, 27, 31, 0.08);
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--onepace), var(--gold));
}

.arc-extra {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.34;
}

.episode-details {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.episode-details summary {
  min-height: 38px;
  padding: 9px 11px;
  color: var(--ink);
  font-weight: 850;
}

.episode-details div {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 0 11px 11px;
}

.episode-details span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.session-episode-details {
  background: var(--surface);
}

.session-episode-details span.is-watched {
  color: rgba(98, 106, 115, 0.48);
  text-decoration: line-through;
}

.source-note {
  padding: 12px 14px;
}

.source-note p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
}

.bottom-nav button {
  display: grid;
  gap: 3px;
  min-height: 54px;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}

.bottom-nav button.is-active {
  background: var(--surface-strong);
  color: var(--ink);
}

@media (max-width: 430px) {
  .app-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .summary-band {
    grid-template-columns: 1fr;
  }

  .minute-wheel {
    width: 98px;
    justify-self: start;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .pace-grid {
    grid-template-columns: 1fr;
  }

  .duration-mini-grid,
  .episode-details div {
    grid-template-columns: repeat(2, 1fr);
  }

  .route-hero {
    grid-template-columns: 1fr;
  }

  .route-visual {
    width: 100%;
    max-width: 190px;
  }
}
