:root {
  --bg: #070911;
  --cave: #10131d;
  --stone: #181b23;
  --stone-2: #242936;
  --panel: rgba(13, 17, 29, .82);
  --panel-2: rgba(32, 36, 49, .78);
  --ink: #fff6dd;
  --muted: #c9c2d7;
  --gold: #f6c64f;
  --gold-hot: #ffe894;
  --purple: #a75cff;
  --blue: #2cb8ff;
  --red: #e05a47;
  --green: #58d68d;
  --board-size: 6;
  --tile-size: 54px;
  --tile-gap: 6px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  background:
    radial-gradient(circle at 16% 18%, rgba(159, 57, 255, .38), transparent 19rem),
    radial-gradient(circle at 88% 28%, rgba(31, 151, 255, .28), transparent 21rem),
    radial-gradient(circle at 50% 5%, rgba(246, 198, 79, .16), transparent 18rem),
    radial-gradient(circle at 50% 110%, rgba(246, 198, 79, .12), transparent 22rem),
    linear-gradient(145deg, #080814 0%, #0d1220 35%, #151321 60%, #080910 100%);
  overscroll-behavior-x: none;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

body::before {
  background:
    conic-gradient(from 215deg at 0% 38%, rgba(111, 55, 175, .22), transparent 18deg, rgba(0, 0, 0, .24) 34deg, transparent 58deg),
    conic-gradient(from 35deg at 100% 42%, rgba(27, 128, 196, .18), transparent 22deg, rgba(0, 0, 0, .26) 42deg, transparent 66deg),
    radial-gradient(ellipse at 8% 55%, rgba(132, 43, 255, .25), transparent 24rem),
    radial-gradient(ellipse at 96% 62%, rgba(0, 177, 255, .2), transparent 22rem),
    linear-gradient(90deg, rgba(255, 255, 255, .03) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, .025) 1px, transparent 1px);
  background-size: auto, auto, auto, auto, 86px 86px, 86px 86px;
  mix-blend-mode: screen;
  opacity: .7;
}

body::after {
  background:
    radial-gradient(circle at 26% 20%, rgba(255, 232, 148, .9) 0 1px, transparent 3px),
    radial-gradient(circle at 72% 16%, rgba(255, 232, 148, .72) 0 1px, transparent 3px),
    radial-gradient(circle at 84% 48%, rgba(79, 199, 255, .42) 0 1px, transparent 3px),
    radial-gradient(circle at 12% 78%, rgba(167, 92, 255, .42) 0 1px, transparent 3px),
    radial-gradient(ellipse at center, transparent 38%, rgba(0, 0, 0, .54) 100%);
  opacity: .88;
}

#app,
.screen,
.modal {
  position: relative;
  z-index: 1;
}

.modal {
  z-index: 5;
}

.effect-layer {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
  contain: layout paint style;
}

.perf-overlay {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 16px));
  padding: 8px 10px;
  border-radius: 6px;
  color: #e8fff8;
  background: rgba(2, 8, 12, .78);
  border: 1px solid rgba(126, 230, 242, .35);
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}

button {
  border: 1px solid rgba(255, 244, 199, .46);
  border-radius: 8px;
  min-height: 44px;
  padding: 0 18px;
  color: #221505;
  background:
    linear-gradient(180deg, #fff0a5 0%, #f6c64f 42%, #c8831d 100%);
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .75),
    inset 0 -2px 0 rgba(112, 62, 12, .52),
    0 4px 0 #744613,
    0 12px 22px rgba(0, 0, 0, .35);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .38);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .14s ease, filter .14s ease, box-shadow .14s ease;
}

button:hover {
  filter: brightness(1.08) saturate(1.08);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .82),
    inset 0 -2px 0 rgba(112, 62, 12, .52),
    0 5px 0 #744613,
    0 0 20px rgba(255, 218, 94, .34),
    0 14px 28px rgba(0, 0, 0, .42);
}

button:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .65),
    inset 0 -1px 0 rgba(112, 62, 12, .5),
    0 2px 0 #744613,
    0 8px 16px rgba(0, 0, 0, .38);
}

button:disabled {
  filter: grayscale(.75);
  opacity: .54;
  cursor: not-allowed;
  transform: none;
}

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 22px calc(18px + var(--safe-bottom));
  overflow-x: hidden;
}

.screen.active { display: block; }

#museumScreen.active {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

#titleScreen {
  place-content: center;
  text-align: center;
  min-height: 100dvh;
}

#titleScreen.active {
  display: grid;
}

#titleScreen::before,
#titleScreen::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff7c8;
  box-shadow:
    0 0 8px #fff7c8,
    0 0 22px rgba(246, 198, 79, .85),
    0 0 44px rgba(167, 92, 255, .5);
  animation: titleSparkle 2.8s ease-in-out infinite;
}

#titleScreen::before {
  top: 17%;
  left: 24%;
}

#titleScreen::after {
  top: 25%;
  right: 19%;
  animation-delay: 1.2s;
}

