/*
 * Apple Human Interface Guidelines layer.
 * Loaded after styles.css (Bootstrap 4 / Freelancer) and overrides it with
 * Apple system typography, colours, materials, corner radii and 44pt targets.
 * https://developer.apple.com/design/human-interface-guidelines
 */

:root {
  /* System colours (light appearance) */
  --hig-blue: #007aff;
  --hig-green: #34c759;
  --hig-red: #ff3b30;
  --hig-orange: #ff9500;
  --hig-yellow: #ffcc00;
  --hig-teal: #30b0c7;
  --hig-indigo: #5856d6;

  /* Darker variants for fills that carry white text (WCAG AA) */
  --hig-blue-fill: #0064d2;
  --hig-green-fill: #248a3d;
  --hig-red-fill: #d70015;
  --hig-teal-fill: #0071a4;
  --hig-gray-fill: #636366;

  /* Tinted text on the page background */
  --hig-blue-text: #0064d2;
  --hig-green-text: #248a3d;
  --hig-red-text: #d70015;
  --hig-teal-text: #0071a4;
  --hig-orange-text: #c93400;

  /* Labels */
  --hig-label: #000;
  --hig-label-secondary: rgba(60, 60, 67, 0.6);
  --hig-label-tertiary: rgba(60, 60, 67, 0.3);

  /* Backgrounds (grouped) */
  --hig-bg: #f2f2f7;
  --hig-bg-elevated: #fff;
  --hig-bg-elevated-2: #f2f2f7;
  --hig-fill: rgba(120, 120, 128, 0.12);
  --hig-fill-strong: rgba(120, 120, 128, 0.2);
  --hig-separator: rgba(60, 60, 67, 0.29);
  --hig-bar: rgba(249, 249, 249, 0.8);
  --hig-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
  --hig-focus: var(--hig-focus);

  /* Alert banners: tinted background + readable text */
  --hig-alert-success-bg: rgba(52, 199, 89, 0.15);
  --hig-alert-success-text: #1d6b31;
  --hig-alert-danger-bg: rgba(255, 59, 48, 0.12);
  --hig-alert-danger-text: #a1000f;
  --hig-alert-warning-bg: rgba(255, 149, 0, 0.15);
  --hig-alert-warning-text: #8a4b00;
  --hig-alert-info-bg: rgba(0, 122, 255, 0.1);
  --hig-alert-info-text: #00449e;

  /* Puzzle grid (used by _puzzle_body.html) */
  --puzzle-ink: #000;
  --puzzle-cell-bg: #d4f1f4;
  --puzzle-input-bg: #b8dcd8;
  --puzzle-input-border: #ccc;
  --puzzle-correct-bg: lightgreen;
  --puzzle-correct-ink: green;

  --hig-radius: 12px;
  --hig-radius-small: 10px;
  --hig-target: 44px;

  --hig-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --hig-font-rounded: ui-rounded, "SF Pro Rounded", var(--hig-font);

  /* Re-point Bootstrap's own variables */
  --primary: var(--hig-blue);
  --success: var(--hig-green);
  --danger: var(--hig-red);
  --warning: var(--hig-orange);
  --info: var(--hig-teal);
  --font-family-sans-serif: var(--hig-font);

  color-scheme: light dark;
}

/* ---------- Typography ---------- */

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--hig-font);
  font-size: 17px; /* iOS Body */
  line-height: 1.47;
  letter-spacing: -0.022em;
  color: var(--hig-label);
  background-color: var(--hig-bg);
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
#mainNav {
  font-family: var(--hig-font);
  letter-spacing: -0.02em;
}

/* Large Title: sentence case, not shouty uppercase */
.page-section .page-section-heading {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1.25rem !important;
  text-transform: none !important;
  color: var(--hig-label) !important;
}

@media (min-width: 992px) {
  .page-section .page-section-heading {
    font-size: 40px;
  }
}

.text-uppercase {
  text-transform: none !important;
}

.text-muted,
.text-white-50 {
  color: var(--hig-label-secondary) !important;
}

a {
  color: var(--hig-blue);
}

a:hover {
  color: var(--hig-blue);
  opacity: 0.8;
  text-decoration: none;
}

/* ---------- Navigation bar (translucent material) ---------- */

