:root {
  --bg: #16231a;
  --panel: #233528;
  --panel-2: #2c4232;
  --edge: #0c140e;
  --text: #f2f5ee;
  --muted: #a9b8a6;
  --accent: #6cc644;
  --gold: #f5c542;
  --common: #c3cbc1;
  --uncommon: #5fd36f;
  --rare: #4fc3ff;
  --legendary: #d08bff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* .big·.card 등의 display 지정이 hidden 속성을 덮지 않게 한다. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(0, 0, 0, 0.18) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, rgba(0, 0, 0, 0.18) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  line-height: 1.45;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(28px + env(safe-area-inset-bottom));
}

.top { display: flex; gap: 12px; align-items: center; margin: 4px 2px 14px; }
.logo { width: 52px; height: 52px; image-rendering: pixelated; filter: drop-shadow(0 3px 0 var(--edge)); }
h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.02em; }
h2 { margin: 0 0 10px; font-size: 1.1rem; }
h3 { margin: 18px 0 8px; font-size: 1rem; }
h4 { margin: 10px 0 6px; font-size: 0.92rem; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }

.panel {
  background: var(--panel);
  border: 3px solid var(--edge);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.07), 0 4px 0 var(--edge);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}
details.panel > summary { cursor: pointer; font-weight: 700; }

.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.muted, .hint { color: var(--muted); font-size: 0.86rem; margin: 6px 0 0; }

button { font: inherit; color: inherit; cursor: pointer; }
.link { background: none; border: none; color: var(--gold); text-decoration: underline; padding: 6px 2px; font-size: 0.9rem; }
.big, .player {
  display: block;
  width: 100%;
  border: 3px solid var(--edge);
  border-radius: 10px;
  padding: 14px;
  font-size: 1.15rem;
  font-weight: 800;
  background: linear-gradient(#7ed957, #4f9e30);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), 0 4px 0 var(--edge);
  color: #10200b;
}
.big:active, .player:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 2px 0 var(--edge); }
.big:disabled { filter: grayscale(0.6); }
.player-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.player { font-size: 1.4rem; padding: 22px 10px; }

.me { font-size: 1.05rem; }
.meter { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 10px 0 6px; }
.slot {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  border: 2px solid var(--edge);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 1.3rem;
}
.slot small { font-size: 0.62rem; color: var(--muted); }
.slot b { font-size: 0.9rem; }
.slot.ready { background: #4a5f2c; animation: bounce 1.2s ease-in-out infinite; }
.slot.scratching { background: #5f5a2c; }
.slot.locked { opacity: 0.75; }
.slot.used { background: #1b2a1f; }
.summary { margin: 4px 0 0; font-weight: 700; }
.countdown { margin: 2px 0 12px; color: var(--gold); font-weight: 800; font-variant-numeric: tabular-nums; }

.card-area { position: relative; }
.card {
  position: relative;
  height: 210px;
  border-radius: 12px;
  border: 4px solid var(--edge);
  background: radial-gradient(circle at 50% 40%, #fffbe8, #f1d98d 70%, #d9b45a);
  color: #2a2110;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.card.tier-uncommon { background: radial-gradient(circle at 50% 40%, #f2fff0, #a9e89f 70%, #6dbf5f); }
.card.tier-rare { background: radial-gradient(circle at 50% 40%, #f0fbff, #9fdcf7 70%, #4fa6d8); }
.card.tier-legendary { background: radial-gradient(circle at 50% 40%, #fff5ff, #e2b5ff 65%, #a361d9); }
.card.empty { display: grid; place-items: center; background: var(--panel-2); color: var(--muted); text-align: center; padding: 18px; }
.empty-text { font-weight: 700; }
.prize { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 2px; }
.prize-icon { width: 88px; height: 88px; image-rendering: pixelated; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.25)); }
.prize-name { font-size: 1.45rem; font-weight: 900; }
.prize-count { font-size: 1.15rem; font-weight: 800; }
.tier { position: absolute; top: 10px; left: 10px; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 800; background: #2a2110; color: #fff; }
.tier.tier-uncommon { background: #1f6b2a; }
.tier.tier-rare { background: #12608c; }
.tier.tier-legendary { background: #6a2a9c; }
.scratch { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity 0.5s ease; }
.scratch.gone { opacity: 0; pointer-events: none; }
.card-actions { display: grid; gap: 6px; justify-items: center; margin-top: 10px; }
.result { min-height: 1.4em; margin: 8px 0 0; text-align: center; font-weight: 800; color: var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 4px;
  border-radius: 8px;
  border: 2px solid var(--edge);
  background: var(--panel-2);
  font-size: 0.88rem;
}
.chip small { color: var(--muted); }
.chip.tier-uncommon { border-color: #2c6b33; }
.chip.tier-rare { border-color: #1f6f9c; }
.chip.tier-legendary { border-color: #8040b8; }
.px { image-rendering: pixelated; }

.history { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.history li { display: grid; grid-template-columns: 2.2em 24px 1fr auto auto; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.15); font-size: 0.9rem; }
.history .num, .history .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.badge { font-size: 0.75rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #3a4a3c; color: var(--muted); white-space: nowrap; }
.badge.wait { background: #5c4a14; color: #ffe08a; }
.badge.done { background: #1f5c2a; color: #b8f5b0; }

.board { display: grid; gap: 10px; }
.board-player { background: rgba(0, 0, 0, 0.16); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.board-name { font-size: 1.05rem; }

.tier-group h4 { color: var(--common); }
.tier-group.tier-uncommon h4 { color: var(--uncommon); }
.tier-group.tier-rare h4 { color: var(--rare); }
.tier-group.tier-legendary h4 { color: var(--legendary); }

footer { color: var(--muted); font-size: 0.78rem; text-align: center; }
footer a { color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  background: #111a13;
  border: 2px solid var(--gold);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  z-index: 20;
}

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti span { position: absolute; top: -40px; animation: fall 2.2s ease-in forwards; }

@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: 0.2; } }
@keyframes bounce { 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) {
  .slot.ready { animation: none; }
  .confetti { display: none; }
}
