:root {
  color-scheme: light only;
  --lsq: #f4ead8;
  --dsq: #8c7d6a;
  --bg: #ece4d2;
  --ink: #1a1a1a;
  --cream: #f4ead8;
  --accent: #f7c32a;
  --accent2: #d6452b;
  --blue: #2e4d8f;
}

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Helvetica Neue', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
  gap: 12px;
}

#topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#topLogo {
  width: 72px;
  height: 72px;
  display: block;
  object-fit: contain;
  flex-shrink: 0;
}

#topbar h1 {
  font-family: 'Bebas Neue', 'Impact', 'Helvetica Neue', sans-serif;
  font-size: 32px;
  letter-spacing: 0.08em;
  font-weight: 700;
}

/* ---------- Menu ---------- */

#menuBtn {
  width: 44px;
  height: 44px;
  background: var(--cream);
  border: 3px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  color: var(--ink);
}

#menuBtn:active {
  background: var(--accent);
}

#menuBtn svg {
  display: block;
}

.menu-panel {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--cream);
  border: 3px solid var(--ink);
  z-index: 50;
  min-width: 200px;
  box-shadow: 4px 4px 0 rgba(26, 26, 26, 0.15);
}

.menu-panel.hidden {
  display: none;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 14px 18px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(26, 26, 26, 0.18);
  font-family: 'Bebas Neue', 'Impact', sans-serif;
  font-size: 18px;
  letter-spacing: 0.08em;
  text-align: left;
  cursor: pointer;
  text-transform: uppercase;
  color: var(--ink);
  appearance: none;
  -webkit-appearance: none;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-item:disabled {
  color: rgba(26, 26, 26, 0.3);
  cursor: not-allowed;
}

.menu-item:not(:disabled):active {
  background: var(--accent);
}

/* ---------- Board ---------- */

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 4px solid var(--ink);
  background: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sq.light {
  background: var(--lsq);
}

.sq.dark {
  background: var(--dsq);
}

.sq svg {
  width: 78%;
  height: 78%;
  pointer-events: none;
  display: block;
  position: relative;
  z-index: 1;
}

/* ---------- Highlights ---------- */

.sq.selected {
  outline: 4px solid var(--accent);
  outline-offset: -4px;
  z-index: 3;
}

.sq.valid-move::after {
  content: '';
  position: absolute;
  width: 28%;
  aspect-ratio: 1;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
}

.sq.valid-capture {
  outline: 4px solid var(--accent2);
  outline-offset: -4px;
  z-index: 2;
}

/* ---------- Panel ---------- */

#panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--ink);
  min-height: 56px;
}

.status-line {
  font-family: 'Bebas Neue', 'Impact', sans-serif;
  font-size: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.die-display {
  width: 54px;
  height: 54px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', 'Impact', sans-serif;
  font-size: 32px;
  color: var(--ink);
  flex-shrink: 0;
}

.die-display.rexy {
  background: var(--accent);
  padding: 2px;
}

.die-display svg,
.die-display img,
.rexy-die-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.die-empty {
  color: var(--ink);
  opacity: 0.4;
}

.roll-btn {
  flex: 1;
  min-height: 54px;
  background: var(--ink);
  color: var(--cream);
  border: none;
  font-family: 'Bebas Neue', 'Impact', sans-serif;
  font-size: 22px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
}

.roll-btn:disabled {
  background: #b6ada0;
  color: #f4ead8;
  cursor: not-allowed;
}

.roll-btn:not(:disabled):active {
  background: var(--accent2);
}

/* ---------- Rexy hunt ---------- */

#board {
  position: relative;
}

.rexy-hunter {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.4, 1.6, 0.5, 1);
}

.rexy-hunter::before {
  content: '';
  position: absolute;
  inset: -4%;
  background: var(--accent);
  border: 3px solid var(--ink);
  border-radius: 50%;
  z-index: -1;
}

