:root {
  --oak-dark: #4b2c16;
  --oak-mid: #704322;
  --oak-light: #9a6439;
  --oak-edge: #2d180b;
  --felt-dark: #314336;
  --felt-mid: #425947;
  --felt-light: #5f775f;
  --bone: #efe2c4;
  --amber: #d4a35e;
  --ink: #21170f;
  --text: #f7edd9;
  --muted: #d6c6ac;
  --danger: #8e3b2d;
  --shadow: rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.1), transparent 25%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.05), transparent 22%),
    linear-gradient(180deg, #25160c 0%, #1a1009 100%);
}

body {
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
}

.page-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 12% 15%, rgba(255,255,255,0.06), transparent 18%),
    radial-gradient(circle at 86% 78%, rgba(255,255,255,0.04), transparent 16%),
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,0.015) 0 2px,
      rgba(0,0,0,0.015) 2px 4px,
      transparent 4px 12px
    ),
    linear-gradient(180deg, #2d1b0f 0%, #1b1008 100%);
  filter: saturate(0.95);
  pointer-events: none;
}

.app-frame {
  position: relative;
  z-index: 1;
  padding: 18px;
}

.tray-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  border-radius: 34px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.08), transparent 20%),
    repeating-linear-gradient(
      8deg,
      rgba(38, 20, 8, 0.25) 0 8px,
      rgba(100, 57, 24, 0.18) 8px 16px,
      rgba(132, 81, 44, 0.2) 16px 24px
    ),
    linear-gradient(140deg, var(--oak-light), var(--oak-mid) 42%, var(--oak-dark));
  border: 4px solid rgba(34, 18, 8, 0.7);
  box-shadow:
    0 24px 60px rgba(0,0,0,0.48),
    inset 0 2px 1px rgba(255,255,255,0.12),
    inset 0 -5px 10px rgba(0,0,0,0.25),
    inset 20px 0 35px rgba(255,255,255,0.04),
    inset -20px 0 35px rgba(0,0,0,0.12);
}

.tray-inner {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 1.35fr 0.72fr;
  gap: 18px;
  padding: 18px;
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 15%, rgba(255,255,255,0.07), transparent 25%),
    radial-gradient(circle at 20% 80%, rgba(255,255,255,0.03), transparent 18%),
    repeating-linear-gradient(
      120deg,
      rgba(255,255,255,0.02) 0 3px,
      rgba(0,0,0,0.02) 3px 6px,
      transparent 6px 14px
    ),
    linear-gradient(180deg, var(--felt-mid), var(--felt-dark));
  border: 2px solid rgba(27, 15, 8, 0.6);
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,0.04),
    inset 0 12px 24px rgba(255,255,255,0.03),
    inset 0 -20px 35px rgba(0,0,0,0.16);
}

.main-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
}

.panel {
  border-radius: 22px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.04)),
    repeating-linear-gradient(
      135deg,
      rgba(255,255,255,0.015) 0 2px,
      transparent 2px 8px
    );
  border: 1px solid rgba(238, 220, 181, 0.16);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.08),
    inset 0 -10px 20px rgba(0,0,0,0.08),
    0 10px 25px rgba(0,0,0,0.18);
  backdrop-filter: blur(2px);
}

.intro-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 2.8vw, 2.5rem);
  color: var(--bone);
  letter-spacing: 0.03em;
}

h2 {
  color: #f0e4ca;
  font-size: 1.3rem;
}

.subtitle,
.section-head p,
.empty-state p,
.history-meta {
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.controls-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

button {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

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

.control-btn,
.clear-btn,
.roll-btn,
.remove-btn {
  border-radius: 14px;
  padding: 12px 14px;
}

.control-btn {
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.13), rgba(255,255,255,0.05)),
    linear-gradient(180deg, rgba(118,76,42,0.4), rgba(71,43,22,0.4));
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 10px 18px rgba(0,0,0,0.18);
}

