:root {
  --bg: #55101d;
  --bg-soft: #3d101b;
  --panel: rgba(64, 19, 31, 0.76);
  --panel-edge: rgba(255, 183, 90, 0.65);
  --text: #ffe4df;
  --muted: rgba(255, 227, 223, 0.7);
  --glow: #ff6d3a;
  --red: #ff344e;
  --gold: #ffd17a;
}

* {
  box-sizing: border-box;
}

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

html {
  background: var(--bg);
}

body {
  overflow: hidden;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% 48%, rgba(205, 59, 36, 0.3), rgba(131, 29, 29, 0.18) 38%, rgba(85, 16, 29, 0) 72%),
    linear-gradient(180deg, #5a1220 0%, var(--bg) 50%, #4f0e1b 100%);
  user-select: none;
}

button {
  font: inherit;
}

input {
  font: inherit;
}

.stage {
  position: relative;
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  place-items: center;
  padding: clamp(1rem, 2.4vw, 2rem);
  cursor: pointer;
  isolation: isolate;
}

.stage::before {
  position: absolute;
  inset: 0;
  z-index: -2;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.016) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black 0%, transparent 72%);
}

.stage::after {
  position: absolute;
  inset: auto 0 0;
  z-index: -1;
  height: 34vh;
  content: "";
  background: linear-gradient(to top, rgba(122, 22, 27, 0.14), transparent);
}

.range-panel {
  position: fixed;
  top: clamp(0.9rem, 2.2vw, 1.6rem);
  left: clamp(0.9rem, 2.2vw, 1.6rem);
  z-index: 4;
  display: grid;
  width: min(21rem, calc(100vw - 1.8rem));
  padding: 0.75rem;
  gap: 0.65rem;
  cursor: default;
  border: 1px solid rgba(255, 129, 85, 0.45);
  border-radius: 8px;
  background:
    linear-gradient(rgba(64, 19, 31, 0.78), rgba(64, 19, 31, 0.78)) padding-box,
    repeating-linear-gradient(
      135deg,
      #d92f2c 0 9px,
      #e8c65e 9px 16px,
      #2f9c65 16px 24px,
      #2166a8 24px 31px,
      #b22d85 31px 39px
    ) border-box;
  box-shadow:
    0 12px 36px rgba(0, 0, 0, 0.3),
    inset 0 0 28px rgba(255, 68, 79, 0.1);
  backdrop-filter: blur(18px);
}

