Which lifestyle event is more likely to kill you?

Interactive quiz comparing everyday risks measured in micromorts — a one-in-a-million chance of death.
#| '!! shinylive warning !!': |
#|   shinylive does not work in self-contained HTML documents.
#|   Please set `embed-resources: false` in your metadata.
#| standalone: true
#| viewerHeight: 1200

library(shiny)
library(bslib)

# ---- Quiz data loaded from separate file (## file: directive) ----
# Data is pre-computed from micromort::quiz_pairs(difficulty = ..., seed = 42)
# 50 per difficulty tier (easy/medium/hard), 150 total
#
# WHY SEPARATE FILE: Shinylive's JS preloader cannot parse CSV embedded in
# R string literals (commas/quotes break the parser). The ## file: directive
# puts the CSV in a virtual file that R reads normally.
#
# PIPELINE TRACKED: vig_quiz_csv_check target verifies this data matches
# the canonical output of quiz_pairs().
#
# TO REGENERATE: Run `Rscript data-raw/generate_quiz_csv.R`
quiz_pool <- read.csv("quiz_pairs.csv", stringsAsFactors = FALSE)

# ---- format_activity_name helper ----
format_activity_name <- function(name) {
  formatted <- sub("\\s*\\(", "<br>(", name)
  HTML(formatted)
}

