:root {
  --bg: #1b1033;
  --bg2: #2d1b4e;
  --paper: #fdf6e3;
  --ink: #2a2a3a;
  --accent: #e63946;
  --gold: #d4af37;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 22px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, #3a2566 0%, transparent 60%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg2) 100%);
  overflow-x: hidden;
}

.card {
  width: min(440px, 100%);
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px 22px;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(45deg, rgba(0,0,0,0.015) 0 2px, transparent 2px 8px);
  pointer-events: none;
}

.head { text-align: center; margin-bottom: 18px; }

.title {
  font-size: 1.7rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 800;
}

.date {
  margin-top: 6px;
  font-size: 0.9rem;
  color: #8a7f6a;
  letter-spacing: 0.04em;
}

.stage {
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== 引く前 ===== */
.draw-area { text-align: center; width: 100%; }

.box {
  width: 96px;
  height: 120px;
  margin: 0 auto 22px;
  position: relative;
  transition: transform 0.4s ease;
}

.box-body {
  position: absolute;
  inset: 18px 0 0;
  background: linear-gradient(180deg, #c0392b, #962d22);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffe9c7;
  font-weight: 700;
  letter-spacing: 0.1em;
  writing-mode: vertical-rl;
  box-shadow: inset 0 -8px 16px rgba(0,0,0,0.25);
}

.box-lid {
  position: absolute;
  top: 0; left: -6px; right: -6px;
  height: 26px;
  background: linear-gradient(180deg, #e8b04b, var(--gold));
  border-radius: 8px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
  z-index: 2;
}

.box.shake { animation: shake 0.6s ease; }

@keyframes shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-9deg) translateY(-4px); }
  40% { transform: rotate(9deg); }
  60% { transform: rotate(-6deg) translateY(-3px); }
  80% { transform: rotate(6deg); }
}

.draw-btn {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #c1121f);
  border: none;
  border-radius: 999px;
  padding: 14px 30px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(230, 57, 70, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  letter-spacing: 0.06em;
}

.draw-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(230, 57, 70, 0.5); }
.draw-btn:active { transform: translateY(0); }
.draw-btn:disabled { opacity: 0.6; cursor: default; transform: none; }

.hint {
  margin-top: 14px;
  font-size: 0.8rem;
  color: #9a8f78;
}

/* ===== 結果 ===== */
.result { text-align: center; width: 100%; animation: rise 0.55s cubic-bezier(.2,.9,.3,1.2); }

@keyframes rise {
  from { opacity: 0; transform: translateY(26px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.result-rank {
  font-size: 3.4rem;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.08em;
  background-clip: text;
  -webkit-background-clip: text;
  color: var(--accent);
  margin-bottom: 8px;
}

.result-msg {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink);
  margin: 8px auto 16px;
  max-width: 30ch;
}

.result-meta {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 700;
  color: #7a5b00;
  background: linear-gradient(135deg, #fff3c4, #ffe08a);
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(212, 175, 55, 0.35);
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.ghost-btn {
  font-size: 0.9rem;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid #d8cdb0;
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ghost-btn:hover { background: #f3ebd6; border-color: #c9bb96; }

/* レア演出用のテーマ（JSで data-tier を付与） */
.result[data-tier="legendary"] .result-rank {
  background: linear-gradient(90deg, #ff4d4d, #ffb84d, #ffe14d, #4dff88, #4db8ff, #b84dff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: rainbow 3s linear infinite;
  background-size: 300% 100%;
}

@keyframes rainbow { to { background-position: 300% 0; } }

.result[data-tier="great"] .result-rank { color: #c1121f; }
.result[data-tier="good"] .result-rank { color: #1d7d4f; }
.result[data-tier="bad"] .result-rank { color: #5b6470; }

.foot {
  margin-top: 18px;
  text-align: center;
  font-size: 0.72rem;
  color: #b3a98e;
  letter-spacing: 0.03em;
}

/* 紙吹雪 */
.confetti {
  position: fixed;
  top: -12px;
  width: 9px;
  height: 14px;
  z-index: 99;
  opacity: 0.9;
  pointer-events: none;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translateY(105vh) rotate(640deg); opacity: 0.2; }
}

@media (prefers-reduced-motion: reduce) {
  .box.shake, .result, .result-rank, .confetti { animation: none !important; }
}
