:root {
  --paper: #f7f5ef;
  --paper-shadow: #ebe6d9;
  --ink: #111111;
  --muted: #555555;
  --rule: #1f1f1f;
  --soft-rule: #c9c2b3;
  --success: #1f5b2b;
  --error: #8f1f1f;
  --info: #2d2d2d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Instrument Sans", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(0, 0, 0, 0.02)),
    var(--paper);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(17, 17, 17, 0.52);
}

.modal-card {
  position: relative;
  width: min(620px, 100%);
  max-height: min(92vh, 760px);
  padding: 22px 18px;
  background: var(--paper);
  border: 1px solid var(--rule);
  text-align: center;
  overflow-x: hidden;
  overflow-y: auto;
}

.modal-card.reward {
  animation: reward-pop 420ms cubic-bezier(0.18, 0.88, 0.32, 1.2);
  box-shadow: 0 18px 40px rgba(17, 17, 17, 0.16);
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 30;
}

.confetti-piece {
  position: absolute;
  top: -10vh;
  width: 10px;
  height: 18px;
  opacity: 0.9;
  animation: confetti-fall 1300ms ease-out forwards;
}

.modal-close {
  position: absolute;
  top: -4px;
  right: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
}

.modal-close-glyph {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  transform: none;
  pointer-events: none;
}

.modal-card h2 {
  margin: 0 0 22px;
  font-family: "Libre Baskerville", serif;
  font-size: 1.55rem;
}

.modal-card p {
  margin: 0;
  line-height: 1.6;
}

#results-year {
  margin-top: 6px;
}

#results-guess {
  margin-top: 14px;
}

#results-score {
  margin-top: 12px;
}

.results-stats-panel {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--soft-rule);
}

.results-stats-heading,
.results-chart-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.results-streak-grid {
  display: flex;
  gap: 22px;
  margin-top: 14px;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
}

.results-streak-item {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 14px;
}

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

.results-stat-value {
  font-family: "Libre Baskerville", serif;
  font-size: 1.55rem;
  line-height: 1.1;
}

.results-chart-panel {
  margin-top: 18px;
}

.results-chart-copy {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.results-score-chart {
  display: flex;
  align-items: end;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
  min-height: 220px;
  padding: 10px 8px 0;
  border-bottom: 1px solid var(--soft-rule);
}

.results-chart-label {
  margin-top: 8px;
  font-size: 0.84rem;
  color: var(--muted);
  text-align: center;
}

.results-chart-column {
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: center;
  gap: 8px;
  width: 52px;
}

.results-chart-bar-shell {
  display: flex;
  align-items: end;
  justify-content: center;
  width: 100%;
  height: 150px;
  padding: 0 3px;
}

.results-chart-bar {
  width: min(100%, 42px);
  min-height: 0;
  background: #8b8b8b;
}

.results-chart-value {
  font-weight: 700;
  color: #111111;
}

.results-chart-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.instruction-pages {
  position: relative;
  min-height: 410px;
  touch-action: pan-y;
}

.instruction-page {
  display: none;
  animation: fade-page 180ms ease;
}

.instruction-page.active {
  display: block;
}

.instruction-page p + p,
.instruction-page .legend-block + p,
.instruction-page p + .legend-block {
  margin-top: 18px;
}

.instruction-page-guide .legend-block {
  margin: 28px 0;
}

.instruction-page-guide .date-stack {
  margin-top: 14px;
}

.instruction-page-guide p:last-child {
  margin-top: 28px;
}

.instruction-page-direction p + .legend-block {
  margin-top: 26px;
}

.instruction-page-direction .flow-figure {
  margin-top: 28px;
  padding: 22px 16px;
}

.instruction-page-direction .flow-example {
  gap: 18px;
}

.direction-context-note {
  max-width: 360px;
  color: var(--muted);
  font-size: 0.82rem;
}

.instruction-headline-grid {
  display: grid;
  gap: 10px;
}

.date-legend {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 18px 0;
}

.legend-block {
  margin: 20px 0;
}

.flow-figure {
  margin-top: 22px;
  padding: 16px 14px;
  border: 1px solid var(--rule);
}

.legend-label {
  margin: 0 0 10px;
  font-size: 0.86rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.date-stack {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.date-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.date-chip.far {
  background: #d9d9d9;
}

.date-chip.close {
  background: #f0d976;
}

.date-chip.exact {
  background: #97b97c;
}

.flow-example {
  display: grid;
  gap: 12px;
  justify-items: center;
}

.example-headline {
  margin: 0;
  font-family: "Libre Baskerville", serif;
  font-size: 1.05rem;
  line-height: 1.45;
}

.flow-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.example-input {
  min-width: 232px;
  padding: 0 0 0 12px;
  border: 1px solid var(--rule);
  background: #ffffff;
  color: var(--muted);
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
}

.example-button,
.example-lede {
  opacity: 1;
}

.instruction-headline-grid .example-button {
  width: 100%;
  min-width: 0;
}

.example-input-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 100%;
  padding: 10px 12px;
  border-left: 1px solid var(--rule);
  background: var(--ink);
  color: #ffffff;
}

.example-input-calendar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 100%;
  padding: 10px 8px;
  background: #ffffff;
  color: var(--muted);
}

.modal-secondary {
  margin-top: 10px;
}

.instruction-footer {
  margin-top: 16px;
}

.instruction-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.instruction-dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: transparent;
}

