@font-face {
  font-family: "Rabar";
  src: url("assets/Rabar_038.ttf") format("truetype");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #fbfaf6;
  --paper: #ffffff;
  --soft: #f5f0e8;
  --text: #191714;
  --muted: #696057;
  --line: #e8ded1;
  --coffee: #7b4d28;
  --coffee-strong: #4b2b16;
  --gold: #b5822f;
  --navy: #072b43;
  --shadow: 0 14px 36px rgba(55, 36, 20, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11100e;
  --paper: #1a1714;
  --soft: #231d18;
  --text: #f6efe6;
  --muted: #c4b4a3;
  --line: #3a3028;
  --coffee: #c5925a;
  --coffee-strong: #e4bf8b;
  --gold: #d6a44d;
  --navy: #9fc3dd;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Rabar", Tahoma, "Noto Naskh Arabic", "Segoe UI", Arial, sans-serif;
  line-height: 1.9;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.25rem;
  padding: 0.85rem clamp(1rem, 4vw, 3rem);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  transition: transform 220ms ease, opacity 220ms ease;
  will-change: transform;
}

.topbar.nav-hidden {
  transform: translateY(calc(-100% - 1rem));
  opacity: 0;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--coffee-strong);
  font-weight: 900;
  white-space: nowrap;
}

.brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.topbar nav,
footer nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
}

.topbar nav a,
footer nav a {
  padding: 0.4rem 0.75rem;
  color: var(--muted);
  border-radius: 7px;
}

.topbar nav a:hover,
footer nav a:hover {
  background: var(--soft);
  color: var(--coffee-strong);
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--coffee-strong);
  border-radius: 7px;
  width: 42px;
  height: 42px;
  padding: 0;
  cursor: pointer;
}

.theme-toggle svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-dark {
  display: none;
}

[data-theme="dark"] .theme-light {
  display: none;
}

[data-theme="dark"] .theme-dark {
  display: inline;
}

main {
  width: min(1080px, calc(100% - 2rem));
  margin: 0 auto;
}

.hero {
  min-height: calc(100vh - 73px);
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: clamp(3rem, 8vw, 6rem) 0;
}

.hero-mark {
  width: min(220px, 46vw);
  height: auto;
  margin-bottom: 1.2rem;
}

.eyebrow,
.section-kicker {
  display: inline-block;
  margin: 0 0 0.55rem;
  color: var(--coffee);
  font-weight: 900;
}

.hero h1 {
  margin: 0;
  color: var(--coffee-strong);
  font-size: clamp(2.6rem, 7vw, 5.8rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.hero-text {
  max-width: 760px;
  margin: 1.1rem auto 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.6rem;
}

.primary-action,
.secondary-action,
.daily-panel a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0.55rem 1.05rem;
  border-radius: 7px;
  font-weight: 900;
}

.primary-action,
.daily-panel a {
  background: var(--coffee);
  color: #fffaf2;
}

.secondary-action {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--coffee-strong);
}

.daily-panel,
.feature-card,
.article-list article,
.side-note,
.calculator,
.term-card,
.formation-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.daily-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  padding: clamp(1.2rem, 3vw, 2rem);
}

.daily-panel h2,
.section-title h2 {
  margin: 0;
  color: var(--coffee-strong);
  line-height: 1.35;
  font-size: clamp(1.55rem, 3vw, 2.6rem);
}

.daily-panel p,
.section-title p,
.feature-card span,
.article-list p,
.side-note p,
.term-card p,
.formation-card p,
.calc-field small {
  color: var(--muted);
}

.daily-panel p,
.section-title p,
.article-list p,
.side-note p,
.term-card p,
.formation-card p {
  margin: 0.35rem 0 0;
}

.offer-section,
.content-section {
  padding-top: clamp(3.5rem, 8vw, 6rem);
}

.section-title {
  margin-bottom: 1.1rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.feature-card {
  display: grid;
  gap: 0.4rem;
  padding: 1.25rem;
  transition: transform 160ms ease, border-color 160ms ease;
}

.feature-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--coffee) 55%, var(--line));
}

