:root {
  color-scheme: dark;
  --bg: #120f0d;
  --bg-soft: #1e1815;
  --panel: rgba(32, 23, 18, 0.82);
  --panel-strong: rgba(54, 39, 29, 0.92);
  --line: rgba(255, 220, 170, 0.12);
  --text: #f8ead6;
  --muted: #cfb99d;
  --accent: #e6b75f;
  --accent-strong: #f2d38f;
  --shadow: rgba(0, 0, 0, 0.42);
  --success: #fff2bf;
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  font-family: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(209, 143, 53, 0.18), transparent 34%),
    radial-gradient(circle at 80% 20%, rgba(186, 91, 38, 0.18), transparent 22%),
    linear-gradient(145deg, #090807 0%, #15110f 52%, #211913 100%);
  color: var(--text);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 225, 179, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 225, 179, 0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at center, black 55%, transparent 100%);
  pointer-events: none;
}

.page-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.ambient {
  position: fixed;
  width: 34rem;
  height: 34rem;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.18;
  pointer-events: none;
}

.ambient-left {
  top: -8rem;
  left: -10rem;
  background: #ecb65a;
}

.ambient-right {
  right: -10rem;
  bottom: -10rem;
  background: #9b4b22;
}

.app-card {
  position: relative;
  width: min(1100px, 100%);
  display: grid;
  gap: 22px;
  padding: clamp(20px, 3vw, 34px);
  border: 1px solid var(--line);
  border-radius: 36px;
  background:
    linear-gradient(180deg, rgba(255, 244, 224, 0.04), rgba(255, 244, 224, 0)),
    rgba(11, 9, 8, 0.68);
  box-shadow:
    0 24px 80px var(--shadow),
    inset 0 1px 0 rgba(255, 237, 206, 0.08);
  backdrop-filter: blur(20px);
}

.app-header h1,
.history-header h2,
.rules-content h2,
.rules-content h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

.rules-panel,
.board,
.history-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 229, 185, 0.05), rgba(255, 229, 185, 0)),
    var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 240, 218, 0.06);
}

.rules-panel {
  padding: 0;
  overflow: hidden;
}

.history-card {
  padding: 0;
  overflow: hidden;
}

.rules-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 18px 22px;
  color: var(--accent-strong);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.history-summary {
  list-style: none;
  cursor: pointer;
  padding: 18px 22px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
}

.rules-panel summary::-webkit-details-marker {
  display: none;
}

.history-summary::-webkit-details-marker {
  display: none;
}

.rules-panel summary::after {
  content: "+";
  float: right;
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
}

.rules-panel[open] summary::after {
  content: "-";
}

.history-summary::after {
  content: "+";
  float: right;
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
}

.history-card[open] .history-summary::after {
  content: "-";
}

.rules-content {
  padding: 0 22px 22px;
  border-top: 1px solid rgba(255, 220, 170, 0.08);
}

.history-content {
  padding: 0 22px 22px;
  border-top: 1px solid rgba(255, 220, 170, 0.08);
}

.rules-content h2 {
  margin-top: 18px;
  margin-bottom: 12px;
  font-size: 1.45rem;
}

.rules-content h3 {
  margin-top: 18px;
  margin-bottom: 8px;
  font-size: 1rem;
  color: var(--accent-strong);
}

.rules-content p,
.rules-content li {
  color: var(--muted);
  line-height: 1.6;
}

.rules-content ul {
  margin: 0;
  padding-left: 20px;
}

.board {
  padding: clamp(18px, 3vw, 28px);
}

.board-top,
.history-header,
.controls {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.score-panel {
  min-width: min(240px, 100%);
  flex: 1 1 240px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 246, 228, 0.03);
}

.panel-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.total-value,
.binary-value {
  display: block;
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  letter-spacing: 0.04em;
}

.dice-tray {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 24px);
  margin: 26px 0;
}

.die {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 120px;
  border-radius: 28px;
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 224, 163, 0.18), transparent 38%),
    linear-gradient(180deg, rgba(255, 250, 239, 0.04), rgba(255, 250, 239, 0)),
    linear-gradient(180deg, rgba(33, 25, 19, 0.96), rgba(19, 14, 11, 0.98));
  border: 1px solid rgba(255, 220, 170, 0.08);
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(255, 244, 224, 0.05),
    0 20px 40px rgba(0, 0, 0, 0.2);
}

.die::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 22px;
  border: 1px solid rgba(255, 229, 192, 0.05);
}