.instruction-dot.active {
  background: var(--ink);
}

.instruction-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.page-shell {
  width: min(680px, calc(100% - 20px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.hero {
  text-align: center;
  padding-bottom: 18px;
}

.hero h1 {
  margin: 0;
  font-family: "Libre Baskerville", serif;
  font-weight: 700;
  font-size: clamp(2.6rem, 11vw, 5rem);
  line-height: 0.95;
}

.hero-copy {
  width: min(560px, 100%);
  margin: 10px auto 0;
  font-size: 1rem;
  line-height: 1.5;
}

.mode-switch {
  display: inline-flex;
  gap: 8px;
  margin-top: 18px;
  padding: 6px;
  border: 1px solid var(--soft-rule);
  background: #f5efe2;
  flex-wrap: wrap;
  justify-content: center;
}

.mode-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--rule);
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  transition: transform 120ms ease, filter 120ms ease;
}

.mode-link:hover {
  transform: translateY(-1px);
  filter: brightness(0.98);
}

.mode-link.active {
  background: var(--ink);
  color: #ffffff;
}

.game-shell {
  padding-top: 6px;
}

.status-panel {
  display: flex;
  justify-content: center;
  text-align: center;
  padding-bottom: 14px;
}

.status-inline {
  display: flex;
  align-items: end;
  gap: 14px;
}

.label {
  margin: 0 0 6px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.value {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.status-help {
  margin-bottom: 2px;
}

.message-banner {
  margin: 14px auto 0;
  max-width: 640px;
  padding: 0;
  text-align: center;
  font-weight: 600;
  min-height: 24px;
}

.message-banner.info {
  color: var(--info);
}

.message-banner.success {
  color: var(--success);
}

.message-banner.error {
  color: var(--error);
}

.clues-panel,
.guess-panel {
  max-width: 600px;
  margin: 24px auto 0;
  text-align: center;
}

.headline-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 24px;
}

.headline-item {
  padding: 0;
}

.headline-text {
  margin: 14px 0 0;
  font-family: "Libre Baskerville", serif;
  font-size: 1.72rem;
  line-height: 1.34;
  font-weight: 700;
  letter-spacing: -0.01em;
  min-height: 1.5em;
}

.headline-item:first-child .headline-text,
.headline-item.revealed .headline-text {
  font-size: 1.86rem;
}

.lede-text {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.65;
  min-height: 1.65em;
}

.typing::after {
  content: "";
  display: inline-block;
  width: 0.08em;
  height: 1em;
  margin-left: 0.08em;
  vertical-align: -0.08em;
  background: currentColor;
  animation: blink-caret 0.8s step-end infinite;
}

.lede-panel {
  margin-top: 16px;
}

.stage-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  align-items: stretch;
}

.stage-guess-form {
  display: flex;
  justify-content: center;
}

.hint-arrow {
  margin: 0;
  font-size: 0.94rem;
  color: var(--muted);
}

.hint-arrow-left::before,
.hint-arrow-right::before {
  display: inline-block;
  margin-right: 6px;
  color: var(--ink);
}

.hint-arrow-left::before {
  content: "◀";
}

.hint-arrow-right::before {
  content: "▶";
}

.guess-input-shell {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  width: min(340px, 100%);
  border: 1px solid var(--rule);
  background: #ffffff;
}

.guess-input-shell input[data-role="guess-input"] {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
}

.guess-input-shell input[data-role="guess-input"]::placeholder {
  color: var(--muted);
}

.guess-input-shell input[data-role="guess-input"]:focus {
  outline: none;
}

.guess-input-shell:focus-within {
  box-shadow: 0 0 0 1px var(--ink);
}

.guess-submit-button {
  min-width: 46px;
  padding: 10px 12px;
  border: 0;
  border-left: 1px solid var(--rule);
  background: var(--ink);
  color: #ffffff;
}

.guess-picker-button {
  min-width: 46px;
  padding: 10px 8px;
  border: 0;
  background: #ffffff;
  color: var(--muted);
}

.calendar-icon {
  position: relative;
  display: inline-block;
  width: 16px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.calendar-icon::before {
  content: "";
  position: absolute;
  top: 3px;
  left: -1.5px;
  right: -1.5px;
  border-top: 1.5px solid currentColor;
}

.calendar-icon::after {
  content: "";
  position: absolute;
  top: -3px;
  left: 3px;
  width: 2px;
  height: 4px;
  background: currentColor;
  box-shadow: 6px 0 0 currentColor;
}

.guess-picker-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ios-picker-overlay .guess-picker-button {
  pointer-events: none;
}

.ios-picker-overlay .guess-picker-input {
  top: 0;
  right: 46px;
  width: 46px;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  z-index: 1;
}

.stage-feedback {
  margin-top: 16px;
}

.date-feedback {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: flex-start;
}

.feedback-part {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.feedback-part-wheel {
  position: relative;
}

.feedback-wheel-context {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: rgba(17, 17, 17, 0.3);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.feedback-wheel-context-top {
  margin-bottom: 6px;
}

.feedback-wheel-context-bottom {
  margin-top: 6px;
}

.feedback-wheel-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  padding: 6px 10px;
  border: 1px solid rgba(17, 17, 17, 0.12);
  background: rgba(17, 17, 17, 0.04);
}

.feedback-wheel-chip-far {
  color: rgba(17, 17, 17, 0.32);
  background: rgba(17, 17, 17, 0.04);
}

.feedback-wheel-chip-close {
  color: rgba(17, 17, 17, 0.54);
  background: rgba(240, 217, 118, 0.28);
}

.feedback-wheel-chip-exact {
  color: rgba(17, 17, 17, 0.62);
  background: rgba(151, 185, 124, 0.3);
}

.feedback-arrow-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 84px;
  min-height: 28px;
}

.feedback-arrow-slot-top {
  margin-bottom:6px;
}

.feedback-arrow-slot-bottom {
  margin-top: 6px;
}

.feedback-arrow-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 84px;
  min-height: 22px;
}

.feedback-hint-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 20px;
  padding: 0 10px;
  color: rgba(17, 17, 17, 0.82);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
}