h1, h2, p { margin: 0; }

h1 {
  position: relative;
  font-size: clamp(3.5rem, 12vw, 8rem);
  line-height: .82;
  color: #ffeaa2;
  background: linear-gradient(180deg, #fff8d1 0%, #ffd95a 30%, #f29b27 54%, #ba63ff 56%, #f2e7ff 74%, #9157ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 2px rgba(6, 8, 15, .88);
  filter:
    drop-shadow(0 3px 0 rgba(39, 18, 8, .95))
    drop-shadow(0 8px 0 rgba(0, 0, 0, .4))
    drop-shadow(0 0 22px rgba(167, 92, 255, .46));
  text-shadow: none;
}

h2 {
  font-size: clamp(1.3rem, 5vw, 2.1rem);
  color: #fff2bd;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35), 0 0 14px rgba(167, 92, 255, .28);
}

.tagline {
  max-width: 650px;
  margin: 20px auto 24px;
  color: #efe8ff;
  font-size: 1.08rem;
  font-weight: 750;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .72);
}

.title-art {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 92px;
  margin-bottom: 18px;
  filter: drop-shadow(0 0 18px rgba(167, 92, 255, .28));
}

.title-art .mineral-icon {
  width: 72px;
  height: 72px;
}

.title-art .mineral-icon:nth-child(2),
.title-art .mineral-icon:nth-child(4) {
  transform: translateY(10px);
}

.mineral-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  place-items: center;
  width: 58px;
  height: 58px;
  line-height: 0;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .42));
}

.mineral-sprite {
  display: block;
  width: 94%;
  height: 94%;
  object-fit: contain;
  margin: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center;
}

.mineral-fallback {
  display: none;
  width: 100%;
  height: 100%;
  background-image: url("assets/mineral_tiles_48.png");
  background-repeat: no-repeat;
  background-size: 500% 500%;
  background-position: calc(var(--sprite-col) * 25%) calc(var(--sprite-row) * 25%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.mineral-icon.sprite-missing .mineral-fallback {
  display: block;
}

.mineral-icon.sprite-missing .mineral-sprite {
  display: none;
}

.mineral-lock {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #f7f1de;
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 3px 5px rgba(0, 0, 0, .55);
}

.menu-buttons {
  display: grid;
  grid-template-columns: minmax(180px, 270px);
  justify-content: center;
  gap: 12px;
  width: min(100%, 350px);
  margin: 0 auto;
  padding: 18px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(35, 28, 48, .86), rgba(10, 13, 22, .9)),
    radial-gradient(circle at 50% 0, rgba(246, 198, 79, .16), transparent 70%);
  border: 1px solid rgba(255, 232, 172, .2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .08),
    inset 0 -14px 28px rgba(0, 0, 0, .32),
    0 22px 60px rgba(0, 0, 0, .46),
    0 0 40px rgba(167, 92, 255, .18);
  backdrop-filter: blur(8px);
}

.danger {
  color: #fff2e9;
  background: linear-gradient(180deg, #ff9b83 0%, #e05a47 56%, #8f2e27 100%);
  border-color: rgba(255, 218, 206, .45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .55),
    inset 0 -2px 0 rgba(96, 24, 20, .54),
    0 4px 0 #70251f,
    0 12px 22px rgba(0, 0, 0, .35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}

.save-hint {
  min-height: 24px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 700;
  text-shadow: 0 2px 9px rgba(0, 0, 0, .75);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(28, 32, 45, .82), rgba(10, 13, 22, .72));
  border: 1px solid rgba(214, 198, 255, .14);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .07),
    0 12px 32px rgba(0, 0, 0, .25);
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.icon-btn { width: 46px; padding: 0; font-size: 1.35rem; }
.small-btn { min-height: 40px; padding: 0 13px; }

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.hud div,
.collect-panel {
  background:
    linear-gradient(180deg, rgba(35, 40, 54, .84), rgba(12, 15, 25, .78));
  border: 1px solid rgba(198, 177, 255, .16);
  border-radius: 8px;
  padding: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .06),
    inset 0 -10px 18px rgba(0, 0, 0, .18),
    0 8px 22px rgba(0, 0, 0, .22);
}

.hud div {
  position: relative;
  overflow: hidden;
}

.hud div::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, rgba(255, 232, 148, .08), transparent);
  opacity: .55;
  pointer-events: none;
}

.hud span {
  display: block;
  color: #d9d1ed;
  font-size: .75rem;
  text-transform: uppercase;
  font-weight: 900;
}

.hud strong {
  display: inline-block;
  font-size: 1.35rem;
  color: #fff4bf;
  text-shadow: 0 0 12px rgba(246, 198, 79, .26);
}

.hud strong.score-pop { animation: scorePop .34s ease-out; }

