:root {
  color-scheme: dark;
  --bg: #11111a;
  --panel: rgba(255, 255, 255, 0.12);
  --panel-strong: rgba(255, 255, 255, 0.18);
  --text: #fff8ef;
  --muted: rgba(255, 248, 239, 0.64);
  --line: rgba(255, 255, 255, 0.13);
  --yellow: #ffd166;
  --pink: #ff7a90;
  --green: #8ce99a;
  --ink: #211622;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  position: fixed;
  inset: 0;
  margin: 0;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 28% 14%, rgba(255, 209, 102, 0.38), transparent 26rem),
    radial-gradient(circle at 86% 22%, rgba(255, 122, 144, 0.3), transparent 22rem),
    radial-gradient(circle at 50% 100%, rgba(140, 233, 154, 0.2), transparent 20rem),
    linear-gradient(155deg, #171221 0%, #221633 46%, #101827 100%);
  content: "";
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(100%, 430px);
  height: 100svh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: rgba(255, 248, 239, 0.82);
  font-size: 14px;
  font-weight: 800;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 18px rgba(140, 233, 154, 0.9);
}

.install-pill {
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.1);
}

.install-pill[hidden],
.ios-tip[hidden],
.image-modal[hidden],
.draw-status[hidden] {
  display: none;
}

.screen {
  display: none;
  height: 100%;
  min-height: 0;
  animation: popIn 260ms ease both;
}

.screen.is-active {
  display: flex;
}

.welcome-screen,
.machine-screen,
.draw-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}

.result-screen {
  flex-direction: column;
  justify-content: flex-start;
  gap: 10px;
  min-height: 0;
  padding-top: 4px;
}

.orb {
  display: grid;
  place-items: center;
  width: min(54vw, 208px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 48px;
  color: var(--ink);
  font-size: 94px;
  font-weight: 1000;
  background:
    radial-gradient(circle at 35% 28%, #fff7c7, transparent 24%),
    linear-gradient(145deg, var(--yellow), var(--pink));
  box-shadow: var(--shadow);
  transform-origin: 50% 50%;
  animation: orbFloat 2.8s ease-in-out infinite;
}

.eyebrow {
  display: inline-flex;
  margin: 0;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.08);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 8em;
  font-size: clamp(42px, 12vw, 58px);
  line-height: 0.98;
  letter-spacing: -0.07em;
}

.subtitle,
.machine-card p {
  max-width: 17em;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.start-button,
.primary-button {
  width: min(100%, 330px);
  min-height: 64px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 1000;
  background: linear-gradient(135deg, #fff0a8, #ff7a90);
  box-shadow: 0 18px 48px rgba(255, 122, 144, 0.32);
}

.start-button::after {
  content: "  ->";
}

.machine-card {
  width: min(100%, 340px);
  padding: 28px 22px;
  border: 1px solid var(--line);
  border-radius: 34px;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.07));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.machine-light {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  margin: 0 auto 18px;
  border-radius: 30px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), transparent 38%),
    linear-gradient(145deg, var(--green), var(--yellow));
  box-shadow: 0 18px 40px rgba(140, 233, 154, 0.22);
}

.machine-light::before {
  color: var(--ink);
  font-size: 44px;
  font-weight: 1000;
  content: "签";
  transform: rotate(-8deg);
}

.machine-card h2 {
  margin: 12px 0 10px;
  font-size: 34px;
  letter-spacing: -0.05em;
}

.draw-box {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 42px);
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow);
  transform-origin: 50% 50%;
}

.draw-screen.is-active .draw-box {
  animation: drawSwing 820ms cubic-bezier(0.45, 0, 0.35, 1) infinite;
}

.draw-box span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 108px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 1000;
  background: linear-gradient(180deg, #fff3b8, #ff8ba1);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
}

.draw-box span:nth-child(2) {
  transform: translateY(-10px) rotate(4deg);
}

.draw-box span:nth-child(3) {
  transform: translateY(8px) rotate(-5deg);
}

.draw-screen h2 {
  font-size: 34px;
  letter-spacing: -0.05em;
}

.draw-screen p {
  max-width: 18em;
  color: var(--muted);
  line-height: 1.5;
}

.draw-status {
  padding: 9px 16px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 1000;
  background: linear-gradient(135deg, #fff0a8, #8ce99a);
  box-shadow: 0 14px 34px rgba(140, 233, 154, 0.22);
  animation: statusPop 260ms ease both;
}

.fortune-card {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: clamp(13px, 4vw, 18px);
  border: 1px solid var(--line);
  border-radius: 34px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.08)),
    var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.fortune-card.is-work {
  background:
    linear-gradient(145deg, rgba(255, 209, 102, 0.24), rgba(255, 255, 255, 0.08)),
    var(--panel);
}

