@font-face {
  font-family: "Cinzel";
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url("fonts/cinzel-latin.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-latin.woff2") format("woff2");
}

:root {
  color-scheme: dark;
  --felt: #14241c;
  --felt-deep: #0c1611;
  --ink: #e8dfc8;
  --muted: #c4beb0;
  --gold: #c4a15a;
  --danger: #9b1d18;
  --card: #3a3834;
  --border: rgba(196, 161, 90, 0.5);
  --display: "Cinzel", serif;
  --body: "IBM Plex Sans", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background-color: var(--felt-deep);
  background-image: radial-gradient(ellipse at center, var(--felt), var(--felt-deep) 70%);
  color: var(--ink);
  font-family: var(--body);
  overflow: hidden;
}

#table {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  background-color: var(--felt-deep);
  background-image: radial-gradient(ellipse at center, var(--felt), var(--felt-deep) 70%);
}

#table canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
}

.tray {
  position: fixed;
  z-index: 2;
  left: max(0.7rem, env(safe-area-inset-left, 0px));
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  justify-items: center;
  gap: 0.65rem;
  padding: 0.9rem 0.7rem;
  max-height: calc(100dvh - 1.2rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  overflow-y: auto;
  background: rgba(42, 40, 36, 0.92);
  border: 1px solid var(--border);
  border-radius: 1rem;
  backdrop-filter: blur(8px);
}

.tray-label,
.cap {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.picker {
  display: grid;
  gap: 0.55rem;
}

.die-wrap {
  position: relative;
}

.die-btn,
#roll-btn,
#clear-btn,
#color-toggle {
  appearance: none;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  width: 3rem;
  height: 3rem;
  border-radius: 0.7rem;
  padding: 0;
  display: grid;
  place-items: center;
}

.die-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.die-face {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.45rem;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.die-face.is-wide {
  font-size: 0.58rem;
}

.badge {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  width: 1.15rem;
  height: 1.15rem;
  border: 0;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.hamburger {
  display: grid;
  gap: 0.22rem;
  width: 1.15rem;
}

.hamburger span {
  display: block;
  height: 2px;
  border-radius: 1px;
  background: var(--gold);
}

.color-panel {
  position: fixed;
  z-index: 5;
  width: 15.4rem;
  padding: 0.75rem 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: rgba(42, 40, 36, 0.96);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.color-panel-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 0.65rem;
}

.color-panel-head p {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.color-panel-head button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
}

.color-swatch {
  appearance: none;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 0.45rem;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  font-family: var(--display);
  font-size: 0.72rem;
  font-weight: 700;
}

.color-swatch.is-light {
  box-shadow: inset 0 0 0 1px rgba(20, 12, 9, 0.18);
}

.color-swatch.is-current {
  border-color: var(--gold);
}

.marble-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
}

.marble-toggle input {
  margin: 0;
  accent-color: var(--gold);
}

.hundred-choice {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.85rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.hundred-label {
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hundred-choice label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  user-select: none;
}

.hundred-choice input {
  margin: 0;
  accent-color: var(--gold);
}

#roll-btn,
#clear-btn {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.06em;
}

#roll-btn {
  background: var(--gold);
  color: #1a1208;
  border-color: var(--gold);
}

#roll-btn:disabled,
#clear-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

#clear-btn {
  font-size: 0.72rem;
  background: transparent;
  color: var(--muted);
}

.result {
  position: fixed;
  z-index: 2;
  right: 1.4rem;
  bottom: 1.4rem;
  text-align: right;
  pointer-events: none;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}

.result[hidden],
.status[hidden],
.color-panel[hidden] {
  display: none;
}

.notation,
.breakdown {
  margin: 0;
  color: var(--muted);
}

.notation {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.breakdown {
  margin-top: 0.2rem;
  font-size: 1.1rem;
}

.total {
  margin: 0.15rem 0 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(3.2rem, 8vw, 6rem);
  line-height: 0.9;
  color: var(--gold);
}

.status {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  background: rgba(42, 40, 36, 0.94);
  color: #e4b4a8;
}

@media (max-width: 720px), (max-height: 700px) {
  .tray {
    left: max(0.45rem, env(safe-area-inset-left, 0px));
    gap: 0.4rem;
    padding: 0.55rem 0.45rem;
  }

  .picker {
    gap: 0.32rem;
  }

  .tray-label {
    display: none;
  }

  .die-btn,
  #roll-btn,
  #clear-btn,
  #color-toggle {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.6rem;
  }

  .die-face {
    width: 1.9rem;
    height: 1.9rem;
    font-size: 0.64rem;
  }

  .hamburger {
    width: 1rem;
    gap: 0.18rem;
  }

  .result {
    right: max(0.8rem, env(safe-area-inset-right, 0px));
    bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }
}

@media (max-height: 520px) {
  .tray {
    grid-template-columns: auto auto;
    gap: 0.3rem;
    padding: 0.4rem;
  }

  .picker {
    grid-column: 1 / -1;
    grid-template-columns: auto auto;
    gap: 0.3rem;
  }

  .cap {
    grid-column: 1 / -1;
  }
}