.rush-timer-bar {
  display: none;
  height: 11px;
  width: min(520px, 100%);
  margin: -2px auto 10px;
  border-radius: 999px;
  border: 1px solid rgba(126, 230, 242, .28);
  background: rgba(3, 8, 16, .62);
  overflow: hidden;
  box-shadow:
    inset 0 1px 4px rgba(0, 0, 0, .5),
    0 0 14px rgba(44, 184, 255, .12);
}

.rush-timer-bar.active {
  display: block;
}

.rush-timer-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green), var(--gold-hot));
  transition: width .12s linear, background .18s ease;
}

.rush-timer-bar.low span {
  background: linear-gradient(90deg, #ffcb5a, #ff8f3d);
}

.rush-timer-bar.critical span {
  background: linear-gradient(90deg, #ff7b5c, var(--red));
  animation: rushPulse .7s ease-in-out infinite alternate;
}

.controls-hint {
  margin: -3px auto 8px;
  color: #f0e8ff;
  font-size: .9rem;
  font-weight: 800;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .72);
}

.collect-panel {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 9px;
}

.collect-panel.active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: start;
}

.collect-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  min-width: 190px;
  max-width: 100%;
  min-height: 34px;
  padding: 5px 9px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(0, 0, 0, .12));
  border: 1px solid rgba(255, 232, 148, .12);
  font-weight: 900;
  color: #fff6dd;
}

.collect-item span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collect-item .mini {
  display: inline-flex;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

.board {
  --gap: var(--tile-gap);
  --tile-size: clamp(48px, calc(65vmin / var(--board-size)), 74px);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  grid-auto-rows: var(--tile-size);
  gap: var(--gap);
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: calc(var(--gap) + 6px);
  border-radius: 12px;
  background:
    linear-gradient(145deg, #35313a 0%, #141821 42%, #090b10 100%);
  border: 1px solid rgba(255, 230, 164, .18);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .06),
    inset 0 -18px 38px rgba(0, 0, 0, .46),
    0 18px 44px rgba(0, 0, 0, .48),
    0 0 38px rgba(80, 158, 255, .12);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.board.board-pulse {
  animation: boardPulse .28s ease-out;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--tile-size);
  height: var(--tile-size);
  min-height: 0;
  padding: 0;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 255, 255, .08), transparent 42%),
    linear-gradient(145deg, #3a3940 0%, #22242c 45%, #0f1117 100%);
  border: 1px solid rgba(255, 233, 181, .14);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .08),
    inset 0 -4px 8px rgba(0, 0, 0, .48),
    0 2px 0 rgba(0, 0, 0, .55);
  transition: transform .12s ease, opacity .16s ease;
  contain: layout paint;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 7px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, .06), rgba(0, 0, 0, .2));
  box-shadow:
    inset 0 2px 5px rgba(255, 255, 255, .05),
    inset 0 -6px 10px rgba(0, 0, 0, .34);
  pointer-events: none;
}

.tile:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .12),
    inset 0 -4px 8px rgba(0, 0, 0, .48),
    0 2px 0 rgba(0, 0, 0, .55),
    0 0 16px rgba(167, 92, 255, .22);
}

.tile.selected {
  outline: 2px solid rgba(255, 244, 194, .98);
  outline-offset: -3px;
  transform: translateY(-2px) scale(1.035);
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 232, 148, .18), transparent 62%),
    radial-gradient(circle at 50% 20%, rgba(255, 255, 255, .1), transparent 42%),
    linear-gradient(145deg, #3d3b44 0%, #252936 45%, #11131a 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .14),
    inset 0 -4px 8px rgba(0, 0, 0, .44),
    0 0 0 4px rgba(246, 198, 79, .18),
    0 0 24px rgba(246, 198, 79, .48),
    0 0 38px rgba(167, 92, 255, .28);
  animation: selectedPulse 1s ease-in-out infinite alternate;
}

.orientation-note {
  display: none;
  margin: 9px auto 0;
  color: #fff2bd;
  font-size: .78rem;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 2px 9px rgba(0, 0, 0, .72);
}

.tile.matched {
  opacity: 0;
  transform: scale(.5) rotate(10deg);
  animation: matchPulse .16s ease-out;
}

.tile.match-big {
  animation-name: matchPulseBig;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .18),
    inset 0 -4px 8px rgba(0, 0, 0, .36),
    0 0 18px rgba(126, 230, 242, .28);
}

.tile.match-huge {
  animation-name: matchPulseHuge;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .22),
    inset 0 -4px 8px rgba(0, 0, 0, .34),
    0 0 22px rgba(255, 232, 148, .3);
}

.tile.invalid {
  animation: invalidShake .14s ease-in-out 2;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 100, 80, .32), transparent 52%),
    linear-gradient(145deg, #463139 0%, #25181d 60%, #100c11 100%);
}

.match-sparkle,
.float-score {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 4;
  pointer-events: none;
  user-select: none;
  contain: layout paint style;
}

