:root {
  color-scheme: dark;
  --navy: #06172c;
  --gold: #ffe091;
  --gold-edge: #cb8b37;
  --ivory: #fff0ce;
  --teal: #79e8f2;
  --display: Georgia, "Times New Roman", serif;
  --text: system-ui, -apple-system, "Segoe UI", sans-serif;
  --frame-metal: linear-gradient(160deg, #fff3b3 0%, #edb753 20%, #a45a18 51%, #f1bb57 72%, #884612 100%);
  --lapis: linear-gradient(180deg, #173c5c, #081a31 52%, #061226);
  --unit: min(1vw, 1.5vh);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: var(--ivory);
  font-family: var(--text);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  isolation: isolate;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) max(8px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
  overflow: hidden;
  background: #242751 url("assets/art/nile-landscape.webp") center 48% / cover no-repeat;
}

#top {
  position: relative;
  z-index: 3;
  flex: none;
  width: 100%;
  height: clamp(64px, 17vh, 158px);
  display: flex;
  justify-content: center;
  padding-top: clamp(3px, 1.2vh, 12px);
  pointer-events: none;
}

#title {
  width: min(43vw, 610px);
  height: 100%;
  font-size: inherit;
}
#title img { width: 100%; height: 100%; object-fit: contain; object-position: center top; }
#hud { position: absolute; right: 4%; bottom: 3%; }
#fs-hud, #win-plate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, var(--unit), 16px);
  border: 1px solid var(--gold-edge);
  box-shadow: inset 0 0 0 1px #9e62256e, 0 2px 5px #271403b3;
  background: var(--lapis);
  color: var(--gold);
  font-family: var(--display);
  font-weight: 700;
}
#fs-hud {
  padding: 5px 12px;
  border-radius: 18px;
  color: var(--teal);
  font-size: clamp(10px, calc(var(--unit) * 1.4), 16px);
}
#fs-hud span:empty { display: none; }

#stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 5px max(17%, calc((100% - 890px) / 2)) 7px;
}

#cleopatra {
  position: absolute;
  z-index: 0;
  height: min(117%, 760px);
  width: auto;
  left: clamp(-95px, calc(43% - 45vh - 70px), 29%);
  bottom: -5%;
  pointer-events: none;
}