.range-panel h2 {
  margin: 0;
  color: rgba(255, 232, 225, 0.76);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.range-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.range-field {
  display: grid;
  gap: 0.28rem;
  min-width: 0;
}

.range-field span {
  color: rgba(255, 232, 225, 0.64);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.range-field input {
  width: 100%;
  min-height: 2.35rem;
  padding: 0.35rem 0.55rem;
  color: #ffe7e2;
  border: 1px solid rgba(255, 112, 88, 0.46);
  border-radius: 8px;
  outline: none;
  background: rgba(41, 7, 16, 0.62);
  box-shadow: inset 0 0 12px rgba(255, 72, 82, 0.12);
  font-size: 1rem;
  font-weight: 850;
}

.range-field input:focus {
  border-color: rgba(255, 205, 132, 0.82);
  box-shadow: 0 0 0 3px rgba(255, 104, 70, 0.18), inset 0 0 12px rgba(255, 72, 82, 0.14);
}

.range-apply-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  padding: 0.55rem 0.8rem;
  gap: 0.45rem;
  color: #fff0ea;
  cursor: pointer;
  border: 1px solid rgba(255, 142, 99, 0.52);
  border-radius: 999px;
  background:
    linear-gradient(rgba(89, 18, 31, 0.9), rgba(66, 12, 24, 0.9)) padding-box,
    repeating-linear-gradient(
      135deg,
      #ff3e43 0 8px,
      #f1bc45 8px 14px,
      #2fb76d 14px 20px,
      #2f72c9 20px 26px,
      #b72b8a 26px 32px
    ) border-box;
  box-shadow: 0 0 16px rgba(255, 60, 55, 0.18), inset 0 0 14px rgba(255, 255, 255, 0.04);
  font-size: 0.82rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  transition: transform 150ms ease, filter 150ms ease;
}

.range-apply-button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.range-apply-button:active {
  transform: translateY(1px) scale(0.98);
}

.range-apply-button svg {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.result-board {
  position: fixed;
  top: clamp(0.9rem, 2.2vw, 1.6rem);
  right: clamp(0.9rem, 2.2vw, 1.6rem);
  z-index: 4;
  width: min(21rem, calc(100vw - 1.8rem));
  max-height: min(36rem, calc(100svh - 2rem));
  padding: 0.65rem;
  overflow: hidden;
  border: 1px solid rgba(255, 129, 85, 0.45);
  border-radius: 8px;
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box,
    repeating-linear-gradient(
      135deg,
      #d92f2c 0 9px,
      #e8c65e 9px 16px,
      #2f9c65 16px 24px,
      #2166a8 24px 31px,
      #b22d85 31px 39px
    ) border-box;
  box-shadow:
    0 12px 36px rgba(0, 0, 0, 0.38),
    inset 0 0 28px rgba(255, 68, 79, 0.12);
  backdrop-filter: blur(18px);
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2rem;
  padding: 0.2rem 0.25rem 0.45rem;
  gap: 0.75rem;
}

.board-header h1 {
  margin: 0;
  color: rgba(255, 232, 225, 0.76);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.reset-button {
  display: inline-grid;
  width: 1.8rem;
  height: 1.8rem;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  color: rgba(255, 232, 225, 0.82);
  cursor: pointer;
  border: 1px solid rgba(255, 202, 147, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
  transition: transform 150ms ease, color 150ms ease, border-color 150ms ease, background 150ms ease;
}

.reset-button:hover {
  color: #fff5ec;
  border-color: rgba(255, 180, 110, 0.5);
  background: rgba(255, 255, 255, 0.09);
  transform: rotate(-24deg);
}

.reset-button:active {
  transform: scale(0.94) rotate(-42deg);
}

.reset-button svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.1;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-height: calc(min(36rem, 100svh - 2rem) - 3.3rem);
  margin: 0;
  padding: 0.2rem 0.05rem 0.05rem;
  gap: 0.55rem;
  overflow: auto;
  list-style: none;
  scrollbar-color: rgba(255, 107, 82, 0.65) rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
}

.history-list:empty::before {
  grid-column: 1 / -1;
  padding: 0.8rem 0.4rem 0.9rem;
  color: rgba(255, 232, 225, 0.48);
  content: "CHƯA CÓ KẾT QUẢ";
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-align: center;
}

.history-item {
  display: grid;
  min-width: 0;
  min-height: 4.75rem;
  align-content: center;
  justify-items: center;
  padding: 0.45rem 0.3rem;
  border: 1px solid rgba(255, 87, 82, 0.5);
  border-radius: 8px;
  background:
    radial-gradient(circle at center, rgba(255, 52, 78, 0.24), rgba(112, 20, 32, 0.18) 62%, rgba(255, 255, 255, 0.03));
  box-shadow:
    inset 0 0 12px rgba(255, 72, 82, 0.35),
    0 0 14px rgba(255, 67, 64, 0.16);
}

.history-turn {
  max-width: 100%;
  color: rgba(255, 232, 225, 0.68);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-align: center;
}

.history-number {
  max-width: 100%;
  color: #ffd8d3;
  font-size: clamp(1.3rem, 2.3vw, 1.85rem);
  font-weight: 900;
  line-height: 1.05;
  text-shadow:
    0 0 8px rgba(255, 46, 73, 0.8),
    0 0 18px rgba(255, 71, 54, 0.45);
}

.centerpiece {
  display: grid;
  width: min(74rem, 92vw);
  justify-items: center;
  gap: clamp(1rem, 3.1vh, 2.2rem);
  transform: translateY(2vh);
}

.number-wrap {
  position: relative;
  display: grid;
  width: min(68rem, 94vw);
  height: clamp(18rem, 62vh, 42rem);
  place-items: center;
}

.number-wrap::before {
  position: absolute;
  width: min(53rem, 80vw);
  height: min(23rem, 33vw);
  content: "";
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 106, 45, 0.32), rgba(255, 106, 45, 0.13) 34%, transparent 72%);
  filter: blur(18px);
}

.number-display {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  max-width: 100%;
  min-width: 0;
  transform-origin: center;
  transition: transform 180ms ease, filter 180ms ease;
  filter:
    drop-shadow(0 1.4rem 1.2rem rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 1.1rem rgba(255, 105, 48, 0.78))
    drop-shadow(0 0 2.3rem rgba(255, 53, 43, 0.42));
}

.number-display.is-rolling {
  animation: numberPulse 420ms ease-in-out infinite;
  filter:
    drop-shadow(0 1.4rem 1.2rem rgba(0, 0, 0, 0.5))
    drop-shadow(0 0 1.7rem rgba(255, 112, 45, 0.95))
    drop-shadow(0 0 3.6rem rgba(255, 42, 65, 0.62));
}

.digit-crop {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  pointer-events: none;
}

.digit-crop + .digit-crop {
  margin-left: var(--digit-overlap, -0.5rem);
}

.digit {
  position: absolute;
  display: block;
  width: auto;
  max-width: none;
  object-fit: contain;
  pointer-events: none;
}

.selected-pill {
  width: min(34rem, 78vw);
  min-height: 4.25rem;
  display: grid;
  place-items: center;
  padding: 0.85rem 1.5rem;
  overflow: hidden;
  border: 0.46rem solid transparent;
  border-radius: 999px;
  color: rgba(255, 232, 225, 0.91);
  background:
    linear-gradient(rgba(61, 18, 30, 0.92), rgba(61, 18, 30, 0.92)) padding-box,
    repeating-linear-gradient(
      135deg,
      #d72e2c 0 10px,
      #f2b844 10px 18px,
      #2c9a58 18px 27px,
      #244ea4 27px 36px,
      #9e287c 36px 45px
    ) border-box;
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.22), 0 0 24px rgba(255, 62, 57, 0.18);
  font-size: clamp(0.9rem, 1.7vw, 1.1rem);
  font-weight: 800;
  letter-spacing: 0.06em;
}