.match-sparkle {
  width: var(--spark-size, 5px);
  height: var(--spark-size, 5px);
  border-radius: 50%;
  background: var(--spark-color, #ffe894);
  box-shadow:
    0 0 6px var(--spark-color, #ffe894),
    0 0 11px rgba(255, 255, 255, .2);
  transform: translate(-50%, -50%);
  animation: sparkleBurst .58s cubic-bezier(.16, .84, .24, 1) forwards;
}

.match-sparkle::after {
  content: "";
  position: absolute;
  inset: -3px;
  background: linear-gradient(90deg, transparent 42%, currentColor 48% 52%, transparent 58%),
              linear-gradient(0deg, transparent 42%, currentColor 48% 52%, transparent 58%);
  color: var(--spark-color, #ffe894);
  opacity: .85;
  transform: rotate(45deg);
}

.modal-sparkle {
  z-index: 6;
}

.float-score {
  width: max-content;
  max-width: calc(100vw - 16px);
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff8d4;
  background: rgba(12, 15, 24, .42);
  border: 1px solid rgba(255, 232, 148, .26);
  font-size: clamp(.86rem, 3.8vw, 1.14rem);
  font-weight: 1000;
  letter-spacing: 0;
  text-shadow:
    0 2px 8px rgba(0, 0, 0, .8),
    0 0 13px rgba(246, 198, 79, .72);
  transform: translate(-50%, -50%);
  animation: floatScore .74s ease-out forwards;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.float-score.big {
  color: #dffbff;
  border-color: rgba(126, 230, 242, .36);
  text-shadow:
    0 2px 8px rgba(0, 0, 0, .82),
    0 0 14px rgba(126, 230, 242, .78);
}

.float-score.huge,
.float-score.cascade {
  color: #fff1a8;
  border-color: rgba(199, 144, 255, .42);
  text-shadow:
    0 2px 8px rgba(0, 0, 0, .82),
    0 0 16px rgba(167, 92, 255, .72),
    0 0 20px rgba(246, 198, 79, .48);
}

.float-score.cascade {
  font-size: clamp(.78rem, 3.4vw, 1.02rem);
  background: rgba(34, 25, 50, .5);
}

.tile .mineral-icon {
  position: absolute;
  z-index: 1;
  inset: 50% auto auto 50%;
  width: calc(var(--tile-size) * .94);
  height: calc(var(--tile-size) * .94);
  transform: translate(-50%, -50%);
}

.tile .mineral-sprite,
.cell .mineral-sprite,
.board-tile .mineral-sprite {
  max-width: 100%;
  max-height: 100%;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 7px;
  background: linear-gradient(135deg, rgba(255, 255, 255, .12), transparent 28%, transparent 74%, rgba(0, 0, 0, .26));
  pointer-events: none;
}

.tile.special-cleavage-h,
.tile.special-cleavage-v,
.tile.special-prismatic {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .14),
    inset 0 -4px 8px rgba(0, 0, 0, .42),
    0 0 0 2px rgba(126, 230, 242, .26),
    0 0 16px rgba(126, 230, 242, .2);
}

.cleavage-line-mark {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 78%;
  height: 5px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .98) 18%, #7ee6f2 50%, rgba(255, 255, 255, .98) 82%, transparent);
  box-shadow:
    0 0 8px rgba(126, 230, 242, .72),
    0 0 13px rgba(255, 232, 148, .28);
  opacity: .95;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.special-cleavage-v .cleavage-line-mark {
  width: 5px;
  height: 78%;
  background:
    linear-gradient(180deg, transparent, rgba(255, 255, 255, .98) 18%, #7ee6f2 50%, rgba(255, 255, 255, .98) 82%, transparent);
}

.tile.special-prismatic {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .16),
    inset 0 -4px 8px rgba(0, 0, 0, .36),
    0 0 0 2px rgba(255, 232, 148, .3),
    0 0 18px rgba(199, 144, 255, .28);
}

.prismatic-mark {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 74%;
  height: 74%;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .88);
  background:
    conic-gradient(from 18deg, rgba(255, 232, 148, .92), rgba(126, 230, 242, .88), rgba(199, 144, 255, .9), rgba(255, 145, 180, .84), rgba(255, 232, 148, .92));
  box-shadow:
    0 0 9px rgba(255, 255, 255, .36),
    0 0 14px rgba(199, 144, 255, .34);
  opacity: .72;
  mix-blend-mode: screen;
  pointer-events: none;
}

.prismatic-mark::after {
  content: "";
  position: absolute;
  inset: 23%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 0 8px rgba(255, 255, 255, .62);
}

.tile.special-forming {
  transform: scale(1.05);
  animation: specialForm .18s ease-out;
}

.tile.line-cleared {
  animation: lineClearFlash .18s ease-out;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .18),
    inset 0 -4px 8px rgba(0, 0, 0, .34),
    0 0 18px rgba(126, 230, 242, .35);
}

.tile.prismatic-cleared {
  animation: prismaticClearFlash .2s ease-out;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .2),
    inset 0 -4px 8px rgba(0, 0, 0, .28),
    0 0 20px rgba(199, 144, 255, .38);
}

