:root {
  --purple-deep: #342044;
  --purple-dark: #22132e;
  --purple-mid: #53336e;
  --cream: #faf8f5;
  --cream-warm: #f2ebe1;
  --gold: #f5b335;
  --gold-bright: #ffd452;
  --coral: #e85d4a;
  --ink: #2c1e36;
  --muted: #72627e;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #442a59 0%, #1d1028 100%);
  font-family: "Noto Sans TC", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 480px;
  max-height: 920px;
  background: var(--cream);
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

@media (min-width: 520px) {
  #game-shell {
    height: min(94dvh, 860px);
    border-radius: 26px;
    border: 3px solid rgba(255, 255, 255, 0.14);
  }
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}

.hud-pill {
  background: rgba(52, 32, 68, 0.88);
  color: #fff;
  border-radius: 14px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 74px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(34, 19, 46, 0.22);
}

.hud-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  opacity: 0.78;
  line-height: 1.1;
}

#hud-score-val,
#hud-combo-val {
  font-size: 18px;
  font-weight: 900;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.hud-combo.fever-on {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  animation: pulse-pop 0.4s ease-in-out infinite alternate;
}

.hud-timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

#hud-timer-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--purple-deep);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(52, 32, 68, 0.2);
  transition: transform 0.12s ease, border-color 0.2s ease;
}

#hud-timer-ring.urgent {
  border-color: var(--coral);
  color: var(--coral);
  animation: pulse-pop 0.35s ease-in-out infinite alternate;
}

#hud-timer-val {
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

#hud-fever-bar {
  width: 84px;
  height: 7px;
  border-radius: 999px;
  background: rgba(52, 32, 68, 0.16);
  overflow: hidden;
}

#hud-fever-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), #ff6b4a);
  transition: width 0.15s ease;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 4px 12px rgba(52, 32, 68, 0.15);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(34, 19, 46, 0.56);
  backdrop-filter: blur(5px);
  z-index: 20;
}

.overlay-transparent {
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
  align-items: flex-start;
  padding-top: 86px;
}

.start-card,
.result-card {
  width: 100%;
  max-width: 360px;
  background: var(--cream);
  border-radius: 26px;
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 22px 50px rgba(20, 10, 30, 0.35);
  border: 2px solid rgba(52, 32, 68, 0.08);
  animation: card-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.badge-tag,
.rank-badge {
  display: inline-block;
  padding: 5px 13px;
  border-radius: 999px;
  background: rgba(52, 32, 68, 0.1);
  color: var(--purple-deep);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.rank-badge {
  background: linear-gradient(135deg, #342044, #5c3779);
  color: var(--gold-bright);
}

.game-title {
  margin: 0 0 10px;
  font-size: 32px;
  font-weight: 900;
  color: var(--purple-deep);
  line-height: 1.15;
  letter-spacing: 0.02em;
}

.title-accent {
  color: var(--coral);
}

.game-sub {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--muted);
}

.legend-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 10px 12px;
  background: var(--cream-warm);
  border-radius: 14px;
  font-size: 12px;
  color: var(--ink);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot-good {
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(245, 179, 53, 0.25);
}

.dot-bad {
  background: var(--coral);
  box-shadow: 0 0 0 3px rgba(232, 93, 74, 0.22);
}

.btn-primary {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 15px 18px;
  background: linear-gradient(180deg, #4b2d63 0%, #342044 100%);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(52, 32, 68, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn-primary:active {
  transform: translateY(2px) scale(0.985);
  box-shadow: 0 4px 12px rgba(52, 32, 68, 0.28);
}

.best-line {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.best-line strong {
  color: var(--purple-deep);
}

/* Roll Climax */
.roll-hud {
  text-align: center;
  width: 100%;
  max-width: 300px;
}

.roll-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.roll-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--purple-deep);
  text-shadow: 0 2px 0 #fff, 0 4px 14px rgba(255, 255, 255, 0.9);
  margin-bottom: 10px;
  animation: pulse-pop 0.26s ease-in-out infinite alternate;
}

.roll-progress-track {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: rgba(52, 32, 68, 0.2);
  border: 2px solid #fff;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(52, 32, 68, 0.2);
}

#roll-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #ff6b4a);
  transition: width 0.06s linear;
}

.roll-timer {
  margin-top: 6px;
  font-size: 16px;
  font-weight: 900;
  color: var(--purple-deep);
  font-variant-numeric: tabular-nums;
}

/* Result Card */
.result-title {
  margin: 0 0 12px;
  font-size: 23px;
  font-weight: 900;
  color: var(--purple-deep);
}

.cross-section-wrap {
  position: relative;
  margin: 0 auto 14px;
  width: 260px;
  height: 170px;
  border-radius: 18px;
  background: radial-gradient(circle at center, #fffdf9 0%, #efe6d8 100%);
  border: 2px solid rgba(52, 32, 68, 0.09);
  display: grid;
  place-items: center;
  overflow: hidden;
}

#result-canvas {
  display: block;
  width: 260px;
  height: 170px;
}

.new-record {
  position: absolute;
  top: 8px;
  right: 8px;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  padding: 4px 9px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.35);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-box {
  background: var(--cream-warm);
  border-radius: 14px;
  padding: 9px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
}

.stat-val {
  font-size: 18px;
  font-weight: 900;
  color: var(--purple-deep);
  font-variant-numeric: tabular-nums;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-order {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  color: var(--purple-deep);
  background: rgba(52, 32, 68, 0.07);
  border: 1.5px solid rgba(52, 32, 68, 0.16);
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-order:hover {
  background: rgba(52, 32, 68, 0.12);
}

.btn-order:active {
  transform: scale(0.985);
}

@keyframes pulse-pop {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.06);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
