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

:root {
  --orange: #ff7a18;
  --orange-deep: #e85d00;
  --glass: rgba(8, 6, 20, 0.55);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text: #f8f4ff;
  --muted: rgba(248, 244, 255, 0.72);
  --pill-asphalt: linear-gradient(135deg, #cfd4dc, #8a919c);
  --pill-dirt: linear-gradient(135deg, #8b6914, #5c4220);
  --font: "Barlow Condensed", system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  color: var(--text);
  background: #120820;
}

.viewport {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(255, 120, 40, 0.35), transparent 55%),
    linear-gradient(160deg, #3d1578 0%, #1a4fd4 42%, #d946a8 100%);
}

.error-banner {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(255, 77, 77, 0.55);
  background: rgba(255, 40, 40, 0.18);
  color: #ffd4d4;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
}

.error-banner[hidden] {
  display: none;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.brand {
  margin: 0;
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.connection {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.connection__dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #ff4d4d;
  box-shadow: 0 0 8px rgba(255, 77, 77, 0.8);
}

.connection__label[data-connected="true"] {
  color: #7dffb2;
}

.connection__label[data-connected="true"] ~ .connection__dot,
.connection:has([data-connected="true"]) .connection__dot {
  background: #3dff9a;
  box-shadow: 0 0 10px rgba(61, 255, 154, 0.85);
}

.connection:has([data-connected="false"]) .connection__dot {
  background: #ff4d4d;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  text-align: center;
}

.result__class {
  margin: 0;
  font-size: clamp(5rem, 28vw, 9rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.02em;
  text-shadow:
    0 4px 0 rgba(0, 0, 0, 0.25),
    0 0 40px rgba(255, 140, 40, 0.45);
}

.result__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.65rem;
  margin-top: 0.5rem;
}

.pill {
  display: inline-block;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  font-size: clamp(1.1rem, 4.5vw, 1.45rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a1028;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.pill--drivetrain {
  background: linear-gradient(135deg, #ffe8c8, #ffb347);
}

.pill--surface.pill--asphalt {
  background: var(--pill-asphalt);
  color: #1a1d22;
}

.pill--surface.pill--dirt {
  background: var(--pill-dirt);
  color: #f5e6c8;
}

.pins {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 28rem;
}

.pin {
  flex: 1 1 5.5rem;
  min-width: 5.5rem;
  min-height: 2.75rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--glass-border);
  border-radius: 0.65rem;
  background: var(--glass);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.pin[data-pinned="true"] {
  border-color: rgba(255, 122, 24, 0.85);
  background: rgba(255, 122, 24, 0.22);
}

.pin__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.pin__state {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: flex-start;
  width: 100%;
  max-width: 18rem;
  text-align: left;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.option input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--orange);
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 20rem;
}

.btn-roll {
  width: 100%;
  min-height: 2.75rem;
  padding: 1rem 1.5rem;
  border: none;
  border-radius: 0.75rem;
  font-family: inherit;
  font-size: clamp(1.75rem, 8vw, 2.25rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #1a0a00;
  cursor: pointer;
  background: linear-gradient(180deg, #ffb347 0%, var(--orange) 45%, var(--orange-deep) 100%);
  box-shadow:
    0 8px 0 #9a3a00,
    0 14px 28px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn-roll:active {
  transform: translateY(4px);
  box-shadow:
    0 4px 0 #9a3a00,
    0 8px 16px rgba(0, 0, 0, 0.4);
}

.btn-copy {
  min-height: 2.75rem;
  min-width: 2.75rem;
  padding: 0.65rem 1.35rem;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.btn-copy--acked,
.btn-copy[data-copied="true"] {
  border-color: rgba(61, 255, 154, 0.75);
  background: rgba(61, 255, 154, 0.12);
  color: #b8ffd8;
}

.confetti-x {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

.history {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem 1rem;
  border-radius: 1rem;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
}

.history__title {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 2.5rem;
  max-height: 8rem;
  overflow-y: auto;
}

.history__list:empty::after {
  content: "No rolls yet — history syncs live across tabs.";
  display: block;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}

.history__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.history__class {
  font-weight: 800;
  font-size: 1.15rem;
}

.history__time {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--muted);
}

.foot {
  margin-top: 0.75rem;
  text-align: center;
}

.foot__meta {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

@media (min-width: 480px) {
  .options {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    max-width: none;
  }
}