.clear-btn {
  color: #fff0e8;
  background:
    linear-gradient(180deg, #a04b38, #723020);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 10px 18px rgba(0,0,0,0.18);
}

.roll-head {
  margin-bottom: 14px;
}

.roll-btn {
  min-width: 180px;
  font-weight: 700;
  color: var(--ink);
  background:
    linear-gradient(180deg, #e2c792, #b68548);
  box-shadow: 0 12px 22px rgba(0,0,0,0.28);
}

.selection-chip {
  padding: 9px 13px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--bone);
  white-space: nowrap;
}

.dice-area {
  min-height: 330px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 18px;
  align-content: start;
}

.empty-state {
  min-height: 230px;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 18px;
  border: 1px dashed rgba(255,255,255,0.16);
  background: rgba(0,0,0,0.06);
  padding: 20px;
}

.die-card {
  position: relative;
  min-height: 144px;
  display: grid;
  place-items: center;
  padding: 18px 12px 14px;
  border-radius: 20px;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,0.16), transparent 24%),
    rgba(0,0,0,0.08);
  border: 1px solid rgba(255,255,255,0.08);
}

.remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  color: var(--text);
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.12);
  z-index: 3;
}

.die-wrap {
  width: 100%;
  display: grid;
  place-items: center;
}

.die-shape {
  position: relative;
  display: grid;
  place-items: center;
  color: #1c140d;
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
  box-shadow:
    0 12px 20px rgba(0,0,0,0.24),
    inset 0 1px 1px rgba(255,255,255,0.35),
    inset 0 -8px 16px rgba(0,0,0,0.14);
  border: 2px solid rgba(63, 39, 17, 0.5);
  background:
    radial-gradient(circle at 28% 24%, rgba(255,255,255,0.35), transparent 20%),
    linear-gradient(145deg, #f3e0b8 0%, #e0c387 52%, #b7894e 100%);
}

.die-label {
  margin-top: 10px;
  font-size: 0.86rem;
  color: var(--bone);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}

.die-value {
  font-size: clamp(1.15rem, 2vw, 1.7rem);
  font-weight: 700;
  z-index: 2;
  text-align: center;
  line-height: 1;
}



.die-shape.d6 {
  width: 86px;
  height: 86px;
  border-radius: 18px;
}

.die-shape.d4 {
  width: 86px;
  height: 76px;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.die-shape.d8 {
  width: 88px;
  height: 92px;
  clip-path: polygon(50% 0%, 100% 35%, 100% 65%, 50% 100%, 0% 65%, 0% 35%);
}

.die-shape.d12 {
  width: 92px;
  height: 92px;
  clip-path: polygon(50% 0%, 76% 6%, 94% 24%, 100% 50%, 94% 76%, 76% 94%, 50% 100%, 24% 94%, 6% 76%, 0% 50%, 6% 24%, 24% 6%);
}

.die-shape.d20 {
  width: 92px;
  height: 92px;
  clip-path: polygon(50% 0%, 80% 10%, 100% 35%, 96% 68%, 80% 90%, 50% 100%, 20% 90%, 4% 68%, 0% 35%, 20% 10%);
}

.die-shape.d100 {
  width: 96px;
  height: 96px;
  clip-path: polygon(50% 0%, 70% 4%, 87% 14%, 98% 31%, 100% 50%, 96% 69%, 86% 86%, 69% 96%, 50% 100%, 31% 96%, 14% 86%, 4% 69%, 0% 50%, 2% 31%, 13% 14%, 30% 4%);
}


.die-shape.coin {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  transform-style: preserve-3d;
  background: transparent;
  border: 4px solid rgba(113, 76, 24, 0.7);
  overflow: visible;
}

.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1.9rem;
  font-weight: 700;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.18), inset 0 -8px 14px rgba(0,0,0,0.18);
}

