:root {
  color-scheme: dark;
  --bg: #081018;
  --surface: rgba(12, 25, 35, 0.9);
  --surface-strong: #112838;
  --border: rgba(125, 177, 199, 0.22);
  --text: #f4fbff;
  --muted: #a3bac6;
  --accent: #fbbf24;
  --accent-2: #38bdf8;
  --success: #4ade80;
  --danger: #fb7185;
  --shadow: rgba(1, 8, 13, 0.4);
}

* { box-sizing: border-box; }

.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;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 10%, rgba(251, 191, 36, 0.14), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(56, 189, 248, 0.18), transparent 28%),
    linear-gradient(180deg, #081018, #091722 45%, #071018);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

#diceApp {
  min-height: 100vh;
}

.dice-app {
  display: grid;
  gap: 1rem;
  min-height: 100vh;
  padding: clamp(0.9rem, 2vw, 1.5rem);
}

.dice-header,
.dice-panel,
.dice-stage,
.dice-history,
.dice-metric {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 24px 54px var(--shadow);
}

.dice-header,
.dice-panel,
.dice-stage,
.dice-history {
  border-radius: 1rem;
}

.dice-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-end;
  padding: 1rem 1.15rem;
}

.dice-title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.dice-subtitle,
.muted,
.panel-copy {
  color: var(--muted);
  line-height: 1.55;
}

.dice-subtitle {
  margin: 0.6rem 0 0;
  max-width: 50rem;
}

.dice-actions,
.panel-actions,
.inline-actions,
.metrics-grid,
.history-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(8, 19, 26, 0.92);
  color: var(--text);
  padding: 0.8rem 1.1rem;
  text-decoration: none;
}

.button.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #061018;
  font-weight: 800;
}

.dice-layout,
.dice-live-layout {
  display: grid;
  gap: 1rem;
  align-items: start;
}

.dice-panel,
.dice-history {
  padding: 1rem;
}

.field-grid {
  display: grid;
  gap: 0.9rem;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field span {
  color: var(--muted);
  font-size: 0.95rem;
}

.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 0.9rem 1rem;
  background: rgba(7, 18, 25, 0.88);
  color: var(--text);
}

.status {
  min-height: 1.5rem;
  margin-bottom: 0.9rem;
  color: var(--muted);
}

.status.success { color: var(--success); }
.status.error { color: #ffc4cf; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  margin-top: 1rem;
}

.dice-metric {
  border-radius: 1rem;
  padding: 1rem;
  background: linear-gradient(180deg, rgba(17, 40, 56, 0.96), rgba(8, 20, 28, 0.96));
}

.dice-metric strong {
  display: block;
  margin-top: 0.3rem;
  font-size: 1.7rem;
}

.dice-stage {
  display: grid;
  gap: 1rem;
  justify-items: center;
  padding: clamp(1rem, 2.2vw, 1.5rem);
}

.stage-head {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.stage-kicker {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.9rem;
}

.stage-title {
  margin: 0.35rem 0 0;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  background: rgba(255,255,255,0.05);
  color: var(--muted);
}

.dice-machine {
  position: relative;
  width: min(88vw, 28rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 2rem;
  background:
    radial-gradient(circle at 30% 22%, rgba(255,255,255,0.12), transparent 28%),
    linear-gradient(180deg, rgba(17, 40, 56, 0.94), rgba(8, 19, 26, 0.98));
  overflow: hidden;
}

.dice-machine::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 1.7rem;
}

.die {
  position: relative;
  z-index: 1;
  width: min(54vw, 14rem);
  aspect-ratio: 1;
  border-radius: 1.6rem;
  background: linear-gradient(180deg, #fcfdff, #dde7f0);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.85),
    0 22px 40px rgba(0,0,0,0.26);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 1rem;
  gap: 0.35rem;
  transition: transform 640ms cubic-bezier(0.18, 0.88, 0.22, 1), opacity 640ms ease;
}

.die.is-rolling {
  animation: diceSpin 240ms linear infinite;
}

.die.is-settled {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.85),
    0 0 0 14px rgba(251, 191, 36, 0.09),
    0 22px 40px rgba(0,0,0,0.28);
}

.die-face-dot {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 999px;
  background: #0c1720;
  align-self: center;
  justify-self: center;
  opacity: 0;
  transform: scale(0.7);
}

.die-face-dot.visible {
  opacity: 1;
  transform: scale(1);
}

.dice-history {
  width: 100%;
}

.history-grid {
  display: grid;
  gap: 0.7rem;
  grid-template-columns: repeat(auto-fill, minmax(4.6rem, 1fr));
  margin-top: 1rem;
}

.history-item {
  display: grid;
  place-items: center;
  min-height: 4.6rem;
  border-radius: 1rem;
  border: 1px solid rgba(255,255,255,0.08);
  background: linear-gradient(180deg, rgba(17, 40, 56, 0.96), rgba(8, 19, 26, 0.96));
  font-size: 1.5rem;
  font-weight: 800;
}

.history-item.latest {
  border-color: rgba(251, 191, 36, 0.42);
  animation: historyPop 700ms cubic-bezier(0.18, 0.88, 0.22, 1);
}

.empty-state {
  padding: 1rem;
  border: 1px dashed rgba(163, 186, 198, 0.22);
  border-radius: 1rem;
  color: var(--muted);
}

@keyframes diceSpin {
  0% { transform: rotate(-5deg) scale(0.97); }
  50% { transform: rotate(6deg) scale(1.03); }
  100% { transform: rotate(-5deg) scale(0.97); }
}

@keyframes historyPop {
  0% { transform: translateY(-1rem) scale(0.8); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@media (min-width: 900px) {
  .dice-layout {
    grid-template-columns: minmax(18rem, 28rem) minmax(0, 1fr);
  }

  .dice-live-layout {
    grid-template-columns: minmax(0, 1.3fr) minmax(18rem, 24rem);
  }
}

@media (max-width: 640px) {
  .button {
    width: 100%;
    text-align: center;
  }
}