.feature-card strong,
.article-list h3,
.side-note h3,
.term-card h3,
.formation-card h3,
.calc-field label {
  margin: 0;
  color: var(--coffee-strong);
  line-height: 1.45;
}

.term-card h3 {
  direction: ltr;
  text-align: left;
  font-weight: 800;
}

.search-panel {
  margin-bottom: 1rem;
}

.search-panel input,
.calc-field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--text);
  padding: 0.65rem 0.85rem;
  outline: none;
}

.search-panel input:focus,
.calc-field input:focus {
  border-color: var(--coffee);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--coffee) 18%, transparent);
}

.term-list,
.formation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.term-card,
.formation-card,
.article-list article,
.side-note,
.calculator {
  padding: 1.15rem;
}

.empty-state {
  grid-column: 1 / -1;
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
}

.term-card small,
.formation-card small {
  display: block;
  color: var(--gold);
  font-weight: 900;
}

.formation-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  object-fit: cover;
  border-radius: 7px;
  margin-bottom: 0.85rem;
  background: var(--soft);
}

.open-formation {
  width: 100%;
  min-height: 44px;
  margin-top: 0.9rem;
  border: 1px solid var(--coffee);
  border-radius: 7px;
  background: var(--coffee);
  color: #fffaf2;
  cursor: pointer;
  font-weight: 900;
}

.formation-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 1rem;
  background: rgba(17, 12, 8, 0.58);
}

.formation-modal.open {
  display: grid;
}

.formation-dialog {
  position: relative;
  width: min(900px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
}

.modal-close {
  position: sticky;
  top: 0.8rem;
  float: left;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin: 0.8rem 0 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--coffee-strong);
  cursor: pointer;
}

.modal-close svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.formation-article {
  padding: clamp(1rem, 3vw, 2rem);
}

.formation-hero-image {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--soft);
  margin-bottom: 1rem;
}

.formation-article small {
  display: block;
  color: var(--gold);
  font-weight: 900;
}

.formation-article h2 {
  margin: 0.25rem 0 0.8rem;
  color: var(--coffee-strong);
  font-size: clamp(1.7rem, 4vw, 3rem);
  line-height: 1.2;
  direction: ltr;
  text-align: left;
}

.formation-summary,
.formation-sections section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 1rem;
}

.formation-summary {
  display: grid;
  gap: 0.55rem;
}

.formation-summary p,
.formation-sections p {
  margin: 0;
  color: var(--muted);
}

.formation-sections {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.formation-sections h3 {
  margin: 0 0 0.3rem;
  color: var(--coffee-strong);
}

.mineral-article {
  padding: clamp(1rem, 3vw, 2.2rem);
}

.mineral-hero-image {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 14px;
  background: var(--soft);
  margin-bottom: 1rem;
}

.mineral-article small {
  display: block;
  color: var(--gold);
  font-weight: 900;
}

.mineral-article h2 {
  margin: 0.25rem 0 0.5rem;
  color: var(--coffee-strong);
  direction: ltr;
  text-align: left;
  font-size: clamp(1.7rem, 4vw, 3rem);
}

.mineral-article > p {
  margin: 0 0 1rem;
  color: var(--muted);
}

.mineral-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.mineral-detail-grid div {
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--soft) 68%, var(--paper));
}

.mineral-detail-grid strong,
.mineral-detail-grid span {
  display: block;
}

.mineral-detail-grid strong {
  color: var(--coffee-strong);
}

.mineral-detail-grid span {
  margin-top: 0.15rem;
  color: var(--muted);
  direction: ltr;
  text-align: left;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem;
  align-items: start;
}

.article-list {
  display: grid;
  gap: 1rem;
}

.side-note {
  position: sticky;
  top: 88px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--soft) 70%, transparent), var(--paper));
}

.dictionary-filters,
.calc-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.dictionary-filters {
  margin-bottom: 1rem;
}

.calc-tabs {
  margin-bottom: 1rem;
}