.float-score.line-clear,
.float-score.tutorial-toast,
.float-score.prismatic-clear {
  color: #dffbff;
  border-color: rgba(126, 230, 242, .38);
  text-shadow:
    0 2px 8px rgba(0, 0, 0, .82),
    0 0 14px rgba(126, 230, 242, .74);
}

.float-score.prismatic-clear {
  color: #fff1a8;
  border-color: rgba(199, 144, 255, .44);
  text-shadow:
    0 2px 8px rgba(0, 0, 0, .82),
    0 0 16px rgba(199, 144, 255, .74),
    0 0 22px rgba(255, 232, 148, .48);
}

.float-score.rush-time {
  color: #dffbff;
  border-color: rgba(88, 214, 141, .38);
  text-shadow:
    0 2px 8px rgba(0, 0, 0, .82),
    0 0 14px rgba(88, 214, 141, .72);
}

.float-score.tutorial-toast {
  width: min(300px, calc(100vw - 28px));
  max-width: min(300px, calc(100vw - 28px));
  white-space: normal;
  text-align: center;
  line-height: 1.18;
  font-size: clamp(.76rem, 3.2vw, .92rem);
}

.museum-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 14px;
  align-items: stretch;
  padding-bottom: calc(18px + var(--safe-bottom));
  touch-action: pan-y;
}

.museum-progress {
  width: 100%;
  height: 10px;
  margin: 0 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 232, 148, .24);
  background: rgba(0, 0, 0, .28);
  overflow: hidden;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .38);
}

.museum-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--gold-hot));
  transition: width .28s ease;
}

.specimen {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
  min-height: 188px;
  padding: 12px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(38, 32, 48, .9), rgba(15, 14, 20, .94));
  border: 1px solid rgba(255, 224, 160, .22);
  text-align: center;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .06),
    0 12px 28px rgba(0, 0, 0, .26);
  color: var(--ink);
  cursor: pointer;
  min-height: 188px;
  width: 100%;
  transform: none;
  touch-action: pan-y;
}

.specimen:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.specimen.recent {
  border-color: rgba(255, 232, 148, .68);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .08),
    0 14px 28px rgba(0, 0, 0, .3),
    0 0 22px rgba(246, 198, 79, .25);
}

.new-badge {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 1;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  color: #231605;
  background: linear-gradient(180deg, #fff4b5, #f6c64f);
  border: 1px solid rgba(255, 255, 255, .5);
  font-size: .68rem;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.pedestal {
  display: grid;
  place-items: center;
  height: 96px;
  margin-bottom: 0;
  border-radius: 8px 8px 3px 3px;
  border-bottom: 10px solid #6d5238;
  background:
    radial-gradient(circle at 50% 25%, rgba(167, 92, 255, .18), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(0, 0, 0, .2));
}

.pedestal .mineral-icon {
  width: 76px;
  height: 76px;
}

.specimen.locked .mineral-icon {
  filter: grayscale(1);
  opacity: .72;
}

.specimen.locked {
  background: linear-gradient(180deg, rgba(28, 29, 38, .9), rgba(12, 13, 18, .94));
  border-color: rgba(205, 212, 230, .14);
}

.plaque {
  display: inline-block;
  width: 100%;
  min-height: 30px;
  padding: 6px;
  border-radius: 4px;
  color: #241704;
  background: linear-gradient(180deg, #f4d06b, #b8822e);
  border: 1px solid rgba(255, 244, 199, .36);
  font-size: .82rem;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
  overflow-wrap: anywhere;
}

.info {
  color: #d2c9e5;
  font-size: .78rem;
  line-height: 1.35;
  display: grid;
  gap: 4px;
  align-content: start;
}

.info small {
  justify-self: center;
  padding: 3px 7px;
  border-radius: 999px;
  color: #dffbff;
  background: rgba(126, 230, 242, .12);
  border: 1px solid rgba(126, 230, 242, .18);
  font-size: .68rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(5px);
}

.modal.hidden { display: none; }

.modal-card {
  width: min(420px, 100%);
  max-height: calc(100dvh - 40px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  padding: 24px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 248, 218, .98), rgba(233, 218, 184, .98));
  color: #15100a;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, .42);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, .48),
    0 0 36px rgba(167, 92, 255, .24);
  animation: modalPop .24s cubic-bezier(.2, 1.1, .32, 1) both;
}

.modal.complete .modal-card,
.modal.unlock .modal-card {
  border-color: rgba(255, 232, 148, .72);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, .5),
    0 0 34px rgba(246, 198, 79, .38),
    0 0 54px rgba(126, 230, 242, .18);
}

.modal.fail .modal-card {
  border-color: rgba(255, 188, 158, .58);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, .48),
    0 0 28px rgba(224, 90, 71, .18);
}

.modal.rush-summary .modal-card {
  border-color: rgba(126, 230, 242, .5);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, .48),
    0 0 30px rgba(44, 184, 255, .22),
    0 0 46px rgba(246, 198, 79, .14);
}

