:root {
  --ends-navy: #1b2040;
  --ends-purple: #5500aa;
  --ends-purple-lt: #a07aff;
  --ends-blue: #1a7fff;
  --ends-blue-dk: #0055bb;
  --ends-green: #007733;
  --ends-red: #aa0011;
  --ends-amber: #a07800;
  --blueprint: var(--ends-navy);
  --blueprint-dark: #11152d;
  --paper: #f5f6f9;
  --paper-line: rgba(27, 32, 64, 0.1);
  --accent: var(--ends-purple-lt);
  --accent-strong: var(--ends-purple);
  --ink: #1a1a28;
  --muted: #4a4a60;
  --boon: #0055bb;
  --bane: #c45000;
  --ability: #007733;
  --trial: #aa0011;
  --mastery: #550099;
  --crisis: #a07800;
  --bottom-safe: max(env(safe-area-inset-bottom), 42px);
  font-family: "Avenir Next Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--blueprint-dark);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-rows: clamp(74px, 10vh, 104px) 1fr calc(clamp(112px, 16vh, 156px) + var(--bottom-safe));
  background:
    linear-gradient(30deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px) 0 0 / 42px 72px,
    linear-gradient(150deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px) 0 0 / 42px 72px,
    radial-gradient(circle at 72% 8%, rgba(160, 122, 255, 0.18), transparent 8rem),
    var(--blueprint);
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: clamp(112px, 18vh, 180px) 1fr;
  color: var(--ends-navy);
  background:
    linear-gradient(30deg, transparent 48%, var(--paper-line) 49%, var(--paper-line) 51%, transparent 52%) 0 0 / 70px 70px,
    linear-gradient(150deg, transparent 48%, var(--paper-line) 49%, var(--paper-line) 51%, transparent 52%) 0 0 / 70px 70px,
    var(--paper);
  opacity: 1;
  transition: opacity 260ms ease, visibility 260ms ease;
}

.loading-screen.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loading-header {
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 16px 18px;
  border-bottom: 4px solid var(--accent-strong);
  background:
    linear-gradient(90deg, rgba(85, 0, 170, 0.32), transparent 58%),
    var(--ends-navy);
}

.loading-logo {
  width: min(24vw, 124px);
  height: min(24vw, 124px);
  border-radius: 22%;
  box-shadow: 0 16px 28px rgba(10, 15, 35, 0.28);
}

.loading-body {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
}

.loading-title {
  max-width: 760px;
  margin: 0;
  color: var(--ends-navy);
  font-family: Cinzel, Georgia, serif;
  font-size: clamp(28px, 6vw, 58px);
  font-weight: 700;
  line-height: 1.1;
}

.loading-copy,
.loading-link,
.loading-credit {
  margin: 0;
  color: var(--muted);
  font: 800 clamp(18px, 3vw, 28px) / 1.2 "Roboto Condensed", "Avenir Next", Arial, sans-serif;
}

.loading-credit {
  margin-top: 6px;
  font-size: clamp(13px, 2vw, 18px);
  opacity: 0.78;
}

.top-band {
  position: relative;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  border-bottom: 4px solid var(--accent-strong);
  background:
    linear-gradient(90deg, rgba(85, 0, 170, 0.32), transparent 58%),
    var(--ends-navy);
}