.dictionary-filters button,
.calc-tabs button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  color: var(--muted);
  min-height: 42px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font-weight: 900;
}

.dictionary-filters button.active,
.calc-tabs button.active {
  background: var(--coffee);
  border-color: var(--coffee);
  color: #fffaf2;
}

.calc-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.calc-field label,
.calc-field small {
  display: block;
}

.calc-field small {
  margin-top: 0.2rem;
}

.calc-result {
  display: block;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 7px;
  background: var(--soft);
  color: var(--coffee-strong);
  font-weight: 900;
}

footer {
  width: min(1080px, calc(100% - 2rem));
  margin: clamp(3.5rem, 8vw, 6rem) auto 0;
  padding: 2rem 0;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.5rem;
  align-items: start;
}

footer img {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

footer strong {
  display: block;
  color: var(--coffee-strong);
  font-size: 1.2rem;
}

footer p {
  max-width: 560px;
  margin: 0.25rem 0 0;
  color: var(--muted);
}

h1,
h2,
h3,
p,
a,
span,
button,
input,
small,
strong {
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topbar nav {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .daily-panel,
  .two-column,
  footer {
    grid-template-columns: 1fr;
  }

  .term-list,
  .formation-grid,
  .calc-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .side-note {
    position: static;
  }
}

@media (max-width: 620px) {
  main,
  footer {
    width: min(100% - 1rem, 1080px);
  }

  .topbar {
    padding-inline: 0.75rem;
  }

  .brand img {
    width: 40px;
    height: 40px;
  }

  .topbar nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.2rem;
  }

  .topbar nav a {
    white-space: nowrap;
  }

  .hero {
    min-height: auto;
  }

  .feature-grid,
  .term-list,
  .formation-grid,
  .calc-form {
    grid-template-columns: 1fr;
  }
}

/* Visual refresh */
:root {
  --bg: #f8f4ed;
  --soft: #f1e7d9;
  --text: #181512;
  --muted: #75685e;
  --line: #e2d3c2;
  --coffee: #8b5a32;
  --coffee-strong: #3d2618;
  --gold: #b87925;
  --shadow: 0 18px 45px rgba(69, 42, 22, 0.1);
  --soft-shadow: 0 8px 22px rgba(69, 42, 22, 0.07);
}

[data-theme="dark"] {
  --soft-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

body {
  background:
    linear-gradient(180deg, rgba(139, 90, 50, 0.08), transparent 420px),
    radial-gradient(circle at 100% 0%, rgba(184, 121, 37, 0.14), transparent 360px),
    var(--bg);
}

.topbar {
  top: 0.75rem;
  width: min(1160px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 0.7rem clamp(0.85rem, 2.4vw, 1.35rem);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--soft-shadow);
}

main,
footer {
  width: min(1160px, calc(100% - 2rem));
}

.brand img {
  width: 42px;
  height: 42px;
}

.topbar nav a,
footer nav a,
.theme-toggle,
.primary-action,
.secondary-action,
.dictionary-filters button,
.calc-tabs button,
.search-panel input,
.calc-field input,
.calc-result,
.open-formation {
  border-radius: 10px;
}

.hero {
  min-height: calc(100vh - 86px);
  padding: clamp(3.5rem, 8vw, 6.5rem) 0 clamp(2.5rem, 6vw, 4.5rem);
}

.hero-mark {
  width: min(180px, 42vw);
  filter: drop-shadow(0 18px 28px rgba(61, 38, 24, 0.14));
}

.hero h1 {
  font-size: clamp(2.8rem, 7vw, 6rem);
}

.daily-panel,
.feature-card,
.article-list article,
.side-note,
.calculator,
.term-card,
.formation-card,
.empty-state {
  border-radius: 12px;
  box-shadow: var(--soft-shadow);
}

.feature-card {
  padding: 1.35rem;
}

.term-list,
.formation-grid {
  gap: 1.15rem;
}

.formation-card {
  padding: 0;
  overflow: hidden;
}

.formation-card small,
.formation-card h3,
.formation-card p,
.formation-card .open-formation {
  margin-left: 1.15rem;
  margin-right: 1.15rem;
}

.formation-card small {
  margin-top: 1rem;
}

.formation-card p:last-of-type {
  margin-bottom: 1rem;
}

.formation-image {
  border-radius: 0;
  margin-bottom: 0;
}

.open-formation {
  width: calc(100% - 2.3rem);
  margin-top: 0.3rem;
  margin-bottom: 1.15rem;
}

.formation-modal {
  background: rgba(17, 12, 8, 0.62);
  backdrop-filter: blur(4px);
}

.formation-dialog {
  width: min(960px, 100%);
  max-height: min(90vh, 940px);
  border-radius: 16px;
}

.modal-close {
  border-radius: 10px;
}

.formation-article {
  padding: clamp(1rem, 3vw, 2.2rem);
}

.formation-hero-image {
  max-height: 380px;
  border-radius: 14px;
}

.formation-summary,
.formation-sections section {
  border-radius: 12px;
  background: color-mix(in srgb, var(--soft) 68%, var(--paper));
}

.formation-summary strong {
  color: var(--coffee-strong);
}

.formation-sections h3 {
  direction: ltr;
  text-align: left;
}

.mineral-grid,
.igneous-grid,
.sedimentary-grid,
.metamorphic-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
}

.mineral-card,
.igneous-card,
.sedimentary-card,
.metamorphic-card {
  position: relative;
  overflow: hidden;
  min-height: 170px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--soft-shadow);
  cursor: pointer;
}

