/* 

----------------TYPOGRAPHY-----------------

FONT SIZES
12px / 16px / 20px / 24px / 32px / 40px/ 48px / 62px

FONT WEIGHTS
400/700

LINE HEIGHTS 
1.2 / 1.5

LETTER SPACING 
0 / -2px

FONT FAMILY
Geist Pixel, Sans Serif

---------------COLORS-----------------

PRIMARY 
Base: #a07603  (Clay)
Tint: #E5DABA (Sand)
Shade: #2C2001 (Mud)

SECONDARY
Base: #339af0 (Sky Blue)
Tint: #d0ebff (Arctic)
Shade: #1c7ed6 (Deep Sea)


Grey 
Base: #495057 (Slate)
Tint: #f1f3f5 (Pebble)
Shade: #212529 (Graphite)
White: #fff (White)
Black: #000 (Black)


---------------BORDER RADIUS-----------------
4px / 8px / 20px


---------------SPACING SYSTEM-----------------

5px / 10px / 15px / 20px / 25px / 30px / 40px / 50px / 60 px/ 70px / 80px / 90px / 100px / 125px / 150px / 200 px / 250px / 300px / 400px / 500px 

*/

:root {
  --clay: #a07603;
  --sand: #E5DABA;
  --mud: #2C2001;

  --sky: #339af0;
  --arctic: #d0ebff;
  --deep-sea: #1c7ed6;

  --slate: #495057;
  --pebble: #f1f3f5;
  --graphite: #212529;
  --white: #fff;
  --black: #000;

  --p1: #fdcb6e;
  --p1-border: #e17055;
  --p2: #0984e3;
  --p2-border: #0056b3;

  --orange: #d35400;
  --orange-light: #e67e22;
  --teal: #00cec9;
  --mint: #e8f8f5;
  --warm: #ffeaa7;

  --radius-sm: 5px;
  --radius-md: 10px;
  --radius-lg: 20px;

  --shadow-soft: 0 12px 30px rgba(44, 32, 1, 0.18);
  --shadow-deep: 0 18px 45px rgba(44, 32, 1, 0.28);
  --pixel-shadow: 5px 5px 0 rgba(44, 32, 1, 0.9);
}

/* ---------------- Global ---------------- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-height: 100%;
}

body {
  font-family: 'Geist Pixel', sans-serif;
  min-height: 100vh;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 1.35;
  color: var(--graphite);

  /* Background Image */
  background-image: url(imgs/egypy_pixel.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

button,
select,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: 'Geist Pixel', sans-serif;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 1px;
  color: var(--graphite);
}

/* ---------------- Shared transitions ---------------- */

.menu-btn,
.modal-btn,
#roll-btn,
#replay-btn,
#riddle-submit-btn,
.menu-select,
#riddle-input {
  transition:
    transform 0.14s ease,
    box-shadow 0.14s ease,
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease;
}

/* ---------------- Menu Overlay ---------------- */

.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;

  /* Background Image */
  background-image: url(imgs/egypy_pixel.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

.menu-content {
  width: min(500px, 100%);
  padding: 46px 38px 38px;
  text-align: center;
  background: var(--sand);
  border: 4px solid var(--mud);
  border-radius: var(--radius-md);
  box-shadow:
    7px 7px 0 var(--mud),
    var(--shadow-deep);
  position: relative;
}

.menu-content::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 2px solid var(--clay);
  border-radius: 6px;
  pointer-events: none;
  opacity: 0.65;
}

.menu-title {
  position: relative;
  z-index: 1;
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 700;
  color: var(--graphite);
  margin-bottom: 34px;
  letter-spacing: -1px;
  text-shadow: 2px 2px 0 var(--clay);
}

.menu-options {
  position: relative;
  z-index: 1;
  padding: 20px;
  margin-bottom: 28px;
  color: var(--sand);
  background: var(--mud);
  border: 3px solid var(--clay);
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 0 2px rgba(229, 218, 186, 0.12);
}

.menu-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  margin-bottom: 16px;
}

.menu-group:last-child {
  margin-bottom: 0;
}

.menu-group label {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--pebble);
  letter-spacing: 0.5px;
}