.rush-summary-content .modal-lede {
  color: #2b1906;
  font-size: 1.05rem;
}

.modal-body,
.modal-card p { color: #3b3123; }

.modal-body {
  margin: 12px 0 20px;
}

.modal-lede {
  margin: 0 0 14px;
  font-weight: 800;
  line-height: 1.35;
}

.modal-content {
  display: grid;
  gap: 14px;
}

.modal-progress-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(50, 34, 14, .08);
  border: 1px solid rgba(90, 58, 20, .16);
}

.modal-stat-row,
.modal-goal-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .44);
  border: 1px solid rgba(111, 81, 38, .12);
  text-align: left;
}

.modal-stat-row {
  grid-template-columns: 1fr auto;
}

.modal-stat-row span,
.modal-goal-row span {
  font-weight: 900;
}

.modal-stat-row strong,
.modal-goal-row strong {
  color: #241704;
}

.modal-stat-row.complete,
.modal-goal-row.complete {
  border-color: rgba(57, 130, 82, .28);
  background: rgba(88, 214, 141, .13);
}

.modal-goal-icon {
  width: 36px;
  height: 36px;
}

.reward-specimen {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 14px 12px;
  border-radius: 8px;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 24%, rgba(255, 232, 148, .3), transparent 42%),
    linear-gradient(180deg, rgba(33, 31, 48, .94), rgba(12, 14, 23, .98));
  border: 1px solid rgba(255, 232, 148, .36);
}

.reward-label {
  color: var(--gold-hot);
  font-size: .78rem;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.reward-sprite .mineral-icon,
.reward-icon {
  width: 92px;
  height: 92px;
}

.reward-specimen h3 {
  margin: 0;
  color: #fff8dc;
  font-size: 1.18rem;
}

.reward-specimen p,
.reward-meta {
  margin: 0;
  color: #d9d2ea;
  font-weight: 800;
  line-height: 1.3;
}

.reward-meta {
  font-size: .76rem;
  opacity: .9;
}

.specimen-detail {
  position: relative;
  display: grid;
  gap: 14px;
  justify-items: center;
}

.detail-badge {
  position: static;
  justify-self: center;
}

.detail-sprite {
  display: grid;
  place-items: center;
  width: min(180px, 64vw);
  aspect-ratio: 1;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 35%, rgba(126, 230, 242, .18), transparent 56%),
    linear-gradient(180deg, rgba(25, 25, 38, .94), rgba(9, 11, 18, .98));
  border: 1px solid rgba(255, 232, 148, .24);
}

.detail-icon,
.detail-sprite .mineral-icon {
  width: min(126px, 46vw);
  height: min(126px, 46vw);
}

.detail-fields {
  width: 100%;
  display: grid;
  gap: 8px;
  text-align: left;
}

.detail-fields div {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .45);
  border: 1px solid rgba(111, 81, 38, .12);
}

.detail-fields span {
  color: #6f542e;
  font-size: .72rem;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.detail-fields strong {
  color: #241704;
  overflow-wrap: anywhere;
}

.detail-note {
  margin: 0;
  line-height: 1.38;
  font-weight: 800;
}

.locked-detail .detail-sprite {
  opacity: .82;
}

.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.modal-actions button.primary {
  flex-grow: 1.5;
}

.modal-actions button.secondary {
  background: linear-gradient(180deg, #efe7ff, #c8b8ef);
  border-color: rgba(255, 255, 255, .48);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .75),
    inset 0 -2px 0 rgba(73, 57, 116, .45),
    0 4px 0 #54417a,
    0 12px 22px rgba(0, 0, 0, .32);
}

.settings-card {
  text-align: left;
}

.modal.dev-menu .modal-card {
  width: min(330px, calc(100vw - 26px));
}

.dev-level-input {
  display: block;
  width: min(180px, 100%);
  min-height: 44px;
  margin: 10px auto 0;
  border: 1px solid rgba(55, 38, 14, .24);
  border-radius: 8px;
  padding: 0 12px;
  text-align: center;
  font: inherit;
  font-weight: 1000;
  color: #2b1906;
  background: rgba(255, 255, 255, .72);
}

.settings-card h2 {
  text-align: center;
  color: #2b1906;
  text-shadow: none;
}

.music-toggle-btn {
  width: 100%;
  margin-top: 14px;
}

.volume-row {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: #261805;
  font-weight: 900;
}

.volume-row span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.volume-row input {
  width: 100%;
  accent-color: var(--gold);
}

.settings-note {
  font-size: .86rem;
  line-height: 1.35;
  text-align: center;
}

@keyframes selectedPulse {
  from { transform: translateY(-2px) scale(1.025); }
  to { transform: translateY(-2px) scale(1.045); }
}

@keyframes invalidShake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-5px) rotate(-1.5deg); }
  48% { transform: translateX(4px) rotate(1.2deg); }
  72% { transform: translateX(-2px) rotate(-.7deg); }
}