.top-band h1 {
  min-width: 0;
  margin: 0;
  color: #f5f6f9;
  font-family: Cinzel, Georgia, serif;
  font-size: clamp(22px, 6vw, 34px);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button,
.roll-button,
.small-icon-button {
  appearance: none;
  border: 0;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-button {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
}

.icon-button:disabled {
  opacity: 0.32;
}

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 34px;
  height: 5px;
  background: currentColor;
}

.hamburger {
  position: relative;
}

.hamburger::before,
.hamburger::after {
  content: "";
  position: absolute;
  left: 0;
}

.hamburger::before {
  top: -13px;
}

.hamburger::after {
  top: 13px;
}

.selection-actions {
  display: flex;
  gap: 6px;
  margin: 0;
}

.roll-dice-icon {
  display: block;
  position: relative;
}

.header-svg {
  width: 34px;
  height: 34px;
}

.roll-button {
  position: static;
  width: 54px;
  height: 54px;
  border: 3px solid var(--accent);
  border-radius: 8px;
  background: rgba(160, 122, 255, 0.1);
  z-index: 3;
}

.roll-dice-icon {
  width: 34px;
  height: 34px;
  margin: auto;
}

.roll-dice-icon::before,
.roll-dice-icon::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid currentColor;
  border-radius: 5px;
  background:
    radial-gradient(circle, currentColor 0 2px, transparent 2.4px) 5px 5px / 9px 9px,
    rgba(160, 122, 255, 0.08);
}

.roll-dice-icon::before {
  right: 0;
  top: 0;
  transform: rotate(9deg);
}

.roll-dice-icon::after {
  left: 0;
  bottom: 0;
  transform: rotate(-8deg);
}

.play-field {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(30deg, transparent 48%, var(--paper-line) 49%, var(--paper-line) 51%, transparent 52%) 0 0 / 70px 70px,
    linear-gradient(150deg, transparent 48%, var(--paper-line) 49%, var(--paper-line) 51%, transparent 52%) 0 0 / 70px 70px,
    var(--paper);
}

.play-field::before,
.play-field::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  z-index: 1;
  background: repeating-linear-gradient(
    to bottom,
    rgba(160, 120, 0, 0.35) 0,
    rgba(160, 120, 0, 0.35) 3px,
    transparent 3px,
    transparent 7px
  );
}

.play-field::before {
  left: 10%;
}

.play-field::after {
  right: 10%;
}

.result-strip {
  position: absolute;
  left: 7vw;
  top: 52px;
  right: 7vw;
  min-height: 88px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  z-index: 2;
}

.outcome-banner {
  flex-basis: 100%;
  margin-bottom: -7px;
  color: var(--ends-green);
  font: 900 22px/1 "Roboto Condensed", "Avenir Next", Arial, sans-serif;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.result-tile {
  width: 72px;
  height: 72px;
  position: relative;
  display: grid;
  place-items: center;
  border: 3px solid rgba(27, 32, 64, 0.9);
  border-radius: 12px;
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.38), transparent 20%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.2), transparent 48%),
    var(--ends-navy);
  box-shadow: 0 10px 18px rgba(27, 32, 64, 0.18);
}

.result-tile .symbol {
  width: 54px;
  height: 54px;
  color: rgba(255, 255, 255, 0.82);
}

.result-tile .count {
  position: absolute;
  right: 6px;
  bottom: 6px;
  min-width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  color: #f5f6f9;
  font: 800 15px/1 "Roboto Condensed", "Avenir Next", Arial, sans-serif;
  background: rgba(27, 32, 64, 0.76);
  border: 1px solid rgba(245, 246, 249, 0.34);
  border-radius: 5px;
}

.dice-stage {
  position: absolute;
  inset: 142px 18px 34px;
}

.rolled-die {
  position: absolute;
  width: 94px;
  height: 94px;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: transform 180ms ease, filter 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.rolled-die.selected::before,
.rolled-die.selected::after {
  content: "";
  position: absolute;
  inset: -9px;
  border: 5px solid var(--ends-purple-lt);
  border-radius: 50%;
  clip-path: polygon(0 0, 32% 0, 32% 100%, 0 100%);
  animation: selectPulse 1.1s ease-in-out infinite alternate;
}

.rolled-die.selected::after {
  transform: rotate(180deg);
}

@keyframes selectPulse {
  from {
    opacity: 0.7;
  }
  to {
    opacity: 1;
  }
}

.bottom-tray {
  display: grid;
  grid-template-columns: repeat(6, minmax(64px, 1fr));
  gap: 7px;
  align-items: center;
  padding: 12px 8px var(--bottom-safe);
  border-top: 4px solid var(--accent-strong);
  border-bottom: 4px solid var(--accent-strong);
  background:
    linear-gradient(30deg, rgba(85, 0, 170, 0.07) 1px, transparent 1px) 0 0 / 42px 72px,
    var(--paper);
}

.die-choice {
  min-width: 0;
  height: 96px;
  display: grid;
  grid-template-rows: 18px 1fr;
  place-items: center;
  gap: 4px;
  border: 0;
  color: white;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tray-label {
  max-width: 100%;
  color: rgba(74, 74, 96, 0.72);
  font: 800 clamp(9.5px, 2.35vw, 12.5px) / 1 "Roboto Condensed", "Avenir Next", Arial, sans-serif;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.die-shape {
  width: min(14vw, 72px);
  height: min(14vw, 72px);
  min-width: 54px;
  min-height: 54px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.46), transparent 18%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.26), transparent 45%),
    currentColor;
}