.menu-select {
  width: 100%;
  padding: 12px 13px;
  font-size: 0.95rem;
  color: var(--mud);
  background: var(--pebble);
  border: 3px solid var(--sand);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
}

.menu-select:hover,
.menu-select:focus {
  border-color: var(--clay);
  transform: translateY(-1px);
}

.menu-btn {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 15px 18px;
  border: 3px solid var(--mud);
  border-radius: var(--radius-sm);
  font-size: 1.12rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--mud);
}

.primary-btn {
  background: var(--clay);
  color: var(--mud);
}

.primary-btn:hover {
  background: var(--mud);
  color: var(--pebble);
  transform: translate(-1px, -3px);
  box-shadow: 6px 7px 0 var(--clay);
}

.primary-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--mud);
}

.secondary-btn {
  background: var(--mud);
  color: var(--pebble);
}

.secondary-btn:hover {
  transform: translateY(-3px);
}

/* ---------------- Instructions and About ---------------- */


.menu-info {
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.info-section {
    background-color: #2C2001;
    border: 3px solid #a07603;
    padding: 20px;
    text-align: left;

    box-shadow:
        5px 5px 0 #a07603;
}

.info-section h2 {
    color: #E5DABA;
    font-family: 'Geist Pixel', sans-serif;
    font-size: 1.2rem;
    letter-spacing: 1px;

    margin-bottom: 15px;

    border-bottom: 2px solid #a07603;
    padding-bottom: 10px;
}

.how-to-play {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.how-to-play p {
    color: #f1f3f5;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* About section */

.about-content {
    min-height: 40px;
    color: #f1f3f5;
    font-size: 0.85rem;
    line-height: 1.5;
}


/* ---------------- Coin Flip Modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;

  /* Background Image */
  background-image: url(imgs/egypy_pixel.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

.modal-content {
  width: min(350px, 100%);
  padding: 34px 30px 30px;
  text-align: center;
  background: var(--sand);
  border: 4px solid var(--mud);
  border-radius: var(--radius-md);
  box-shadow:
    7px 7px 0 var(--mud),
    var(--shadow-deep);
}

.modal-content h2 {
  color: var(--mud);
  margin-bottom: 22px;
  font-size: 1.65rem;
}

#coin-result {
  min-height: 24px;
  margin: 18px 0 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--mud);
}

.coin {
  width: 104px;
  height: 104px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--mud);
  background: #dfe6e9;
  border: 5px solid #bcbec3;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 4px var(--sand),
    0 8px 0 rgba(44, 32, 1, 0.35);
}

.modal-btn {
  width: 100%;
  margin-top: 12px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--mud);
  background: var(--clay);
  border: 3px solid var(--mud);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--mud);
}

.modal-btn:hover:not(:disabled) {
  color: var(--pebble);
  background: var(--mud);
  transform: translateY(-2px);
  box-shadow: 4px 5px 0 var(--clay);
}

.modal-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 1px 1px 0 var(--mud);
}

.modal-btn:disabled {
  background: #b2bec3;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.75;
}

.flip-animation {
  animation: flipCoin 1s ease-in-out forwards;
}

@keyframes flipCoin {
  0%   { transform: rotateY(0) scale(1); }
  50%  { transform: rotateY(720deg) scale(1.28); }
  100% { transform: rotateY(1440deg) scale(1); }
}

/* ---------------- Main Game ---------------- */

.app-container {
  width: min(1120px, 100%);
  background: var(--warm);
  padding: 26px;
  border: 4px solid var(--mud);
  border-radius: var(--radius-md);
  box-shadow:
    8px 8px 0 var(--mud),
    var(--shadow-deep);
}

header {
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 3px solid var(--mud);
}

header h1,
h1 {
  margin-bottom: 12px;
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  text-shadow: 2px 2px 0 var(--sand);
}

#turn-indicator {
  display: inline-block;
  padding: 9px 16px;
  border: 2px solid var(--mud);
  border-radius: var(--radius-sm);
  font-size: 0.98rem;
  font-weight: 700;
  box-shadow: 3px 3px 0 rgba(44, 32, 1, 0.28);
}

.turn-p1 {
  background: var(--mud);
  color: var(--pebble);
}