.feedback-hint-badge::before,
.feedback-hint-badge::after {
  content: "";
  position: absolute;
  height: 1px;
  background: rgba(17, 17, 17, 0.82);
}

.feedback-hint-earlier::before {
  width: calc(50% - 14px);
  top: -7px;
  left: 50%;
  transform: translateX(-100%) rotate(-12deg);
  transform-origin: right center;
}

.feedback-hint-earlier::after {
  width: calc(50% - 14px);
  top: -7px;
  left: 50%;
  transform: rotate(12deg);
  transform-origin: left center;
}

.feedback-hint-later::before {
  width: calc(50% - 16px);
  bottom: -3px;
  left: 50%;
  transform: translateX(-100%) rotate(12deg);
  transform-origin: right center;
}

.feedback-hint-later::after {
  width: calc(50% - 16px);
  bottom: -3px;
  left: 50%;
  transform: rotate(-12deg);
  transform-origin: left center;
}

.feedback-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  animation: reveal-chip 260ms ease;
}

.feedback-chip.far {
  background: #d9d9d9;
}

.feedback-chip.close {
  background: #f0d976;
}

.feedback-chip.exact {
  background: #97b97c;
}

button {
  border: 1px solid var(--rule);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(0.98);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.headline-button:disabled,
.example-button:disabled,
.example-final:disabled,
.example-lede:disabled {
  opacity: 1;
}

.primary-button,
.headline-button,
.lede-button {
  padding: 10px 14px;
}

.primary-button {
  background: var(--ink);
  color: #ffffff;
}

.headline-button {
  color: #111111;
  min-width: min(100%, 440px);
}

.lede-button {
  background: #ffffff;
  color: var(--ink);
  padding-top: 9px;
  padding-bottom: 9px;
}

#share-button {
  margin-top: 12px;
}