.mineral-card:hover,
.igneous-card:hover,
.sedimentary-card:hover,
.metamorphic-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--coffee) 55%, var(--line));
}

.mineral-card:focus-visible,
.igneous-card:focus-visible,
.sedimentary-card:focus-visible,
.metamorphic-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--coffee) 35%, transparent);
  outline-offset: 3px;
}

.mineral-card > img,
.igneous-card > img,
.igneous-card > video,
.sedimentary-card > img,
.metamorphic-card > img {
  width: 100%;
  height: 100%;
  min-height: 170px;
  object-fit: cover;
  background: var(--soft);
}

.mineral-card span,
.igneous-card span,
.sedimentary-card span,
.metamorphic-card span {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 28px;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  color: var(--coffee);
  font-weight: 900;
  direction: ltr;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
}

.mineral-card h3,
.igneous-card h3,
.sedimentary-card h3,
.metamorphic-card h3 {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  margin: 0;
  padding: 1.5rem 0.7rem 0.65rem;
  color: #fffaf2;
  background: linear-gradient(180deg, transparent, rgba(32, 20, 12, 0.84));
  direction: ltr;
  text-align: left;
  font-size: 1rem;
  line-height: 1.2;
}

.minerals-table-card {
  margin-top: 1.1rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--soft-shadow);
}

.rock-chooser {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.rock-chooser button {
  min-height: 58px;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--coffee-strong);
  box-shadow: var(--soft-shadow);
  cursor: pointer;
  font-weight: 900;
  direction: ltr;
}

.rock-chooser button.active {
  border-color: var(--coffee);
  background: var(--coffee);
  color: #fffaf2;
}

.rock-panel {
  display: none;
}

.rock-panel.active {
  display: block;
}

.rock-info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.rock-info-grid article {
  min-height: 190px;
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--soft-shadow);
}

.rock-info-grid span {
  color: var(--gold);
  font-weight: 900;
}

.rock-info-grid h3 {
  margin: 0.35rem 0;
  color: var(--coffee-strong);
  direction: ltr;
  text-align: left;
}

.rock-info-grid p {
  margin: 0;
  color: var(--muted);
}

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

.minerals-table-head h3 {
  margin: 0;
  color: var(--coffee-strong);
}

.minerals-table-head a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  background: var(--coffee);
  color: #fffaf2;
  font-weight: 900;
  white-space: nowrap;
}

.minerals-table-wrap {
  overflow-x: auto;
}

.minerals-table-wrap table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
  direction: ltr;
  text-align: left;
}