# ---- CSS ----
quiz_css <- "
  .quiz-title {
    white-space: nowrap;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
  }
  .quiz-btn {
    min-height: 180px;
    width: 100%;
    white-space: normal;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 12px;
    font-size: 1rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background-color: #2b3e50;
    color: #ffffff;
    transition: border-color 0.3s, background-color 0.1s;
    user-select: text;
    -webkit-user-select: text;
  }
  .quiz-btn:hover { border-color: #2c7be5; background-color: #1a2a3a; color: #ffffff; }
  .quiz-btn .activity-name { font-weight: 600; font-size: 1.1rem; line-height: 1.3; }
  .quiz-btn .badge { font-size: 0.75em; }
  .quiz-btn-correct {
    border: 3px solid #198754 !important;
    background-color: #d1e7dd !important;
    color: #0f5132 !important;
  }
  .quiz-btn-wrong {
    border: 3px solid #dc3545 !important;
    background-color: #f8d7da !important;
    color: #842029 !important;
  }
  .quiz-btn-neutral {
    border: 3px solid #6c757d !important;
    background-color: #e9ecef !important;
    color: #495057 !important;
  }
  .quiz-btn .help-icon { font-size: 0.8rem; color: #adb5bd; cursor: help; margin-left: 4px; }
  .quiz-btn .help-link { font-size: 0.7rem; color: #8bb9fe; text-decoration: none; }
  .quiz-btn .help-link:hover { text-decoration: underline; }
  .explanation-panel { background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 8px; padding: 12px 16px; font-size: 0.9rem; }
  .gap-3 { gap: 1rem; }
  #submit_btn:disabled { opacity: 0.6; cursor: not-allowed; }
  .option-btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
  .option-btn {
    padding: 8px 18px; border: 2px solid #dee2e6; border-radius: 8px;
    background-color: #2b3e50; color: #ffffff; font-size: 1rem;
    cursor: pointer; transition: border-color 0.3s, background-color 0.1s;
    text-align: center; min-width: 60px;
  }
  .option-btn:hover { border-color: #2c7be5; background-color: #1a2a3a; }
  .option-btn.selected { border-color: #2c7be5; background-color: #2c7be5; color: #fff; }
  .option-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
  .option-label { font-weight: 600; white-space: nowrap; min-width: 140px; }
  .detail-scroll { overflow-x: auto; width: 100%; }
  .detail-table { white-space: nowrap; width: auto; min-width: 100%; }
  .detail-table th, .detail-table td { padding: 6px 10px; }
"

# ---- Leaderboard JS ----
leaderboard_js <- "
var FORM_URL = 'https://docs.google.com/forms/d/e/1FAIpQLSc1HX5kPVO6G982zOxH2BLv1FWexiITPnbjfWMN3a1M9yDtvw/formResponse';
var SHEET_URL = 'https://docs.google.com/spreadsheets/d/17HLtIdV3r55dIh06cSaWT8kFXzNrkR-Fu2ZJkjszG8k/gviz/tq?tqx=out:json';
var scoreSubmitted = false;
function resetLeaderboard() {
  scoreSubmitted = false;
  var btn = document.getElementById('submit_btn');
  if (btn) { btn.disabled = false; btn.textContent = 'Submit Score'; btn.className = 'btn btn-warning btn-lg'; }
  var el = document.getElementById('percentile_text');
  if (el) el.textContent = '';
}
function submitScore(score, total, difficulty, nQuestions) {
  if (scoreSubmitted) return;
  var btn = document.getElementById('submit_btn');
  if (btn) {
    btn.disabled = true;
    btn.textContent = 'Submitting...';
    btn.className = 'btn btn-secondary btn-lg';
  }
  var data = new URLSearchParams();
  data.append('entry.335579146', score);
  data.append('entry.2122920576', total);
  data.append('entry.621716914', new Date().toISOString());
  data.append('entry.268026248', 'acute');
  data.append('entry.232879816', difficulty || '');
  data.append('entry.2010782223', nQuestions || '');
  fetch(FORM_URL, {method: 'POST', mode: 'no-cors', body: data}).then(function() {
    scoreSubmitted = true;
    if (btn) {
      btn.textContent = 'Submitted!';
      btn.className = 'btn btn-success btn-lg';
    }
    getPercentile(score, total, difficulty, nQuestions);
  }).catch(function() {
    scoreSubmitted = true;
    if (btn) {
      btn.textContent = 'Score saved locally';
      btn.className = 'btn btn-info btn-lg';
    }
  });
}
var STATS_URL = 'https://johngavin.github.io/micromort/api/quiz_stats.json';
function interpolatePercentile(scorePct, group) {
  var p = group.percentiles;
  var s = group.scores_pct;
  for (var i = s.length - 1; i >= 0; i--) {
    if (scorePct >= s[i]) return p[i];
  }
  return 0;
}
function getPercentile(score, total, difficulty, nQuestions) {
  var pct = score / total * 100;
  fetch(STATS_URL).then(function(r) {
    if (!r.ok) throw new Error('stats unavailable');
    return r.json();
  }).then(function(stats) {
    var data = stats.acute;
    var overallPct = interpolatePercentile(pct, data.overall);
    var msg = 'You scored better than ' + overallPct + '% of all players';
    var configKey = (difficulty || 'mixed') + '_' + (nQuestions || 10);
    var sub = data.by_config[configKey];
    if (sub && sub.n >= 10) {
      var subPct = interpolatePercentile(pct, sub);
      msg += ' (' + subPct + '% of ' + difficulty + '/' + nQuestions + 'Q players)';
    }
    msg += '! (' + data.overall.n + ' submissions)';
    var el = document.getElementById('percentile_text');
    if (el) el.textContent = msg;
  }).catch(function(err) {
    console.log('Stats JSON fetch failed:', err, '— trying live Sheet');
    getPercentileLive(score, total);
  });
}
function getPercentileLive(score, total) {
  var el = document.getElementById('percentile_text');
  if (el) el.textContent = 'Loading rankings...';
  fetch(SHEET_URL).then(function(r) { return r.text(); }).then(function(text) {
    var json = JSON.parse(text.replace(/.*google.visualization.Query.setResponse\\(/, '').replace(/\\);$/, ''));
    var rows = json.table.rows;
    var pct = score / total * 100;
    var below = 0;
    for (var i = 0; i < rows.length; i++) {
      var s = rows[i].c[0] ? rows[i].c[0].v : 0;
      var t = rows[i].c[1] ? rows[i].c[1].v : 10;
      if ((s / t * 100) < pct) below++;
    }
    var percentile = rows.length > 0 ? Math.round(below / rows.length * 100) : 50;
    if (el) el.textContent = 'You scored better than ' + percentile + '% of players! (' + rows.length + ' submissions)';
  }).catch(function(err2) {
    console.log('Live Sheet fetch also failed:', err2);
    if (el) el.textContent = 'Score submitted! Rankings unavailable right now.';
  });
}
"

# ---- Fun result phrases ----
quiz_result_phrase <- function(pct) {
  phrases <- list(
    list(min = 95, phrase = "Actuarial genius!",
         fact = "Actuaries quantify risk for a living.",
         link = "https://en.wikipedia.org/wiki/Actuary"),
    list(min = 90, phrase = "You think in micromorts!",
         fact = "A micromort is a one-in-a-million chance of death.",
         link = "https://en.wikipedia.org/wiki/Micromort"),
    list(min = 80, phrase = "Sharp intuition!",
         fact = "Humans tend to overestimate dramatic risks and underestimate common ones.",
         link = "https://en.wikipedia.org/wiki/Risk_perception"),
    list(min = 70, phrase = "Better than a coin toss!",
         fact = "We judge risk by how easily examples come to mind.",
         link = "https://en.wikipedia.org/wiki/Availability_heuristic"),
    list(min = 60, phrase = "Getting there!",
         fact = "Losses loom larger than gains in our risk calculus.",
         link = "https://en.wikipedia.org/wiki/Prospect_theory"),
    list(min = 50, phrase = "About average!",
         fact = "Ignoring base rates is one of the most common reasoning errors.",
         link = "https://en.wikipedia.org/wiki/Base_rate_fallacy"),
    list(min = 30, phrase = "Surprises everywhere!",
         fact = "We tend to assume things will keep going as normal.",
         link = "https://en.wikipedia.org/wiki/Normalcy_bias"),
    list(min = -1, phrase = "Toss a coin \u2014 less risky!",
         fact = "Past outcomes don\'t change future probabilities.",
         link = "https://en.wikipedia.org/wiki/Gambler%27s_fallacy")
  )
  for (p in phrases) {
    if (pct >= p$min) return(p)
  }
  phrases[[length(phrases)]]
}

# ---- Encouragement lines ----
quiz_encouragement_lines <- function() {
  c(
    "Go on, your inner actuary is dying to play. (Not literally.)",
    "Warning: may cause sudden urge to recalculate your commute.",
    "Spoiler: everything is riskier than you think.",
    "No micromorts were harmed in the making of this quiz.",
    "Side effects may include newfound respect for seatbelts.",
    "Think you know risk? Prove it.",
    "Your overconfidence is showing. Let\'s test it.",
    "Statistically, you\'ll enjoy this. Probably."
  )
}

# quiz_title_ui removed — title already in page header

# ---- Instructions page ----
instructions_ui <- function() {
  encouragement <- sample(quiz_encouragement_lines(), 1L)

  tagList(
    card(
      card_body(
        tags$ul(class = "mb-1",
          tags$li("Each question shows ", tags$b(tags$em("two risky activities")), "."),
          tags$li("Tap the activity that you think is ", tags$b(tags$em("riskier")), "."),
          tags$li("You can ", tags$b(tags$em("skip")), " questions or go ",
                   tags$b(tags$em("back")), " and review previous answers."),
          tags$li("Skipped (unanswered) questions score zero."),
          tags$li("A ", tags$b(tags$em("micromort (mm)")), " is a one-in-a-million chance of death.")
        ),
        div(class = "mb-1", style = "padding-left: 1.5em;", tags$em(encouragement)),
        div(class = "option-row",
          span(class = "option-label", "Difficulty:"),
          div(class = "option-btn-group", id = "grp_diff",
            actionButton("diff_easy", "Easy", class = "option-btn",
              onclick = "selectInGroup('grp_diff', this)"),
            actionButton("diff_medium", "Medium", class = "option-btn",
              onclick = "selectInGroup('grp_diff', this)"),
            actionButton("diff_hard", "Hard", class = "option-btn",
              onclick = "selectInGroup('grp_diff', this)"),
            actionButton("diff_mixed", "Mixed", class = "option-btn selected",
              onclick = "selectInGroup('grp_diff', this)"))
        ),
        div(class = "option-row",
          span(class = "option-label", "Questions:"),
          div(class = "option-btn-group", id = "grp_nq",
            actionButton("nq_5", "5", class = "option-btn selected",
              onclick = "selectInGroup('grp_nq', this)"),
            actionButton("nq_10", "10", class = "option-btn",
              onclick = "selectInGroup('grp_nq', this)"))
        ),
        div(class = "text-center mt-3",
            actionButton("start_quiz", "Start Quiz", class = "btn-primary btn-lg"))
      )
    )
  )
}

# ---- Question page ----
question_ui <- function(state) {
  q <- state$current_q
  n <- state$n_questions
  pair <- state$pairs[q, ]
  ord <- state$display_order[[q]]
  revealed <- state$revealed[q]
  answer <- state$answers[q]
  correct_answer <- pair$answer

  left_side <- ord[1]
  right_side <- ord[2]

  left_activity <- pair[[paste0("activity_", left_side)]]
  left_category <- pair[[paste0("category_", left_side)]]
  left_mm <- pair[[paste0("micromorts_", left_side)]]
  left_period <- pair[[paste0("period_", left_side)]]
  left_desc <- pair[[paste0("description_", left_side)]]
  left_help <- pair[[paste0("help_url_", left_side)]]

  right_activity <- pair[[paste0("activity_", right_side)]]
  right_category <- pair[[paste0("category_", right_side)]]
  right_mm <- pair[[paste0("micromorts_", right_side)]]
  right_period <- pair[[paste0("period_", right_side)]]
  right_desc <- pair[[paste0("description_", right_side)]]
  right_help <- pair[[paste0("help_url_", right_side)]]

  left_class <- "btn quiz-btn"
  right_class <- "btn quiz-btn"
  left_extra <- ""
  right_extra <- ""

  if (revealed) {
    is_left_riskier <- left_mm > right_mm
    is_right_riskier <- right_mm > left_mm
    if (!is.na(answer)) {
      chose_left <- answer == left_side
      chose_right <- answer == right_side
    } else {
      chose_left <- FALSE
      chose_right <- FALSE
    }
    if (is_left_riskier) {
      left_class <- paste(left_class, "quiz-btn-correct")
      right_class <- paste(right_class, if (chose_right) "quiz-btn-wrong" else "quiz-btn-neutral")
    } else if (is_right_riskier) {
      right_class <- paste(right_class, "quiz-btn-correct")
      left_class <- paste(left_class, if (chose_left) "quiz-btn-wrong" else "quiz-btn-neutral")
    } else {
      left_class <- paste(left_class, "quiz-btn-correct")
      right_class <- paste(right_class, "quiz-btn-correct")
    }
    left_extra <- sprintf("%.2f mm", left_mm)
    right_extra <- sprintf("%.2f mm", right_mm)
  }

  make_btn_content <- function(activity, category, period, mm_text,
                               description = NULL, help_url = NULL) {
    name_el <- span(class = "activity-name", format_activity_name(activity))
    if (!is.null(description) && nzchar(description)) {
      name_el <- tagList(name_el,
        tooltip(span(class = "help-icon", "\u24d8"), description))
    }
    parts <- list(name_el,
      div(span(class = "badge bg-secondary me-1", category),
          span(class = "badge bg-info", period)))
    if (nzchar(mm_text)) {
      parts <- c(parts, list(strong(mm_text, style = "font-size: 1.2rem; color: #333;")))
    }
    if (!is.null(help_url) && nzchar(help_url)) {
      parts <- c(parts, list(tags$a(class = "help-link", href = help_url,
        target = "_blank", onclick = "event.stopPropagation();", "Learn more \u2192")))
    }
    parts
  }

  result_text <- NULL
  explanation_panel <- NULL
  if (revealed) {
    user_correct <- !is.na(answer) && answer == correct_answer
    result_text <- if (user_correct) {
      div(class = "alert alert-success text-center mt-2 py-2", strong("Correct!"))
    } else {
      riskier <- pair[[paste0("activity_", correct_answer)]]
      div(class = "alert alert-danger text-center mt-2 py-2",
          if (is.na(answer)) "Skipped! " else tagList(strong("Incorrect! ")),
          sprintf("%s is riskier.", riskier))
    }

    ratio_text <- sprintf("%.1f", pair$ratio)
    riskier_side <- pair$answer
    safer_side <- if (riskier_side == "a") "b" else "a"
    hedge_a <- pair$hedgeable_pct_a
    hedge_b <- pair$hedgeable_pct_b

    explanation_panel <- card(
      class = "explanation-panel mt-2",
      card_body(
        tags$p(strong(pair[[paste0("activity_", riskier_side)]]),
               sprintf(" has %.2f mm: ", pair[[paste0("micromorts_", riskier_side)]]),
               pair[[paste0("description_", riskier_side)]]),
        tags$p(strong(pair[[paste0("activity_", safer_side)]]),
               sprintf(" has %.2f mm: ", pair[[paste0("micromorts_", safer_side)]]),
               pair[[paste0("description_", safer_side)]]),
        tags$p(sprintf("%s is %sx riskier than %s.",
               pair[[paste0("activity_", riskier_side)]], ratio_text,
               pair[[paste0("activity_", safer_side)]])),
        if (hedge_a > 0 || hedge_b > 0) {
          hedgeable_parts <- character(0)
          if (hedge_a > 0) hedgeable_parts <- c(hedgeable_parts,
            sprintf("%s is %.0f%% hedgeable", pair$activity_a, hedge_a))
          if (hedge_b > 0) hedgeable_parts <- c(hedgeable_parts,
            sprintf("%s is %.0f%% hedgeable", pair$activity_b, hedge_b))
          tags$p(tags$em(paste(hedgeable_parts, collapse = "; "),
                         " \u2014 you can reduce this risk!"))
        }
      )
    )
  }

  # Global score: count ALL answered questions, not just up to current
  all_qs <- seq_len(n)
  answered_so_far <- sum(!is.na(state$answers[all_qs]) & state$revealed[all_qs])
  correct_so_far <- sum(vapply(all_qs, function(i) {
    !is.na(state$answers[i]) && state$answers[i] == state$pairs$answer[i]
  }, logical(1)))
  tally_text <- sprintf("Score: %d/%d correct", correct_so_far, answered_so_far)

  nav_ui <- div(
    class = "d-flex justify-content-between align-items-center mb-3",
    actionButton("prev_q", "\u2190 Back", class = "btn-secondary"),
    span(class = "text-muted",
      if ("difficulty" %in% names(pair) && !is.na(pair$difficulty)) {
        diff_colors <- c(easy = "success", medium = "warning", hard = "danger")
        span(class = paste0("badge bg-", diff_colors[pair$difficulty], " me-2"),
             pair$difficulty)
      },
      sprintf("%d of %d", q, n),
      " \u00b7 ", tags$small(tally_text)),
    actionButton("next_q", if (q == n) "Finish" else "Next \u2192", class = "btn-primary")
  )

  tagList(
    nav_ui,
    div(class = "row align-items-center",
      div(class = "col-5",
        if (!revealed) {
          actionButton("choose_left",
            tagList(make_btn_content(left_activity, left_category, left_period,
                                     left_extra, left_desc, left_help)),
            class = left_class)
        } else {
          div(class = left_class,
              make_btn_content(left_activity, left_category, left_period,
                               left_extra, left_desc, left_help))
        }),
      div(class = "col-2 text-center", h3("VS", class = "text-muted mb-0")),
      div(class = "col-5",
        if (!revealed) {
          actionButton("choose_right",
            tagList(make_btn_content(right_activity, right_category, right_period,
                                     right_extra, right_desc, right_help)),
            class = right_class)
        } else {
          div(class = right_class,
              make_btn_content(right_activity, right_category, right_period,
                               right_extra, right_desc, right_help))
        })
    ),
    result_text,
    explanation_panel
  )
}

# ---- Results summary page ----
results_summary_ui <- function(state) {
  pairs <- state$pairs
  answers <- state$answers
  n <- state$n_questions

  correct <- vapply(seq_len(n), function(i) {
    !is.na(answers[i]) && answers[i] == pairs$answer[i]
  }, logical(1))
  score <- sum(correct)
  pct <- score / n * 100
  baseline <- n / 2

  result_info <- quiz_result_phrase(pct)

  tagList(
    h2("Results", class = "text-center mb-4"),
    div(class = "row mb-4",
      div(class = "col-6",
        div(class = "card text-white bg-primary mb-3",
          div(class = "card-body text-center",
            tags$small("Your Score"), h2(sprintf("%d / %d", score, n), class = "mb-0")))),
      div(class = "col-6",
        div(class = "card text-white bg-secondary mb-3",
          div(class = "card-body text-center",
            tags$small("Random Guessing"), h2(sprintf("~%.1f / %d", baseline, n), class = "mb-0"))))
    ),
    div(class = "text-center mb-4",
      h3(result_info$phrase),
      tags$em(result_info$fact), br(),
      tags$a(href = result_info$link, target = "_blank", "Learn more \u2192")),
    div(class = "d-flex justify-content-center gap-3",
      tags$button(id = "submit_btn", class = "btn btn-warning btn-lg",
        onclick = sprintf("submitScore(%d, %d, '%s', %d)", score, n,
                          state$sel_difficulty, state$sel_nq), "Submit Score"),
      tags$button(id = "share_btn", class = "btn btn-success btn-lg",
        onclick = sprintf(paste0(
          "var pEl=document.getElementById('percentile_text');",
          "var pLine=pEl&&pEl.textContent?'\\n'+pEl.textContent+'\\n':'\\n';",
          "var text='\\u2620\\ufe0f Micromort Quiz: I scored %d/%d!'+pLine+",
          "'Which lifestyle event is more likely to kill you?\\n",
          "Can you beat my score? \\u2620\\ufe0f\\n",
          "https://johngavin.github.io/micromort/articles/quiz_shinylive.html';",
          "navigator.clipboard.writeText(text).then(function(){",
          "var btn=document.getElementById('share_btn');",
          "btn.textContent='Copied!';",
          "setTimeout(function(){btn.textContent='Share';},2000);",
          "});"), score, n),
        "Share"),
      actionButton("view_details", "View Details", class = "btn-outline-primary btn-lg"),
      actionButton("try_again", "Try Again", class = "btn-primary btn-lg",
        onclick = "resetLeaderboard()")
    ),
    div(class = "text-center mt-2",
      tags$small(id = "percentile_text", class = "text-muted"),
      tags$br(),
      tags$small(class = "text-muted",
                 "Scores are recorded anonymously (score, total, timestamp only)."))
  )
}

# ---- Results detail page ----
results_detail_ui <- function(state) {
  pairs <- state$pairs
  answers <- state$answers
  n <- state$n_questions

  detail_rows <- lapply(seq_len(n), function(i) {
    user_ans <- if (is.na(answers[i])) "Skipped"
                else if (answers[i] == "a") pairs$activity_a[i] else pairs$activity_b[i]
    correct_ans <- if (pairs$answer[i] == "a") pairs$activity_a[i] else pairs$activity_b[i]
    result <- if (is.na(answers[i])) "\u2014"
              else if (answers[i] == pairs$answer[i]) "\u2713" else "\u2717"
    link_a <- if (!is.na(pairs$help_url_a[i]) && nzchar(pairs$help_url_a[i]))
      tags$a(href = pairs$help_url_a[i], target = "_blank", pairs$activity_a[i])
    else pairs$activity_a[i]
    link_b <- if (!is.na(pairs$help_url_b[i]) && nzchar(pairs$help_url_b[i]))
      tags$a(href = pairs$help_url_b[i], target = "_blank", pairs$activity_b[i])
    else pairs$activity_b[i]
    tags$tr(tags$td(i), tags$td(link_a),
            tags$td(sprintf("%.2f", pairs$micromorts_a[i])),
            tags$td(link_b),
            tags$td(sprintf("%.2f", pairs$micromorts_b[i])),
            tags$td(user_ans), tags$td(correct_ans), tags$td(result))
  })

  tagList(
    div(class = "d-flex justify-content-between align-items-center mb-4",
      actionButton("back_to_summary", "\u2190 Back to Results", class = "btn-secondary"),
      h3("Your quiz details", class = "mb-0"),
      actionButton("try_again_detail", "Try Again", class = "btn-primary",
        onclick = "resetLeaderboard()")),
    div(class = "detail-scroll",
      tags$table(class = "table table-striped table-hover detail-table",
        tags$thead(tags$tr(tags$th("Q"), tags$th("Activity A"), tags$th("mm A"),
                           tags$th("Activity B"), tags$th("mm B"),
                           tags$th("Your Answer"), tags$th("Correct"), tags$th("Result"))),
        tags$tbody(detail_rows)))
  )
}

# ---- App ----
ui <- page_fluid(
  theme = bs_theme(bootswatch = "flatly", version = 5),
  tags$head(
    tags$style(HTML(quiz_css)),
    tags$script(HTML(leaderboard_js)),
    tags$script(HTML("
      function selectInGroup(groupId, clicked) {
        var grp = document.getElementById(groupId);
        if (!grp) return;
        var btns = grp.querySelectorAll('.option-btn');
        for (var i = 0; i < btns.length; i++) {
          btns[i].classList.remove('selected');
        }
        clicked.classList.add('selected');
      }
    "))
  ),
  div(class = "container-fluid",
      style = "max-width: 100%; padding: 20px;",
      uiOutput("main_ui"))
)

server <- function(input, output, session) {
  state <- reactiveValues(
    phase = "instructions", n_questions = 5L, current_q = 1L,
    pairs = NULL, answers = NULL, display_order = NULL, revealed = NULL,
    sel_difficulty = "mixed", sel_nq = 5L,
    seen_pairs = character())

  # Difficulty button handlers
  observeEvent(input$diff_easy, { state$sel_difficulty <- "easy" })
  observeEvent(input$diff_medium, { state$sel_difficulty <- "medium" })
  observeEvent(input$diff_hard, { state$sel_difficulty <- "hard" })
  observeEvent(input$diff_mixed, { state$sel_difficulty <- "mixed" })
  # N questions button handlers
  observeEvent(input$nq_5, { state$sel_nq <- 5L })
  observeEvent(input$nq_10, { state$sel_nq <- 10L })

  observeEvent(input$start_quiz, {
    n <- state$sel_nq
    diff <- state$sel_difficulty
    pool <- if (!is.null(diff) && diff != "mixed") {
      quiz_pool[quiz_pool$difficulty == diff, ]
    } else {
      quiz_pool
    }
    # Exclude pairs seen in previous rounds
    pair_keys <- paste(pmin(pool$activity_a, pool$activity_b),
                       pmax(pool$activity_a, pool$activity_b), sep = "|||")
    unseen <- !(pair_keys %in% state$seen_pairs)
    if (sum(unseen) >= n) {
      pool <- pool[unseen, ]
    }
    # If not enough unseen pairs, reset history
    if (nrow(pool) < n) {
      state$seen_pairs <- character()
      pool <- if (!is.null(diff) && diff != "mixed") {
        quiz_pool[quiz_pool$difficulty == diff, ]
      } else {
        quiz_pool
      }
    }
    n <- min(n, nrow(pool))
    state$n_questions <- n
    selected <- pool[sample(nrow(pool), n), ]
    # Record these pairs as seen
    new_keys <- paste(pmin(selected$activity_a, selected$activity_b),
                      pmax(selected$activity_a, selected$activity_b), sep = "|||")
    state$seen_pairs <- c(state$seen_pairs, new_keys)
    state$pairs <- selected
    state$answers <- rep(NA_character_, n)
    state$display_order <- lapply(seq_len(n), function(i) sample(c("a", "b")))
    state$revealed <- rep(FALSE, n)
    state$current_q <- 1L
    state$phase <- "question"
  })

  observeEvent(input$choose_left, {
    q <- state$current_q
    state$answers[q] <- state$display_order[[q]][1]
    state$revealed[q] <- TRUE
  })
  observeEvent(input$choose_right, {
    q <- state$current_q
    state$answers[q] <- state$display_order[[q]][2]
    state$revealed[q] <- TRUE
  })
  observeEvent(input$next_q, {
    if (state$current_q < state$n_questions) state$current_q <- state$current_q + 1L
    else state$phase <- "results_summary"
  })
  observeEvent(input$prev_q, {
    if (state$current_q > 1L) state$current_q <- state$current_q - 1L
    else state$phase <- "instructions"
  })
  observeEvent(input$view_details, { state$phase <- "results_detail" })
  observeEvent(input$back_to_summary, { state$phase <- "results_summary" })
  observeEvent(input$try_again, { state$phase <- "instructions" })
  observeEvent(input$try_again_detail, { state$phase <- "instructions" })

  output$main_ui <- renderUI({
    switch(state$phase,
      instructions = instructions_ui(),
      question = question_ui(state),
      results_summary = results_summary_ui(state),
      results_detail = results_detail_ui(state))
  })
}

shinyApp(ui, server)

## file: quiz_pairs.csv
## type: text
"activity_b","activity_a","micromorts_a","category_a","hedgeable_pct_a","period_a","micromorts_b","category_b","hedgeable_pct_b","period_b","ratio","difficulty","answer","description_a","help_url_a","description_b","help_url_b"
"Airline pilot (annual radiation)","COVID-19 unvaccinated (age 18-49)",1,"COVID-19",0,"11 weeks (2022)",0.15,"Occupation",100,"per year",6.66666666666667,"easy","a","Young adult unvaccinated COVID-19 mortality was low but non-negligible.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Cumulative cosmic radiation exposure from ~700 flight hours per year at altitude.","https://en.wikipedia.org/wiki/Airline_pilot"
"Airline pilot (annual radiation)","Living 2 months with a smoker",1,"Environment",0,"per 2 months",0.15,"Occupation",100,"per year",6.66666666666667,"easy","a","Secondhand smoke exposure increases cardiovascular and respiratory disease risk.","https://en.wikipedia.org/wiki/Passive_smoking","Cumulative cosmic radiation exposure from ~700 flight hours per year at altitude.","https://en.wikipedia.org/wiki/Airline_pilot"
"Airline pilot (annual radiation)","Walking (20 miles)",1,"Travel",0,"per trip",0.15,"Occupation",100,"per year",6.66666666666667,"easy","a","Pedestrian fatality risk from traffic collisions over a 20-mile walk.","https://en.wikipedia.org/wiki/Pedestrian","Cumulative cosmic radiation exposure from ~700 flight hours per year at altitude.","https://en.wikipedia.org/wiki/Airline_pilot"
"All US workers baseline (per work day)","Walking (20 miles)",1,"Travel",0,"per trip",0.15,"Occupation",0,"per day",6.66666666666667,"easy","a","Pedestrian fatality risk from traffic collisions over a 20-mile walk.","https://en.wikipedia.org/wiki/Pedestrian","Average occupational fatality rate across all US industries; baseline for comparison.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"All US workers baseline (per work day)","Train (1000 miles)",1,"Travel",0,"per trip",0.15,"Occupation",0,"per day",6.66666666666667,"easy","a","Rail travel is one of the safest transport modes per mile.","https://en.wikipedia.org/wiki/Rail_transport","Average occupational fatality rate across all US industries; baseline for comparison.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"All US workers baseline (per work day)","Driving (230 miles)",1,"Travel",0,"per trip",0.15,"Occupation",0,"per day",6.66666666666667,"easy","a","Traffic fatality risk for a typical 230-mile car journey.","https://en.wikipedia.org/wiki/Traffic_collision","Average occupational fatality rate across all US industries; baseline for comparison.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Barium enema (radiation per scan)","American football",20,"Sport",0,"per game",3,"Medical",0,"per event",6.66666666666667,"easy","a","Contact sport risk from traumatic injury including spinal and head trauma.","https://en.wikipedia.org/wiki/American_football","Moderate radiation dose from fluoroscopic imaging of the large intestine.","https://en.wikipedia.org/wiki/Barium_enema"
"Barium enema (radiation per scan)","COVID-19 unvaccinated (all ages)",20,"COVID-19",0,"11 weeks (2022)",3,"Medical",0,"per event",6.66666666666667,"easy","a","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Moderate radiation dose from fluoroscopic imaging of the large intestine.","https://en.wikipedia.org/wiki/Barium_enema"
"Base jumping (per jump)","Matterhorn ascent",2840,"Mountaineering",0,"per ascent",430,"Sport",0,"per jump",6.6046511627907,"easy","a","One of the Alps' deadliest peaks due to rockfall, exposure, and technical climbing difficulty.","https://en.wikipedia.org/wiki/Matterhorn","Parachuting from fixed objects (buildings, cliffs) with minimal altitude for recovery.","https://en.wikipedia.org/wiki/BASE_jumping"
"Bee/wasp sting (general)","COVID-19 monovalent vaccine (age 18-49)",0.2,"COVID-19",0,"11 weeks (2022)",0.03,"Wildlife",100,"per sting",6.66666666666667,"easy","a","Young adult monovalent-vaccinated COVID-19 mortality was very low.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Bee or wasp sting fatality risk for non-allergic individuals.","https://en.wikipedia.org/wiki/Bee_sting"
"COVID-19 bivalent booster (age 65-79)","American football",20,"Sport",0,"per game",3,"COVID-19",0,"11 weeks (2022)",6.66666666666667,"easy","a","Contact sport risk from traumatic injury including spinal and head trauma.","https://en.wikipedia.org/wiki/American_football","Bivalent-boosted 65-79 year-olds had lowest but still measurable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 monovalent vaccine (age 50-64)","Ecstasy/MDMA (per dose)",13,"Drugs",0,"per dose",2,"COVID-19",0,"11 weeks (2022)",6.5,"easy","a","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA","Monovalent-vaccinated 50-64 year-olds had low residual COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 monovalent vaccine (all ages)","US military in Afghanistan (2010)",25,"Military",0,"per day",4,"COVID-19",0,"11 weeks (2022)",6.25,"easy","a","Daily risk during peak combat operations in Afghanistan's most dangerous year.","https://en.wikipedia.org/wiki/War_in_Afghanistan_(2001%E2%80%932021)","Population-average residual COVID-19 risk after monovalent vaccination.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 unvaccinated (age 65-79)","Living (one day, age 90)",463,"Daily Life",0,"per day",76,"COVID-19",0,"11 weeks (2022)",6.0921052631579,"easy","a","Daily background mortality risk at age 90 reflects accumulated physiological decline.","https://en.wikipedia.org/wiki/Mortality_rate","Unvaccinated 65-79 year-olds had substantially elevated COVID-19 mortality in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"Crossing a road","Commuting by car (30 min)",0.13,"Travel",0,"per trip",0.02,"Daily Life",0,"per event",6.5,"easy","a","Short car commute with crash risk from traffic collisions.","https://en.wikipedia.org/wiki/Traffic_collision","Pedestrian collision risk at a single road crossing.","https://en.wikipedia.org/wiki/Pedestrian"
"CT scan head (radiation per scan)","Ecstasy/MDMA (per dose)",13,"Drugs",0,"per dose",2,"Medical",0,"per event",6.5,"easy","a","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA","Low-moderate radiation dose (~2 mSv) for neurological imaging.","https://en.wikipedia.org/wiki/CT_scan"
"Dog bite (US)","Flying (2h short-haul)",1.1,"Travel",0,"per 2h flight",6.7,"Wildlife",100,"per bite",6.09090909090909,"easy","b","Short-haul flight risk is dominated by takeoff/landing crash risk; DVT and radiation are minimal.","https://en.wikipedia.org/wiki/Aviation_safety","Dog bite fatality risk in a high-income setting with rabies PEP available.","https://en.wikipedia.org/wiki/Dog_bite"
"Dog bite (US)","Walking (20 miles)",1,"Travel",0,"per trip",6.7,"Wildlife",100,"per bite",6.7,"easy","b","Pedestrian fatality risk from traffic collisions over a 20-mile walk.","https://en.wikipedia.org/wiki/Pedestrian","Dog bite fatality risk in a high-income setting with rabies PEP available.","https://en.wikipedia.org/wiki/Dog_bite"
"First day of life (newborn)","Matterhorn ascent",2840,"Mountaineering",0,"per ascent",430,"Daily Life",0,"per day",6.6046511627907,"easy","a","One of the Alps' deadliest peaks due to rockfall, exposure, and technical climbing difficulty.","https://en.wikipedia.org/wiki/Matterhorn","The first 24 hours carry elevated risk from birth complications and congenital conditions.","https://en.wikipedia.org/wiki/Neonatal_death"
"Flying (12h ultra-long-haul)","COVID-19 unvaccinated (age 18-49)",1,"COVID-19",0,"11 weeks (2022)",6.6,"Travel",75.8,"per 12h flight",6.6,"easy","b","Young adult unvaccinated COVID-19 mortality was low but non-negligible.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (12h ultra-long-haul)","Eating 1000 bananas (radiation)",1,"Diet",0,"per event",6.6,"Travel",75.8,"per 12h flight",6.6,"easy","b","Cumulative potassium-40 radiation dose from 1000 bananas equals roughly 1 micromort.","https://en.wikipedia.org/wiki/Banana_equivalent_dose","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (12h ultra-long-haul)","Living 2 months with a smoker",1,"Environment",0,"per 2 months",6.6,"Travel",75.8,"per 12h flight",6.6,"easy","b","Secondhand smoke exposure increases cardiovascular and respiratory disease risk.","https://en.wikipedia.org/wiki/Passive_smoking","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (2h short-haul)","Running a marathon",7,"Sport",0,"per event",1.1,"Travel",0,"per 2h flight",6.36363636363636,"easy","a","Cardiac events during extreme endurance exercise, mainly in older or predisposed runners.","https://en.wikipedia.org/wiki/Marathon","Short-haul flight risk is dominated by takeoff/landing crash risk; DVT and radiation are minimal.","https://en.wikipedia.org/wiki/Aviation_safety"
"Flying (8h long-haul)","US military in Afghanistan (2010)",25,"Military",0,"per day",3.9,"Travel",64.1,"per 8h flight",6.41025641025641,"easy","a","Daily risk during peak combat operations in Afghanistan's most dangerous year.","https://en.wikipedia.org/wiki/War_in_Afghanistan_(2001%E2%80%932021)","Long-haul flights have significant DVT risk, especially for those with risk factors.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Frequent executive flyer (annual cosmic)","COVID-19 unvaccinated (age 18-49)",1,"COVID-19",0,"11 weeks (2022)",0.15,"Travel",0,"per year",6.66666666666667,"easy","a","Young adult unvaccinated COVID-19 mortality was low but non-negligible.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Heavy business travel (~150,000 miles/year) accumulates cosmic radiation dose.","https://en.wikipedia.org/wiki/Cosmic_ray"
"Frequent executive flyer (annual cosmic)","Living 2 months with a smoker",1,"Environment",0,"per 2 months",0.15,"Travel",0,"per year",6.66666666666667,"easy","a","Secondhand smoke exposure increases cardiovascular and respiratory disease risk.","https://en.wikipedia.org/wiki/Passive_smoking","Heavy business travel (~150,000 miles/year) accumulates cosmic radiation dose.","https://en.wikipedia.org/wiki/Cosmic_ray"
"Frequent executive flyer (annual cosmic)","Eating 1000 bananas (radiation)",1,"Diet",0,"per event",0.15,"Travel",0,"per year",6.66666666666667,"easy","a","Cumulative potassium-40 radiation dose from 1000 bananas equals roughly 1 micromort.","https://en.wikipedia.org/wiki/Banana_equivalent_dose","Heavy business travel (~150,000 miles/year) accumulates cosmic radiation dose.","https://en.wikipedia.org/wiki/Cosmic_ray"
"Hang gliding (per flight)","Living in NYC COVID-19 (Mar-May 2020)",50,"COVID-19",0,"per 8 weeks",8,"Sport",0,"per flight",6.25,"easy","a","New York City experienced extreme COVID-19 mortality during the initial wave.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_New_York_City","Unpowered flight with risk from turbulence, structural failure, and pilot error.","https://en.wikipedia.org/wiki/Hang_gliding"
"Interventional cardiologist (annual radiation)","Flying (2h short-haul)",1.1,"Travel",0,"per 2h flight",0.175,"Occupation",100,"per year",6.28571428571429,"easy","a","Short-haul flight risk is dominated by takeoff/landing crash risk; DVT and radiation are minimal.","https://en.wikipedia.org/wiki/Aviation_safety","Highest occupational medical radiation dose from fluoroscopy-guided procedures.","https://en.wikipedia.org/wiki/Interventional_cardiology"
"Living (one day, age 50)","US military in Afghanistan (2010)",25,"Military",0,"per day",4,"Daily Life",0,"per day",6.25,"easy","a","Daily risk during peak combat operations in Afghanistan's most dangerous year.","https://en.wikipedia.org/wiki/War_in_Afghanistan_(2001%E2%80%932021)","Daily mortality at age 50 is roughly 4x that of a 20-year-old.","https://en.wikipedia.org/wiki/Mortality_rate"
"Living (one day, age 90)","Matterhorn ascent",2840,"Mountaineering",0,"per ascent",463,"Daily Life",0,"per day",6.13390928725702,"easy","a","One of the Alps' deadliest peaks due to rockfall, exposure, and technical climbing difficulty.","https://en.wikipedia.org/wiki/Matterhorn","Daily background mortality risk at age 90 reflects accumulated physiological decline.","https://en.wikipedia.org/wiki/Mortality_rate"
"Logging (per work day)","American football",20,"Sport",0,"per game",3.3,"Occupation",0,"per day",6.06060606060606,"easy","a","Contact sport risk from traumatic injury including spinal and head trauma.","https://en.wikipedia.org/wiki/American_football","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Logging (per work day)","COVID-19 unvaccinated (all ages)",20,"COVID-19",0,"11 weeks (2022)",3.3,"Occupation",0,"per day",6.06060606060606,"easy","a","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Logging (per work day)","Horse riding",0.5,"Sport",0,"per ride",3.3,"Occupation",0,"per day",6.6,"easy","b","Falls from horseback can cause traumatic brain and spinal injuries.","https://en.wikipedia.org/wiki/Equestrianism","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Mining (per work day)","Living (one day, age 45)",6,"Daily Life",0,"per day",0.9,"Occupation",0,"per day",6.66666666666667,"easy","a","Daily background mortality at age 45 reflects middle-age cardiovascular and cancer risk.","https://en.wikipedia.org/wiki/Mortality_rate","Roof collapse, gas explosion, and heavy equipment hazards in underground and surface mining.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Night in hospital","Living (one day, age 90)",463,"Daily Life",0,"per day",75,"Medical",0,"per night",6.17333333333333,"easy","a","Daily background mortality risk at age 90 reflects accumulated physiological decline.","https://en.wikipedia.org/wiki/Mortality_rate","Hospital stays carry risk from medical errors, hospital-acquired infections, and underlying illness severity.","https://en.wikipedia.org/wiki/Hospital-acquired_infection"
"Night in hospital","Living in US during COVID-19 (Jul 2020)",500,"COVID-19",0,"per month",75,"Medical",0,"per night",6.66666666666667,"easy","a","Peak US COVID-19 mortality before vaccines were available.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_the_United_States","Hospital stays carry risk from medical errors, hospital-acquired infections, and underlying illness severity.","https://en.wikipedia.org/wiki/Hospital-acquired_infection"
"Rock climbing (per day)","COVID-19 unvaccinated (all ages)",20,"COVID-19",0,"11 weeks (2022)",3,"Sport",0,"per day",6.66666666666667,"easy","a","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Risk from falls, rockfall, and equipment failure on natural rock. Per full day of climbing.","https://en.wikipedia.org/wiki/Rock_climbing"
"Roofing (per work day)","Swimming",12,"Sport",0,"per swim",1.9,"Occupation",0,"per day",6.31578947368421,"easy","a","Drowning risk per swim session, higher for open water and unsupervised settings.","https://en.wikipedia.org/wiki/Drowning","Falls from height are the primary cause of roofing fatalities.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Skydiving (UK)","Living in NYC COVID-19 (Mar-May 2020)",50,"COVID-19",0,"per 8 weeks",8,"Sport",0,"per event",6.25,"easy","a","New York City experienced extreme COVID-19 mortality during the initial wave.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_New_York_City","UK skydiving fatality rate based on British Parachute Association data.","https://en.wikipedia.org/wiki/Skydiving"
"Skydiving (US)","Living in NYC COVID-19 (Mar-May 2020)",50,"COVID-19",0,"per 8 weeks",8,"Sport",0,"per event",6.25,"easy","a","New York City experienced extreme COVID-19 mortality during the initial wave.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_New_York_City","US skydiving fatality rate based on USPA incident reports.","https://en.wikipedia.org/wiki/Skydiving"
"Structural iron/steel work (per work day)","General anesthesia (emergency)",10,"Medical",0,"per event",1.5,"Occupation",0,"per day",6.66666666666667,"easy","a","Emergency anesthesia carries higher risk than elective due to patient instability.","https://en.wikipedia.org/wiki/General_anaesthesia","Working at height on building frames with fall and struck-by hazards.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Structural iron/steel work (per work day)","Skydiving (per jump)",10,"Sport",0,"per jump",1.5,"Occupation",0,"per day",6.66666666666667,"easy","a","Risk from parachute malfunction, mid-air collision, and landing errors.","https://en.wikipedia.org/wiki/Skydiving","Working at height on building frames with fall and struck-by hazards.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Structural iron/steel work (per work day)","Motorcycling (60 miles)",10,"Travel",0,"per trip",1.5,"Occupation",0,"per day",6.66666666666667,"easy","a","Per-mile fatality rate roughly 30x higher than car travel due to exposure and instability.","https://en.wikipedia.org/wiki/Motorcycle_safety","Working at height on building frames with fall and struck-by hazards.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Swimming","Night in hospital",75,"Medical",0,"per night",12,"Sport",0,"per swim",6.25,"easy","a","Hospital stays carry risk from medical errors, hospital-acquired infections, and underlying illness severity.","https://en.wikipedia.org/wiki/Hospital-acquired_infection","Drowning risk per swim session, higher for open water and unsupervised settings.","https://en.wikipedia.org/wiki/Drowning"
"Swimming","COVID-19 unvaccinated (age 65-79)",76,"COVID-19",0,"11 weeks (2022)",12,"Sport",0,"per swim",6.33333333333333,"easy","a","Unvaccinated 65-79 year-olds had substantially elevated COVID-19 mortality in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Drowning risk per swim session, higher for open water and unsupervised settings.","https://en.wikipedia.org/wiki/Drowning"
"Truck driving (per work day)","COVID-19 unvaccinated (age 50-64)",8,"COVID-19",0,"11 weeks (2022)",1.2,"Occupation",0,"per day",6.66666666666667,"easy","a","Unvaccinated 50-64 year-olds had moderately elevated COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Long hours and highway driving make truck driving a high-fatality occupation by total deaths.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Truck driving (per work day)","Skydiving (UK)",8,"Sport",0,"per event",1.2,"Occupation",0,"per day",6.66666666666667,"easy","a","UK skydiving fatality rate based on British Parachute Association data.","https://en.wikipedia.org/wiki/Skydiving","Long hours and highway driving make truck driving a high-fatality occupation by total deaths.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Truck driving (per work day)","Skydiving (US)",8,"Sport",0,"per event",1.2,"Occupation",0,"per day",6.66666666666667,"easy","a","US skydiving fatality rate based on USPA incident reports.","https://en.wikipedia.org/wiki/Skydiving","Long hours and highway driving make truck driving a high-fatality occupation by total deaths.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Working in an office (8 hours)","COVID-19 monovalent vaccine (age 18-49)",0.2,"COVID-19",0,"11 weeks (2022)",0.03,"Daily Life",0,"per day",6.66666666666667,"easy","a","Young adult monovalent-vaccinated COVID-19 mortality was very low.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Background mortality rate during sedentary office work.","https://en.wikipedia.org/wiki/Mortality_rate"
"Airline pilot (annual radiation)","Horse riding",0.5,"Sport",0,"per ride",0.15,"Occupation",100,"per year",3.33333333333333,"medium","a","Falls from horseback can cause traumatic brain and spinal injuries.","https://en.wikipedia.org/wiki/Equestrianism","Cumulative cosmic radiation exposure from ~700 flight hours per year at altitude.","https://en.wikipedia.org/wiki/Airline_pilot"
"All US workers baseline (per work day)","Horse riding",0.5,"Sport",0,"per ride",0.15,"Occupation",0,"per day",3.33333333333333,"medium","a","Falls from horseback can cause traumatic brain and spinal injuries.","https://en.wikipedia.org/wiki/Equestrianism","Average occupational fatality rate across all US industries; baseline for comparison.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Barium enema (radiation per scan)","Skydiving (per jump)",10,"Sport",0,"per jump",3,"Medical",0,"per event",3.33333333333333,"medium","a","Risk from parachute malfunction, mid-air collision, and landing errors.","https://en.wikipedia.org/wiki/Skydiving","Moderate radiation dose from fluoroscopic imaging of the large intestine.","https://en.wikipedia.org/wiki/Barium_enema"
"Bee/wasp sting (general)","Mammogram (radiation per scan)",0.1,"Medical",0,"per event",0.03,"Wildlife",100,"per sting",3.33333333333333,"medium","a","Very low radiation dose used for breast cancer screening; net benefit is strongly positive.","https://en.wikipedia.org/wiki/Mammography","Bee or wasp sting fatality risk for non-allergic individuals.","https://en.wikipedia.org/wiki/Bee_sting"
"Bee/wasp sting (general)","Chest X-ray (radiation per scan)",0.1,"Medical",0,"per event",0.03,"Wildlife",100,"per sting",3.33333333333333,"medium","a","Very low radiation dose (~0.02 mSv), equivalent to a few hours of background radiation.","https://en.wikipedia.org/wiki/Chest_radiograph","Bee or wasp sting fatality risk for non-allergic individuals.","https://en.wikipedia.org/wiki/Bee_sting"
"Commercial fishing (per work day)","CT scan abdomen (radiation per scan)",10,"Medical",0,"per event",3,"Occupation",0,"per day",3.33333333333333,"medium","a","Higher radiation dose (~10 mSv) for abdominal imaging; benefits usually outweigh risks.","https://en.wikipedia.org/wiki/CT_scan","Extreme weather, vessel sinking, and deck machinery make fishing one of the deadliest occupations.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Commercial fishing (per work day)","Skydiving (per jump)",10,"Sport",0,"per jump",3,"Occupation",0,"per day",3.33333333333333,"medium","a","Risk from parachute malfunction, mid-air collision, and landing errors.","https://en.wikipedia.org/wiki/Skydiving","Extreme weather, vessel sinking, and deck machinery make fishing one of the deadliest occupations.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"COVID-19 bivalent booster (age 65-79)","General anesthesia (emergency)",10,"Medical",0,"per event",3,"COVID-19",0,"11 weeks (2022)",3.33333333333333,"medium","a","Emergency anesthesia carries higher risk than elective due to patient instability.","https://en.wikipedia.org/wiki/General_anaesthesia","Bivalent-boosted 65-79 year-olds had lowest but still measurable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 bivalent booster (age 65-79)","Motorcycling (60 miles)",10,"Travel",0,"per trip",3,"COVID-19",0,"11 weeks (2022)",3.33333333333333,"medium","a","Per-mile fatality rate roughly 30x higher than car travel due to exposure and instability.","https://en.wikipedia.org/wiki/Motorcycle_safety","Bivalent-boosted 65-79 year-olds had lowest but still measurable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 bivalent booster (age 80+)","Night in hospital",75,"Medical",0,"per night",23,"COVID-19",0,"11 weeks (2022)",3.26086956521739,"medium","a","Hospital stays carry risk from medical errors, hospital-acquired infections, and underlying illness severity.","https://en.wikipedia.org/wiki/Hospital-acquired_infection","Bivalent-boosted elderly still faced elevated COVID-19 risk due to immunosenescence.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 monovalent vaccine (age 65-79)","Heroin use (per dose)",30,"Drugs",0,"per dose",9,"COVID-19",0,"11 weeks (2022)",3.33333333333333,"medium","a","Each dose carries risk of respiratory depression, overdose, and contaminated supply.","https://en.wikipedia.org/wiki/Heroin","Monovalent-vaccinated 65-79 year-olds had reduced but still notable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 monovalent vaccine (age 80+)","Caesarean birth (mother)",170,"Medical",0,"per event",55,"COVID-19",0,"11 weeks (2022)",3.09090909090909,"medium","a","Major abdominal surgery carrying risks of hemorrhage, infection, and anesthesia complications.","https://en.wikipedia.org/wiki/Caesarean_section","Even with monovalent vaccination, elderly remained at elevated COVID-19 risk in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 monovalent vaccine (all ages)","Ecstasy/MDMA (per dose)",13,"Drugs",0,"per dose",4,"COVID-19",0,"11 weeks (2022)",3.25,"medium","a","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA","Population-average residual COVID-19 risk after monovalent vaccination.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"CT scan chest (radiation per scan)","COVID-19 bivalent booster (age 80+)",23,"COVID-19",0,"11 weeks (2022)",7,"Medical",0,"per event",3.28571428571429,"medium","a","Bivalent-boosted elderly still faced elevated COVID-19 risk due to immunosenescence.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Moderate radiation dose (~7 mSv) used for diagnosing pulmonary embolism, cancer, and trauma.","https://en.wikipedia.org/wiki/CT_scan"
"Flying (12h ultra-long-haul)","American football",20,"Sport",0,"per game",6.6,"Travel",75.8,"per 12h flight",3.03030303030303,"medium","a","Contact sport risk from traumatic injury including spinal and head trauma.","https://en.wikipedia.org/wiki/American_football","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (12h ultra-long-haul)","COVID-19 unvaccinated (all ages)",20,"COVID-19",0,"11 weeks (2022)",6.6,"Travel",75.8,"per 12h flight",3.03030303030303,"medium","a","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (12h ultra-long-haul)","COVID-19 monovalent vaccine (age 50-64)",2,"COVID-19",0,"11 weeks (2022)",6.6,"Travel",75.8,"per 12h flight",3.3,"medium","b","Monovalent-vaccinated 50-64 year-olds had low residual COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (8h long-haul)","Swimming",12,"Sport",0,"per swim",3.9,"Travel",64.1,"per 8h flight",3.07692307692308,"medium","a","Drowning risk per swim session, higher for open water and unsupervised settings.","https://en.wikipedia.org/wiki/Drowning","Long-haul flights have significant DVT risk, especially for those with risk factors.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (8h long-haul)","Ecstasy/MDMA (per dose)",13,"Drugs",0,"per dose",3.9,"Travel",64.1,"per 8h flight",3.33333333333333,"medium","a","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA","Long-haul flights have significant DVT risk, especially for those with risk factors.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Frequent executive flyer (annual cosmic)","Horse riding",0.5,"Sport",0,"per ride",0.15,"Travel",0,"per year",3.33333333333333,"medium","a","Falls from horseback can cause traumatic brain and spinal injuries.","https://en.wikipedia.org/wiki/Equestrianism","Heavy business travel (~150,000 miles/year) accumulates cosmic radiation dose.","https://en.wikipedia.org/wiki/Cosmic_ray"
"Living (one day, age 45)","American football",20,"Sport",0,"per game",6,"Daily Life",0,"per day",3.33333333333333,"medium","a","Contact sport risk from traumatic injury including spinal and head trauma.","https://en.wikipedia.org/wiki/American_football","Daily background mortality at age 45 reflects middle-age cardiovascular and cancer risk.","https://en.wikipedia.org/wiki/Mortality_rate"
"Living (one day, age 45)","COVID-19 unvaccinated (all ages)",20,"COVID-19",0,"11 weeks (2022)",6,"Daily Life",0,"per day",3.33333333333333,"medium","a","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Daily background mortality at age 45 reflects middle-age cardiovascular and cancer risk.","https://en.wikipedia.org/wiki/Mortality_rate"
"Living (one day, age 50)","Ecstasy/MDMA (per dose)",13,"Drugs",0,"per dose",4,"Daily Life",0,"per day",3.25,"medium","a","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA","Daily mortality at age 50 is roughly 4x that of a 20-year-old.","https://en.wikipedia.org/wiki/Mortality_rate"
"Living (one day, under age 1)","Living in NYC COVID-19 (Mar-May 2020)",50,"COVID-19",0,"per 8 weeks",15,"Daily Life",0,"per day",3.33333333333333,"medium","a","New York City experienced extreme COVID-19 mortality during the initial wave.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_New_York_City","Infant mortality from congenital conditions, SIDS, and birth complications.","https://en.wikipedia.org/wiki/Infant_mortality"
"Living in NYC COVID-19 (Mar-May 2020)","Scuba diving, trained (yearly)",164,"Sport",0,"per year",50,"COVID-19",0,"per 8 weeks",3.28,"medium","a","Cumulative annual risk for trained divers from decompression sickness, drowning, and equipment failure.","https://en.wikipedia.org/wiki/Scuba_diving","New York City experienced extreme COVID-19 mortality during the initial wave.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_New_York_City"
"Logging (per work day)","Skydiving (per jump)",10,"Sport",0,"per jump",3.3,"Occupation",0,"per day",3.03030303030303,"medium","a","Risk from parachute malfunction, mid-air collision, and landing errors.","https://en.wikipedia.org/wiki/Skydiving","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Logging (per work day)","Motorcycling (60 miles)",10,"Travel",0,"per trip",3.3,"Occupation",0,"per day",3.03030303030303,"medium","a","Per-mile fatality rate roughly 30x higher than car travel due to exposure and instability.","https://en.wikipedia.org/wiki/Motorcycle_safety","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Logging (per work day)","General anesthesia (emergency)",10,"Medical",0,"per event",3.3,"Occupation",0,"per day",3.03030303030303,"medium","a","Emergency anesthesia carries higher risk than elective due to patient instability.","https://en.wikipedia.org/wiki/General_anaesthesia","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Mining (per work day)","Barium enema (radiation per scan)",3,"Medical",0,"per event",0.9,"Occupation",0,"per day",3.33333333333333,"medium","a","Moderate radiation dose from fluoroscopic imaging of the large intestine.","https://en.wikipedia.org/wiki/Barium_enema","Roof collapse, gas explosion, and heavy equipment hazards in underground and surface mining.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Mining (per work day)","COVID-19 bivalent booster (age 65-79)",3,"COVID-19",0,"11 weeks (2022)",0.9,"Occupation",0,"per day",3.33333333333333,"medium","a","Bivalent-boosted 65-79 year-olds had lowest but still measurable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Roof collapse, gas explosion, and heavy equipment hazards in underground and surface mining.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Mining (per work day)","Rock climbing (per day)",3,"Sport",0,"per day",0.9,"Occupation",0,"per day",3.33333333333333,"medium","a","Risk from falls, rockfall, and equipment failure on natural rock. Per full day of climbing.","https://en.wikipedia.org/wiki/Rock_climbing","Roof collapse, gas explosion, and heavy equipment hazards in underground and surface mining.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Night in hospital","COVID-19 unvaccinated (age 80+)",234,"COVID-19",0,"11 weeks (2022)",75,"Medical",0,"per night",3.12,"medium","a","Unvaccinated elderly face the highest COVID-19 mortality rates.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Hospital stays carry risk from medical errors, hospital-acquired infections, and underlying illness severity.","https://en.wikipedia.org/wiki/Hospital-acquired_infection"
"Normal background radiation","Business traveller (annual cosmic)",0.0375,"Travel",0,"per year",0.12,"Environment",0,"per year",3.2,"medium","b","Moderate annual cosmic radiation from ~40,000 miles of flying per year.","https://en.wikipedia.org/wiki/Cosmic_ray","Average annual radiation dose from natural sources (radon, cosmic, internal, terrestrial).","https://en.wikipedia.org/wiki/Background_radiation"
"Rock climbing (per day)","General anesthesia (emergency)",10,"Medical",0,"per event",3,"Sport",0,"per day",3.33333333333333,"medium","a","Emergency anesthesia carries higher risk than elective due to patient instability.","https://en.wikipedia.org/wiki/General_anaesthesia","Risk from falls, rockfall, and equipment failure on natural rock. Per full day of climbing.","https://en.wikipedia.org/wiki/Rock_climbing"
"Rock climbing (per day)","Motorcycling (60 miles)",10,"Travel",0,"per trip",3,"Sport",0,"per day",3.33333333333333,"medium","a","Per-mile fatality rate roughly 30x higher than car travel due to exposure and instability.","https://en.wikipedia.org/wiki/Motorcycle_safety","Risk from falls, rockfall, and equipment failure on natural rock. Per full day of climbing.","https://en.wikipedia.org/wiki/Rock_climbing"
"Roofing (per work day)","Living (one day, age 45)",6,"Daily Life",0,"per day",1.9,"Occupation",0,"per day",3.1578947368421,"medium","a","Daily background mortality at age 45 reflects middle-age cardiovascular and cancer risk.","https://en.wikipedia.org/wiki/Mortality_rate","Falls from height are the primary cause of roofing fatalities.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Running a marathon","COVID-19 bivalent booster (age 80+)",23,"COVID-19",0,"11 weeks (2022)",7,"Sport",0,"per event",3.28571428571429,"medium","a","Bivalent-boosted elderly still faced elevated COVID-19 risk due to immunosenescence.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Cardiac events during extreme endurance exercise, mainly in older or predisposed runners.","https://en.wikipedia.org/wiki/Marathon"
"Scuba diving, trained (yearly)","Living in US during COVID-19 (Jul 2020)",500,"COVID-19",0,"per month",164,"Sport",0,"per year",3.04878048780488,"medium","a","Peak US COVID-19 mortality before vaccines were available.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_the_United_States","Cumulative annual risk for trained divers from decompression sickness, drowning, and equipment failure.","https://en.wikipedia.org/wiki/Scuba_diving"
"Shark encounter (ocean swim)","COVID-19 monovalent vaccine (age 18-49)",0.2,"COVID-19",0,"11 weeks (2022)",0.06,"Wildlife",100,"per swim",3.33333333333333,"medium","a","Young adult monovalent-vaccinated COVID-19 mortality was very low.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Shark attack fatality risk per ocean swim, based on ISAF incident data.","https://www.floridamuseum.ufl.edu/shark-attacks/"
"Skydiving (UK)","US military in Afghanistan (2010)",25,"Military",0,"per day",8,"Sport",0,"per event",3.125,"medium","a","Daily risk during peak combat operations in Afghanistan's most dangerous year.","https://en.wikipedia.org/wiki/War_in_Afghanistan_(2001%E2%80%932021)","UK skydiving fatality rate based on British Parachute Association data.","https://en.wikipedia.org/wiki/Skydiving"
"Skydiving (US)","US military in Afghanistan (2010)",25,"Military",0,"per day",8,"Sport",0,"per event",3.125,"medium","a","Daily risk during peak combat operations in Afghanistan's most dangerous year.","https://en.wikipedia.org/wiki/War_in_Afghanistan_(2001%E2%80%932021)","US skydiving fatality rate based on USPA incident reports.","https://en.wikipedia.org/wiki/Skydiving"
"Spanish flu infection","COVID-19 infection (unvaccinated)",10000,"COVID-19",0,"per infection",3000,"Disease",0,"per infection",3.33333333333333,"medium","a","Unvaccinated COVID-19 infection carries substantial mortality risk, especially for older adults.","https://en.wikipedia.org/wiki/COVID-19","The 1918 influenza pandemic killed an estimated 50-100 million people worldwide.","https://en.wikipedia.org/wiki/Spanish_flu"
"Structural iron/steel work (per work day)","Scuba diving, trained (per dive)",5,"Sport",0,"per dive",1.5,"Occupation",0,"per day",3.33333333333333,"medium","a","Single-dive risk for trained divers from decompression sickness and equipment failure.","https://en.wikipedia.org/wiki/Scuba_diving","Working at height on building frames with fall and struck-by hazards.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Truck driving (per work day)","COVID-19 monovalent vaccine (all ages)",4,"COVID-19",0,"11 weeks (2022)",1.2,"Occupation",0,"per day",3.33333333333333,"medium","a","Population-average residual COVID-19 risk after monovalent vaccination.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Long hours and highway driving make truck driving a high-fatality occupation by total deaths.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Truck driving (per work day)","Living (one day, age 50)",4,"Daily Life",0,"per day",1.2,"Occupation",0,"per day",3.33333333333333,"medium","a","Daily mortality at age 50 is roughly 4x that of a 20-year-old.","https://en.wikipedia.org/wiki/Mortality_rate","Long hours and highway driving make truck driving a high-fatality occupation by total deaths.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Truck driving (per work day)","Flying (8h long-haul)",3.9,"Travel",64.1,"per 8h flight",1.2,"Occupation",0,"per day",3.25,"medium","a","Long-haul flights have significant DVT risk, especially for those with risk factors.","https://en.wikipedia.org/wiki/Economy_class_syndrome","Long hours and highway driving make truck driving a high-fatality occupation by total deaths.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"US military in Afghanistan (2010)","COVID-19 unvaccinated (age 65-79)",76,"COVID-19",0,"11 weeks (2022)",25,"Military",0,"per day",3.04,"medium","a","Unvaccinated 65-79 year-olds had substantially elevated COVID-19 mortality in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Daily risk during peak combat operations in Afghanistan's most dangerous year.","https://en.wikipedia.org/wiki/War_in_Afghanistan_(2001%E2%80%932021)"
"Working in an office (8 hours)","Chest X-ray (radiation per scan)",0.1,"Medical",0,"per event",0.03,"Daily Life",0,"per day",3.33333333333333,"medium","a","Very low radiation dose (~0.02 mSv), equivalent to a few hours of background radiation.","https://en.wikipedia.org/wiki/Chest_radiograph","Background mortality rate during sedentary office work.","https://en.wikipedia.org/wiki/Mortality_rate"
"Working in an office (8 hours)","Mammogram (radiation per scan)",0.1,"Medical",0,"per event",0.03,"Daily Life",0,"per day",3.33333333333333,"medium","a","Very low radiation dose used for breast cancer screening; net benefit is strongly positive.","https://en.wikipedia.org/wiki/Mammography","Background mortality rate during sedentary office work.","https://en.wikipedia.org/wiki/Mortality_rate"
"Working in an office (8 hours)","Kangaroo encounter",0.1,"Wildlife",0,"per encounter",0.03,"Daily Life",0,"per day",3.33333333333333,"medium","a","Vehicle collisions with kangaroos cause fatalities in rural Australia.","https://en.wikipedia.org/wiki/Kangaroo","Background mortality rate during sedentary office work.","https://en.wikipedia.org/wiki/Mortality_rate"
"Agriculture (per work day)","Flying (2h short-haul)",1.1,"Travel",0,"per 2h flight",0.7,"Occupation",0,"per day",1.57142857142857,"hard","a","Short-haul flight risk is dominated by takeoff/landing crash risk; DVT and radiation are minimal.","https://en.wikipedia.org/wiki/Aviation_safety","Tractor rollovers, machinery entanglement, and livestock injuries on farms and ranches.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"American football","Heroin use (per dose)",30,"Drugs",0,"per dose",20,"Sport",0,"per game",1.5,"hard","a","Each dose carries risk of respiratory depression, overdose, and contaminated supply.","https://en.wikipedia.org/wiki/Heroin","Contact sport risk from traumatic injury including spinal and head trauma.","https://en.wikipedia.org/wiki/American_football"
"Barium enema (radiation per scan)","COVID-19 monovalent vaccine (age 50-64)",2,"COVID-19",0,"11 weeks (2022)",3,"Medical",0,"per event",1.5,"hard","b","Monovalent-vaccinated 50-64 year-olds had low residual COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Moderate radiation dose from fluoroscopic imaging of the large intestine.","https://en.wikipedia.org/wiki/Barium_enema"
"Bee/wasp sting (general)","COVID-19 bivalent booster (age 18-49)",0.05,"COVID-19",0,"11 weeks (2022)",0.03,"Wildlife",100,"per sting",1.66666666666667,"hard","a","Bivalent-boosted young adults had near-baseline COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Bee or wasp sting fatality risk for non-allergic individuals.","https://en.wikipedia.org/wiki/Bee_sting"
"Bee/wasp sting (general)","Crossing a road",0.02,"Daily Life",0,"per event",0.03,"Wildlife",100,"per sting",1.5,"hard","b","Pedestrian collision risk at a single road crossing.","https://en.wikipedia.org/wiki/Pedestrian","Bee or wasp sting fatality risk for non-allergic individuals.","https://en.wikipedia.org/wiki/Bee_sting"
"Commercial fishing (per work day)","COVID-19 monovalent vaccine (age 50-64)",2,"COVID-19",0,"11 weeks (2022)",3,"Occupation",0,"per day",1.5,"hard","b","Monovalent-vaccinated 50-64 year-olds had low residual COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Extreme weather, vessel sinking, and deck machinery make fishing one of the deadliest occupations.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Commercial fishing (per work day)","CT scan head (radiation per scan)",2,"Medical",0,"per event",3,"Occupation",0,"per day",1.5,"hard","b","Low-moderate radiation dose (~2 mSv) for neurological imaging.","https://en.wikipedia.org/wiki/CT_scan","Extreme weather, vessel sinking, and deck machinery make fishing one of the deadliest occupations.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Commuting by car (30 min)","COVID-19 monovalent vaccine (age 18-49)",0.2,"COVID-19",0,"11 weeks (2022)",0.13,"Travel",0,"per trip",1.53846153846154,"hard","a","Young adult monovalent-vaccinated COVID-19 mortality was very low.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Short car commute with crash risk from traffic collisions.","https://en.wikipedia.org/wiki/Traffic_collision"
"Coronary angiogram (radiation per scan)","Skydiving (US)",8,"Sport",0,"per event",5,"Medical",0,"per event",1.6,"hard","a","US skydiving fatality rate based on USPA incident reports.","https://en.wikipedia.org/wiki/Skydiving","Moderate radiation dose from fluoroscopy-guided cardiac catheterisation.","https://en.wikipedia.org/wiki/Coronary_catheterization"
"Coronary angiogram (radiation per scan)","Skydiving (UK)",8,"Sport",0,"per event",5,"Medical",0,"per event",1.6,"hard","a","UK skydiving fatality rate based on British Parachute Association data.","https://en.wikipedia.org/wiki/Skydiving","Moderate radiation dose from fluoroscopy-guided cardiac catheterisation.","https://en.wikipedia.org/wiki/Coronary_catheterization"
"COVID-19 bivalent booster (age 65-79)","Scuba diving, trained (per dive)",5,"Sport",0,"per dive",3,"COVID-19",0,"11 weeks (2022)",1.66666666666667,"hard","a","Single-dive risk for trained divers from decompression sickness and equipment failure.","https://en.wikipedia.org/wiki/Scuba_diving","Bivalent-boosted 65-79 year-olds had lowest but still measurable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 monovalent vaccine (age 50-64)","Rock climbing (per day)",3,"Sport",0,"per day",2,"COVID-19",0,"11 weeks (2022)",1.5,"hard","a","Risk from falls, rockfall, and equipment failure on natural rock. Per full day of climbing.","https://en.wikipedia.org/wiki/Rock_climbing","Monovalent-vaccinated 50-64 year-olds had low residual COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 monovalent vaccine (all ages)","Living (one day, age 45)",6,"Daily Life",0,"per day",4,"COVID-19",0,"11 weeks (2022)",1.5,"hard","a","Daily background mortality at age 45 reflects middle-age cardiovascular and cancer risk.","https://en.wikipedia.org/wiki/Mortality_rate","Population-average residual COVID-19 risk after monovalent vaccination.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 unvaccinated (age 50-64)","Swimming",12,"Sport",0,"per swim",8,"COVID-19",0,"11 weeks (2022)",1.5,"hard","a","Drowning risk per swim session, higher for open water and unsupervised settings.","https://en.wikipedia.org/wiki/Drowning","Unvaccinated 50-64 year-olds had moderately elevated COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 unvaccinated (age 65-79)","Vaginal birth (mother)",120,"Medical",0,"per event",76,"COVID-19",0,"11 weeks (2022)",1.57894736842105,"hard","a","Maternal mortality risk from hemorrhage, infection, and eclampsia during vaginal delivery.","https://en.wikipedia.org/wiki/Maternal_death","Unvaccinated 65-79 year-olds had substantially elevated COVID-19 mortality in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"COVID-19 unvaccinated (all ages)","Heroin use (per dose)",30,"Drugs",0,"per dose",20,"COVID-19",0,"11 weeks (2022)",1.5,"hard","a","Each dose carries risk of respiratory depression, overdose, and contaminated supply.","https://en.wikipedia.org/wiki/Heroin","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm"
"CT scan abdomen (radiation per scan)","Flying (12h ultra-long-haul)",6.6,"Travel",75.8,"per 12h flight",10,"Medical",0,"per event",1.51515151515152,"hard","b","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome","Higher radiation dose (~10 mSv) for abdominal imaging; benefits usually outweigh risks.","https://en.wikipedia.org/wiki/CT_scan"
"CT scan head (radiation per scan)","COVID-19 bivalent booster (age 65-79)",3,"COVID-19",0,"11 weeks (2022)",2,"Medical",0,"per event",1.5,"hard","a","Bivalent-boosted 65-79 year-olds had lowest but still measurable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Low-moderate radiation dose (~2 mSv) for neurological imaging.","https://en.wikipedia.org/wiki/CT_scan"
"CT scan head (radiation per scan)","Rock climbing (per day)",3,"Sport",0,"per day",2,"Medical",0,"per event",1.5,"hard","a","Risk from falls, rockfall, and equipment failure on natural rock. Per full day of climbing.","https://en.wikipedia.org/wiki/Rock_climbing","Low-moderate radiation dose (~2 mSv) for neurological imaging.","https://en.wikipedia.org/wiki/CT_scan"
"Ecstasy/MDMA (per dose)","American football",20,"Sport",0,"per game",13,"Drugs",0,"per dose",1.53846153846154,"hard","a","Contact sport risk from traumatic injury including spinal and head trauma.","https://en.wikipedia.org/wiki/American_football","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA"
"Ecstasy/MDMA (per dose)","COVID-19 unvaccinated (all ages)",20,"COVID-19",0,"11 weeks (2022)",13,"Drugs",0,"per dose",1.53846153846154,"hard","a","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA"
"Flying (12h ultra-long-haul)","General anesthesia (emergency)",10,"Medical",0,"per event",6.6,"Travel",75.8,"per 12h flight",1.51515151515152,"hard","a","Emergency anesthesia carries higher risk than elective due to patient instability.","https://en.wikipedia.org/wiki/General_anaesthesia","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (12h ultra-long-haul)","Skydiving (per jump)",10,"Sport",0,"per jump",6.6,"Travel",75.8,"per 12h flight",1.51515151515152,"hard","a","Risk from parachute malfunction, mid-air collision, and landing errors.","https://en.wikipedia.org/wiki/Skydiving","Ultra-long-haul flights carry the highest DVT risk; compression socks can reduce it ~65%.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"Flying (2h short-haul)","Skiing",0.7,"Sport",0,"per day",1.1,"Travel",0,"per 2h flight",1.57142857142857,"hard","b","Risk from collisions with trees/other skiers and avalanche in backcountry.","https://en.wikipedia.org/wiki/Skiing","Short-haul flight risk is dominated by takeoff/landing crash risk; DVT and radiation are minimal.","https://en.wikipedia.org/wiki/Aviation_safety"
"Flying (8h long-haul)","Living (one day, age 45)",6,"Daily Life",0,"per day",3.9,"Travel",64.1,"per 8h flight",1.53846153846154,"hard","a","Daily background mortality at age 45 reflects middle-age cardiovascular and cancer risk.","https://en.wikipedia.org/wiki/Mortality_rate","Long-haul flights have significant DVT risk, especially for those with risk factors.","https://en.wikipedia.org/wiki/Economy_class_syndrome"
"General anesthesia (emergency)","Living (one day, under age 1)",15,"Daily Life",0,"per day",10,"Medical",0,"per event",1.5,"hard","a","Infant mortality from congenital conditions, SIDS, and birth complications.","https://en.wikipedia.org/wiki/Infant_mortality","Emergency anesthesia carries higher risk than elective due to patient instability.","https://en.wikipedia.org/wiki/General_anaesthesia"
"Heroin use (per dose)","Living in NYC COVID-19 (Mar-May 2020)",50,"COVID-19",0,"per 8 weeks",30,"Drugs",0,"per dose",1.66666666666667,"hard","a","New York City experienced extreme COVID-19 mortality during the initial wave.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_New_York_City","Each dose carries risk of respiratory depression, overdose, and contaminated supply.","https://en.wikipedia.org/wiki/Heroin"
"Living (one day, age 45)","COVID-19 monovalent vaccine (age 65-79)",9,"COVID-19",0,"11 weeks (2022)",6,"Daily Life",0,"per day",1.5,"hard","a","Monovalent-vaccinated 65-79 year-olds had reduced but still notable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Daily background mortality at age 45 reflects middle-age cardiovascular and cancer risk.","https://en.wikipedia.org/wiki/Mortality_rate"
"Living (one day, age 75)","Caesarean birth (mother)",170,"Medical",0,"per event",105,"Daily Life",0,"per day",1.61904761904762,"hard","a","Major abdominal surgery carrying risks of hemorrhage, infection, and anesthesia complications.","https://en.wikipedia.org/wiki/Caesarean_section","Daily background mortality at age 75 is roughly 100x that of a 20-year-old.","https://en.wikipedia.org/wiki/Mortality_rate"
"Living (one day, age 75)","Scuba diving, trained (yearly)",164,"Sport",0,"per year",105,"Daily Life",0,"per day",1.56190476190476,"hard","a","Cumulative annual risk for trained divers from decompression sickness, drowning, and equipment failure.","https://en.wikipedia.org/wiki/Scuba_diving","Daily background mortality at age 75 is roughly 100x that of a 20-year-old.","https://en.wikipedia.org/wiki/Mortality_rate"
"Living in NYC COVID-19 (Mar-May 2020)","Night in hospital",75,"Medical",0,"per night",50,"COVID-19",0,"per 8 weeks",1.5,"hard","a","Hospital stays carry risk from medical errors, hospital-acquired infections, and underlying illness severity.","https://en.wikipedia.org/wiki/Hospital-acquired_infection","New York City experienced extreme COVID-19 mortality during the initial wave.","https://en.wikipedia.org/wiki/COVID-19_pandemic_in_New_York_City"
"Logging (per work day)","Scuba diving, trained (per dive)",5,"Sport",0,"per dive",3.3,"Occupation",0,"per day",1.51515151515152,"hard","a","Single-dive risk for trained divers from decompression sickness and equipment failure.","https://en.wikipedia.org/wiki/Scuba_diving","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Logging (per work day)","Coronary angiogram (radiation per scan)",5,"Medical",0,"per event",3.3,"Occupation",0,"per day",1.51515151515152,"hard","a","Moderate radiation dose from fluoroscopy-guided cardiac catheterisation.","https://en.wikipedia.org/wiki/Coronary_catheterization","Highest US occupational fatality rate; hazards include falling trees, chainsaw injuries, and terrain.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Motorcycling (60 miles)","Living (one day, under age 1)",15,"Daily Life",0,"per day",10,"Travel",0,"per trip",1.5,"hard","a","Infant mortality from congenital conditions, SIDS, and birth complications.","https://en.wikipedia.org/wiki/Infant_mortality","Per-mile fatality rate roughly 30x higher than car travel due to exposure and instability.","https://en.wikipedia.org/wiki/Motorcycle_safety"
"Normal background radiation","COVID-19 monovalent vaccine (age 18-49)",0.2,"COVID-19",0,"11 weeks (2022)",0.12,"Environment",0,"per year",1.66666666666667,"hard","a","Young adult monovalent-vaccinated COVID-19 mortality was very low.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Average annual radiation dose from natural sources (radon, cosmic, internal, terrestrial).","https://en.wikipedia.org/wiki/Background_radiation"
"Roofing (per work day)","Barium enema (radiation per scan)",3,"Medical",0,"per event",1.9,"Occupation",0,"per day",1.57894736842105,"hard","a","Moderate radiation dose from fluoroscopic imaging of the large intestine.","https://en.wikipedia.org/wiki/Barium_enema","Falls from height are the primary cause of roofing fatalities.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Roofing (per work day)","Rock climbing (per day)",3,"Sport",0,"per day",1.9,"Occupation",0,"per day",1.57894736842105,"hard","a","Risk from falls, rockfall, and equipment failure on natural rock. Per full day of climbing.","https://en.wikipedia.org/wiki/Rock_climbing","Falls from height are the primary cause of roofing fatalities.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Roofing (per work day)","COVID-19 bivalent booster (age 65-79)",3,"COVID-19",0,"11 weeks (2022)",1.9,"Occupation",0,"per day",1.57894736842105,"hard","a","Bivalent-boosted 65-79 year-olds had lowest but still measurable COVID-19 risk.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Falls from height are the primary cause of roofing fatalities.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Scuba diving, trained (per dive)","COVID-19 unvaccinated (age 50-64)",8,"COVID-19",0,"11 weeks (2022)",5,"Sport",0,"per dive",1.6,"hard","a","Unvaccinated 50-64 year-olds had moderately elevated COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Single-dive risk for trained divers from decompression sickness and equipment failure.","https://en.wikipedia.org/wiki/Scuba_diving"
"Shark encounter (ocean swim)","Business traveller (annual cosmic)",0.0375,"Travel",0,"per year",0.06,"Wildlife",100,"per swim",1.6,"hard","b","Moderate annual cosmic radiation from ~40,000 miles of flying per year.","https://en.wikipedia.org/wiki/Cosmic_ray","Shark attack fatality risk per ocean swim, based on ISAF incident data.","https://www.floridamuseum.ufl.edu/shark-attacks/"
"Shark encounter (ocean swim)","Mammogram (radiation per scan)",0.1,"Medical",0,"per event",0.06,"Wildlife",100,"per swim",1.66666666666667,"hard","a","Very low radiation dose used for breast cancer screening; net benefit is strongly positive.","https://en.wikipedia.org/wiki/Mammography","Shark attack fatality risk per ocean swim, based on ISAF incident data.","https://www.floridamuseum.ufl.edu/shark-attacks/"
"Shark encounter (ocean swim)","Chest X-ray (radiation per scan)",0.1,"Medical",0,"per event",0.06,"Wildlife",100,"per swim",1.66666666666667,"hard","a","Very low radiation dose (~0.02 mSv), equivalent to a few hours of background radiation.","https://en.wikipedia.org/wiki/Chest_radiograph","Shark attack fatality risk per ocean swim, based on ISAF incident data.","https://www.floridamuseum.ufl.edu/shark-attacks/"
"Skydiving (per jump)","Living (one day, under age 1)",15,"Daily Life",0,"per day",10,"Sport",0,"per jump",1.5,"hard","a","Infant mortality from congenital conditions, SIDS, and birth complications.","https://en.wikipedia.org/wiki/Infant_mortality","Risk from parachute malfunction, mid-air collision, and landing errors.","https://en.wikipedia.org/wiki/Skydiving"
"Skydiving (US)","Ecstasy/MDMA (per dose)",13,"Drugs",0,"per dose",8,"Sport",0,"per event",1.625,"hard","a","Risk from hyperthermia, serotonin syndrome, and contaminated supply.","https://en.wikipedia.org/wiki/MDMA","US skydiving fatality rate based on USPA incident reports.","https://en.wikipedia.org/wiki/Skydiving"
"Structural iron/steel work (per work day)","Walking (20 miles)",1,"Travel",0,"per trip",1.5,"Occupation",0,"per day",1.5,"hard","b","Pedestrian fatality risk from traffic collisions over a 20-mile walk.","https://en.wikipedia.org/wiki/Pedestrian","Working at height on building frames with fall and struck-by hazards.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Structural iron/steel work (per work day)","COVID-19 unvaccinated (age 18-49)",1,"COVID-19",0,"11 weeks (2022)",1.5,"Occupation",0,"per day",1.5,"hard","b","Young adult unvaccinated COVID-19 mortality was low but non-negligible.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Working at height on building frames with fall and struck-by hazards.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Structural iron/steel work (per work day)","Living 2 months with a smoker",1,"Environment",0,"per 2 months",1.5,"Occupation",0,"per day",1.5,"hard","b","Secondhand smoke exposure increases cardiovascular and respiratory disease risk.","https://en.wikipedia.org/wiki/Passive_smoking","Working at height on building frames with fall and struck-by hazards.","https://www.bls.gov/iif/fatal-injuries-tables.htm"
"Swimming","COVID-19 unvaccinated (all ages)",20,"COVID-19",0,"11 weeks (2022)",12,"Sport",0,"per swim",1.66666666666667,"hard","a","Population-average COVID-19 mortality risk for unvaccinated individuals in 2022.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Drowning risk per swim session, higher for open water and unsupervised settings.","https://en.wikipedia.org/wiki/Drowning"
"Working in an office (8 hours)","COVID-19 bivalent booster (age 18-49)",0.05,"COVID-19",0,"11 weeks (2022)",0.03,"Daily Life",0,"per day",1.66666666666667,"hard","a","Bivalent-boosted young adults had near-baseline COVID-19 mortality.","https://www.cdc.gov/mmwr/volumes/72/wr/mm7206a3.htm","Background mortality rate during sedentary office work.","https://en.wikipedia.org/wiki/Mortality_rate"
"Working in an office (8 hours)","Dental X-ray (radiation per scan)",0.05,"Medical",0,"per event",0.03,"Daily Life",0,"per day",1.66666666666667,"hard","a","Extremely low radiation dose (~0.005 mSv) for dental diagnostics.","https://en.wikipedia.org/wiki/Dental_radiography","Background mortality rate during sedentary office work.","https://en.wikipedia.org/wiki/Mortality_rate"