:root {
  color-scheme: dark;
  --page: #0d0f12;
  --surface: #17191d;
  --surface-raised: #202329;
  --line: #343840;
  --line-soft: #292c32;
  --text: #f5f6f7;
  --muted: #989da6;
  --red: #df2d38;
  --red-dark: #a91220;
  --blue: #1975d1;
  --blue-dark: #07509a;
  --gold: #e9b94f;
  --green: #56bc78;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.35);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    var(--page);
  background-size: 28px 28px;
  color: var(--text);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(233, 185, 79, 0.55);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 1120px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 28px env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 86px;
  border-bottom: 1px solid var(--line);
}

.brand-block,
.topbar-status,
.stage-heading,
.history-heading,
.zone-label,
.actions {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 13px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.38);
}

.brand-kicker,
.section-label {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.2;
}

h2 {
  margin: 0;
  font-size: 1.35rem;
}

.attempt-status {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.topbar-status {
  gap: 10px;
}

.network-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
}

.network-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px rgba(86, 188, 120, 0.55);
}

.network-status.is-offline i {
  background: var(--gold);
}

.install-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
}

main {
  padding-top: 44px;
}

.draw-section {
  width: min(100%, 920px);
  margin: 0 auto;
}

.stage-heading,
.history-heading {
  justify-content: space-between;
}

.phase-display {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 124px;
  min-height: 36px;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: #dfe1e4;
  font-size: 0.82rem;
  font-weight: 650;
}

.phase-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.phase-display.is-active .phase-dot {
  background: var(--gold);
  box-shadow: 0 0 10px rgba(233, 185, 79, 0.65);
  animation: status-pulse 1s ease-in-out infinite;
}

.phase-display.is-complete .phase-dot {
  background: var(--green);
}

.draw-board {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 5fr) 42px minmax(150px, 2fr);
  align-items: center;
  min-height: 274px;
  margin-top: 20px;
  overflow: hidden;
  border: 1px solid #3b3f47;
  border-radius: 7px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.075), transparent 42%),
    linear-gradient(145deg, #202329, #121418 72%);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}

.board-sheen {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.035) 50%, transparent 65%);
}

.number-zone {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 32px;
}

.zone-label {
  justify-content: space-between;
  margin-bottom: 24px;
}

.zone-label > span {
  font-size: 0.86rem;
  font-weight: 750;
}

.front-zone .zone-label > span {
  color: #ff737b;
}

.back-zone .zone-label > span {
  color: #69b5ff;
}

.zone-label small {
  color: var(--muted);
  font-size: 0.7rem;
}

.ball-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: clamp(8px, 1.5vw, 16px);
  width: 100%;
}

.number-ball {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-size: clamp(1.05rem, 2.8vw, 1.72rem);
  font-variant-numeric: tabular-nums;
  font-weight: 820;
  line-height: 1;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
  box-shadow:
    inset -8px -10px 15px rgba(0, 0, 0, 0.24),
    inset 5px 6px 10px rgba(255, 255, 255, 0.2),
    0 9px 16px rgba(0, 0, 0, 0.34);
}

.number-ball::after {
  position: absolute;
  top: 13%;
  left: 20%;
  width: 27%;
  height: 16%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.38);
  content: "";
  filter: blur(2px);
  transform: rotate(-28deg);
}

.number-ball.front {
  background: linear-gradient(145deg, #f44a54 8%, var(--red) 52%, var(--red-dark));
}

.number-ball.back {
  background: linear-gradient(145deg, #3798ef 8%, var(--blue) 52%, var(--blue-dark));
}

.number-ball.placeholder {
  border: 1px dashed #575c65;
  background: #282b31;
  color: #777c85;
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.22);
  text-shadow: none;
}

.number-ball.placeholder::after {
  display: none;
}

.number-ball.is-revealed {
  animation: ball-reveal 520ms cubic-bezier(0.2, 0.85, 0.25, 1.15) both;
}

.zone-divider {
  position: relative;
  z-index: 1;
  display: grid;
  height: 150px;
  place-items: center;
  color: var(--muted);
}

.zone-divider::before {
  position: absolute;
  width: 1px;
  height: 100%;
  background: var(--line);
  content: "";
}

.zone-divider span {
  z-index: 1;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #17191d;
}

.countdown {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(13, 15, 18, 0.88);
  color: var(--gold);
  font-size: clamp(5rem, 20vw, 9rem);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 36px rgba(233, 185, 79, 0.25);
}

.countdown[hidden],
.install-button[hidden],
.toast[hidden] {
  display: none;
}

.progress-track {
  height: 3px;
  margin-top: 20px;
  overflow: hidden;
  background: var(--line-soft);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--blue));
  transition: width 420ms ease;
}

