:root {
  --bg: #120c08; --panel: #22160fcc; --line: #ffffff1f; --text: #fff4e6; --muted: #c9ae93;
  --cyan: #ffb347; --pink: #ff3b6b; --yellow: #ffd84a; --lava: #ff6b3d; --ink: #140904;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#shell { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
[hidden] { display: none !important; }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.screen { position: absolute; inset: 0; }

/* ---------- menu: a drill core through the Earth */
#menu {
  display: grid; grid-template-columns: minmax(250px, 36%) 1fr; gap: 22px;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background:
    radial-gradient(90% 70% at 0% 100%, #ff6b3d22 0%, transparent 60%),
    radial-gradient(70% 60% at 100% 0%, #ffd08a14 0%, transparent 70%),
    repeating-linear-gradient(-8deg, #ffffff05 0 2px, transparent 2px 26px),
    linear-gradient(180deg, #1d130d 0%, #120c08 55%, #1a0905 100%);
}
.menu-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; touch-action: pan-y; padding-right: 4px; }
.eyebrow { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.logo { margin: 2px 0 0; font: 900 clamp(38px, 6.4vw, 72px)/.88 "Arial Black", "Segoe UI Black", Impact, system-ui, sans-serif; letter-spacing: .01em; }
.logo span {
  display: block; color: transparent; -webkit-text-stroke: 2px var(--ink);
  background: repeating-linear-gradient(180deg, #f6d79c 0 .17em, #c98a4e .17em .29em, #8d5a35 .29em .37em, #e7b48d .37em .52em, #6f4a33 .52em .6em);
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(3px 4px 0 var(--ink));
}
.logo em { display: block; font-style: normal; font-size: .56em; letter-spacing: .42em; color: var(--lava); text-shadow: 0 0 18px #ff6b3d99, 2px 3px 0 var(--ink); margin-top: 4px; }
.tagline { margin: 0; color: var(--muted); max-width: 440px; font-size: 13px; line-height: 1.45; }

.descend {
  display: flex; align-items: center; gap: 14px; width: min(100%, 320px); min-height: 62px; margin-top: 6px; padding: 8px 18px 8px 10px;
  font: inherit; text-align: left; color: #2a1102; cursor: pointer;
  background: linear-gradient(180deg, #ffd36b, #ff9a3d); border: 3px solid var(--ink); border-radius: 14px 40px 40px 14px; box-shadow: 0 5px 0 var(--ink);
  transition: transform .12s, box-shadow .12s;
}
.descend:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.descend i { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--ink); position: relative;
  background: conic-gradient(from 0deg, #d7dbe6 0 25%, #8b93a6 0 50%, #d7dbe6 0 75%, #8b93a6 0); animation: spin 1.2s linear infinite; }
.descend i::after { content: ''; position: absolute; inset: 11px; border-radius: 50%; background: #2a1102; }
.descend b { display: block; font-size: 21px; letter-spacing: .02em; }
.descend small { display: block; font-size: 12px; font-weight: 700; opacity: .8; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .descend i { animation: none; } }
.tally { margin: 0; font-size: 12px; color: var(--muted); font-weight: 700; }

.settings { max-width: 440px; }
.settings summary { cursor: pointer; padding: 8px 0; min-height: 40px; font-size: 13px; font-weight: 700; color: var(--text); }
.settings[open] .options { padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.options { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; color: var(--muted); }
.options label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.options input { accent-color: var(--cyan); }
.options button { font: inherit; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; cursor: pointer; }
.options button:disabled { opacity: .6; cursor: wait; }
.options .lang select { font: inherit; font-size: 13px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; }
.options .lang select option { background: #2a1c13; color: var(--text); }
.skins { display: flex; gap: 6px; }
.skin { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #ffffff33; cursor: pointer; padding: 0; }
.skin.on { border-color: #fff; box-shadow: 0 0 10px #fff8; }
footer { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); margin-top: auto; padding-top: 6px; }

/* the core sample: one stratum per world, grouped into crust, mantle and core */
.core-sample {
  min-height: 0; overflow-y: auto; touch-action: pan-y; position: relative;
  border: 3px solid var(--ink); border-radius: 18px; background: #0c0705; box-shadow: inset 0 0 0 2px #ffffff10, 0 6px 0 var(--ink);
}
.zone { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 10px; padding: 7px 14px;
  font-size: 11px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); background: #0c0705ee; border-bottom: 2px solid var(--ink); }
.zone span:last-child { letter-spacing: .05em; opacity: .75; }
.stratum {
  --a: #8d8a7e; --m: #b0aa98; --d: #6f6c63; --g: #9ad1d4;
  position: relative; width: 100%; display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  min-height: 70px; margin-top: -7px; padding: 15px 16px 10px 12px; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer;
  clip-path: polygon(0 7px, 9% 1px, 21% 6px, 36% 0, 52% 7px, 67% 2px, 83% 6px, 100% 0, 100% 100%, 0 100%);
  background:
    linear-gradient(var(--shade, 90deg), #0c0705e0 0%, #0c0705b8 48%, #0c070533 100%),
    radial-gradient(circle at 78% 40%, #ffffff22 0 2px, transparent 3px) 0 0 / 23px 19px,
    radial-gradient(circle at 30% 70%, #00000033 0 3px, transparent 4px) 0 0 / 31px 27px,
    repeating-linear-gradient(-3deg, var(--a) 0 10px, var(--m) 10px 14px, var(--d) 14px 25px);
  transition: filter .12s, padding .12s;
}
.stratum:first-of-type { margin-top: 0; }
.stratum:hover, .stratum:focus-visible { filter: brightness(1.18); outline: none; padding-left: 18px; }
.stratum:focus-visible { box-shadow: inset 4px 0 0 var(--yellow); }
.stratum .sample { width: 44px; height: 44px; display: grid; place-items: center; font-size: 13px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px #000;
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); }
.stratum .info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.stratum .info b { font-size: 16px; overflow-wrap: anywhere; hyphens: auto; text-shadow: 0 1px 2px #000; }
.stratum .info small { color: #e9d9c6; font-size: 12px; text-shadow: 0 1px 2px #000; }
.stratum .result { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; font-size: 12px; font-weight: 800; text-shadow: 0 1px 2px #000; white-space: nowrap; }
.stratum .fossils { color: var(--yellow); letter-spacing: 2px; }
.stratum .bar { width: 72px; height: 6px; border-radius: 3px; background: #00000080; overflow: hidden; border: 1px solid #00000099; }
.stratum .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--g), #fff); }
.stratum.next::before { content: ''; position: absolute; left: 0; top: 7px; bottom: 0; width: 5px; background: var(--yellow); box-shadow: 0 0 12px var(--yellow); }
.stratum.done .info b::after { content: ' ✓'; color: #86efac; }
.tier { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-shadow: 0 1px 2px #000; }
.t1 { color: #86efac; } .t2 { color: #7dd3fc; } .t3 { color: #fde047; } .t4 { color: #fb923c; } .t5 { color: #f472b6; } .t6 { color: #ff3b6b; }

/* ---------- HUD: progress is a vertical bore-hole gauge on the right */
#hud { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 12px; pointer-events: none; }
#hud > * { pointer-events: auto; }
#btn-pause { width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; border: 3px solid var(--ink); background: radial-gradient(circle at 35% 30%, #9a8a7c, #5d5249); color: var(--text); font-weight: 900; cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.hud-title { display: flex; flex-direction: column; min-width: 120px; flex: 1; }
.hud-title b { font-size: 15px; text-shadow: 1px 1px 0 var(--ink), 0 0 6px #000; }
.hud-title span { font-size: 11px; color: var(--muted); text-shadow: 0 0 4px #000; }
.progress {
  position: fixed; right: max(12px, env(safe-area-inset-right)); top: calc(max(10px, env(safe-area-inset-top)) + 56px); bottom: max(46px, env(safe-area-inset-bottom));
  width: 14px; border-radius: 8px; border: 2.5px solid var(--ink); overflow: visible;
  background: repeating-linear-gradient(180deg, #6f4a33 0 10px, #8d5a35 10px 18px, #4e3427 18px 26px);
}
.progress i { position: absolute; left: 0; right: 0; top: 0; height: 0; border-radius: 5px; background: linear-gradient(180deg, #ffd36b, var(--lava)); }
.progress i::after { content: ''; position: absolute; left: 50%; bottom: -9px; width: 18px; height: 18px; transform: translateX(-50%) rotate(45deg); background: #c084fc; border: 2.5px solid var(--ink); border-radius: 3px; }
.progress span { position: absolute; top: 100%; right: -6px; margin-top: 8px; font-size: 11px; font-weight: 900; text-shadow: 1px 1px 0 var(--ink); white-space: nowrap; }
.coins { color: var(--yellow); letter-spacing: 2px; font-size: 15px; text-shadow: 1px 1px 0 var(--ink); margin-right: 26px; }

/* ---------- dialogs: chiselled stone slabs */
.dialog-wrap { display: grid; place-items: center; padding: 10px; background: #0a0503a0; backdrop-filter: blur(4px); }
.dialog {
  min-width: 260px; max-height: 100%; overflow-y: auto; touch-action: pan-y; display: flex; flex-direction: column; gap: 10px; text-align: center; padding: 22px 26px;
  border: 3px solid var(--ink); border-radius: 8px 22px 10px 26px; box-shadow: 0 6px 0 var(--ink);
  background: repeating-linear-gradient(-4deg, #ffffff06 0 2px, transparent 2px 22px), linear-gradient(180deg, #3a2a1f, #24170f);
}
.dialog h2 { margin: 2px 0 6px; font-size: 26px; }
.dialog p { margin: 0 0 6px; color: var(--muted); }
.dialog button { font: inherit; font-weight: 800; padding: 11px 16px; border-radius: 11px; border: 2.5px solid var(--ink); box-shadow: 0 3px 0 var(--ink); background: #ffffff10; color: var(--text); cursor: pointer; }
.dialog button:hover { background: #ffffff1c; }
.dialog button.primary { background: linear-gradient(180deg, #ffd36b, #ff9a3d); color: #2a1102; }
.dialog .fact { max-width: 440px; font-size: 13px; line-height: 1.45; text-align: left; background: #00000030; border-left: 4px solid var(--cyan); border-radius: 6px; padding: 10px 12px; margin: 6px 0 10px; }
.dialog .fact b { color: var(--cyan); }
.dialog.wide { max-width: min(520px, 90vw); }

#toast { position: absolute; left: 50%; top: 70px; transform: translate(-50%, -8px); padding: 8px 16px; border-radius: 10px; background: #22160fe6; border: 2px solid var(--ink);
  font-weight: 800; font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 700px) and (orientation: portrait) {
  #menu { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); overflow-y: auto; }
  .menu-side { overflow: visible; }
  .menu-side footer { display: none; }
}
@media (max-height: 460px) {
  #menu { gap: 14px; }
  .logo { font-size: 34px; }
  .tagline { display: none; }
  .descend { min-height: 52px; }
  .stratum { min-height: 60px; padding-top: 12px; padding-bottom: 8px; }
}
@media (max-width: 640px) {
  .hud-title span { display: none; }
  .stratum .bar { width: 52px; }
}

/* Telegram fullscreen: keep HUD and menu below the client's own controls */
.tg #hud { top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 8px); }
.tg #menu { padding-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 12px); }

#rotate { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center; padding: 24px; background: #120c08e6; z-index: 5; }
#rotate b { font-size: 56px; color: var(--cyan); }
#rotate p { margin: 0; font-weight: 700; }
#rotate button { font: inherit; font-weight: 800; padding: 10px 16px; border-radius: 11px; border: 2.5px solid var(--ink); background: #ffffff14; color: var(--text); box-shadow: 0 3px 0 var(--ink); }

[dir=rtl] .dialog .fact { text-align: right; border-left: 0; border-right: 4px solid var(--cyan); }
[dir=rtl] .stratum { text-align: right; --shade: 270deg; }
[dir=rtl] .stratum .result { align-items: flex-start; }
[dir=rtl] .stratum.next::before { left: auto; right: 0; }
[dir=rtl] .descend { text-align: right; border-radius: 40px 14px 14px 40px; }
[dir=rtl] .progress { right: auto; left: max(12px, env(safe-area-inset-left)); }
[dir=rtl] .coins { margin-right: 0; margin-left: 26px; }
/* room for the AdMob banner under the world menu (apps only) */
.ads #menu { padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