#board-wrap {
  position: relative;
  isolation: isolate;
  z-index: 1;
  flex: none;
  --rim: clamp(4px, .65vw, 9px);
}
#board-wrap::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: calc(var(--rim) * -.58);
  border: 1px solid #ffe6a4;
  border-radius: calc(var(--rim) + 5px);
  background: var(--frame-metal);
  box-shadow: 0 5px 12px #241403bb, inset 0 0 0 2px #75401c;
}
#board-wrap::after {
  content: "";
  position: absolute;
  z-index: 2;
  inset: calc(var(--rim) * -.72);
  pointer-events: none;
  background:
    radial-gradient(circle, #b3fbff 7%, #23b4ce 25%, #064969 44%, #ffeea8 48%, #a26423 65%, transparent 69%) top left,
    radial-gradient(circle, #b3fbff 7%, #23b4ce 25%, #064969 44%, #ffeea8 48%, #a26423 65%, transparent 69%) top right,
    radial-gradient(circle, #b3fbff 7%, #23b4ce 25%, #064969 44%, #ffeea8 48%, #a26423 65%, transparent 69%) bottom left,
    radial-gradient(circle, #b3fbff 7%, #23b4ce 25%, #064969 44%, #ffeea8 48%, #a26423 65%, transparent 69%) bottom right;
  background-repeat: no-repeat;
  background-size: calc(var(--rim) * 2.5) calc(var(--rim) * 2.5);
}
#board {
  position: absolute;
  inset: 0;
  border: 1px solid #47abc0;
  border-radius: 6px;
  background:
    linear-gradient(to right, transparent calc(100% - 1px), #d1ab573e 100%) 0 0 / calc(100% / 6) 100% content-box,
    linear-gradient(to bottom, transparent calc(100% - 1px), #d1ab573e 100%) 0 0 / 100% calc(100% / 5) content-box,
    radial-gradient(ellipse at 50% 20%, #122e50, #061529 72%);
  overflow: hidden;
  box-shadow: inset 0 0 16px #011022;
}

.cell {
  position: absolute;
  width: calc(100% / 6);
  height: calc(100% / 5);
  left: calc(var(--c) * 100% / 6);
  top: calc(var(--r) * 100% / 5);
  display: grid;
  place-items: center;
  transition: top .28s cubic-bezier(.3, 1.2, .5, 1);
}
.cell.instant { transition: none; }

/* 338px square sprite windows in the 1448×1086 source atlas, centered on each icon. */
[data-symbol="LAPIS"] { --sprite-x: 4.414%; --sprite-y: 1.471%; }
[data-symbol="EMERALD"] { --sprite-x: 35.225%; --sprite-y: 1.471%; }
[data-symbol="RUBY"] { --sprite-x: 65.315%; --sprite-y: 1.471%; }
[data-symbol="AMETHYST"] { --sprite-x: 95.405%; --sprite-y: 1.471%; }
[data-symbol="SCARAB"] { --sprite-x: 4.054%; --sprite-y: 46.658%; }
[data-symbol="HORUS"] { --sprite-x: 35.135%; --sprite-y: 47.594%; }
[data-symbol="ANKH"] { --sprite-x: 64.595%; --sprite-y: 47.059%; }
[data-symbol="ANUBIS"] { --sprite-x: 94.054%; --sprite-y: 46.658%; }
[data-symbol="CLEO"] { --sprite-x: 3.153%; --sprite-y: 94.251%; }
[data-symbol="SPHINX"] { --sprite-x: 33.423%; --sprite-y: 95.321%; }
[data-symbol="ORB"] { --sprite-x: 64.144%; --sprite-y: 94.251%; }
.sym, .sw {
  background: url("assets/art/symbol-atlas.webp") var(--sprite-x) var(--sprite-y) / 428.402% 321.302% no-repeat;
}
.sym { position: relative; width: 90%; height: 90%; display: grid; place-items: center; }
.sym.custom-symbol { background: none; }
.sym img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.orb-value {
  position: relative;
  line-height: 1;
  font: 700 clamp(9px, calc(var(--tile) * .28), 32px) var(--display);
  font-variant-numeric: lining-nums tabular-nums;
  color: #fff8c6;
  text-shadow: -1px -1px #58230c, 1px 1px #58230c, 0 2px 3px #44210c;
}
.cell.win::before, .cell.flash::before {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 17%;
  border: 1px solid #ffe292;
  box-shadow: inset 0 0 9px #d77b24, 0 0 9px #eb9e46aa;
}
.cell.win .sym { animation: pulse .45s ease-in-out 2; }
.cell.flash .sym { animation: pulse .4s ease-in-out 3; }
.cell.pop { animation: pop .3s ease-in forwards; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes pop { to { transform: scale(.2); opacity: 0; } }
#fx { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font: 700 clamp(10px, calc(var(--unit) * 2.2), 24px) var(--display);
  color: var(--ivory);
  background: #061529ed;
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 2px 8px;
  animation: rise .9s ease-out forwards;
  white-space: nowrap;
}
@keyframes rise { to { transform: translate(-50%, -90%); opacity: 0; } }
#msg {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 36px);
  padding: .4em .75em;
  border: 1px solid var(--gold);
  border-radius: 14px;
  background: var(--lapis);
  text-align: center;
  pointer-events: none;
  font: 700 clamp(16px, calc(var(--unit) * 4), 44px) / 1.15 var(--display);
  color: var(--gold);
  text-shadow: 0 2px 4px #000;
  box-shadow: 0 4px 16px #101426d9;
  white-space: pre-line;
}
#msg:empty { display: none; }

#bar {
  position: relative;
  z-index: 5;
  flex: none;
  width: min(calc(100% - 30px), clamp(520px, 60vw, 820px));
  display: grid;
  justify-items: stretch;
  gap: clamp(4px, .75vh, 10px);
  --spin-size: clamp(56px, 12vh, 112px);
}
#win-plate {
  justify-self: center;
  min-width: min(37%, 215px);
  padding: 3px 14px;
  border-radius: 14px;
}
#win-plate label, #win-plate output { display: inline; color: var(--gold); }

#primary-controls {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 2.05fr) var(--spin-size) minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(4px, .9vw, 12px);
  align-items: center;
  padding: 0 clamp(6px, 1vw, 14px);
}
#primary-controls::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 12% 0;
  border: 1px solid #f8d986;
  border-radius: 16px;
  background: var(--frame-metal);
  box-shadow: inset 0 0 0 2px #bd7735, 0 3px 10px #211309d9;
}

