* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #2e2440; color: #f2e9d8;
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
#wrap { position: fixed; inset: 0; width: 100%; height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

#hud {
  padding: calc(8px + env(safe-area-inset-top)) 14px 6px;
  display: flex; justify-content: space-between; align-items: center;
  background: #241b33; border-bottom: 3px solid #4d3a6b;
  font-weight: 700; font-size: 14px;
}
#score-box { font-size: 17px; background: rgba(255,255,255,.1); padding: 4px 12px; border-radius: 18px; }
#strike-box { font-size: 15px; letter-spacing: 2px; }
#strike-box .used { opacity: 1; }
#strike-box .left { opacity: .25; filter: grayscale(1); }
#pile-left-box { font-size: 12px; color: #b8a8d0; }

#pile-zone {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 120px;
}
#pile-hint { font-size: 14px; color: #b8a8d0; margin-bottom: 8px; animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
#pile-img {
  font-size: 110px; cursor: pointer; filter: drop-shadow(0 8px 18px rgba(0,0,0,.5));
  transition: transform .1s;
}
#pile-img:active { transform: scale(.93); }
#pile-img.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px) rotate(-4deg); } 75% { transform: translateX(8px) rotate(4deg); } }

#card-zone {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 8;
  background: rgba(20,14,30,.78);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#card-item {
  width: 190px; height: 250px; border-radius: 18px; background: #fdf8ee;
  border: 5px solid #b8a8d0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 14px 40px rgba(0,0,0,.6); position: relative; overflow: hidden;
  animation: cardIn .35s cubic-bezier(.2,1.5,.4,1);
}
@keyframes cardIn { from { transform: translateY(120px) scale(.5); opacity: 0; } }
#card-item.fly-left { transition: transform .22s ease-in, opacity .22s; transform: translateX(-300px) rotate(-20deg); opacity: 0; }
#card-item.fly-right { transition: transform .22s ease-in, opacity .22s; transform: translateX(300px) rotate(20deg); opacity: 0; }
#card-beam {
  position: absolute; inset: -40%; display: none;
  background: conic-gradient(transparent, rgba(255,240,180,.9), transparent 30%);
  animation: spin 2s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#card-item.g1 { border-color: #4a7fe0; }
#card-item.g2 { border-color: #9b59d0; }
#card-item.g2 #card-beam { display: block; }
#card-item.g3 { border-color: #e0a92e; }
#card-item.g3 #card-beam { display: block; }
#card-icon { font-size: 74px; z-index: 2; }
#card-name { font-size: 17px; font-weight: 800; color: #3d2f4f; margin-top: 8px; z-index: 2; }
#card-grade { font-size: 14px; font-weight: 700; margin-top: 3px; z-index: 2; }
#card-actions { display: flex; gap: 16px; margin-top: 22px; }
#card-actions button {
  min-width: 120px; min-height: 50px; border-radius: 12px; border: none;
  font-family: inherit; font-size: 16px; font-weight: 800; cursor: pointer;
}
#btn-discard { background: #5a4a70; color: #d8cce8; box-shadow: 0 3px 0 #3d2f4f; }
#btn-keep { background: #e0a92e; color: #3d2f10; box-shadow: 0 3px 0 #a67b1a; }
#card-actions button:active { transform: translateY(2px); box-shadow: none; }

#basket-wrap { padding: 6px 14px 4px; }
#basket-title { font-size: 13px; font-weight: 700; color: #b8a8d0; margin-bottom: 5px; }
#basket-value { color: #e0a92e; }
#basket-sets { color: #8fd8a0; font-size: 12px; }
#basket-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  background: #241b33; border: 3px solid #4d3a6b; border-radius: 12px; padding: 7px;
}
.bcell {
  aspect-ratio: 1; border-radius: 8px; background: rgba(255,255,255,.06);
  border: 2px dashed rgba(184,168,208,.3);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  position: relative;
}
.bcell.filled { border: 2px solid #4d3a6b; background: rgba(255,255,255,.12); }
.bcell .bval { position: absolute; bottom: 1px; right: 3px; font-size: 9px; font-weight: 800; color: #e0a92e; }
.bcell.swappable { outline: 3px solid #e0a92e; }

#btn-cashout {
  margin: auto 14px calc(12px + env(safe-area-inset-bottom)); min-height: 54px;
  border: none; border-radius: 14px; font-family: inherit;
  font-size: 17px; font-weight: 800; color: #2a1f08;
  background: linear-gradient(180deg, #f5c84e, #e0a92e);
  box-shadow: 0 4px 0 #a67b1a; cursor: pointer;
}
#btn-cashout:active { transform: translateY(3px); box-shadow: 0 1px 0 #a67b1a; }

.overlay {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(30,22,44,.97);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.title-kr { font-size: 46px; font-weight: 900; color: #f5c84e; text-shadow: 0 3px 0 rgba(0,0,0,.4); margin-bottom: 8px; }
.title-sub { font-size: 14px; color: #b8a8d0; margin-bottom: 14px; }
.best-line { font-size: 13px; color: #e0a92e; font-weight: 700; margin-bottom: 12px; }
.howto { margin-bottom: 22px; display: flex; flex-direction: column; gap: 10px; }
.how-row { display: flex; align-items: center; gap: 11px; text-align: left; font-size: 13px; line-height: 1.4; max-width: 310px; }
.how-ico { font-size: 22px; flex-shrink: 0; width: 32px; text-align: center; }
.big-btn {
  min-width: 190px; min-height: 54px; padding: 13px 30px;
  font-size: 19px; font-weight: 800; font-family: inherit;
  color: #2a1f08; background: linear-gradient(180deg, #f5c84e, #e0a92e);
  border: none; border-radius: 12px; cursor: pointer;
  box-shadow: 0 4px 0 #a67b1a;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a67b1a; }

.float-num {
  position: absolute; font-weight: 900; font-size: 18px; color: #f5c84e;
  pointer-events: none; animation: floatUp 1s ease-out forwards; z-index: 20;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
}
@keyframes floatUp { to { transform: translateY(-70px); opacity: 0; } }

.icon-btn {
  position: absolute; bottom: calc(12px + env(safe-area-inset-bottom)); right: 12px; z-index: 12;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.12); border: 2px solid #4d3a6b; color: #f2e9d8; font-size: 19px; cursor: pointer;
}
@media (max-height: 700px) {
  #pile-img { font-size: 78px; }
  #card-item { width: 160px; height: 210px; }
  #card-icon { font-size: 58px; }
}