@keyframes matchPulse {
  0% { opacity: 1; transform: scale(1); }
  55% { opacity: .92; transform: scale(1.11); }
  100% { opacity: 0; transform: scale(.5) rotate(10deg); }
}

@keyframes matchPulseBig {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: .96; transform: scale(1.17) rotate(-2deg); }
  100% { opacity: 0; transform: scale(.48) rotate(11deg); }
}

@keyframes matchPulseHuge {
  0% { opacity: 1; transform: scale(1); }
  46% { opacity: .98; transform: scale(1.24) rotate(2deg); }
  100% { opacity: 0; transform: scale(.45) rotate(13deg); }
}

@keyframes boardPulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

@keyframes specialForm {
  0% { transform: scale(.86); opacity: .9; }
  65% { transform: scale(1.08); }
  100% { transform: scale(1.02); opacity: 1; }
}

@keyframes lineClearFlash {
  0% { transform: scale(.96); opacity: .94; }
  48% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(.55); opacity: 0; }
}

@keyframes prismaticClearFlash {
  0% { transform: scale(.94); opacity: .96; }
  45% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(.48) rotate(12deg); opacity: 0; }
}

@keyframes sparkleBurst {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.5) rotate(0deg); }
  70% { opacity: .9; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -24px))) scale(.12) rotate(95deg); }
}

@keyframes floatScore {
  0% { opacity: 0; transform: translate(-50%, -38%) scale(.85); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(.94); }
}

