:root {
  /* Warm paper and ink */
  --paper: #f5f1e8;
  --paper-2: #fffdf7;
  --paper-3: #ebe4d6;
  --track: #e7e0d1;
  --ink: #1c1a16;
  --ink-soft: #4d473c;
  --ink-deep: #0d0c09;
  --muted: #6b6252;
  --line: #e0d8c7;
  --line-2: #cabfa9;

  /* Printed inks: a deep music red and a single ochre spot colour */
  --accent: #b3271d;
  --accent-2: #8f1c14;
  --accent-soft: #f5e4df;
  --feature: #b0741a;

  /* Notes */
  --note-bg: #f7efd8;
  --note-line: #dcc074;
  --note-ink: #6d5312;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 4px;
  --shadow-pop: 0 8px 24px rgba(28, 26, 22, 0.14);
}

* {
  box-sizing: border-box;
}

/* Hidden always wins over layout classes. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  background: var(--paper);
}

body {
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  padding: 0 20px 72px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Masthead */
.hero {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 0 22px;
  border-top: 4px solid var(--ink);
  border-bottom: 1px solid var(--line);
  text-align: start;
}

.kicker {
  margin: 0 0 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 7vw, 4rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.02;
  color: var(--ink);
}

.hero .dot {
  color: var(--accent);
}

.tagline {
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
  max-width: 52ch;
  text-wrap: pretty;
}

main {
  max-width: 820px;
  margin: 28px auto 0;
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border: 1.5px dashed var(--line-2);
  border-radius: var(--radius);
  background: var(--paper-2);
  padding: 32px 28px;
  text-align: start;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone:focus-visible {
  border-color: var(--accent);
}

.dropzone.dragover {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-soft);
}

.dz-icon {
  display: inline-flex;
  color: var(--accent);
  margin-bottom: 10px;
}

.dz-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
}

.dz-sub {
  color: var(--muted);
  font-size: 0.95rem;
}