#results-share-button {
  display: block;
  margin: 26px auto 0;
}

.share-feedback {
  margin: 8px 0 0;
  color: var(--success);
  font-size: 0.88rem;
  line-height: 1.4;
}

.results-bonus-button {
  margin-top: 28px;
}

.bonus-copy {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.bonus-panel {
  margin-top: 26px;
}

.bonus-headline {
  margin: 0;
  font-family: "Libre Baskerville", serif;
  font-size: 1.22rem;
  line-height: 1.4;
}

.bonus-lede {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.6;
}

.site-footer {
  max-width: 600px;
  margin: 32px auto 0;
  padding-top: 20px;
  border-top: 1px solid var(--soft-rule);
  text-align: center;
}

.edition-link,
.footer-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.78rem;
}

.edition-link {
  margin-bottom: 10px;
}

.edition-link a {
  color: var(--ink);
}

.hidden {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .modal {
    align-items: flex-start;
    padding: 10px;
  }

  .modal-card {
    max-height: calc(100vh - 20px);
    padding: 16px 14px;
  }

  .modal-card h2 {
    margin-bottom: 16px;
    font-size: 1.34rem;
  }

  .results-streak-grid {
    gap: 14px 18px;
  }

  .results-score-chart {
    gap: 6px;
    min-height: 190px;
    padding-left: 0;
    padding-right: 0;
  }

  .results-chart-column {
    width: 44px;
  }

  .results-chart-bar-shell {
    height: 120px;
    padding: 0 2px;
  }

  .results-chart-label {
    font-size: 0.72rem;
  }

  .page-shell {
    width: min(100% - 20px, 760px);
    padding-top: 14px;
  }

  .mode-switch {
    display: flex;
  }

  .mode-link {
    flex: 1 1 180px;
  }

  .status-inline {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .headline-text {
    font-size: 1.42rem;
  }

  .headline-item:first-child .headline-text,
  .headline-item.revealed .headline-text {
    font-size: 1.56rem;
  }

  .primary-button,
  .headline-button,
  .lede-button,
  .guess-input-shell,
  .stage-guess-form {
    width: 100%;
  }

  .guess-submit-button {
    width: auto;
  }

  .instruction-pages {
    min-height: 0;
  }

  .instruction-page p + p,
  .instruction-page .legend-block + p,
  .instruction-page p + .legend-block {
    margin-top: 14px;
  }

  .legend-block {
    margin: 16px 0;
  }

  .flow-figure {
    padding: 14px 10px;
  }

  .instruction-page-direction .flow-figure {
    margin-top: 18px;
    padding: 16px 10px;
  }

  .instruction-page-direction .flow-example {
    gap: 14px;
  }

  .instruction-footer {
    margin-top: 14px;
  }

  .date-stack {
    gap: 6px;
  }

  .date-chip {
    min-width: 0;
    flex: 1 1 0;
    padding: 8px 4px;
    font-size: 0.72rem;
  }

  .feedback-arrow-slot {
    width: 100%;
  }

  .instruction-headline-grid {
    gap: 8px;
  }
}

@keyframes reveal-chip {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink-caret {
  0%,
  45% {
    opacity: 1;
  }

  50%,
  100% {
    opacity: 0;
  }
}

@keyframes fade-page {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes reward-pop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.95);
  }

  65% {
    opacity: 1;
    transform: translateY(-4px) scale(1.02);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0.95;
  }

  100% {
    transform: translate3d(var(--drift, 0), 115vh, 0) rotate(540deg);
    opacity: 0;
  }
}