.turn-p2 {
  background: var(--deep-sea);
  color: var(--graphite);
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 28px;
  align-items: start;
}

#board-container {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 8px;
  background: var(--mud);
  border: 4px solid var(--clay);
  box-shadow:
    6px 6px 0 var(--mud),
    var(--shadow-soft);
}

#board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 2px;
  background: var(--clay);
  border: 3px solid var(--mud);
}

.tile {
  position: relative;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: var(--sand);
  border: 1px solid rgba(44, 32, 1, 0.28);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.tile-alt {
  background: var(--clay);
  border: 2px solid var(--mud);
}

.tile:hover {
  z-index: 4;
  filter: brightness(1.04);
  transform: scale(1.045);
}

.tile-number {
  position: absolute;
  top: 3px;
  left: 4px;
  z-index: 2;
  font-size: clamp(0.52rem, 1.4vw, 0.72rem);
  font-weight: 700;
  color: var(--graphite);
  line-height: 1;
}

.tile-icon {
  font-size: clamp(1rem, 2.3vw, 1.55rem);
  opacity: 0.92;
  filter: drop-shadow(1px 2px 0 rgba(44, 32, 1, 0.25));
}

.token {
  display: inline-block;
  width: clamp(13px, 2vw, 19px);
  height: clamp(13px, 2vw, 19px);
  margin: 2px;
  z-index: 10;
  border: 2px solid var(--mud);
  box-shadow: 2px 2px 0 rgba(44, 32, 1, 0.35);
  animation: tokenPop 0.18s ease-out;
}

.token-p1 {
  background: var(--p1);
  border-color: var(--p1-border);
  border-radius: 50%;
}

.token-p2 {
  background: var(--p2);
  border-color: var(--p2-border);
  border-radius: 50%;
}

@keyframes tokenPop {
  from { transform: scale(0.72); }
  to   { transform: scale(1); }
}

/* ---------------- Right-side Controls ---------------- */

.controls-wrapper {
  min-width: 0;
}

.controls {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.dice-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  padding: 18px;
  background: var(--sand);
  border: 3px solid var(--mud);
  border-radius: var(--radius-md);
  box-shadow: 4px 4px 0 rgba(44, 32, 1, 0.4);
}

#dice {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  font-size: 3rem;
  background: var(--pebble);
  border: 3px solid var(--graphite);
  border-radius: var(--radius-sm);
  box-shadow:
    inset 0 0 0 3px var(--sand),
    4px 4px 0 rgba(44, 32, 1, 0.35);
}

#roll-btn,
#replay-btn {
  width: 100%;
  padding: 12px 20px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--mud);
  background: var(--white);
  border: 3px solid var(--mud);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--mud);
}

#roll-btn:hover:not(:disabled),
#replay-btn:hover {
  background: var(--sand);
  transform: translate(-1px, -2px);
  box-shadow: 5px 5px 0 var(--mud);
}

#roll-btn:active,
#replay-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--mud);
}

#roll-btn:disabled {
  background: var(--pebble);
  cursor: not-allowed;
  opacity: 0.65;
  box-shadow: none;
}

#replay-btn {
  margin-top: 0;
  color: var(--white);
  background: var(--mud);
}

/* ---------------- Logger ---------------- */

.logger-box {
  width: 100%;
  max-width: none;
  min-height: 175px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  background: var(--pebble);
  border: 3px solid var(--graphite);
  border-radius: var(--radius-md);
  box-shadow: 4px 4px 0 rgba(44, 32, 1, 0.3);
}

.logger-box h3 {
  margin-bottom: 10px;
  padding-bottom: 8px;
  text-align: left;
  font-size: 0.95rem;
  color: var(--mud);
  border-bottom: 3px solid var(--graphite);
}

#game-log {
  flex-grow: 1;
  height: 135px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-right: 4px;
  text-align: left;
  scrollbar-width: thin;
}

#game-log::-webkit-scrollbar {
  width: 7px;
}

#game-log::-webkit-scrollbar-track {
  background: var(--pebble);
}

#game-log::-webkit-scrollbar-thumb {
  background: #b2bec3;
  border: 1px solid var(--graphite);
}