.die-shadow {
  width: min(14vw, 72px);
  height: min(14vw, 72px);
  min-width: 54px;
  min-height: 54px;
  display: grid;
  place-items: center;
  filter: drop-shadow(10px 13px 5px rgba(16, 32, 47, 0.28));
}

.rolled-die .die-shadow,
.rolled-die .die-shape {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.d6 {
  border-radius: 17%;
  transform: rotate(-12deg) skew(-4deg);
}

.die-choice .d6,
.rolled-die .d6 {
  transform: rotate(-12deg) skew(-4deg) scale(0.82);
}

.d8 {
  clip-path: polygon(50% 0, 95% 50%, 50% 100%, 5% 50%);
}

.d12 {
  clip-path: polygon(50% 0, 78% 10%, 98% 34%, 94% 65%, 72% 92%, 38% 100%, 10% 82%, 0 50%, 12% 20%);
}

.boon {
  color: var(--boon);
}

.bane {
  color: var(--bane);
}

.ability {
  color: var(--ability);
}

.trial {
  color: var(--trial);
}

.mastery {
  color: var(--mastery);
}

.crisis {
  color: var(--crisis);
}

.symbol {
  width: 42%;
  height: 42%;
  display: inline-block;
  color: currentColor;
  background: currentColor;
  flex: 0 0 auto;
}

.symbol.success {
  clip-path: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.symbol.failure {
  clip-path: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='m6 6 12 12'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='m6 6 12 12'/%3E%3C/svg%3E") center / contain no-repeat;
}

.symbol.boon {
  clip-path: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='M12 5v14'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='M12 5v14'/%3E%3C/svg%3E") center / contain no-repeat;
}

.symbol.bane {
  clip-path: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E") center / contain no-repeat;
}

.symbol.breakthrough {
  clip-path: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.801 10A10 10 0 1 1 17 3.335'/%3E%3Cpath d='m9 11 3 3L22 4'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.801 10A10 10 0 1 1 17 3.335'/%3E%3Cpath d='m9 11 3 3L22 4'/%3E%3C/svg%3E") center / contain no-repeat;
}

.symbol.calamity {
  clip-path: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m15 9-6 6'/%3E%3Cpath d='m9 9 6 6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m15 9-6 6'/%3E%3Cpath d='m9 9 6 6'/%3E%3C/svg%3E") center / contain no-repeat;
}

.die-choice .die-shape > .symbol,
.die-choice .die-shape .face-symbols {
  color: rgba(255, 255, 255, 0.94);
}

.face-symbols {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  color: white;
}

.face-symbols .symbol {
  width: 30px;
  height: 30px;
}

.rolled-die .face-symbols {
  width: 64%;
  max-height: 64%;
  gap: 3px;
  overflow: hidden;
}

.rolled-die .face-symbols .symbol {
  width: 25px;
  height: 25px;
}

.rolled-die .blank-face {
  width: 28px;
  height: 6px;
}

.blank-face {
  width: 22px;
  height: 5px;
  border-radius: 5px;
  background: currentColor;
  opacity: 0.45;
}

.settings-panel,
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 20;
  background: rgba(10, 18, 24, 0.52);
}

.settings-panel.open,
.modal-backdrop.open {
  display: grid;
}

.settings-panel {
  justify-items: start;
}

.settings-card {
  width: min(82vw, 340px);
  min-height: 100%;
  padding: max(24px, env(safe-area-inset-top)) 22px 22px;
  color: white;
  background: var(--ends-navy);
  border-right: 4px solid var(--accent-strong);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.settings-head h2,
.face-card h2 {
  margin: 0;
  color: white;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.small-icon-button {
  width: 42px;
  height: 42px;
  font-size: 40px;
  line-height: 1;
}

.toggle-row,
.slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 22px;
  font-weight: 700;
}

.slider-row {
  display: grid;
}

.toggle-row input {
  width: 28px;
  height: 28px;
  accent-color: var(--accent);
}

.slider-row input {
  width: 100%;
  accent-color: var(--accent);
}

.settings-action {
  width: 100%;
  margin-top: 18px;
  padding: 12px 14px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: #f5f6f9;
  background: rgba(160, 122, 255, 0.12);
  font: 800 18px/1 "Roboto Condensed", "Avenir Next", Arial, sans-serif;
  text-transform: uppercase;
}

.settings-action.enabled {
  color: #ffffff;
  border-color: var(--ends-green);
  background: rgba(0, 119, 51, 0.32);
}

.settings-note {
  margin: 10px 0 0;
  color: rgba(245, 246, 249, 0.72);
  font: 700 14px/1.25 "Roboto Condensed", "Avenir Next", Arial, sans-serif;
}

.settings-link {
  display: block;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--accent);
  font: 800 20px/1.2 "Roboto Condensed", "Avenir Next", Arial, sans-serif;
  text-decoration: none;
  text-transform: uppercase;
}

.modal-backdrop {
  place-items: center;
  padding: 18px;
}

.face-card {
  width: min(88vw, 430px);
  padding: 22px;
  border: 4px solid var(--accent-strong);
  background: var(--ends-navy);
  text-align: center;
}

.face-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 18px;
  padding: 7px;
  background: #07192c;
}