.die::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: 14px;
  height: 14px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.32), transparent 72%);
  filter: blur(6px);
}

.die-reel {
  --symbol-size: clamp(92px, 11vw, 110px);
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(68%, 148px);
  height: var(--symbol-size);
  transform: translate(-50%, -50%);
  border-radius: 24px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 248, 231, 0.06), rgba(255, 248, 231, 0)),
    linear-gradient(180deg, rgba(12, 9, 7, 0.9), rgba(20, 15, 12, 0.96));
  border: 1px solid rgba(255, 220, 170, 0.08);
  box-shadow:
    inset 0 18px 28px rgba(255, 255, 255, 0.025),
    inset 0 -18px 28px rgba(0, 0, 0, 0.3);
}

.die-reel::before,
.die-reel::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 24px;
  z-index: 2;
  pointer-events: none;
}

.die-reel::before {
  top: 0;
  background: linear-gradient(180deg, rgba(14, 10, 8, 0.92), transparent);
}

.die-reel::after {
  bottom: 0;
  background: linear-gradient(0deg, rgba(14, 10, 8, 0.92), transparent);
}

.reel-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  transform: translateY(calc(var(--reel-position, 0) * -1 * var(--symbol-size)));
  transition: transform var(--spin-duration, 1100ms) cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.reel-symbol {
  height: var(--symbol-size);
  display: grid;
  place-items: center;
}

.reel-dot {
  width: clamp(36px, 4vw, 44px);
  height: clamp(36px, 4vw, 44px);
  border-radius: 50%;
  border: 3px solid rgba(247, 216, 158, 0.9);
  background: transparent;
  box-shadow:
    0 0 0 8px rgba(255, 226, 177, 0.05),
    inset 0 1px 0 rgba(255, 252, 241, 0.14);
  transition:
    background-color 220ms ease,
    box-shadow 220ms ease,
    transform 220ms ease;
}

.reel-symbol.is-filled .reel-dot {
  background: radial-gradient(circle at 35% 35%, #fff4d3 0%, #f0c973 22%, #d09438 58%, #8f5a17 100%);
  box-shadow:
    0 0 0 8px rgba(255, 226, 177, 0.08),
    0 10px 20px rgba(195, 129, 33, 0.18),
    inset 0 1px 0 rgba(255, 250, 238, 0.5);
}

.die.is-marked .die-reel {
  border-color: rgba(242, 211, 143, 0.18);
  box-shadow:
    inset 0 18px 28px rgba(255, 255, 255, 0.03),
    inset 0 -18px 28px rgba(0, 0, 0, 0.3),
    0 0 28px rgba(221, 160, 67, 0.12);
}

.die.is-marked .reel-dot {
  transform: scale(1.04);
}

.die.is-marked {
  border-color: rgba(239, 204, 128, 0.12);
}

.die.is-idle {
  --reel-position: 0;
}

.die.is-rolling {
  border-color: rgba(239, 204, 128, 0.14);
}

button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.roll-button,
.ghost-button {
  min-height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  transition:
    transform 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.roll-button {
  color: #28190c;
  font-weight: 700;
  background:
    linear-gradient(180deg, #f4ddb4 0%, #e5b969 58%, #c38432 100%);
  box-shadow:
    0 12px 32px rgba(208, 142, 47, 0.26),
    inset 0 1px 0 rgba(255, 244, 222, 0.82);
}

.ghost-button {
  color: var(--text);
  border: 1px solid rgba(255, 227, 185, 0.16);
  background: rgba(255, 247, 232, 0.04);
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 2px solid rgba(255, 227, 160, 0.8);
  outline-offset: 3px;
}

.eyebrow,
.eyebrow-small {
  display: none;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 224, 185, 0.08);
  background:
    linear-gradient(90deg, rgba(255, 233, 198, 0.05), rgba(255, 233, 198, 0.01)),
    rgba(255, 245, 231, 0.02);
}

.history-roll {
  color: var(--success);
  font-size: 1rem;
}

.history-bits {
  color: var(--muted);
  font-family: "Courier New", monospace;
  letter-spacing: 0.12em;
}

@media (max-width: 760px) {
  .page-shell {
    padding: 14px;
  }

  .app-card {
    border-radius: 28px;
    padding: 16px;
  }

  .dice-tray {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .die {
    min-height: 132px;
  }

  .die-reel {
    --symbol-size: min(28vw, 108px);
    width: min(70%, 148px);
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}