#secondary-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 1vw, 14px);
}
#secondary-controls button { min-width: clamp(34px, 6vw, 88px); min-height: clamp(28px, 4.5vh, 44px); }
#secondary-controls #info { min-width: clamp(30px, 4vw, 46px); border-radius: 50%; font-size: 1.05rem; }
#bet-ctrl, #balance-plate {
  min-height: clamp(42px, calc(var(--spin-size) * .62), 68px);
  border: 1px solid #e3ac55;
  border-radius: 10px;
  background: var(--lapis);
  box-shadow: inset 0 2px 5px #010915;
  padding: 2px;
}
#bet-ctrl {
  display: grid;
  align-items: center;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: clamp(1px, .35vw, 5px);
}
.stat { min-width: 0; text-align: center; }
.stat label {
  display: block;
  color: #f3cc7c;
  font-family: var(--text);
  font-size: clamp(8px, calc(var(--unit) * 1.05), 13px);
  font-weight: 700;
  letter-spacing: .045em;
}
.stat output {
  display: block;
  font: 700 clamp(13px, calc(var(--unit) * 2.25), 30px) / 1.15 var(--display);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--ivory);
  overflow-wrap: anywhere;
}
#balance-plate { display: grid; align-content: center; }
#balance { font-size: clamp(10px, calc(var(--unit) * 2.18 * var(--amount-scale, 1)), 28px); white-space: nowrap; }
#ante-cost { display: block; color: var(--teal); font-size: clamp(7px, 1vw, 11px); line-height: 1.1; }

button {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ivory);
  background: var(--lapis);
  border: 1px solid var(--gold-edge);
  border-radius: 10px;
  min-height: 34px;
  padding: 0 clamp(4px, .8vw, 10px);
  box-shadow: inset 0 1px 2px #edf2ff28, 0 2px 4px #150e09b3;
  text-shadow: 0 1px 2px #110c0b;
  font: 700 clamp(9px, calc(var(--unit) * 1.55), 16px) / 1.06 var(--display);
}
button small { font: 600 .75em / 1.2 var(--text); color: var(--teal); }
button:disabled { cursor: default; }
button:focus-visible { outline: 2px solid #91f0ff; outline-offset: 2px; }
button.toggle[aria-pressed="true"] { border-color: #a6f3f4; color: var(--teal); }
#bet-dn, #bet-up {
  width: clamp(24px, 6.9vw, 42px);
  height: clamp(30px, 5.5vh, 44px);
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  font-size: clamp(16px, calc(var(--unit) * 2.2), 28px);
}
#spin {
  width: var(--spin-size);
  height: var(--spin-size);
  min-height: 0;
  padding: 0 2px;
  border-radius: 50%;
  border: 2px solid #ffe3a0;
  background: radial-gradient(circle at 42% 28%, #ffec99, #edac28 35%, #bc6314 75%, #743507);
  box-shadow: inset 0 0 0 3px #198da6, inset 0 0 0 5px #fac266, inset 0 0 0 7px #8e440d, 0 3px 7px #341505d9;
  color: #fff1be;
  text-shadow: -1px 0 #7a350e, 1px 0 #7a350e, 0 2px 2px #582808;
  font-size: calc(var(--spin-size) * .255);
}
#spin.stop { font-size: calc(var(--spin-size) * .176); background: radial-gradient(circle at 42% 28%, #c4683c, #813013 60%, #4d200e); }
#buy {
  min-width: 0;
  min-height: clamp(42px, calc(var(--spin-size) * .62), 68px);
  color: #fff0af;
  background: radial-gradient(ellipse at 50% 18%, #af4fbb, #59136f 64%, #320b54);
}
#buy small { color: #ffe3b8; }

#modal { position: fixed; inset: 0; background: #040b17c7; display: grid; place-items: center; z-index: 10; padding: 12px; }
#modal-card {
  position: relative;
  width: min(720px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--lapis);
  border: 2px solid var(--gold-edge);
  border-radius: 16px;
  padding: 16px 18px 20px;
  font-size: clamp(12px, 1.6vh, 16px);
  line-height: 1.45;
  box-shadow: 0 4px 24px #030a14e0;
}
#modal-x { position: sticky; top: 0; float: right; min-width: 36px; min-height: 36px; font-size: 22px; z-index: 2; }
#modal h2 { color: var(--gold); margin: 4px 36px 8px 0; font: 700 1.5em var(--display); }
#modal h3 { color: var(--gold); margin: 14px 0 4px; font: 700 1.2em var(--display); }
#modal table { border-collapse: collapse; width: 100%; margin: 6px 0; }
#modal td, #modal th { border-bottom: 1px solid #f0c24a40; padding: 4px 6px; text-align: left; font-variant-numeric: tabular-nums; }
#modal .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
#modal .sw { display: inline-block; width: 1.65em; height: 1.65em; vertical-align: middle; margin-right: 6px; }
#modal select { font: inherit; padding: 6px 10px; border-radius: 8px; background: var(--navy); color: var(--ivory); border: 1px solid var(--gold-edge); }