.log-entry {
  padding: 7px 8px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--graphite);
  background: #f1f2f6;
  border: 1px solid rgba(33, 37, 41, 0.12);
  animation: fadeIn 0.25s ease-in;
}

.log-p1 {
  border-left: 4px solid var(--p1);
}

.log-p2 {
  border-left: 4px solid var(--p2);
}

.log-system {
  background: var(--mint);
  border-left: 4px solid var(--teal);
}

.log-alert {
  background: var(--warm);
  border-left: 4px solid var(--clay);
  font-weight: 700;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------------- Riddle Box ---------------- */

.riddle-box {
  margin-top: 18px;
  padding: 18px;
  text-align: center;
  background: var(--warm);
  border: 3px solid var(--p1);
  border-radius: var(--radius-md);
  box-shadow:
    4px 4px 0 var(--mud),
    0 8px 20px rgba(44, 32, 1, 0.14);
  animation: riddleReveal 0.28s ease-out;
}

@keyframes riddleReveal {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.riddle-box h3 {
  margin-bottom: 12px;
  padding-bottom: 9px;
  font-size: 1.05rem;
  color: var(--orange);
  border-bottom: 2px solid var(--clay);
}

#riddle-text {
  margin-bottom: 14px;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--graphite);
}

#riddle-tries {
  margin-bottom: 13px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--p1-border);
}

.riddle-input-group {
  display: flex;
  justify-content: center;
  gap: 9px;
}

#riddle-input {
  min-width: 0;
  flex: 1;
  max-width: 100%;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--graphite);
  background: var(--white);
  border: 3px solid var(--graphite);
  border-radius: var(--radius-sm);
  outline: none;
}

#riddle-input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(211, 84, 0, 0.14);
}

#riddle-submit-btn {
  flex-shrink: 0;
  padding: 10px 15px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--pebble);
  background: var(--orange);
  border: 3px solid var(--mud);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--mud);
}

#riddle-submit-btn:hover {
  background: var(--orange-light);
  transform: translateY(-2px);
  box-shadow: 4px 4px 0 var(--mud);
}

#riddle-submit-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--mud);
}

.bot-guess-label {
  display: inline-block;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--p2);
  background: var(--white);
  border: 2px dashed #74b9ff;
  border-radius: var(--radius-sm);
}

/* ---------------- Utility ---------------- */

.hidden {
  display: none !important;
}

/* ---------------- Media Responsive ---------------- */

@media (max-width: 900px) {
  body {
    padding: 16px;
    align-items: flex-start;
  }

  .app-container {
    width: min(680px, 100%);
    padding: 20px;
  }

  main {
    grid-template-columns: 1fr;
  }

  .controls-wrapper {
    width: min(560px, 100%);
    margin: 0 auto;
  }

  .controls {
    display: grid;
    grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1.2fr);
    align-items: stretch;
  }

  .logger-box {
    min-height: 100%;
  }
}

@media (max-width: 580px) {
  body {
    padding: 10px;
  }

  .menu-content,
  .modal-content {
    box-shadow:
      4px 4px 0 var(--mud),
      var(--shadow-soft);
  }

  .menu-content {
    padding: 34px 22px 26px;
  }

  .menu-title {
    margin-bottom: 25px;
  }

  .app-container {
    padding: 14px;
    border-width: 3px;
    box-shadow: 4px 4px 0 var(--mud);
  }

  main {
    gap: 20px;
  }

  #board-container {
    padding: 5px;
    border-width: 3px;
    box-shadow: 4px 4px 0 var(--mud);
  }

  #board {
    gap: 1px;
    border-width: 2px;
  }

  .tile-alt {
    border-width: 1px;
  }

  .tile-number {
    top: 2px;
    left: 2px;
    font-size: 0.46rem;
  }

  .tile-icon {
    font-size: 0.92rem;
  }

  .token {
    width: 12px;
    height: 12px;
    margin: 1px;
    border-width: 1px;
  }

  .controls {
    display: flex;
    flex-direction: column;
  }

  .riddle-input-group {
    flex-direction: column;
  }

  #riddle-submit-btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   POLISH PASS — Egyptian pixel-art assets, motion & sound UI
   Preserves the original game layout and palette.
   ============================================================ */