.progress-text {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.actions {
  justify-content: center;
  min-height: 82px;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 190px;
  min-height: 52px;
  padding: 0 28px;
  border: 1px solid #f2c459;
  border-radius: 6px;
  background: var(--gold);
  color: #17130a;
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(233, 185, 79, 0.16);
  transition: background 160ms ease, transform 160ms ease;
}

.primary-action:hover {
  background: #f3ca6b;
}

.primary-action:active {
  transform: translateY(1px);
}

.primary-action:disabled {
  border-color: var(--line);
  background: var(--surface-raised);
  box-shadow: none;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.82;
  transform: none;
}

.primary-action.is-skip {
  border-color: #51565f;
  background: transparent;
  color: var(--text);
  box-shadow: none;
}

.history-section {
  width: min(100%, 920px);
  margin: 26px auto 0;
  padding: 30px 0 16px;
  border-top: 1px solid var(--line);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  border-color: #696e78;
  color: var(--text);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.history-list {
  margin-top: 18px;
  border-top: 1px solid var(--line-soft);
}

.history-item {
  display: grid;
  grid-template-columns: minmax(96px, 0.7fr) minmax(280px, 1.7fr) minmax(130px, 0.7fr);
  align-items: center;
  min-height: 66px;
  gap: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.history-issue strong,
.history-time {
  display: block;
}

.history-issue strong {
  font-size: 0.9rem;
}

.history-issue span,
.history-time {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
}

.history-numbers {
  display: flex;
  align-items: center;
  gap: 7px;
}

.history-ball {
  display: inline-grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.history-ball.front {
  background: var(--red-dark);
}

.history-ball.back {
  background: var(--blue-dark);
}

.history-gap {
  width: 5px;
}

.history-time {
  margin: 0;
  text-align: right;
}

.empty-history {
  display: grid;
  min-height: 124px;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: #666b74;
}

.empty-history span {
  font-size: 0.86rem;
}

.empty-history p {
  margin: 0;
  font-size: 0.8rem;
}

footer {
  display: flex;
  justify-content: space-between;
  width: min(100%, 920px);
  margin: 38px auto 0;
  padding: 20px 0 26px;
  border-top: 1px solid var(--line-soft);
  color: #777c85;
  font-size: 0.7rem;
}

footer p {
  margin: 0;
}

.toast {
  position: fixed;
  z-index: 10;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #25282e;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.8rem;
}

@keyframes ball-reveal {
  0% { opacity: 0; transform: translateY(-28px) rotate(-20deg) scale(0.72); }
  70% { opacity: 1; transform: translateY(3px) rotate(3deg) scale(1.04); }
  100% { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}

@keyframes status-pulse {
  50% { opacity: 0.35; }
}

@media (max-width: 720px) {
  .app-shell {
    padding-right: 18px;
    padding-left: 18px;
  }

  .topbar {
    min-height: 76px;
  }

  .brand-icon {
    width: 42px;
    height: 42px;
  }

  .brand-kicker {
    display: none;
  }

  h1 {
    font-size: 1.08rem;
  }

  .network-status {
    font-size: 0;
  }

  .network-status i {
    width: 9px;
    height: 9px;
  }

  .install-button {
    font-size: 0.76rem;
  }

  main {
    padding-top: 30px;
  }

  .draw-board {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .number-zone {
    padding: 26px 22px;
  }

  .front-zone {
    padding-bottom: 20px;
  }

  .back-zone {
    padding-top: 20px;
  }

  .zone-divider {
    width: calc(100% - 44px);
    height: 1px;
    margin: 0 22px;
    background: var(--line);
  }

  .zone-divider::before {
    display: none;
  }

  .zone-divider span {
    position: absolute;
  }

  .back-zone .ball-row {
    width: 40%;
  }

  .number-ball {
    font-size: clamp(1rem, 5.2vw, 1.45rem);
  }

  .history-item {
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
    padding: 12px 0;
  }

  .history-numbers {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .history-time {
    grid-column: 2;
    grid-row: 1;
  }

  footer {
    display: block;
    text-align: center;
  }

  footer span {
    display: block;
    margin-top: 6px;
  }
}

@media (max-width: 390px) {
  .app-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .phase-display {
    min-width: 104px;
  }

  #stageTitle {
    font-size: 1.08rem;
  }

  .number-zone {
    padding-right: 16px;
    padding-left: 16px;
  }

  .zone-divider {
    width: calc(100% - 32px);
    margin-right: 16px;
    margin-left: 16px;
  }

  .history-ball {
    width: 29px;
    height: 29px;
    font-size: 0.68rem;
  }

  .history-numbers {
    gap: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