#mainNav {
  padding: 0 !important;
  min-height: 52px;
  font-weight: 600;
  background-color: var(--hig-bar) !important;
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--hig-separator);
}

#mainNav .navbar-brand {
  color: var(--hig-label) !important;
  font-size: 20px !important;
  font-weight: 700;
  letter-spacing: -0.02em;
  min-height: var(--hig-target);
  display: inline-flex;
  align-items: center;
}

#mainNav .navbar-nav {
  margin-top: 0;
}

#mainNav .navbar-nav li.nav-item .nav-link {
  color: var(--hig-blue) !important;
  font-weight: 500;
  font-size: 17px;
  min-height: var(--hig-target);
  display: flex;
  align-items: center;
  border-radius: var(--hig-radius-small);
  background: none !important;
}

#mainNav .navbar-nav li.nav-item span.nav-link {
  color: var(--hig-label-secondary) !important;
}

#mainNav .navbar-nav li.nav-item .nav-link:hover {
  background-color: var(--hig-fill) !important;
  opacity: 1;
}

#mainNav .navbar-nav li.nav-item .nav-link.active,
#mainNav .navbar-nav > li.nav-item > a.nav-link.active {
  color: var(--hig-label) !important;
  font-weight: 600;
  background-color: var(--hig-fill) !important;
}

/* Pricing call-to-action in the bar */
#mainNav .nav-link.nav-cta {
  color: #fff !important;
  background-color: var(--hig-blue-fill) !important;
  border-radius: 980px;
  padding-left: 1rem !important;
  padding-right: 1rem !important;
}

#mainNav .navbar-toggler {
  min-width: var(--hig-target);
  min-height: var(--hig-target);
  padding: 0;
  font-size: 22px;
  color: var(--hig-blue) !important;
  background: none;
  border: 0;
}

#mainNav .navbar-toggler:focus { outline: none; }

#mainNav .navbar-toggler:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--hig-focus);
  border-radius: var(--hig-radius-small);
}

@media (max-width: 991.98px) {
  #mainNav .navbar-collapse {
    padding-bottom: 0.5rem;
  }
}

/* Home screen app: keep the bar clear of the notch and rounded corners */
#mainNav {
  padding-top: env(safe-area-inset-top) !important;
}

#mainNav > .container-fluid {
  padding-left: max(1.5rem, env(safe-area-inset-left)) !important;
  padding-right: max(1.5rem, env(safe-area-inset-right)) !important;
}

.copyright {
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)) !important;
}

/* ---------- Page sections ---------- */

/* The bright blue section becomes a grouped background */
.page-section {
  padding-top: 6rem;
  padding-bottom: 4rem;
}

.page-section.bg-primary {
  background-color: var(--hig-bg) !important;
  color: var(--hig-label) !important;
}

.page-section.bg-primary label.text-white,
.page-section.bg-primary h3.text-white,
.page-section.bg-primary p.text-white,
.page-section.bg-primary small.text-white {
  color: var(--hig-label) !important;
}

/* Drop the decorative star dividers; spacing does the separating */
div.divider-custom {
  display: none;
}

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