/* The original desert illustration remains the game's backdrop. */
.menu-title::before {
  content: '';
  display: block;
  width: 78px;
  height: 78px;
  margin: -16px auto 12px;
  background: url('./imgs/icons/sphinx.svg') center / contain no-repeat;
  filter: drop-shadow(3px 5px 0 rgba(44, 32, 1, .28));
}

/* Stronger, instantly recognizable board features. */
.tile-ladder {
  background-image: radial-gradient(circle at 60% 70%, rgba(255, 213, 116, .36), transparent 72%);
}
.tile-sphinx {
  background-image: radial-gradient(circle at center, rgba(203, 120, 60, .27), transparent 74%);
}
.tile-icon {
  display: block;
  width: 76%;
  height: 76%;
  max-width: 42px;
  max-height: 42px;
  margin: 3px 0 0;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  opacity: 1;
  filter: drop-shadow(0 2px 1px rgba(44,32,1,.35));
  transition: transform .18s ease, filter .18s ease;
}
.tile:hover .tile-icon {
  transform: scale(1.13);
  filter: drop-shadow(0 3px 2px rgba(44,32,1,.46));
}
.tile-sphinx .tile-number,
.tile-ladder .tile-number { text-shadow: 0 1px 0 rgba(255,246,201,.8); }

/* Replace tiny plain discs with readable pharaoh and scarab medallions. */
.token {
  position: absolute;
  z-index: 12;
  display: grid;
  place-items: center;
  width: clamp(21px, 2.5vw, 29px);
  height: clamp(21px, 2.5vw, 29px);
  margin: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  box-shadow: none;
  pointer-events: none;
  animation: none;
}
.token img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(1px 2px 1px rgba(42,25,9,.48));
}
.token-p1 { left: 0; bottom: 0; background: none; border: 0; }
.token-p2 { right: 0; bottom: 0; background: none; border: 0; }
.token-step { animation: tokenHop .19s cubic-bezier(.2, .7, .3, 1.3) both; }
@keyframes tokenHop {
  0% { transform: translateY(2px) scale(.78); }
  58% { transform: translateY(-6px) scale(1.14); }
  100% { transform: translateY(0) scale(1); }
}