.rexy-hunter img {
  width: 110%;
  height: 110%;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.rexy-hunter.bounce img {
  animation: rexyBounce 0.3s ease-out;
}

.rexy-hunter.pounce img {
  animation: rexyPounce 0.5s cubic-bezier(0.4, 1.5, 0.5, 1);
}

@keyframes rexyBounce {
  0%, 100% { transform: scale(1) rotate(0); }
  50% { transform: scale(1.25) rotate(-4deg); }
}

@keyframes rexyPounce {
  0% { transform: scale(1) rotate(0); }
  30% { transform: scale(1.6) rotate(-14deg); }
  60% { transform: scale(1.45) rotate(10deg); }
  100% { transform: scale(1.35) rotate(0); }
}

.rexy-toast {
  position: fixed;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: var(--accent);
  border: 3px solid var(--ink);
  padding: 14px 24px;
  font-family: 'Bebas Neue', 'Impact', sans-serif;
  font-size: 24px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition:
    opacity 0.22s ease-out,
    transform 0.32s cubic-bezier(0.2, 1.5, 0.5, 1);
}

.rexy-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@media (prefers-reduced-motion: reduce) {
  .winner-card { transition: none; }
  .winner-modal { transition: none; }
  .rexy-hunter { transition: none; }
  .rexy-hunter.bounce img,
  .rexy-hunter.pounce img { animation: none; }
  .rexy-toast { transition: opacity 0.1s; }
  .load-splash .splash-card { transition: opacity 0.2s; }
  .load-splash .splash-logo { animation: none; }
}

/* ---------- Load splash ---------- */

.load-splash {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
}

.load-splash.exit {
  opacity: 0;
  transition: opacity 0.4s ease-out;
  pointer-events: none;
}

.splash-card {
  text-align: center;
  transform: scale(0.5);
  opacity: 0;
  transition:
    transform 0.55s cubic-bezier(0.2, 1.7, 0.5, 1),
    opacity 0.3s ease-out;
}

.load-splash.show .splash-card {
  transform: scale(1);
  opacity: 1;
}

.splash-logo {
  width: min(60vw, 260px);
  height: auto;
  display: block;
  margin: 0 auto;
}

.load-splash.show .splash-logo {
  animation: splashWiggle 1.6s ease-in-out 0.55s infinite;
  transform-origin: 50% 80%;
}

.splash-title {
  font-family: 'Bebas Neue', 'Impact', 'Helvetica Neue', sans-serif;
  font-size: 44px;
  letter-spacing: 0.12em;
  color: var(--ink);
  margin-top: 18px;
}

@keyframes splashWiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-5deg); }
  40% { transform: rotate(4deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(2deg); }
}

/* ---------- Winner modal ---------- */

.winner-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 26, 0);
  z-index: 90;
  transition: background 0.2s ease-out;
}

.winner-modal.show {
  background: rgba(26, 26, 26, 0.55);
}

.winner-card {
  background: var(--cream);
  border: 4px solid var(--ink);
  padding: 28px 22px;
  max-width: 320px;
  width: calc(100% - 48px);
  text-align: center;
  transform: scale(0.85);
  opacity: 0;
  transition:
    transform 0.28s cubic-bezier(0.2, 1.4, 0.5, 1),
    opacity 0.18s ease-out;
}

.winner-modal.show .winner-card {
  transform: scale(1);
  opacity: 1;
}

.winner-text {
  font-family: 'Bebas Neue', 'Impact', sans-serif;
  font-size: 36px;
  letter-spacing: 0.1em;
  color: var(--ink);
  margin-bottom: 22px;
}

.winner-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.winner-new-game,
.winner-close {
  min-height: 48px;
  padding: 12px 16px;
  font-family: 'Bebas Neue', 'Impact', sans-serif;
  font-size: 22px;
  letter-spacing: 0.1em;
  border: 3px solid var(--ink);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.winner-new-game {
  background: var(--ink);
  color: var(--cream);
}

.winner-close {
  background: var(--cream);
  color: var(--ink);
}

.winner-new-game:active { background: var(--accent2); }
.winner-close:active { background: var(--bg); }