.fortune-card.is-chaos {
  background:
    linear-gradient(145deg, rgba(255, 122, 144, 0.28), rgba(255, 255, 255, 0.08)),
    var(--panel);
}

.fortune-card.is-luck {
  background:
    linear-gradient(145deg, rgba(140, 233, 154, 0.22), rgba(255, 255, 255, 0.08)),
    var(--panel);
}

.fortune-card.is-social {
  background:
    linear-gradient(145deg, rgba(151, 128, 255, 0.28), rgba(255, 255, 255, 0.08)),
    var(--panel);
}

.fortune-card::before {
  position: absolute;
  inset: -90px -80px auto auto;
  width: 190px;
  height: 190px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.2);
  content: "";
}

.result-image {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 100%;
  height: clamp(82px, 19svh, 132px);
  margin: 8px auto 2px;
}

.result-image svg {
  width: min(100%, 258px);
  height: 100%;
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, 0.22));
}

.card-topline,
.spirit,
.fortune-list,
.advice {
  position: relative;
}

.card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--ink);
  background: var(--yellow);
}

.result-hero {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  margin-top: 8px;
}

.result-sticker {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 24px;
  color: var(--ink);
  font-size: 38px;
  font-weight: 1000;
  background: linear-gradient(145deg, #fff1a8, #ff8ba1);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.18);
  transform: rotate(-5deg);
}

.spirit-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-hero h2 {
  min-height: 0;
  font-size: clamp(28px, 8.5vw, 38px);
  line-height: 1.06;
  letter-spacing: -0.06em;
}

.result-subtitle {
  position: relative;
  flex: 0 0 auto;
  margin-top: 8px;
  color: rgba(255, 248, 239, 0.76);
  font-size: 14px;
  line-height: 1.45;
}

.fortune-list {
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 8px;
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  margin: 10px 0 0;
  padding-right: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.fortune-item {
  display: flex;
  align-items: center;
  min-height: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
}

.fortune-label {
  display: inline;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.fortune-value {
  display: inline;
  margin-left: 4px;
  font-size: 15px;
  font-weight: 1000;
  line-height: 1.35;
}

.advice {
  flex: 0 0 auto;
  margin-top: 10px;
  padding: 12px;
  border-radius: 18px;
  color: rgba(255, 248, 239, 0.88);
  font-size: 14px;
  line-height: 1.45;
  background: rgba(255, 122, 144, 0.13);
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.secondary-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-weight: 900;
  background: rgba(255, 255, 255, 0.12);
}

.start-button:active,
.primary-button:active,
.secondary-button:active,
.install-pill:active {
  transform: translateY(1px) scale(0.99);
}

.ios-tip {
  position: absolute;
  right: 16px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
}

.ios-tip strong {
  color: var(--yellow);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 4;
  width: max-content;
  max-width: calc(100% - 36px);
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--ink);
  font-weight: 900;
  background: var(--yellow);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  background: rgba(9, 7, 14, 0.82);
  backdrop-filter: blur(18px);
}

.image-modal-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 420px);
  max-height: 100%;
}

.image-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.12);
}

.image-modal-header strong,
.image-modal-header span {
  display: block;
}

.image-modal-header strong {
  color: var(--text);
  font-size: 15px;
}

.image-modal-header span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.image-modal-header button {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  background: var(--yellow);
}

#savePreviewImage {
  display: block;
  width: 100%;
  max-height: calc(100svh - 120px);
  border-radius: 24px;
  object-fit: contain;
  box-shadow: var(--shadow);
  -webkit-user-select: auto;
  user-select: auto;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes orbFloat {
  0%,
  100% {
    transform: translateX(-7px) rotate(-3deg) scale(1);
  }

  50% {
    transform: translateX(7px) rotate(3deg) scale(1.02);
  }
}

@keyframes drawSwing {
  0%,
  100% {
    transform: rotate(-6deg);
  }

  25% {
    transform: rotate(5deg);
  }

  50% {
    transform: rotate(-3deg);
  }

  75% {
    transform: rotate(4deg);
  }
}

@keyframes statusPop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.92);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-height: 700px) {
  .app-header {
    min-height: 30px;
  }

  .welcome-screen,
  .machine-screen {
    gap: 12px;
  }

  .orb {
    width: min(44vw, 150px);
    border-radius: 36px;
    font-size: 72px;
  }

  h1 {
    font-size: clamp(36px, 11vw, 48px);
  }

  .result-image {
    height: 74px;
  }

  .fortune-item {
    padding: 8px 10px;
  }

  .advice {
    font-size: 13px;
  }
}