@media (max-aspect-ratio: 4/5) {
  #app {
    background-image: url("assets/art/nile-portrait.webp");
    background-position: center;
    padding-bottom: max(clamp(12px, 11vh, 104px), env(safe-area-inset-bottom));
  }
  #top { height: clamp(96px, 22vh, 220px); }
  #title { width: min(82vw, 620px); }
  #hud { right: 4.5%; bottom: 0; }
  #stage { align-items: flex-end; justify-content: flex-end; padding: 5px 3.5% 7px 13%; }
  #cleopatra { height: 118%; bottom: -10%; left: clamp(-136px, calc(16vw - 18vh), -46px); }
  #msg { left: 54.75%; }
  #bar { width: min(calc(100% - 14px), 760px); --spin-size: clamp(61px, 17.5vw, 112px); }
  #win-plate { margin-left: 8%; }
  .stat output { font-size: clamp(12px, 3.45vw, 28px); }
  #balance { font-size: clamp(9px, calc(2.96vw * var(--amount-scale, 1)), 25px); }
  #win-plate output { font-size: clamp(14px, 4.25vw, 29px); }
  #buy { font-size: clamp(10px, 2.75vw, 19px); }
}

@media (max-aspect-ratio: 4/5) and (min-width: 600px) {
  #title { width: min(68vw, 580px); }
  #cleopatra { height: 116%; bottom: -3%; }
}

@media (max-aspect-ratio: 4/5) and (max-height: 630px) {
  #app { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  #top { height: 16vh; }
}

@media (min-aspect-ratio: 81/100) and (max-height: 450px) {
  #top { height: 16vh; padding-top: 2px; }
  #bar { --spin-size: clamp(41px, 13vh, 61px); width: min(calc(100% - 20px), 540px); gap: 3px; }
  #win-plate { padding-block: 1px; }
  #primary-controls { padding-inline: 7px; }
  #bet-ctrl, #balance-plate, #buy { min-height: 34px; }
  #secondary-controls button { min-height: 24px; }
  #stage { padding-block: 4px; }
}

#preview-label {
  position: absolute;
  bottom: 3px;
  left: max(8px, env(safe-area-inset-left));
  padding: 3px 6px;
  border: 1px solid #cb8b37;
  border-radius: 6px;
  background: #06172ce8;
  color: #fff0ce;
  font: 700 9px / 1.1 var(--text);
  letter-spacing: .03em;
}
@media (max-aspect-ratio: 4/5) { #preview-label { bottom: auto; top: 1px; font-size: 8px; } }

@media (max-width: 599px) and (max-aspect-ratio: 4/5) {
  #app {
    --phone-rise: clamp(18px, 7vh, 60px);
    --phone-header: clamp(96px, 22vh, 220px);
    --phone-logo-room: calc(82vw / 3 + clamp(3px, 1.2vh, 12px) + 4px);
    padding-bottom: calc(max(clamp(12px, 11vh, 104px), env(safe-area-inset-bottom)) + var(--phone-rise));
  }
  #top { height: min(var(--phone-header), max(var(--phone-logo-room), calc(var(--phone-header) - var(--phone-rise)))); }
  #title { height: auto; align-self: flex-start; }
  #title img { display: block; height: auto; max-height: calc(var(--phone-header) - clamp(3px, 1.2vh, 12px)); }
  #stage { justify-content: center; padding-inline: 8.25%; }
  #cleopatra { display: none; }
  #msg { left: 50%; }
  #win-plate { margin-left: 0; }
}

@media (max-width: 599px) and (min-aspect-ratio: 3/5) and (max-aspect-ratio: 4/5) {
  #app { --phone-rise: clamp(12px, 3.75vh, 30px); }
}

@media (max-width: 599px) and (max-aspect-ratio: 4/5) and (max-height: 630px) {
  #app {
    --phone-header: 16vh;
    padding-bottom: calc(max(10px, env(safe-area-inset-bottom)) + clamp(12px, 3vh, 20px));
  }
  #top { height: var(--phone-header); }
}

@media (max-width: 960px) and (max-height: 450px) and (min-aspect-ratio: 4/3) and (pointer: coarse) and (hover: none) {
  #app { padding-bottom: calc(max(8px, env(safe-area-inset-bottom)) + 8px); }
  #top { height: calc(16vh - 8px); }
  #cleopatra { display: none; }
}