.btn {
  font-family: var(--hig-font);
  font-weight: 600;
  font-size: 17px;
  min-height: var(--hig-target);
  padding: 0.5rem 1.25rem;
  border-radius: var(--hig-radius);
  border-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.btn-sm {
  font-size: 15px;
  min-height: 36px;
  padding: 0.25rem 0.875rem;
  border-radius: var(--hig-radius-small);
}

.btn-lg,
.btn-xl {
  font-size: 17px;
  min-height: 50px;
  padding: 0.75rem 1.75rem;
  border-radius: 14px;
}

.btn:active {
  opacity: 0.7;
}

.btn:focus,
.btn.focus {
  box-shadow: 0 0 0 3px var(--hig-focus) !important;
}

.btn-primary,
.btn-primary:hover,
.btn-primary:not(:disabled):not(.disabled):active {
  background-color: var(--hig-blue-fill);
  color: #fff;
}

.btn-success,
.btn-success:hover,
.btn-success:not(:disabled):not(.disabled):active {
  background-color: var(--hig-green-fill);
  color: #fff;
}

.btn-danger,
.btn-danger:hover,
.btn-danger:not(:disabled):not(.disabled):active {
  background-color: var(--hig-red-fill);
  color: #fff;
}

.btn-info,
.btn-info:hover,
.btn-info:not(:disabled):not(.disabled):active {
  background-color: var(--hig-teal-fill);
  color: #fff;
}

.btn-warning,
.btn-warning:hover,
.btn-warning:not(:disabled):not(.disabled):active {
  background-color: var(--hig-orange);
  color: #000;
}

.btn-secondary,
.btn-secondary:hover,
.btn-secondary:not(:disabled):not(.disabled):active {
  background-color: var(--hig-gray-fill);
  color: #fff;
}

.btn-primary:hover,
.btn-success:hover,
.btn-danger:hover,
.btn-info:hover,
.btn-warning:hover,
.btn-secondary:hover {
  opacity: 0.88;
}

/* Outline buttons become tinted (gray) buttons */
[class*="btn-outline-"] {
  background-color: var(--hig-fill);
  border: 0;
}

.btn-outline-primary { color: var(--hig-blue); }
.btn-outline-secondary { color: var(--hig-label); }
.btn-outline-success { color: var(--hig-green-text); }
.btn-outline-danger { color: var(--hig-red-text); }
.btn-outline-info { color: var(--hig-teal-text); }
.btn-outline-warning { color: var(--hig-orange-text); }

[class*="btn-outline-"]:hover {
  background-color: var(--hig-fill-strong);
}

.btn-outline-primary:hover { color: var(--hig-blue); }
.btn-outline-secondary:hover { color: var(--hig-label); }
.btn-outline-success:hover { color: var(--hig-green-text); }
.btn-outline-danger:hover { color: var(--hig-red-text); }
.btn-outline-info:hover { color: var(--hig-teal-text); }
.btn-outline-warning:hover { color: var(--hig-orange-text); }

.btn-link {
  color: var(--hig-blue);
  font-weight: 400;
}

.btn:disabled,
.btn.disabled {
  opacity: 1;
  background-color: var(--hig-fill);
  color: var(--hig-label-tertiary);
}

/* ---------- Bootstrap 5 utilities used by some templates ---------- */

.d-grid { display: grid !important; }
.gap-2 { gap: 0.5rem !important; }
.text-end { text-align: right !important; }
.me-1 { margin-right: 0.25rem !important; }
.me-2 { margin-right: 0.5rem !important; }
.me-3 { margin-right: 1rem !important; }
.form-label { display: inline-block; margin-bottom: 0.5rem; }
.form-select { min-height: 36px; border-radius: 8px; border: 0; padding: 0 0.5rem;
  background-color: var(--hig-fill); color: var(--hig-label); font-size: 15px; }

/* ---------- Cards (inset grouped) ---------- */

.card {
  border: 0;
  border-radius: var(--hig-radius);
  background-color: var(--hig-bg-elevated);
  box-shadow: var(--hig-shadow);
  overflow: hidden;
  color: var(--hig-label);
}

.card-header {
  border-bottom: 0.5px solid var(--hig-separator);
  font-weight: 600;
  padding: 0.875rem 1.25rem;
}

.card-header:first-child {
  border-radius: var(--hig-radius) var(--hig-radius) 0 0;
}

.card-footer {
  background-color: transparent;
  border-top: 0.5px solid var(--hig-separator);
}

/* ---------- Background / text utilities -> system colours ---------- */

.bg-primary { background-color: var(--hig-blue-fill) !important; }
.bg-success { background-color: var(--hig-green-fill) !important; }
.bg-danger { background-color: var(--hig-red-fill) !important; }
.bg-info { background-color: var(--hig-teal-fill) !important; }
.bg-warning { background-color: var(--hig-orange) !important; }
.bg-secondary { background-color: var(--hig-gray-fill) !important; }
.bg-dark { background-color: #1c1c1e !important; }
.bg-light { background-color: var(--hig-bg) !important; }

.text-primary { color: var(--hig-blue) !important; }
.text-success { color: var(--hig-green-text) !important; }
.text-danger { color: var(--hig-red-text) !important; }
.text-info { color: var(--hig-teal-text) !important; }
.text-warning { color: var(--hig-orange-text) !important; }
.text-secondary { color: var(--hig-label-secondary) !important; }

/* ---------- Badges ---------- */

.badge {
  font-weight: 600;
  border-radius: 980px;
  padding: 0.35em 0.75em;
}

.badge-primary { background-color: var(--hig-blue-fill); }
.badge-success { background-color: var(--hig-green-fill); }
.badge-danger { background-color: var(--hig-red-fill); }
.badge-info { background-color: var(--hig-teal-fill); }
.badge-warning { background-color: var(--hig-orange); color: #000; }
.badge-secondary { background-color: var(--hig-fill); color: var(--hig-label); }

/* ---------- Forms ---------- */

.form-control,
.custom-select {
  font-family: var(--hig-font);
  font-size: 17px;
  min-height: var(--hig-target);
  border: 0;
  border-radius: var(--hig-radius-small);
  background-color: var(--hig-bg-elevated);
  box-shadow: inset 0 0 0 0.5px var(--hig-separator);
  color: var(--hig-label);
}

select.form-control {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23007aff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
}

textarea:not(.form-control) {
  font-family: var(--hig-font);
  font-size: 17px;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: var(--hig-radius-small);
  background-color: var(--hig-bg-elevated);
  color: var(--hig-label);
  box-shadow: inset 0 0 0 0.5px var(--hig-separator);
}

textarea:not(.form-control):focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--hig-focus);
}

.form-control:focus,
.custom-select:focus {
  border: 0;
  box-shadow: 0 0 0 3px var(--hig-focus);
}

.form-control::placeholder {
  color: var(--hig-label-tertiary);
}

label {
  font-weight: 500;
}

/* ---------- Alerts (banners) ---------- */

.alert {
  border: 0;
  border-radius: var(--hig-radius);
  font-size: 15px;
}

.alert-success { background-color: var(--hig-alert-success-bg); color: var(--hig-alert-success-text); }
.alert-danger { background-color: var(--hig-alert-danger-bg); color: var(--hig-alert-danger-text); }
.alert-warning { background-color: var(--hig-alert-warning-bg); color: var(--hig-alert-warning-text); }
.alert-info { background-color: var(--hig-alert-info-bg); color: var(--hig-alert-info-text); }

/* Top-of-page banners from layout.html sit flush under the bar */
body > .alert {
  border-radius: 0;
}

/* ---------- Tables / lists ---------- */

.table {
  color: var(--hig-label);
}

.table td,
.table th {
  border-top: 0.5px solid var(--hig-separator);
  vertical-align: middle;
}

.table thead th {
  border-bottom: 0.5px solid var(--hig-separator);
  font-weight: 600;
  font-size: 13px;
  color: var(--hig-label-secondary);
}

.list-group-item {
  border-color: var(--hig-separator);
  border-width: 0.5px;
  min-height: var(--hig-target);
}

.list-group {
  border-radius: var(--hig-radius-small);
  overflow: hidden;
}

.list-group-item {
  display: flex;
  align-items: center;
}

/* ---------- Segmented control (week switcher) ---------- */

.pagination {
  display: inline-flex;
  padding: 2px;
  border-radius: 9px;
  background-color: var(--hig-fill);
  width: auto;
}

nav > .pagination.divider-custom {
  display: flex;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

.pagination .page-item .page-link {
  border: 0;
  margin: 0;
  min-height: 36px;
  min-width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px !important;
  background: transparent;
  color: var(--hig-label);
  font-size: 15px;
  font-weight: 500;
}

/* The week on screen; layout.html marks it from the address */
.pagination .page-item.active .page-link {
  color: var(--hig-label);
  background-color: var(--hig-segment-selected, var(--hig-bg-elevated));
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
}

.pagination .page-item .page-link:hover {
  opacity: 0.7;
}

/* ---------- Puzzle grid ---------- */

table.table-primary {
  background-color: transparent;
}

#grid {
  background-color: var(--hig-bg-elevated);
  border-radius: var(--hig-radius);
  box-shadow: var(--hig-shadow);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}

/* The wrapper table around #grid adds no padding of its own */
table.table-primary > tbody > tr > td {
  padding: 0;
}

#grid > tbody > tr > td,
#grid td {
  background-color: transparent;
  border: 0;
}

