/* =============================================================================
   Cambridge Bumps — stylesheet

   Direction: the chart is the hero and "follow your crew" is the signature
   interaction, so the chrome stays quiet. Deep river-ink chrome sits on a cool
   paper ground; titles are set in a heritage serif (the event is old), the rest
   in the system sans. Positions use tabular figures so the order reads like a
   results board. Mobile-first — it lives on a phone on the bank.
   ============================================================================= */

:root {
  --ink: #15333f;          /* river-ink: chrome, primary actions */
  --ink-soft: #1d4250;     /* hover for ink surfaces */
  --paper: #f2f3f1;        /* cool paper ground */
  --surface: #ffffff;      /* cards */
  --band: #f4f2ee;         /* matches the chart's division bands */
  --line: #e4e3dd;         /* hairline */
  --text: #1b1c1a;         /* body text */
  --muted: #6c6f69;        /* secondary text */
  --up: #2f7d4f;           /* places gained */
  --down: #c0492f;         /* places lost */
  --accent: #c1452f;       /* collision red: the followed crew */
  --accent-tint: #fbeeea;  /* followed-crew row background */
  --focus: rgba(21, 51, 63, 0.14);

  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
}

a { color: var(--ink); }

p { margin: 0 0 12px; }

/* --- Top bar (sticky, bleeds past the app gutter) -------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 -16px 16px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  color: #fff;
}

.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  color: #fff;
  text-decoration: none;
  font-size: 20px;
}
.topbar .link:hover { background: rgba(255, 255, 255, 0.12); }

.topbar .right {
  display: inline-flex;
  justify-content: flex-end;
  gap: 8px;
}

.topbar .btn {
  min-height: 36px;
  padding: 6px 13px;
  font-size: 13px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.22);
}
.topbar .btn:hover { background: rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.3); }

/* --- Cards & generic blocks ----------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
}

.pad { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

/* Sticky save bar in the editor — always reachable above the home indicator. */
.actions.sticky {
  position: sticky;
  bottom: 0;
  z-index: 9;
  margin: 16px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

/* --- Buttons --------------------------------------------------------------- */

.btn {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  min-height: 44px;
  padding: 11px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.btn:hover { border-color: #cdccc4; }

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn.primary:hover { background: var(--ink-soft); border-color: var(--ink-soft); }

.btn.danger { color: var(--down); }
.btn.danger:hover { border-color: var(--down); background: #fdf3f0; }

/* --- Home: event list ------------------------------------------------------ */

.eventrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}
.eventrow .grow {
  text-decoration: none;
  color: inherit;
}
.eventrow .btn {
  flex-shrink: 0;
  min-height: 38px;
  padding: 8px 12px;
  font-size: 13px;
}

.grow { flex: 1 1 auto; min-width: 0; }

.ev-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.eventrow .muted {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Viewer: summary, chart, crew list ------------------------------------ */

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
}
.summary > div { flex: 1 1 30%; min-width: 110px; }
.summary strong { font-family: var(--serif); font-size: 18px; font-weight: 600; }

.chart-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.chart-wrap svg { display: block; }

.crewlist { display: flex; flex-direction: column; }

.crewrow {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 10px;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background-color 0.12s ease;
}
.crewrow:last-child { border-bottom: none; }
.crewrow:hover { background: #faf9f7; }
.crewrow.selected {
  background: var(--accent-tint);
  border-left-color: var(--accent);
}
.crewrow .grow { font-weight: 500; }

.pos {
  flex-shrink: 0;
  min-width: 26px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
}

.startfin {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

/* Net movement markers */
.up, .down, .same {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.up { color: var(--up); }
.down { color: var(--down); }
.same { color: var(--muted); font-weight: 500; }

/* --- Editor: day selector -------------------------------------------------- */

.dayrow {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0 12px;
}

.daybtn {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  flex: 0 0 auto;
  position: relative;
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.daybtn:hover { border-color: #cdccc4; }
.daybtn.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* a filled-in day carries a small mark */
.daybtn.filled:not(.active)::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 9px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--up);
}

/* --- Editor: line-up rows & resulting order ------------------------------- */

.divhead {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.lurow {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
}
.lurow:last-child { border-bottom: none; }
.lurow .grow { font-weight: 500; }
.lurow.bumped { background: #f0f7f1; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink);
  background: var(--band);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--ink);
}

/* --- New-event form -------------------------------------------------------- */

.form label {
  display: block;
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.form input,
.form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming the field on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.form textarea {
  font-family: var(--sans);
  line-height: 1.5;
  resize: vertical;
}
.form input:focus,
.form textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--focus);
}

/* --- Manual-order textarea ------------------------------------------------- */

textarea.override {
  display: block;
  width: 100%;
  margin: 10px 0;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  resize: vertical;
}
textarea.override:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--focus);
}

/* --- Errors & flashes ------------------------------------------------------ */

.err { color: var(--down); }

.card.err {
  border-color: #e7b8ac;
  background: #fdf3f0;
  color: #7a2e1c;
}

.flash {
  margin: 0 0 14px;
  padding: 10px 14px;
  font-size: 14px;
  color: #1f5a37;
  background: #eef6f0;
  border: 1px solid #cfe6d6;
  border-radius: 10px;
}

/* --- Accessibility --------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.topbar .link:focus-visible,
.topbar .btn:focus-visible {
  outline-color: #fff;
}

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