/* Animate significant board moments without changing the rules. */
.tile-encounter {
  z-index: 5;
  animation: sphinxTilePulse 1.1s ease-in-out infinite;
}
.tile-encounter .tile-icon { filter: drop-shadow(0 0 5px #ff7e33); }
@keyframes sphinxTilePulse {
  0%, 100% { box-shadow: inset 0 0 0 2px #a34d29, 0 0 6px rgba(204,70,27,.48); }
  50% { box-shadow: inset 0 0 0 3px #f0af65, 0 0 16px rgba(244,113,50,.9); }
}
.tile-ascend { animation: ladderTileGlow 1.15s ease-out; }
@keyframes ladderTileGlow {
  0% { box-shadow: inset 0 0 0 2px #fff4b3, 0 0 22px #f5c66b; }
  100% { box-shadow: none; }
}
#dice.dice-rolling { animation: diceWobble .6s ease-in-out; }
@keyframes diceWobble {
  0%, 100% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-14deg) scale(1.04); }
  45% { transform: rotate(12deg) scale(1.1); }
  70% { transform: rotate(-8deg) scale(1.03); }
}

/* Board announcements stay legible but never intercept clicks. */
.board-toast {
  position: absolute;
  top: 41%;
  left: 50%;
  z-index: 30;
  width: max-content;
  max-width: 86%;
  padding: 11px 17px;
  border: 3px solid #f1c979;
  border-radius: 5px;
  background: rgba(39, 28, 20, .95);
  color: #fff0c2;
  box-shadow: 4px 5px 0 rgba(35, 24, 15, .38);
  font-weight: 700;
  font-size: clamp(.67rem, 1.6vw, .91rem);
  letter-spacing: .6px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px) scale(.94);
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}
.board-toast.visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0) scale(1);
}
.board-toast.sphinx { border-color: #db7539; color: #ffd6aa; }
.board-toast.ladder { border-color: #e9b34a; color: #ffe59c; }
.board-toast.success { border-color: #63ceb6; color: #adffe8; }

/* Stronger Sphinx challenge visual hierarchy. */
.riddle-box {
  background: linear-gradient(155deg, #fff0bd, #f4d68b);
  border-color: #a07603;
  box-shadow: 4px 4px 0 var(--mud), inset 0 0 0 3px rgba(255,244,189,.85), 0 9px 22px rgba(44,32,1,.16);
}
.riddle-box .riddle-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #6c361d;
  line-height: 1.3;
}
.riddle-title img {
  width: 37px;
  height: 37px;
  flex: none;
  filter: drop-shadow(1px 2px 1px rgba(82,44,17,.25));
}
#riddle-input:focus-visible,
.sound-toggle:focus-visible,
.audio-panel summary:focus-visible { outline: 3px solid #168ba2; outline-offset: 2px; }

/* Accessible volume and toggle panel, available from all game screens. */
.audio-panel {
  position: fixed;
  z-index: 280;
  right: 17px;
  bottom: 17px;
  width: min(265px, calc(100vw - 30px));
  color: #f8e6bb;
  background: rgba(39, 30, 24, .97);
  border: 2px solid #cf9640;
  border-radius: 7px;
  box-shadow: 4px 5px 0 rgba(37,28,20,.55), 0 12px 22px rgba(37,28,20,.27);
  font-family: 'Geist Pixel', sans-serif;
}
.audio-panel:not([open]) { width: max-content; min-width: 113px; }
.audio-panel summary {
  padding: 10px 14px;
  font-size: .81rem;
  font-weight: 700;
  color: #f4cf76;
  cursor: pointer;
  list-style: none;
  user-select: none;
  letter-spacing: .5px;
}
.audio-panel summary::-webkit-details-marker { display: none; }
.audio-panel summary span { color: #f6e8bd; margin-right: 5px; }
.audio-panel[open] summary { border-bottom: 1px solid rgba(232,186,101,.42); }
.audio-panel-body { padding: 13px 14px 16px; }
.audio-setting-row { display: flex; align-items: center; justify-content: space-between; gap: 9px; margin-bottom: 9px; }
.audio-setting-row label { font-size: .76rem; line-height: 1.25; }
.audio-panel input[type='range'] { width: 100%; accent-color: #e2b055; cursor: pointer; margin-bottom: 17px; }
.audio-panel input[type='range']:last-child { margin-bottom: 2px; }
.audio-panel input[type='range']:disabled { opacity: .33; cursor: not-allowed; }
.sound-toggle {
  min-width: 48px;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid #e8ba68;
  background: #e8b866;
  color: #312519;
  font-size: .68rem;
  font-weight: 700;
  cursor: pointer;
}
.sound-toggle[aria-pressed='false'] { background: #4f4437; color: #f2d7b3; border-color: #8d7052; }

@media (max-width: 580px) {
  .menu-title::before { width: 60px; height: 60px; margin-top: -9px; }
  .tile-icon { width: 87%; height: 87%; max-height: none; max-width: none; margin-top: 1px; }
  .token { width: clamp(16px, 5.2vw, 21px); height: clamp(16px, 5.2vw, 21px); border-width: 0; margin: 0; }
  .tile-number { z-index: 3; }
  .board-toast { padding: 8px 11px; font-size: .65rem; }
  .audio-panel { right: 10px; bottom: 10px; }
  .audio-panel summary { font-size: .77rem; padding: 10px 12px; }
}

/* Small matching iconography in the instructions and a token key. */
.how-to-play p {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}
.how-icon {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
}
.player-legend {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 13px;
  margin-left: 18px;
  vertical-align: middle;
}
.player-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .74rem;
  font-weight: 700;
  color: #4b3423;
}
.player-legend img { width: 29px; height: 29px; }
@media (max-width: 580px) {
  .menu-overlay { overflow-y: auto; align-items: flex-start; }
  .menu-content { margin: auto 0; }
  .player-legend { display: flex; margin: 9px 0 0; gap: 8px; }
  .player-legend img { width: 23px; height: 23px; }
}

/* Measured ladder overlay: tile backgrounds < ladders < icons/numbers < tokens. */
#board { position: relative; isolation: isolate; }
#ladder-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: visible;
  pointer-events: none;
}
/* Keep tiles out of stacking contexts so their tokens can clear the overlay. */
#board .tile { z-index: auto; }
#board .tile:hover { transform: none; filter: none; }
#board .tile-icon { position: relative; z-index: 2; }
#board .tile-number {
  z-index: 3;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--mud);
  /* Outline the glyphs only, leaving the ladder visible around each digit. */
  text-shadow:
    -.5px -.5px 0 #fff1ce, .5px -.5px 0 #fff1ce,
    -.5px .5px 0 #fff1ce, .5px .5px 0 #fff1ce;
}
.board-ladder { opacity: .94; }
.board-ladder.is-active {
  opacity: 1;
  filter: drop-shadow(0 0 3px #fff0ac);
  animation: ladderHighlight 1.15s ease-out;
}
@keyframes ladderHighlight {
  0%, 45% { filter: drop-shadow(0 0 5px #fff0ac) brightness(1.35); }
  100% { filter: drop-shadow(0 0 3px #fff0ac); }
}
@media (prefers-reduced-motion: reduce) {
  .board-ladder.is-active { animation: none; }
}

/* Responsive menu, board and controls, including short landscape screens. */
.menu-overlay,
.modal-overlay {
  overflow-y: auto;
  align-items: flex-start;
  padding-bottom: 80px;
}
.menu-content,
.modal-content { margin-block: auto; flex-shrink: 0; }

@media (max-width: 900px) {
  body { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  main, .controls-wrapper, .controls > * { min-width: 0; }
  .controls { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); }
  .menu-select, #riddle-input { font-size: 16px; }
  button, .menu-select, .audio-panel summary { min-height: 44px; }
  .audio-panel input[type='range'] { min-height: 32px; }
  .audio-panel {
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }
  .riddle-box, .log-entry { overflow-wrap: anywhere; }
}

@media (max-width: 580px) {
  body { padding-inline: 8px; padding-top: 8px; }
  .menu-overlay, .modal-overlay { padding: 14px 14px 80px; }
  .menu-content { padding: 24px 18px; }
  .menu-title { font-size: clamp(1.65rem, 7vw, 2.3rem); margin-bottom: 20px; }
  .menu-options { padding: 14px; margin-bottom: 20px; }
  .menu-info { margin-top: 22px; gap: 16px; }
  .info-section { padding: 14px; }
  .how-to-play p, .about-content { font-size: .875rem; }
  .modal-content { padding: 24px 18px; }
  .app-container { padding: 10px; }
  header { margin-bottom: 14px; padding-bottom: 10px; }
  header h1 { font-size: clamp(1.35rem, 6vw, 2rem); letter-spacing: 0; }
  #turn-indicator { font-size: .85rem; padding: 8px 10px; }
  .player-legend { gap: 6px 12px; }
  .player-legend span { font-size: .7rem; }
  main { gap: 14px; }
  #board-container { padding: 3px; border-width: 2px; }
  #board .tile-number {
    top: 1px;
    left: 1px;
    font-size: clamp(9px, 2.5vw, 12px);
    letter-spacing: 0;
  }
  .controls { gap: 12px; }
  .dice-box {
    display: grid;
    grid-template-columns: 60px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 10px;
  }
  #dice { width: 56px; height: 56px; font-size: 2.25rem; grid-row: 1 / span 2; }
  #roll-btn, #replay-btn { grid-column: 2; padding: 10px 8px; font-size: .95rem; }
  .logger-box { min-height: 0; padding: 10px; }
  .logger-box h3 { margin-bottom: 6px; padding-bottom: 6px; }
  #game-log { height: 100px; flex-grow: 0; }
  .riddle-box { padding: 12px; margin-top: 14px; }
  .riddle-box h3 { font-size: .95rem; }
  #riddle-text { font-size: .95rem; }
  .riddle-input-group { gap: 10px; }
}

@media (max-width: 360px) {
  .app-container { padding: 7px; }
  .menu-content { padding-inline: 14px; }
  .info-section { padding: 12px; }
  .how-to-play p { gap: 6px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .menu-overlay, .modal-overlay { padding-top: 12px; }
  .menu-content, .modal-content { margin-top: 0; }
}