.face-option {
  min-height: 82px;
  border: 0;
  display: grid;
  place-items: center;
  color: white;
  background: var(--ends-purple);
  cursor: pointer;
}

.face-option:active,
.die-choice:active,
.rolled-die:active,
.roll-button:active,
.icon-button:active {
  transform: scale(0.96);
}

.rolling .rolled-die {
  animation: tumble 520ms ease-in-out;
}

@keyframes tumble {
  0% {
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
  }
  45% {
    transform: translate(-50%, -50%) rotate(28deg) scale(1.12);
  }
  100% {
    transform: translate(-50%, -50%) rotate(-8deg) scale(1);
  }
}

@media (max-width: 430px) {
  .top-band {
    grid-template-columns: 48px minmax(0, 1fr) auto auto;
    gap: 4px;
  }

  .selection-actions {
    gap: 4px;
  }

  .icon-button {
    width: 48px;
  }

  .roll-button {
    width: 50px;
    height: 50px;
  }

  .result-strip {
    left: 5vw;
    top: 34px;
    gap: 9px;
  }

  .outcome-banner {
    margin-bottom: -3px;
    font-size: 19px;
  }

  .result-tile {
    width: 62px;
    height: 62px;
  }

  .result-tile .symbol {
    width: 47px;
    height: 47px;
  }

  .result-tile .count {
    min-width: 19px;
    height: 19px;
    font-size: 13px;
  }

  .rolled-die {
    width: 82px;
    height: 82px;
  }

  .rolled-die .face-symbols .symbol {
    width: 21px;
    height: 21px;
  }

  .bottom-tray {
    grid-template-columns: repeat(6, 1fr);
    gap: 1px;
    padding-left: 2px;
    padding-right: 2px;
  }

  .tray-label {
    font-size: 8.5px;
  }
}