.progress-track {
  position: fixed;
  left: 50%;
  bottom: clamp(4.35rem, 7vh, 5.1rem);
  width: min(31rem, 58vw);
  height: 0.45rem;
  overflow: visible;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transform: translateX(-50%);
  box-shadow: inset 0 0 9px rgba(0, 0, 0, 0.32);
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background:
    repeating-linear-gradient(
      135deg,
      #ff443f 0 11px,
      #f3c653 11px 20px,
      #37b56b 20px 29px,
      #286fc7 29px 38px,
      #be338d 38px 47px
    );
  box-shadow: 0 0 18px rgba(255, 65, 62, 0.62);
  transition: width 280ms ease;
}

.progress-knob {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 1.35rem;
  height: 1.35rem;
  border: 1px solid rgba(255, 205, 132, 0.8);
  border-radius: 999px;
  background: radial-gradient(circle at 34% 30%, #ffd48e, #ff4f45 48%, #951426 78%);
  box-shadow: 0 0 22px rgba(255, 78, 59, 0.78);
  transform: translate(-50%, -50%);
  transition: left 280ms ease;
}

.selected-summary-button {
  position: fixed;
  left: 50%;
  bottom: clamp(0.7rem, 2.2vh, 1.15rem);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.65rem;
  padding: 0.65rem 1rem;
  gap: 0.55rem;
  color: #fff0ea;
  cursor: pointer;
  border: 1px solid rgba(255, 142, 99, 0.56);
  border-radius: 999px;
  background:
    linear-gradient(rgba(89, 18, 31, 0.88), rgba(66, 12, 24, 0.88)) padding-box,
    repeating-linear-gradient(
      135deg,
      #ff3e43 0 8px,
      #f1bc45 8px 14px,
      #2fb76d 14px 20px,
      #2f72c9 20px 26px,
      #b72b8a 26px 32px
    ) border-box;
  box-shadow: 0 0 18px rgba(255, 60, 55, 0.28), inset 0 0 16px rgba(255, 255, 255, 0.05);
  font-size: 0.86rem;
  font-weight: 850;
  letter-spacing: 0.03em;
  transform: translateX(-50%);
  transition: transform 160ms ease, filter 160ms ease;
}

.selected-summary-button:hover {
  filter: brightness(1.08);
  transform: translateX(-50%) translateY(-1px);
}

.selected-summary-button:active {
  transform: translateX(-50%) translateY(1px) scale(0.98);
}

.selected-summary-button svg,
.modal-close-button svg {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.1;
}

.selected-modal {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 3vw, 2rem);
  background: rgba(21, 3, 9, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  backdrop-filter: blur(5px);
}

.selected-modal[hidden] {
  display: none;
}

.selected-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.selected-modal-panel {
  width: min(42rem, 92vw);
  max-height: min(35rem, 78svh);
  padding: 0.75rem;
  overflow: hidden;
  border: 1px solid rgba(255, 126, 82, 0.52);
  border-radius: 8px;
  background:
    linear-gradient(rgba(70, 14, 27, 0.93), rgba(49, 9, 20, 0.95)) padding-box,
    repeating-linear-gradient(
      135deg,
      #db302f 0 10px,
      #efbd4d 10px 18px,
      #2da35f 18px 27px,
      #255fae 27px 36px,
      #a92982 36px 45px
    ) border-box;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), 0 0 42px rgba(255, 78, 55, 0.24);
  transform: translateY(0.5rem) scale(0.98);
  transition: transform 180ms ease;
}