.minerals-table-wrap th,
.minerals-table-wrap td {
  padding: 0.68rem 0.75rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  vertical-align: top;
}

.minerals-table-wrap th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, var(--soft) 76%, var(--paper));
  color: var(--coffee-strong);
  font-weight: 900;
}

.minerals-table-wrap td:nth-child(1),
.minerals-table-wrap td:nth-child(2),
.minerals-table-wrap td:nth-child(9) {
  color: var(--coffee-strong);
  font-weight: 900;
}

.minerals-table-wrap tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--soft) 42%, transparent);
}

.minerals-table-wrap tbody tr:last-child td {
  border-bottom: 0;
}

.petrohub-hero {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--soft) 72%, var(--paper));
}

.petrohub-hero img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 10px;
  background: var(--soft);
}

.petrohub-hero h3 {
  margin: 0 0 0.25rem;
  color: var(--coffee-strong);
}

.petrohub-hero h3 span {
  display: inline-block;
  direction: ltr;
  color: var(--gold);
  font-size: 0.9em;
}

.petrohub-hero p,
.petrohub-list p {
  margin: 0.35rem 0 0;
}

.well-tools {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

.well-tools p {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
}

.petrohub-list h3 span {
  display: inline-block;
  direction: ltr;
  color: var(--gold);
  font-size: 0.9em;
}

.field-table {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.field-table > div {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--soft) 74%, var(--paper));
}

.field-table strong,
.field-table span {
  overflow-wrap: anywhere;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.book-card {
  display: grid;
  align-content: start;
  gap: 0.55rem;
  min-height: 250px;
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--soft-shadow);
}

.book-card span {
  width: fit-content;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--coffee) 14%, transparent);
  color: var(--coffee-strong);
  font-weight: 900;
  direction: ltr;
}

.book-card h3 {
  margin: 0;
  color: var(--coffee-strong);
  line-height: 1.4;
}

.book-card p {
  margin: 0;
  color: var(--muted);
}

.book-card a {
  align-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 0.35rem;
  border-radius: 10px;
  background: var(--coffee);
  color: #fffaf2;
  font-weight: 900;
}

.about-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
  align-items: start;
}

.about-panel article,
.contact-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--soft-shadow);
  padding: 1.2rem;
}

.about-panel p,
.about-panel li,
.contact-card dd {
  color: var(--muted);
}

.about-panel h3,
.contact-card h3 {
  margin: 1rem 0 0.35rem;
  color: var(--coffee-strong);
}

.about-panel h3:first-child,
.contact-card h3 {
  margin-top: 0;
}

.about-panel ul {
  margin: 0.5rem 0 0;
  padding: 0 1.2rem 0 0;
}

.contact-card {
  position: sticky;
  top: 6rem;
}

.contact-card p {
  margin: 0 0 0.8rem;
}

.contact-card dl {
  display: grid;
  gap: 0.65rem;
  margin: 0;
}

.contact-card div {
  padding: 0.7rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--soft) 72%, var(--paper));
}

.contact-card dt {
  color: var(--coffee-strong);
  font-weight: 900;
}

.contact-card dd {
  margin: 0.2rem 0 0;
  direction: ltr;
  text-align: left;
}

.contact-card dd.rtl-contact {
  direction: rtl;
  text-align: right;
}

@media (max-width: 720px) {
  .petrohub-hero {
    grid-template-columns: 1fr;
  }

  .mineral-grid,
  .igneous-grid,
  .sedimentary-grid,
  .metamorphic-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .field-table > div {
    grid-template-columns: 1fr;
  }

  .field-table > div:first-child {
    display: none;
  }

  .field-table > div:not(:first-child) {
    gap: 0.35rem;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--paper) 82%, var(--soft));
  }

  .field-table span {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    align-items: center;
    gap: 0.65rem;
    padding: 0.15rem 0;
    direction: rtl;
    text-align: right;
  }

  .field-table span::before {
    content: attr(data-label);
    color: var(--coffee-strong);
    font-weight: 900;
    direction: rtl;
    text-align: right;
  }

  .library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rock-chooser,
  .rock-info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .about-panel {
    grid-template-columns: 1fr;
  }

  .contact-card {
    position: static;
  }
}

