:root {
  --gold: #e4c56a;
  --gold-bright: #ffe9a8;
  --gold-dim: #9a7428;
  --ink: #140e08;
  --sand: #c4a574;
  --lapis: #1a3358;
  --grout: #1c1208;
  --panel: #2a1b10;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  min-height: 100dvh;
  background: #0a0704 url("../assets/bg.jpg") center/cover no-repeat fixed;
  color: var(--gold-bright);
  font-family: "Cormorant Garamond", Georgia, serif;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 20px 32px;
  overflow-x: hidden;
  touch-action: manipulation;
}

.vignette {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, #000000cc 100%);
  pointer-events: none;
  z-index: 0;
}

.torches {
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse at 12% 78%, #ff9a2a22, transparent 42%),
    radial-gradient(ellipse at 88% 28%, #ffb43a18, transparent 36%);
  animation: flicker 3.6s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes flicker {
  0%, 100% { opacity: .65; }
  40% { opacity: 1; }
  70% { opacity: .8; }
}

.top, .table, .overlay { position: relative; z-index: 2; }

.top {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 16px;
  text-align: center;
}

.top h1 {
  font-family: "Cinzel Decorative", Cinzel, serif;
  font-size: clamp(24px, 3.6vw, 44px);
  letter-spacing: .12em;
  color: var(--gold);
  text-shadow: 0 2px 0 #3a2508, 0 0 24px #e4c56a66;
}

.sub {
  font-style: italic;
  color: #ead9b4;
  letter-spacing: .06em;
  font-size: 18px;
  margin-top: 4px;
}

.ankh-deco { height: 42px; filter: drop-shadow(0 4px 6px #0008); }

.table {
  display: flex;
  gap: 32px;
  align-items: stretch;
  justify-content: center;
  width: min(1380px, 100%);
}

.board-col { display: flex; align-items: center; }

.tray {
  position: relative;
  padding: 22px 22px 28px 28px;
  background:
    linear-gradient(145deg, #6a4a22, #2a1a0c);
  border: 3px solid var(--gold);
  box-shadow:
    inset 0 0 24px #000c,
    0 18px 50px #000a,
    0 0 0 6px #3a250c;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 3px;
  width: min(76vh, 70vw, 730px);
  aspect-ratio: 1;
  background: var(--grout);
  position: relative;
}

.cell {
  position: relative;
  background: url("../assets/tile.jpg") center/cover;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
}

.cell.mid { background-image: url("../assets/tile-mid.jpg"); }
.cell.high { background-image: url("../assets/tile-high.jpg"); }

.cell::after {
  content: "";
  position: absolute; inset: 0;
  background:
    linear-gradient(
      to top right,
      transparent 20%,
      rgba(255, 186, 40, calc(var(--heat, 0) * 0.62))
    );
  pointer-events: none;
}

.cell.visited { filter: saturate(1.2) brightness(1.06); }

.cell.current {
  z-index: 3;
  overflow: visible;
  box-shadow: 0 0 0 3px #f6e187, 0 0 18px #e4c56add;
}

.cell .val {
  position: relative;
  z-index: 2;
  margin-top: 5%;
  padding: 2px 5px;
  border-radius: 3px;
  background: #140e08ee;
  border: 1px solid #e4c56aaa;
  font-family: Cinzel, serif;
  font-weight: 700;
  font-size: clamp(15px, 2.1vw, 19px);
  color: #fff3c8;
  letter-spacing: .01em;
  pointer-events: none;
}

.cell.high .val {
  color: #fff6c8;
  border-color: #ffe08a;
  box-shadow: 0 0 8px #e4c56a99;
}

.cell.start .ankh {
  width: 42%;
  margin-top: 22%;
  opacity: .85;
  filter: drop-shadow(0 2px 2px #0006);
}

.cell.door,
.cell.trap {
  overflow: hidden;
}

.cell .mark {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.cell .door-art {
  width: 72%;
  bottom: 6%;
  left: 50%;
  transform: translateX(-50%);
  filter: drop-shadow(0 3px 4px #0008);
}

.cell .stairs {
  width: 22%;
  top: 6%;
  right: 6%;
  filter: drop-shadow(0 2px 2px #0008);
}

.cell .stairs.down { transform: rotate(180deg); }

.cell .trap-art {
  width: 78%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.board.shift-up { animation: shiftUp .32s ease-in both; }
.board.shift-down { animation: shiftDown .32s ease-in both; }
.board.shift-in { animation: shiftIn .28s ease-out both; }

@keyframes shiftUp {
  to { transform: translateY(-18px); opacity: 0; }
}
@keyframes shiftDown {
  to { transform: translateY(18px); opacity: 0; }
}
@keyframes shiftIn {
  from { opacity: 0; transform: scale(.97); }
  to { opacity: 1; transform: none; }
}

.cell.goal .coin-mark {
  position: absolute;
  right: 6%;
  bottom: 6%;
  width: 28%;
  z-index: 2;
  opacity: .9;
  filter: drop-shadow(0 2px 3px #0008);
}

.player {
  position: absolute;
  width: 11%;
  height: auto;
  z-index: 6;
  pointer-events: none;
  transform: translate(-50%, -42%);
  filter: drop-shadow(0 10px 6px #000c);
  transition: left .42s cubic-bezier(.2, .8, .2, 1), top .42s cubic-bezier(.2, .8, .2, 1);
}

.player.bump {
  animation: bump .32s ease;
}

.player.eject {
  z-index: 8;
  animation: eject .85s ease-in forwards;
}

@keyframes bump {
  0%, 100% { filter: drop-shadow(0 10px 6px #000c); }
  40% { filter: drop-shadow(0 10px 6px #000c) brightness(1.4); }
}

@keyframes eject {
  0% { transform: translate(-50%, -42%) rotate(0deg) scale(1); opacity: 1; }
  35% { transform: translate(-30%, -90%) rotate(-25deg) scale(1.15); }
  100% { transform: translate(40vw, 70vh) rotate(520deg) scale(.2); opacity: 0; }
}

.axis {
  position: absolute;
  font-family: Cinzel, serif;
  font-size: 13px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--gold);
}

.y-axis {
  left: 6px;
  top: 22px;
  bottom: 28px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  display: flex;
  align-items: center;
}

.x-axis {
  left: 28px;
  right: 22px;
  bottom: 8px;
  text-align: right;
}

.side {
  width: min(410px, 36vw);
  min-width: 320px;
  background: url("../assets/panel.jpg") center/100% 100% no-repeat;
  box-shadow: 0 18px 50px #000a;
  display: flex;
}

.side-inner {
  padding: 64px 52px 72px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.stat {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #140e08aa;
  border: 1px solid #e4c56a44;
  padding: 8px 12px;
}

.stat img { width: 40px; height: 40px; object-fit: contain; }

.lbl {
  font-family: Cinzel, serif;
  font-size: 15px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #e6d09a;
}

.num {
  font-family: Cinzel, serif;
  font-size: 34px;
  color: var(--gold);
  line-height: 1.1;
}

.meta {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  color: #ead9b4;
  padding: 0 4px;
}

.meta b { color: var(--gold); font-family: Cinzel, serif; }

.floor-hud {
  background: #140e08aa;
  border: 1px solid #e4c56a44;
  padding: 8px 12px;
  text-align: center;
}

.floor-name {
  font-family: Cinzel, serif;
  font-size: 16px;
  color: var(--gold);
  margin: 2px 0 6px;
}

.pips {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: transparent;
}

.pip.done { background: #e4c56a66; }
.pip.on { background: var(--gold); box-shadow: 0 0 8px #e4c56acc; }

.well {
  position: relative;
  align-self: center;
  width: 166px;
  height: 166px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #3a2a16, #0e0a06 72%);
  border: 3px solid var(--gold-dim);
  box-shadow: inset 0 8px 18px #000c, 0 0 12px #e4c56a33;
  display: grid;
  place-items: center;
  overflow: visible;
  cursor: pointer;
}

.well > * {
  grid-area: 1 / 1;
}

.well img { pointer-events: none; }

.compass {
  position: absolute;
  z-index: 3;
  font-family: Cinzel, serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--gold);
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

.compass.n { top: 6px; left: 50%; transform: translateX(-50%); }
.compass.s { bottom: 6px; left: 50%; transform: translateX(-50%); }
.compass.e { right: 8px; top: 50%; transform: translateY(-50%); }
.compass.w { left: 8px; top: 50%; transform: translateY(-50%); }

.well.spinning {
  box-shadow: inset 0 8px 18px #000c, 0 0 22px #e4c56acc;
}

.well img {
  height: 132px;
  transform-origin: 50% 50%;
  will-change: transform;
  filter: drop-shadow(0 4px 6px #000a);
}

.well.spinning img {
  filter: drop-shadow(0 0 10px #e4c56acc) drop-shadow(0 4px 6px #000a);
}

.dir-label {
  text-align: center;
  font-family: Cinzel, serif;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-size: 18px;
  color: var(--gold-bright);
  min-height: 1.2em;
}

.cartouche {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 94px;
  border: 0;
  background: transparent url("../assets/btn.png") center/100% 100% no-repeat;
  color: #fff6d0;
  cursor: pointer;
  font-family: Cinzel, serif;
  filter: drop-shadow(0 6px 8px #0008);
  transition: filter .15s, transform .12s;
}

.cartouche:hover:not(:disabled) {
  filter: drop-shadow(0 0 12px #e4c56acc) brightness(1.08);
}

.cartouche:active:not(:disabled) {
  transform: translateY(2px);
  filter: brightness(.9);
}

.cartouche:disabled {
  filter: grayscale(.45) brightness(.75);
  cursor: default;
  opacity: .75;
}

.btn-title {
  font-weight: 700;
  font-size: 22px;
  letter-spacing: .14em;
  line-height: 1;
  color: #fff8dc;
  background: #120c08f0;
  border: 1px solid #e4c56a99;
  border-radius: 4px;
  padding: 5px 16px;
  text-shadow: 0 1px 2px #000;
}

.btn-sub {
  font-family: Cinzel, serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .06em;
  color: #f6ead0;
  background: #120c08e6;
  border-radius: 3px;
  padding: 2px 10px;
}

.hint {
  font-size: 17px;
  line-height: 1.4;
  color: #f6ead0;
  text-align: center;
  background: #140e08cc;
  border: 1px solid #e4c56a33;
  padding: 10px 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #140e08ee;
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-family: Cinzel, serif;
  font-size: 18px;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 12px 22px;
  z-index: 20;
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  background: #000000b8;
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 20px;
  overflow-y: auto;
}

.overlay[hidden] { display: none; }

.scroll {
  width: min(500px, 92vw);
  background: url("../assets/panel.jpg") center/100% 100% no-repeat;
  padding: 72px 56px 64px;
  text-align: center;
  box-shadow: 0 24px 80px #000;
}

.scroll-icon { height: 56px; margin-bottom: 8px; }

.scroll h2 {
  font-family: "Cinzel Decorative", Cinzel, serif;
  color: var(--gold);
  font-size: 30px;
  margin-bottom: 14px;
  letter-spacing: .06em;
}

.scroll p {
  color: #f6ead0;
  font-size: 20px;
  line-height: 1.45;
  margin-bottom: 12px;
}

.scroll .cartouche { margin-top: 16px; }

.score {
  list-style: none;
  margin: 12px 0 8px;
  color: #f0e2c4;
  font-size: 20px;
}

.score li {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  border-bottom: 1px solid #e4c56a33;
}

.score .total {
  color: var(--gold);
  font-family: Cinzel, serif;
  font-size: 22px;
  margin-top: 6px;
}

.fly-coin {
  position: fixed;
  width: 36px;
  height: 36px;
  z-index: 40;
  pointer-events: none;
  transition: transform .7s cubic-bezier(.2, .7, .2, 1), opacity .7s;
}

@media (max-width: 920px) {
  body {
    padding: max(8px, env(safe-area-inset-top)) 8px max(10px, env(safe-area-inset-bottom));
  }

  .top {
    gap: 8px;
    margin-bottom: 6px;
  }

  .top h1 {
    font-size: clamp(18px, 5.4vw, 26px);
    letter-spacing: .08em;
  }

  .sub { display: none; }
  .ankh-deco { height: 22px; }

  .table {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .tray {
    padding: 8px;
    box-shadow: inset 0 0 12px #000c, 0 8px 24px #0008, 0 0 0 4px #3a250c;
  }

  .axis { display: none; }

  .board {
    width: min(calc(100vw - 32px), 50dvh);
  }

  .cell .val {
    font-size: clamp(9px, 2.6vw, 12px);
    padding: 1px 3px;
    margin-top: 3%;
  }

  .side {
    width: min(calc(100vw - 16px), 520px);
    min-width: 0;
  }

  .side-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 12px 14px 14px;
    gap: 8px;
    align-content: space-between;
  }

  .stat { padding: 6px 8px; gap: 8px; }
  .stat img { width: 28px; height: 28px; }
  .lbl { font-size: 11px; }
  .num { font-size: 22px; }

  .meta,
  .floor-hud,
  .well,
  .dir-label,
  .hint {
    grid-column: 1 / -1;
  }

  .meta { font-size: 15px; padding: 0 2px; }

  .well {
    width: 92px;
    height: 92px;
    justify-self: center;
  }

  .dir-label { justify-self: center; font-size: 14px; }

  .well img { height: 74px; }

  .cartouche {
    height: 64px;
    gap: 2px;
  }

  .btn-title {
    font-size: 16px;
    padding: 4px 10px;
    letter-spacing: .1em;
  }

  .btn-sub { font-size: 11px; padding: 1px 8px; }

  .hint { display: none; }

  .scroll {
    width: min(500px, 94vw);
    padding: 40px 24px 28px;
  }

  .scroll-icon { height: 36px; }

  .scroll h2 { font-size: 22px; margin-bottom: 10px; }

  .scroll p { font-size: 16px; margin-bottom: 8px; }

  .score { font-size: 17px; }

  .toast {
    font-size: 14px;
    padding: 8px 14px;
    bottom: max(16px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 920px) and (orientation: landscape) {
  body { padding: 6px 10px; }
  .top { display: none; }
  .table {
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
    height: calc(100dvh - 12px);
  }
  .board { width: min(88dvh, 54vw); }
  .side {
    width: min(42vw, 380px);
    flex: 1;
  }
  .side-inner {
    padding: 10px 12px;
    gap: 6px;
    height: 100%;
    align-content: space-between;
  }
  .well { width: 72px; height: 72px; }
  .well img { height: 58px; }
  .cartouche { height: 56px; }
}

@media (max-height: 720px) and (orientation: portrait) {
  .board { width: min(calc(100vw - 32px), 42dvh); }
  .well { width: 72px; height: 72px; }
  .well img { height: 58px; }
  .cartouche { height: 56px; }
  .btn-sub { display: none; }
  .num { font-size: 20px; }
}
