:root {
  color-scheme: light;
  --ink: #171411;
  --ink-soft: #47423c;
  --muted: #6b747b;
  --paper: #f5f7f7;
  --paper-deep: #e9eef1;
  --surface: #ffffff;
  --border: #d4dde3;
  --border-strong: #9facb6;
  --red: #b53728;
  --red-dark: #7f221a;
  --red-soft: rgba(181, 55, 40, 0.08);
  --gold: #d99b2b;
  --green: #2f6b55;
  --blue: #2f5f86;
  --shadow-sm: 0 1px 2px rgba(23, 20, 17, 0.04), 0 2px 6px rgba(23, 20, 17, 0.05);
  --shadow-md: 0 8px 24px rgba(42, 34, 25, 0.08);
  --shadow-lg: 0 18px 44px rgba(42, 34, 25, 0.1);
  --radius: 10px;
  --radius-sm: 8px;
  --max: 1160px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 20% -10%, #ffffff 0%, transparent 60%),
    linear-gradient(180deg, #ffffff 0%, var(--paper) 44%, var(--paper-deep) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
}

/* ============================================================
   HEADER — sticky on every viewport, safe-area aware
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--header-h);
  padding: 0 16px;
  padding-top: var(--safe-top);
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  border-bottom: 1px solid rgba(212, 221, 227, 0.86);
  background: rgba(245, 247, 247, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
  letter-spacing: -0.01em;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #fff;
  background: var(--ink);
  border-radius: 50%;
  font-size: 14px;
  box-shadow: inset 0 -7px 14px rgba(255, 255, 255, 0.12);
}

main {
  overflow-x: clip;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ============================================================
   ARCHIVE — mobile-first
   ============================================================ */
.archive {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 28px 16px 56px;
}

.archive * {
  min-width: 0;
}

.archive-heading {
  display: grid;
  gap: 18px;
  margin-bottom: 20px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.eyeline {
  margin: 0 0 14px;
  color: var(--red);
  font-size: 10px;
  line-height: 1.3;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}

h1,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(40px, 11vw, 56px);
  line-height: 0.95;
  font-weight: 700;
  letter-spacing: -0.015em;
}

h1 span {
  display: block;
}

#result-summary {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.archive-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ============================================================
   BUTTONS — proper 44px touch targets
   ============================================================ */
.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.button-secondary {
  border-color: var(--ink);
  color: #fff;
  background: var(--ink);
}

.button-ghost {
  background: rgba(255, 255, 255, 0.6);
}

.button-ghost:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ============================================================
   CONTROLS — sticky on mobile so search is always reachable
   ============================================================ */
.controls {
  position: sticky;
  top: calc(var(--header-h) + var(--safe-top));
  z-index: 10;
  display: grid;
  gap: 10px;
  margin: 0 -4px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-md);
}

.search-field,
.select-field {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  font-weight: 700;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23171411' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}

input::placeholder {
  color: #97a1a8;
  font-weight: 600;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(47, 95, 134, 0.32);
  outline-offset: 2px;
}

.select-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ============================================================
   CHIPS — horizontal snap-scroll on mobile
   ============================================================ */
.chip-row {
  display: flex;
  gap: 8px;
  margin: 16px -16px 20px;
  padding: 4px 16px 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.chip:active {
  transform: scale(0.97);
}

.chip.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
  box-shadow: 0 6px 16px rgba(23, 20, 17, 0.16);
}

/* ============================================================
   PREDICTION CARDS — mobile-first
   ============================================================ */
.prediction-list {
  display: grid;
  gap: 12px;
}

.prediction-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(23, 20, 17, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.prediction-card:hover {
  box-shadow: var(--shadow-md);
}

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

.prediction-number {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--red);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
}

.category-tag {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.failed-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red-dark);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.failed-badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
}

.prediction-body {
  display: grid;
  gap: 14px;
}

.card-topline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.card-topline time {
  color: var(--ink-soft);
}

.tweet-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  color: var(--blue);
  text-decoration: none;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 800;
  -webkit-tap-highlight-color: transparent;
}

.tweet-link::after {
  content: "↗";
  font-size: 12px;
  transform: translateY(-0.5px);
}

.tweet-link:hover {
  text-decoration: underline;
}

.tweet-text {
  position: relative;
  margin: 0;
  padding: 14px 14px 14px 16px;
  border-left: 3px solid var(--red);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.32;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.detail-grid {
  display: grid;
  gap: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.detail-box {
  display: grid;
  gap: 6px;
}

.detail-box span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.detail-box p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.outcome-box span {
  color: var(--red-dark);
}

.outcome-box p {
  color: var(--ink);
  font-weight: 600;
}

.empty-state {
  padding: 36px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

/* ============================================================
   TABLET — 640px+
   ============================================================ */
@media (min-width: 640px) {
  .archive {
    padding: 36px 24px 72px;
  }

  .controls {
    grid-template-columns: 1fr 200px 180px;
    gap: 12px;
    align-items: end;
  }

  .select-row {
    display: contents;
  }

  .prediction-card {
    padding: 22px;
  }

  .tweet-text {
    font-size: 19px;
  }

  .detail-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0;
  }

  .detail-box {
    padding-right: 18px;
  }

  .detail-box + .detail-box {
    padding-right: 0;
    padding-left: 18px;
    border-left: 1px solid var(--border);
  }
}

/* ============================================================
   DESKTOP — 860px+
   ============================================================ */
@media (min-width: 860px) {
  :root {
    --header-h: 62px;
  }

  .site-header {
    padding: 0 clamp(18px, 4vw, 48px);
  }

  .archive {
    width: min(var(--max), calc(100% - 36px));
    min-height: calc(100vh - var(--header-h));
    padding: clamp(42px, 7vw, 88px) 0 88px;
  }

  .archive-heading {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 28px;
    margin-bottom: 28px;
    padding-bottom: 28px;
  }

  .eyeline {
    max-width: 620px;
    margin-bottom: 18px;
    font-size: 12px;
  }

  h1 {
    max-width: 920px;
    margin-bottom: 18px;
    font-size: clamp(60px, 7.2vw, 98px);
    line-height: 0.93;
  }

  h1 span {
    display: inline;
  }

  #result-summary {
    font-size: 15px;
  }

  .archive-actions {
    display: flex;
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 10px;
  }

  .controls {
    position: static;
    margin: 0;
    padding: 14px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
  }

  .chip-row {
    flex-wrap: wrap;
    margin: 18px 0 26px;
    padding: 0;
    overflow: visible;
    mask-image: none;
    -webkit-mask-image: none;
  }

  .chip {
    white-space: normal;
  }

  .prediction-list {
    gap: 14px;
  }

  .prediction-card {
    grid-template-columns: 88px minmax(0, 1fr);
    grid-template-areas:
      "index body";
    gap: 22px;
    padding: clamp(20px, 2.5vw, 28px);
  }

  .prediction-head {
    grid-area: index;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .prediction-number {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
    font-size: 23px;
  }

  .failed-badge {
    margin-left: 0;
  }

  .prediction-body {
    grid-area: body;
  }

  .card-topline {
    margin-bottom: 0;
  }

  .tweet-text {
    padding: 20px 20px 20px 24px;
    border-left-width: 4px;
    font-size: clamp(20px, 2.4vw, 28px);
    line-height: 1.22;
  }
}

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