@media (max-width: 620px) {
  main,
  footer {
    width: min(100% - 1rem, 1160px);
  }

  .topbar {
    top: 0.5rem;
    width: min(100% - 1rem, 1160px);
  }

  .library-grid {
    grid-template-columns: 1fr;
  }

  .rock-chooser,
  .rock-info-grid,
  .mineral-detail-grid {
    grid-template-columns: 1fr;
  }

  .mineral-card,
  .igneous-card,
  .sedimentary-card,
  .metamorphic-card {
    min-height: 138px;
  }

  .mineral-card > img,
  .igneous-card > img,
  .igneous-card > video,
  .sedimentary-card > img,
  .metamorphic-card > img {
    min-height: 138px;
  }

  .minerals-table-head {
    display: grid;
  }

  .minerals-table-head a {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.18rem;
    padding: 0.48rem 0.6rem 0.44rem;
  }

  .brand {
    min-width: 0;
    gap: 0.45rem;
  }

  .brand img {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
  }

  .brand span {
    overflow: hidden;
    font-size: 0.95rem;
    line-height: 1.2;
    text-overflow: ellipsis;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
  }

  .theme-toggle svg {
    width: 18px;
    height: 18px;
  }

  .topbar nav {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.18rem;
    overflow: visible;
    padding-bottom: 0;
    margin-top: 0.02rem;
  }

  .topbar nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 0.24rem 0.24rem;
    font-size: 0.8rem;
    line-height: 1.28;
    white-space: normal;
    text-align: center;
  }

  .hero {
    padding-top: 2.2rem;
  }

  .hero-mark {
    width: min(132px, 38vw);
    margin-bottom: 0.75rem;
  }

  .eyebrow,
  .section-kicker {
    font-size: 0.9rem;
  }

  .hero h1 {
    font-size: clamp(2rem, 10.5vw, 2.75rem);
    line-height: 1.18;
  }

  .hero-text {
    font-size: 0.96rem;
    line-height: 1.85;
  }
}

@media (max-width: 380px) {
  .brand span {
    font-size: 0.84rem;
  }

  .topbar nav a {
    font-size: 0.78rem;
    padding-inline: 0.42rem;
  }

  .mineral-grid,
  .igneous-grid,
  .sedimentary-grid,
  .metamorphic-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }

  .mineral-card,
  .igneous-card,
  .sedimentary-card,
  .metamorphic-card,
  .mineral-card > img,
  .igneous-card > img,
  .igneous-card > video,
  .sedimentary-card > img,
  .metamorphic-card > img {
    min-height: 126px;
  }

  .mineral-card h3,
  .igneous-card h3,
  .sedimentary-card h3,
  .metamorphic-card h3 {
    font-size: 0.88rem;
    padding: 1.3rem 0.55rem 0.5rem;
  }

  .mineral-card span,
  .igneous-card span,
  .sedimentary-card span,
  .metamorphic-card span {
    min-width: 30px;
    min-height: 24px;
    font-size: 0.78rem;
  }
}

/* Dark mode must come after the visual refresh overrides. */
[data-theme="dark"] {
  --bg: #11100e;
  --paper: #1a1714;
  --soft: #241d18;
  --text: #f6efe6;
  --muted: #c7b6a5;
  --line: #42352b;
  --coffee: #c5925a;
  --coffee-strong: #f0cf9f;
  --gold: #d6a44d;
  --navy: #9fc3dd;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --soft-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

[data-theme="dark"] body {
  background:
    linear-gradient(180deg, rgba(197, 146, 90, 0.08), transparent 420px),
    radial-gradient(circle at 100% 0%, rgba(214, 164, 77, 0.12), transparent 360px),
    var(--bg);
}

[data-theme="dark"] .hero-mark,
[data-theme="dark"] footer img,
[data-theme="dark"] .brand img {
  filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.28));
}