.letter-cell {
  font-family: var(--hig-font-rounded);
  font-weight: 500;
}

.letter-input {
  border-radius: 6px;
  font-family: var(--hig-font-rounded);
}

/* ---------- Week with no words ---------- */

.empty-week {
  max-width: 480px;
}

.empty-week-icon {
  font-size: 40px;
  color: var(--hig-label-secondary);
  margin-bottom: 0.75rem;
}

.empty-week-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.empty-week-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* The empty grid stays, faded, so the page keeps its shape */
.puzzle-empty #grid {
  opacity: 0.35;
}

/* ---------- Modals ---------- */

.modal-content {
  border: 0;
  border-radius: 14px;
  overflow: hidden;
}

.modal-header,
.modal-footer {
  border-color: var(--hig-separator);
}

.modal-backdrop.show {
  opacity: 0.4;
}

/* ---------- Footer ---------- */

.footer {
  padding: 2.5rem 0 1.5rem;
  background-color: var(--hig-bg);
  color: var(--hig-label-secondary);
  border-top: 0.5px solid var(--hig-separator);
}

.footer h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--hig-label-secondary);
}

.footer .lead {
  font-size: 15px;
  color: var(--hig-label);
}

.copyright {
  background-color: var(--hig-bg) !important;
  color: var(--hig-label-secondary) !important;
  font-size: 12px;
}

