:root {
  --tile: 64px;
  --bg: #0b1220;
  --panel: #141d31;
  --line: #263454;
  --text: #e6ebf5;
  --muted: #94a3b8;
  --tile1: #e8ebf3;
  --tile2: #d9deea;
  --accent: #34d399;
  --hint: #fbbf24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 700px at 50% -10%, #16213c, var(--bg));
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
}

.app {
  width: min(760px, 100vw);
  padding: 18px 16px 32px;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px 10px;
}

.hud h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
}

.chip {
  white-space: nowrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip b { color: var(--text); font-size: 13px; }

.dev-chip {
  border-color: var(--hint);
  color: var(--hint);
  cursor: pointer;
}

.buttons { margin-left: auto; display: flex; gap: 5px; }

button {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 5px 10px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:hover { background: #1d2947; }
button:active { transform: translateY(1px); }

.message {
  min-height: 20px;
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 3D scene ---------- */
/* Parallel projection (no perspective): edges stay parallel, so the die
   and board render as clean isometric solids. */
.scene {
  position: relative;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  overflow: visible;
}

.tilt {
  transform: rotateX(54.7deg) rotateZ(-30deg);
  transform-style: preserve-3d;
  flex: none;
}

.board {
  position: relative;
  transform-style: preserve-3d;
}

/* ---------- tiles ---------- */
.cell {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  cursor: pointer;
}

.cell.on-wall .tile {
  filter: brightness(0.94) saturate(1.05);
}

.tile {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--tile) * 0.14);
  background: var(--tile1);
  box-shadow: 0 calc(var(--tile) * 0.09) 0 rgba(8, 12, 24, 0.55);
}

.tile.alt { background: var(--tile2); }

.tile.bridge {
  background:
    repeating-linear-gradient(90deg,
      rgba(43, 24, 8, 0.28) 0 2px,
      transparent 2px calc(var(--tile) / 4)),
    linear-gradient(160deg, #c99a62, #9a6d3c);
  box-shadow:
    inset 0 0 0 2px rgba(58, 35, 13, 0.45),
    0 calc(var(--tile) * 0.09) 0 rgba(40, 24, 8, 0.7);
}

.tile.collapsed {
  visibility: hidden;
  pointer-events: none;
}

.tile.spinner {
  background:
    radial-gradient(circle at 50% 50%, rgba(124, 140, 248, 0.16) 0 54%, transparent 55%),
    var(--tile1);
}

.tile.spinner::after {
  content: '\27F3';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * 0.46);
  font-weight: 700;
  color: #7c8cf8;
  opacity: 0.85;
}

/* ---------- crates ---------- */
.crate-pos {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  transition: transform 230ms cubic-bezier(0.35, 0.1, 0.35, 1);
  cursor: pointer;
}

.crate-body {
  position: absolute;
  transform-style: preserve-3d;
}

.crate-face {
  position: absolute;
  background:
    repeating-linear-gradient(0deg,
      rgba(38, 22, 8, 0.25) 0 2px,
      transparent 2px 9px),
    linear-gradient(160deg, #a97e4c, #7c5730);
  box-shadow: inset 0 0 0 2px rgba(46, 28, 10, 0.55);
  backface-visibility: hidden;
}

.crate-top {
  background:
    linear-gradient(45deg, transparent 46%, rgba(46, 28, 10, 0.5) 46%, rgba(46, 28, 10, 0.5) 54%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, rgba(46, 28, 10, 0.5) 46%, rgba(46, 28, 10, 0.5) 54%, transparent 54%),
    linear-gradient(160deg, #b98c57, #8a6238);
  box-shadow: inset 0 0 0 3px rgba(46, 28, 10, 0.6);
}

.crate-body.sunk .crate-face {
  filter: brightness(0.75);
}

.tile.start::after {
  content: '';
  position: absolute;
  inset: 38%;
  border-radius: 50%;
  border: 2px dashed #9aa7bf;
  opacity: 0.7;
}

.tile.goal {
  background: linear-gradient(160deg, #baf7dd, #6ee7b7);
  box-shadow:
    0 calc(var(--tile) * 0.09) 0 rgba(6, 60, 40, 0.65),
    0 0 calc(var(--tile) * 0.5) rgba(52, 211, 153, 0.55);
  animation: goal-pulse 1.8s ease-in-out infinite;
}

@keyframes goal-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
}

/* ---------- pip faces ---------- */
.mini-face, .face {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  place-items: center;
}

.mini-face {
  width: 19px;
  height: 19px;
  background: #fff;
  border-radius: 5px;
  padding: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.mini-face .pip {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #1f2937;
}

.mini-face.val-1 .pip { background: #dc2626; }

.mini-face.on-tile {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 58%;
  height: 58%;
  padding: 12%;
  border-radius: 18%;
  background: rgba(255, 255, 255, 0.92);
}

.mini-face.on-tile .pip {
  width: 55%;
  height: 55%;
}

/* ---------- die ---------- */
.die-pos, .die-lift, .die-hop, .cube {
  position: absolute;
  transform-style: preserve-3d;
}

.die-pos {
  left: 0;
  top: 0;
  transition: transform 230ms cubic-bezier(0.35, 0.1, 0.35, 1);
  pointer-events: none;
}

.die-hop, .cube { inset: 0; }

.cube { transition: transform 230ms cubic-bezier(0.35, 0.1, 0.35, 1); }

.no-anim { transition: none !important; }

.die-shadow {
  position: absolute;
  left: 12%;
  top: 12%;
  width: 76%;
  height: 76%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45), transparent 68%);
  transform: translateZ(0.6px);
  opacity: 0.45;
}

.face {
  position: absolute;
  inset: 0;
  background: linear-gradient(150deg, #ffffff, #e4e7ee);
  border-radius: 16%;
  padding: 12%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  backface-visibility: hidden;
}

.face .pip {
  width: 62%;
  height: 62%;
  border-radius: 50%;
  background: #1f2430;
  box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.55);
}

.face.val-1 .pip { background: #d81f3d; }

/* ---------- hint ---------- */
.hint-cell {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.hint-arrow {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * 0.62);
  font-weight: 700;
  color: var(--hint);
  text-shadow: 0 0 14px rgba(251, 191, 36, 0.9);
}

/* ---------- win overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 9, 18, 0.55);
  backdrop-filter: blur(2px);
  z-index: 10;
}

.overlay.hidden { display: none; }

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 34px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.card h2 { margin: 0 0 6px; font-size: 24px; color: var(--accent); }
.card p { margin: 0 0 16px; color: var(--muted); }
.card .btn-row { display: flex; gap: 10px; justify-content: center; }

#btn-next,
#btn-daily,
#btn-daily-info {
  background: var(--accent);
  border-color: transparent;
  color: #06281c;
  font-weight: 600;
}

#btn-next:hover,
#btn-daily:hover,
#btn-daily-info:hover { background: #4ade9f; }

/* Amber dot on the Daily buttons while today's puzzle is unsolved. */
#btn-daily,
#btn-daily-info { position: relative; }

.daily-new { padding-right: 13px; }

.daily-new::after {
  content: '';
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fbbf24;
  border: 2px solid #0b1220;
  animation: daily-pulse 2s ease-in-out infinite;
}

@keyframes daily-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.confetti span {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  opacity: 0;
}

.info-btn {
  width: 28px;
  padding: 5px 0;
  border-radius: 50%;
  font-style: italic;
  font-family: Georgia, serif;
  font-weight: 700;
  color: var(--muted);
}

.info-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 9, 18, 0.6);
  backdrop-filter: blur(2px);
  padding: 20px;
}

.info-modal.hidden { display: none; }

.info-card {
  max-width: 440px;
  text-align: left;
  padding: 24px 28px;
}

.info-card h2 {
  margin: 0 0 10px;
  font-size: 20px;
  color: var(--text);
}

.info-card p {
  margin: 0 0 10px;
  color: var(--muted);
}

.info-card ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.info-card li { margin-bottom: 6px; }

.info-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  padding: 3px 0;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
}

/* ---------- compact single line header on narrow screens ---------- */
.info-share { margin-top: 14px; }

body.dev #btn-daily { display: none; }

@media (max-width: 660px) {
  .wide-share { display: none; }
  .hud { gap: 4px 6px; flex-wrap: wrap; }
  .hud h1 { font-size: 15px; }
  .chip { padding: 2px 7px; font-size: 11px; gap: 4px; }
  .chip b { font-size: 12px; }
  .buttons { gap: 4px; }
  button { padding: 4px 7px; font-size: 12px; }
  .info-btn { width: 24px; padding: 4px 0; }
  .mini-face { width: 17px; height: 17px; }
  .wide-only { display: none; }
}

@media (max-width: 400px) {
  .mid-only { display: none; }
  .hud { gap: 2px 3px; }
  .hud h1 { display: none; }
  .buttons { gap: 2px; }
}

@media (max-width: 480px) {
  .app { padding: 12px 10px 24px; }
  .hud { gap: 3px 4px; }
  .hud h1 { font-size: 13px; }
  .chip { padding: 2px 5px; font-size: 10px; gap: 3px; }
  .chip b { font-size: 11px; }
  .buttons { gap: 3px; }
  button { padding: 3px 6px; font-size: 11px; }
  .info-btn { width: 21px; padding: 3px 0; }
  .mini-face { width: 15px; height: 15px; }
}