.coin-face.coin-heads {
  color: #3f2810;
  background:
    radial-gradient(circle at 30% 26%, rgba(255,255,255,0.42), transparent 18%),
    linear-gradient(145deg, #f7e5ad, #d9ae4f 58%, #9d6f21);
  transform: rotateY(0deg);
}

.coin-face.coin-tails {
  color: #f6efe4;
  background:
    radial-gradient(circle at 30% 26%, rgba(255,255,255,0.28), transparent 18%),
    linear-gradient(145deg, #b88266, #8e573e 58%, #5c3323);
  transform: rotateY(180deg);
}

.die-shape.coin.heads {
  transform: rotateY(0deg);
}

.die-shape.coin.tails {
  transform: rotateY(180deg);
}

.die-card.rolling .die-shape {
  animation: tumble 0.85s ease-in-out;
}

@keyframes tumble {
  0% { transform: translateY(0) rotate(0deg) scale(1); }
  18% { transform: translate(-4px, -8px) rotate(-14deg) scale(1.05); }
  34% { transform: translate(6px, 2px) rotate(17deg) scale(0.96); }
  50% { transform: translate(-6px, 6px) rotate(-18deg) scale(1.03); }
  68% { transform: translate(5px, -3px) rotate(12deg) scale(0.98); }
  84% { transform: translate(-2px, 2px) rotate(-6deg) scale(1.01); }
  100% { transform: translateY(0) rotate(0deg) scale(1); }
}

.history-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.history-item {
  border-radius: 16px;
  padding: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  border: 1px solid rgba(255,255,255,0.12);
}

.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.86rem;
}

.history-results {
  line-height: 1.45;
  color: var(--bone);
}

@media (max-width: 960px) {
  .tray-inner {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .history-panel {
    min-height: 280px;
  }
}

@media (max-width: 680px) {
  .app-frame {
    padding: 12px;
  }

  .tray-shell,
  .tray-inner {
    padding: 12px;
  }

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

  .dice-area {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .roll-btn {
    width: 100%;
  }

  .selection-chip {
    white-space: normal;
  }
}


.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1.9rem;
  font-weight: 700;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.18), inset 0 -8px 14px rgba(0,0,0,0.18);
}

.coin-face.coin-heads {
  color: #3f2810;
  background:
    radial-gradient(circle at 30% 26%, rgba(255,255,255,0.42), transparent 18%),
    linear-gradient(145deg, #f7e5ad, #d9ae4f 58%, #9d6f21);
  transform: rotateY(0deg);
}

.coin-face.coin-tails {
  color: #f6efe4;
  background:
    radial-gradient(circle at 30% 26%, rgba(255,255,255,0.28), transparent 18%),
    linear-gradient(145deg, #b88266, #8e573e 58%, #5c3323);
  transform: rotateY(180deg);
}

.die-shape.coin {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  transform-style: preserve-3d;
  background: transparent;
  border: 4px solid rgba(113, 76, 24, 0.7);
  overflow: visible;
}

.die-shape.coin.heads {
  transform: rotateY(0deg);
}

.die-shape.coin.tails {
  transform: rotateY(180deg);
}

.die-card.rolling .die-shape.coin {
  animation: coin-toss 1s ease-in-out;
}

  20% { transform: translateY(-18px) rotateX(540deg) rotateY(12deg); }
  45% { transform: translateY(-34px) rotateX(1260deg) rotateY(-10deg); }
  70% { transform: translateY(-14px) rotateX(1980deg) rotateY(8deg); }
  100% { transform: translateY(0) rotateX(2520deg) rotateY(0deg); }
}


.die-card.rolling .die-shape.coin {
  animation: coin-toss 1s ease-in-out;
}

@keyframes coin-toss {
  0% { transform: translateY(0) rotateX(0deg) rotateY(0deg); }
  20% { transform: translateY(-18px) rotateX(540deg) rotateY(12deg); }
  45% { transform: translateY(-34px) rotateX(1260deg) rotateY(-10deg); }
  70% { transform: translateY(-14px) rotateX(1980deg) rotateY(8deg); }
  100% { transform: translateY(0) rotateX(2520deg) rotateY(0deg); }
}