.scroll-to-top a {
  width: var(--hig-target);
  height: var(--hig-target);
  line-height: var(--hig-target);
  border-radius: 50% !important;
  background-color: rgba(120, 120, 128, 0.32);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

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

:focus-visible {
  outline: 3px solid rgba(0, 122, 255, 0.5);
  outline-offset: 2px;
}

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

@media (prefers-contrast: more) {
  :root {
    --hig-separator: rgba(60, 60, 67, 0.6);
    --hig-label-secondary: rgba(60, 60, 67, 0.85);
  }
}

/* ---------- Dark Mode ----------
 * Follows the system appearance. Tokens switch to Apple's dark system
 * colours; the rest re-points Bootstrap pieces that hard-code light colours.
 */

@media (prefers-color-scheme: dark) {
  :root {
    --hig-blue: #0a84ff;
    --hig-green: #30d158;
    --hig-red: #ff453a;
    --hig-orange: #ff9f0a;
    --hig-yellow: #ffd60a;
    --hig-teal: #40c8e0;
    --hig-indigo: #5e5ce6;

    --hig-blue-fill: #0a84ff;
    --hig-green-fill: #248a3d;
    --hig-red-fill: #d70015;
    --hig-teal-fill: #0071a4;
    --hig-gray-fill: #636366;

    --hig-blue-text: #409cff;
    --hig-green-text: #30d158;
    --hig-red-text: #ff6961;
    --hig-teal-text: #5de6ff;
    --hig-orange-text: #ffb340;

    --hig-label: #fff;
    --hig-label-secondary: rgba(235, 235, 245, 0.6);
    --hig-label-tertiary: rgba(235, 235, 245, 0.3);

    --hig-bg: #000;
    --hig-bg-elevated: #1c1c1e;
    --hig-bg-elevated-2: #2c2c2e;
    --hig-fill: rgba(120, 120, 128, 0.24);
    --hig-fill-strong: rgba(120, 120, 128, 0.36);
    --hig-separator: rgba(84, 84, 88, 0.65);
    --hig-bar: rgba(22, 22, 23, 0.8);
    --hig-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.06);
    --hig-focus: rgba(10, 132, 255, 0.5);
    --hig-segment-selected: #636366;

    --hig-alert-success-bg: rgba(48, 209, 88, 0.18);
    --hig-alert-success-text: #7ee2a0;
    --hig-alert-danger-bg: rgba(255, 69, 58, 0.18);
    --hig-alert-danger-text: #ff9a94;
    --hig-alert-warning-bg: rgba(255, 159, 10, 0.18);
    --hig-alert-warning-text: #ffc66e;
    --hig-alert-info-bg: rgba(10, 132, 255, 0.18);
    --hig-alert-info-text: #8cc4ff;

    --puzzle-ink: #fff;
    --puzzle-cell-bg: #12363c;
    --puzzle-input-bg: #1d4e56;
    --puzzle-input-border: rgba(84, 84, 88, 0.65);
    --puzzle-correct-bg: rgba(48, 209, 88, 0.25);
    --puzzle-correct-ink: #30d158;

    --primary: var(--hig-blue);
    --success: var(--hig-green);
    --danger: var(--hig-red);
    --warning: var(--hig-orange);
    --info: var(--hig-teal);
    --light: #2c2c2e;
    --dark: #f2f2f7;
  }

  body {
    background-color: var(--hig-bg);
    color: var(--hig-label);
  }

  h1, h2, h3, h4, h5, h6,
  .h1, .h2, .h3, .h4, .h5, .h6 {
    color: inherit;
  }

  hr {
    border-top-color: var(--hig-separator);
  }

  code {
    color: #ff7ab2;
  }

  pre,
  pre code {
    color: var(--hig-label);
  }

  /* Surfaces */
  .bg-white { background-color: var(--hig-bg-elevated) !important; }
  .bg-light { background-color: var(--hig-bg-elevated-2) !important; }
  .bg-dark { background-color: #2c2c2e !important; }

  .text-dark,
  .text-body {
    color: var(--hig-label) !important;
  }

  /* Dark text stays dark on the yellow/orange fills */
  .bg-warning.text-dark,
  .bg-warning .text-dark {
    color: #000 !important;
  }

  .border,
  .border-top,
  .border-bottom {
    border-color: var(--hig-separator) !important;
  }

  .card-header:not([class*="bg-"]) {
    background-color: var(--hig-bg-elevated-2);
  }

  .modal-content,
  .dropdown-menu,
  .popover,
  .list-group-item {
    background-color: var(--hig-bg-elevated);
    color: var(--hig-label);
  }

  .dropdown-item {
    color: var(--hig-label);
  }

  .dropdown-item:hover,
  .dropdown-item:focus {
    background-color: var(--hig-fill);
    color: var(--hig-label);
  }

  .close {
    color: var(--hig-label);
    text-shadow: none;
  }

  /* Forms */
  .form-control,
  .custom-select,
  .input-group-text {
    background-color: var(--hig-bg-elevated-2);
    color: var(--hig-label);
  }

  .form-control:focus {
    background-color: var(--hig-bg-elevated-2);
    color: var(--hig-label);
  }

  .form-control:disabled,
  .form-control[readonly] {
    background-color: var(--hig-bg-elevated);
    color: var(--hig-label-secondary);
  }

  select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%230a84ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }

  /* Tables */
  .table {
    color: var(--hig-label);
  }

  .table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(120, 120, 128, 0.08);
  }

  .table-hover tbody tr:hover {
    color: var(--hig-label);
    background-color: var(--hig-fill);
  }

  .table-primary,
  .table-primary > th,
  .table-primary > td {
    background-color: transparent;
    color: var(--hig-label);
  }

  /* Buttons and badges that assume a light page */
  .btn-light {
    background-color: var(--hig-fill);
    color: var(--hig-label);
  }

  .btn-outline-light {
    color: var(--hig-label);
  }

  .btn-outline-primary,
  .btn-outline-primary:hover {
    color: var(--hig-blue-text);
  }

  .badge-light,
  .badge.bg-light {
    color: var(--hig-label);
  }

  .alert-light,
  .alert-secondary {
    background-color: var(--hig-fill);
    color: var(--hig-label);
  }

  .progress {
    background-color: var(--hig-fill);
  }

  /* Puzzle cells: puzzle.js writes light colours inline, so map them here.
     Red and green feedback keep their hue, brightened for the dark page. */
  #grid [style*="color: black"],
  #grid [style*="color:black"] {
    color: var(--puzzle-ink) !important;
  }

  #grid [style*="color: green"],
  #grid [style*="color:green"] {
    color: var(--hig-green) !important;
  }

  #grid [style*="color: red"],
  #grid [style*="color:red"] {
    color: var(--hig-red) !important;
  }

  #grid [style*="#d4f1f4"],
  #grid [style*="212, 241, 244"] {
    background-color: var(--puzzle-cell-bg) !important;
  }

  #grid [style*="#b8dcd8"],
  #grid [style*="184, 220, 216"] {
    background-color: var(--puzzle-input-bg) !important;
  }

  .letter-cell {
    color: var(--puzzle-ink);
  }

  /* QR codes need a light quiet zone to scan */
  img[src*="qr"],
  .qr-code-image {
    background-color: #fff;
  }

  .copyright,
  .footer {
    background-color: var(--hig-bg) !important;
  }
}