.selected-modal.is-open .selected-modal-panel {
  transform: translateY(0) scale(1);
}

.selected-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.25rem 0.7rem;
  gap: 1rem;
}

.selected-modal-header h2 {
  margin: 0;
  color: rgba(255, 236, 229, 0.92);
  font-size: clamp(1rem, 2.4vw, 1.25rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.modal-close-button {
  display: grid;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  color: rgba(255, 237, 230, 0.86);
  cursor: pointer;
  border: 1px solid rgba(255, 202, 147, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.modal-close-button:hover {
  border-color: rgba(255, 188, 120, 0.55);
  background: rgba(255, 255, 255, 0.1);
  transform: rotate(12deg);
}

.selected-modal-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(5.4rem, 1fr));
  max-height: calc(min(35rem, 78svh) - 4.2rem);
  margin: 0;
  padding: 0.1rem 0.05rem 0.05rem;
  gap: 0.6rem;
  overflow: auto;
  list-style: none;
  scrollbar-color: rgba(255, 107, 82, 0.65) rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
}

.selected-modal-list:empty::before {
  grid-column: 1 / -1;
  padding: 2rem 1rem;
  color: rgba(255, 232, 225, 0.58);
  content: "CHƯA CÓ SỐ NÀO";
  font-size: 0.86rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-align: center;
}

.selected-modal-item {
  display: grid;
  min-height: 5.2rem;
  align-content: center;
  justify-items: center;
  padding: 0.55rem 0.4rem;
  border: 1px solid rgba(255, 92, 82, 0.48);
  border-radius: 8px;
  background:
    radial-gradient(circle at center, rgba(255, 54, 78, 0.3), rgba(112, 20, 32, 0.2) 62%, rgba(255, 255, 255, 0.04));
  box-shadow: inset 0 0 14px rgba(255, 72, 82, 0.34), 0 0 14px rgba(255, 67, 64, 0.14);
}

.selected-modal-turn {
  color: rgba(255, 232, 225, 0.68);
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  line-height: 1.15;
}

.selected-modal-number {
  color: #ffe0dc;
  font-size: clamp(1.5rem, 3.8vw, 2.35rem);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 0 10px rgba(255, 46, 73, 0.82), 0 0 22px rgba(255, 71, 54, 0.4);
}

@keyframes numberPulse {
  0%,
  100% {
    transform: scale(1) rotate(-0.2deg);
  }
  50% {
    transform: scale(1.035) rotate(0.2deg);
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .stage {
    align-content: center;
    min-height: 100svh;
    padding-top: 15.7rem;
    padding-bottom: 8.3rem;
  }

  .result-board {
    left: 0.8rem;
    right: 0.8rem;
    width: auto;
    max-height: 8rem;
  }

  .range-panel {
    top: 9.15rem;
    left: 0.8rem;
    right: 0.8rem;
    width: auto;
    padding: 0.65rem;
  }

  .history-list {
    grid-auto-flow: column;
    grid-auto-columns: 5.35rem;
    grid-template-columns: none;
    max-height: 4.9rem;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .history-item {
    min-height: 4.3rem;
  }

  .number-wrap {
    height: clamp(13rem, 48vh, 27rem);
  }

  .progress-track {
    bottom: 4.85rem;
    width: min(26rem, 64vw);
  }
}

@media (max-width: 480px) {
  .stage {
    padding-top: 15.2rem;
  }

  .centerpiece {
    width: 100%;
    gap: 0.85rem;
    transform: none;
  }

  .number-wrap {
    height: clamp(12rem, 42vh, 22rem);
  }

  .selected-pill {
    min-height: 3.55rem;
    border-width: 0.36rem;
  }

  .progress-track {
    bottom: 4.75rem;
    width: min(22rem, 70vw);
  }

  .selected-summary-button {
    width: min(18rem, 78vw);
    min-height: 2.55rem;
    font-size: 0.8rem;
  }

  .selected-modal-list {
    grid-template-columns: repeat(auto-fit, minmax(4.85rem, 1fr));
  }
}