.dz-cta {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.privacy {
  width: 100%;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.status {
  color: var(--muted);
  min-height: 1.4em;
  margin: 14px 0 0;
  font-size: 0.9rem;
}

/* Controls */
.controls {
  margin-top: 28px;
  display: grid;
  gap: 16px;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

.control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.control > label {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

.control-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.control-hint {
  color: var(--muted);
  font-size: 0.78rem;
}

.control-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
}

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

.controls select,
.controls input[type='text'],
.controls input[type='date'],
.controls input[type='month'] {
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 8px 10px;
  font: inherit;
  font-size: 0.9rem;
}

.controls select:focus,
.controls input:focus {
  border-color: var(--accent);
}

.controls select.period {
  min-width: 260px;
}

.controls input[type='text'] {
  min-width: 210px;
}

.controls input[type='checkbox'] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.btn {
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 9px 16px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.btn:hover {
  background: var(--ink-deep);
  border-color: var(--ink-deep);
}

.btn:active {
  transform: scale(0.98);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 6px 12px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  min-height: 32px;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.btn-ghost:hover {
  color: var(--ink);
  border-color: var(--ink-soft);
}

.btn-ghost:active {
  transform: scale(0.98);
}

.btn-ghost[disabled] {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.control-mapping {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.mapping-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.mapping-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 0.86rem;
}

.mapping-list .mapping-empty {
  border-bottom: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 4px 0;
}

.mapping-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combo {
  position: relative;
  display: inline-block;
}

.combo-list {
  position: absolute;
  z-index: 20;
  inset-inline: 0;
  top: 100%;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  background: var(--paper-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}

.combo-item {
  padding: 8px 10px;
  border-radius: 3px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combo-item.active,
.combo-item:hover {
  background: var(--accent-soft);
  color: var(--accent-2);
}

/* Results */
.results {
  margin-top: 28px;
  display: grid;
  gap: 28px;
}

.warnings {
  background: var(--note-bg);
  border: 1px solid var(--note-line);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--note-ink);
  font-size: 0.88rem;
}

.warnings p {
  margin: 4px 0;
}

.range {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(124px, 1fr));
  gap: 1px;
  background: var(--line);
  border-block: 1px solid var(--line);
}

.stat {
  background: var(--paper);
  padding: 16px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--ink);
}

.stat-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  margin-bottom: -1px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.panel {
  display: grid;
  gap: 30px;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.82rem;
}

.pager-info {
  font-variant-numeric: tabular-nums;
}

.pager-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.page-input,
.num-input {
  width: 64px;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 6px 8px;
  font: inherit;
  font-size: 0.85rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.num-input {
  width: 72px;
}

.minutes-body > .control {
  margin-top: 16px;
}

.minutes-body > .control-hint {
  margin: 8px 0 0;
}

.card {
  border-top: 2px solid var(--ink);
  padding-top: 14px;
}

.card-title {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 18px;
  max-width: 64ch;
  text-wrap: pretty;
}

.rank {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rank-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.rank-row:first-child {
  border-top: 0;
}

.rank-n {
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.rank-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rank-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rank-name {
  font-weight: 600;
  font-size: 0.98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-sub {
  color: var(--muted);
  font-size: 0.78rem;
}

.rank-val {
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-2);
  border-radius: 3px;
  padding: 2px 7px;
  white-space: nowrap;
}

.bar {
  display: flex;
  height: 4px;
  background: var(--track);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  display: block;
  flex: 0 0 auto;
  height: 100%;
  background: var(--accent);
}

.bar-fill.feature {
  background: var(--feature);
}

.years {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  overflow-x: auto;
  padding-top: 10px;
}

.year-col {
  flex: 1 0 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.year-count {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.year-bar {
  width: 100%;
  height: 150px;
  display: flex;
  align-items: flex-end;
}

.year-fill {
  width: 100%;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  min-height: 3px;
}

.year-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.strip {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 150px;
}

.strip-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
}

.strip-bar {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: flex-end;
}

.strip-fill {
  width: 100%;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  min-height: 2px;
}

.strip-label {
  font-size: 0.75rem;
  color: var(--muted);
  height: 1em;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fact-value {
  font-family: var(--serif);
  font-size: 2.1rem;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
}

.fact-label {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.fact-sub {
  color: var(--muted);
  font-size: 0.78rem;
}

.pending {
  color: var(--muted);
  font-style: italic;
  margin: 0;
}

footer {
  max-width: 820px;
  margin: 56px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: start;
}

/* Results meta row */
.share-open {
  white-space: nowrap;
}

.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
}

/* Share dialog */
.share {
  width: min(940px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(28, 26, 22, 0.28);
}

.share[open] {
  display: flex;
  flex-direction: column;
}

.share::backdrop {
  background: rgba(28, 26, 22, 0.45);
}

.share-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}

.share-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
}

.share-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 28px;
  padding: 22px;
}

.share-preview {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.share-canvas {
  width: 100%;
  max-width: 320px;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(28, 26, 22, 0.18);
}

.share-options {
  display: grid;
  gap: 20px;
  align-content: start;
}

.share-field {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.share-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.share select {
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 9px 10px;
  font: inherit;
  font-size: 0.9rem;
  min-width: 240px;
}

.share select:focus {
  border-color: var(--accent);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg button {
  background: transparent;
  border: 0;
  border-inline-start: 1px solid var(--line-2);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.85rem;
  padding: 8px 13px;
  min-height: 40px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg button:first-child {
  border-inline-start: 0;
}

.seg button:hover {
  color: var(--ink);
}

.seg button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}

.seg button[aria-pressed='true']:hover {
  color: var(--paper);
}

.share-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
}

.share-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 760px) {
  .share-body {
    grid-template-columns: 1fr;
  }

  .share-canvas {
    max-width: 260px;
  }
}

@media (max-width: 639px) {
  /* iOS Safari zooms the viewport when a field is under 16px */
  .controls select,
  .controls input[type='text'],
  .controls input[type='date'],
  .controls input[type='month'],
  .page-input,
  .num-input,
  .share select {
    font-size: 1rem;
  }

  .share-field {
    width: 100%;
  }

  .seg {
    flex-wrap: wrap;
  }

  .share select {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 560px) {
  body {
    padding: 0 16px 56px;
  }

  .rank-row {
    grid-template-columns: 32px 1fr auto;
    gap: 10px;
  }

  .rank-n {
    font-size: 0.95rem;
  }

  .summary {
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  }
}

@media (pointer: coarse) {
  .btn-ghost {
    min-height: 44px;
  }

  .tab {
    padding: 12px 14px;
  }

  .seg button {
    min-height: 44px;
  }

  .combo-item {
    padding: 12px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