@keyframes modalPop {
  0% { opacity: 0; transform: translateY(12px) scale(.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes scorePop {
  0% { transform: scale(1); color: var(--ink); }
  45% { transform: scale(1.16); color: #ffe08a; }
  100% { transform: scale(1); color: #fff4bf; }
}

@keyframes rushPulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.28);
  }
}

@keyframes titleSparkle {
  0%, 100% { opacity: .28; transform: scale(.75) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.35) rotate(45deg); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .float-score {
    animation: none !important;
    opacity: 1;
    transform: translate(-50%, -50%);
  }

  .board.board-pulse {
    animation: none !important;
  }
}

@media (max-width: 640px) {
  body::before {
    opacity: .38;
    background:
      radial-gradient(ellipse at 10% 54%, rgba(132, 43, 255, .18), transparent 20rem),
      radial-gradient(ellipse at 96% 62%, rgba(0, 177, 255, .16), transparent 18rem);
    mix-blend-mode: normal;
  }

  .menu-buttons,
  .modal {
    backdrop-filter: none;
  }

  .mineral-icon,
  .mineral-sprite {
    filter: none;
  }

  :root {
    --tile-size: min(12.2vw, 48px);
    --tile-gap: 4px;
  }
  .screen {
    width: 100%;
    padding: calc(10px + var(--safe-top)) 10px calc(12px + var(--safe-bottom));
  }
  #titleScreen {
    align-content: start;
    gap: 8px;
    padding-top: calc(18px + var(--safe-top));
    overflow-y: auto;
  }
  h1 {
    max-width: 100%;
    font-size: clamp(3rem, 18vw, 5.3rem);
    line-height: .86;
    overflow-wrap: anywhere;
  }
  h2 { font-size: clamp(1.08rem, 5vw, 1.45rem); }
  .tagline {
    max-width: 31rem;
    margin: 8px auto 10px;
    font-size: .92rem;
    line-height: 1.3;
  }
  .menu-buttons {
    width: min(100%, 320px);
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
    padding: 12px;
  }
  .menu-buttons button { width: 100%; }
  #gameScreen.active {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }
  .topbar {
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
    padding: 8px;
  }
  .topbar > div:nth-child(2) {
    min-width: 0;
    flex: 1 1 auto;
  }
  .topbar p {
    margin-top: 2px;
    font-size: .76rem;
    line-height: 1.2;
  }
  .topbar-actions {
    flex: 0 0 auto;
    flex-direction: column;
    gap: 6px;
  }
  .small-btn {
    min-height: 36px;
    padding: 0 9px;
    font-size: .78rem;
  }
  .icon-btn {
    width: 40px;
    min-height: 40px;
  }
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 6px;
  }
  .hud div { padding: 6px 7px; }
  .hud span { font-size: .64rem; }
  .hud strong { font-size: 1.05rem; }
  .controls-hint {
    margin: 0 auto 5px;
    font-size: .72rem;
    line-height: 1.2;
  }
  .collect-panel {
    gap: 5px;
    margin-bottom: 6px;
    padding: 6px;
  }
  .collect-item {
    flex: 1 1 150px;
    min-width: min(150px, 100%);
    min-height: 36px;
    padding: 5px 8px;
    gap: 6px;
    font-size: .76rem;
  }
  .collect-item .mini {
    display: inline-flex;
    width: 20px;
    height: 20px;
    flex-basis: 20px;
  }
  .board {
    --gap: var(--tile-gap);
    --tile-size: clamp(30px, calc((100vw - 42px) / var(--board-size)), 52px);
    padding: calc(var(--gap) + 3px);
    border-radius: 9px;
  }
  .tile {
    border-radius: 6px;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, .07),
      inset 0 -3px 6px rgba(0, 0, 0, .38),
      0 1px 0 rgba(0, 0, 0, .44);
  }
  .tile::before,
  .tile::after {
    inset: 2px;
    border-radius: 5px;
  }
  .tile::before {
    box-shadow:
      inset 0 1px 3px rgba(255, 255, 255, .04),
      inset 0 -4px 7px rgba(0, 0, 0, .25);
  }
  .tile.selected {
    outline-width: 3px;
    outline-offset: -2px;
    transform: scale(1.025);
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, .14),
      inset 0 -4px 8px rgba(0, 0, 0, .44),
      0 0 0 4px rgba(246, 198, 79, .2),
      0 0 16px rgba(255, 232, 148, .36);
  }
  .tile.match-big {
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, .15),
      inset 0 -3px 6px rgba(0, 0, 0, .32),
      0 0 12px rgba(126, 230, 242, .22);
  }
  .tile.match-huge {
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, .18),
      inset 0 -3px 6px rgba(0, 0, 0, .3),
      0 0 14px rgba(255, 232, 148, .24);
  }
  .tile.special-cleavage-h,
  .tile.special-cleavage-v,
  .tile.special-prismatic {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, .1),
      inset 0 -3px 6px rgba(0, 0, 0, .36),
      0 0 0 1px rgba(126, 230, 242, .24),
      0 0 10px rgba(126, 230, 242, .18);
  }
  .cleavage-line-mark {
    height: 4px;
    box-shadow:
      0 0 5px rgba(126, 230, 242, .58),
      0 0 9px rgba(255, 232, 148, .2);
  }
  .special-cleavage-v .cleavage-line-mark {
    width: 4px;
  }
  .prismatic-mark {
    width: 70%;
    height: 70%;
    border-width: 2px;
    box-shadow:
      0 0 6px rgba(255, 255, 255, .3),
      0 0 9px rgba(199, 144, 255, .28);
  }
  .match-sparkle {
    box-shadow:
      0 0 4px var(--spark-color, #ffe894),
      0 0 8px rgba(255, 255, 255, .16);
  }
  .title-art .mineral-icon {
    width: clamp(42px, 13vw, 54px);
    height: clamp(42px, 13vw, 54px);
  }
  .title-art {
    min-height: 58px;
    margin-bottom: 4px;
    gap: 8px;
  }
  button {
    min-height: 44px;
    padding: 0 13px;
  }
  .save-hint {
    min-height: 0;
    margin-top: 7px;
    font-size: .78rem;
  }
  #museumScreen.active {
    height: 100dvh;
    overflow-y: auto;
  }
  .museum-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding-bottom: var(--safe-bottom);
  }
  .specimen {
    min-height: 170px;
    padding: 10px;
  }
  .pedestal {
    height: 78px;
    margin-bottom: 6px;
  }
  .pedestal .mineral-icon {
    width: 62px;
    height: 62px;
  }
  .plaque {
    min-height: 28px;
    padding: 5px 4px;
    font-size: .75rem;
  }
  .info {
    font-size: .72rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }
  .modal {
    padding: calc(14px + var(--safe-top)) 14px calc(14px + var(--safe-bottom));
    overflow-y: auto;
  }
  .modal-card {
    width: min(430px, calc(100vw - 28px));
    padding: 18px;
  }
  .modal-card h2 {
    font-size: 1.45rem;
    line-height: 1.1;
  }
  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .modal-actions button {
    width: 100%;
    min-height: 46px;
  }
  .reward-sprite .mineral-icon,
  .reward-icon {
    width: 82px;
    height: 82px;
  }
  .modal-stat-row,
  .modal-goal-row {
    padding: 8px;
  }
}

@media (max-width: 380px) {
  :root { --tile-gap: 3px; }
  .screen {
    padding-left: 7px;
    padding-right: 7px;
  }
  .topbar { padding: 7px; }
  .hud { gap: 5px; }
  .hud div { padding: 5px 6px; }
  .controls-hint { display: none; }
  .board {
    --tile-size: clamp(29px, calc((100vw - 28px) / var(--board-size)), 50px);
    padding: calc(var(--gap) + 2px);
  }
  .museum-grid {
    gap: 8px;
  }
  .specimen {
    min-height: 160px;
    padding: 8px;
  }
  .pedestal {
    height: 70px;
  }
  .pedestal .mineral-icon {
    width: 56px;
    height: 56px;
  }
  .plaque {
    font-size: .7rem;
  }
  .info {
    font-size: .68rem;
  }
}

@media (max-width: 320px) {
  .museum-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) and (orientation: landscape) {
  #gameScreen.active {
    overflow-y: auto;
  }
  .orientation-note {
    display: block;
  }
}
