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

:root {
  --bg: #0a0a0f; --bg2: #13131a; --bg3: #1c1c28;
  --border: #2a2a3a; --text: #f0f0ff; --text2: #7070a0;
  --purple: #7c5cfc; --purple2: #9b7ffe; --gold: #ffd200; --green: #43e97b;
}

body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', -apple-system, sans-serif; min-height: 100vh; }

/* ── Header ── */
.game-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 32px; border-bottom: 1px solid var(--border);
  background: rgba(10,10,15,0.9); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10;
}
.game-title {
  font-size: 1.6rem; font-weight: 900;
  background: linear-gradient(135deg, var(--purple), var(--purple2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.header-meta { display: flex; gap: 10px; }
.badge { background: var(--bg3); border: 1px solid var(--border); padding: 6px 14px; border-radius: 50px; font-size: 0.85rem; font-weight: 700; }
.badge-gold { background: rgba(255,210,0,0.1); border-color: rgba(255,210,0,0.3); color: var(--gold); }

/* ── Layout ── */
.game-container { max-width: 900px; margin: 0 auto; padding: 32px 24px; display: flex; flex-direction: column; gap: 32px; }
.dice-section { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.dice-row { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }

/* ── Die Wrapper ── */
.die-wrapper { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; user-select: none; }

/* 평면+3D를 겹치기 위한 컨테이너 */
.die-container { position: relative; width: 76px; height: 76px; }

/* ── 평면 주사위 (기본) ── */
.die-flat {
  width: 76px; height: 76px;
  background: #f5f0e8;
  border-radius: 13px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 9px;
  border: 3px solid transparent;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.8);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.die-flat.held {
  border-color: var(--gold); background: #fffbe6;
  box-shadow: 0 0 0 3px rgba(255,210,0,0.35), 0 6px 20px rgba(255,210,0,0.3);
}
/* 굴리는 중엔 평면 숨김 — visibility 사용 (opacity는 preserve-3d를 망가뜨림) */
.die-flat.rolling { visibility: hidden; }

/* ── 3D 주사위 (굴릴 때만) ── */
.die-3d {
  position: absolute; inset: 0;
  perspective: 260px;
  visibility: hidden;   /* 기본: 숨김 */
}
.die-3d.rolling { visibility: visible; }

.die-cube {
  width: 76px; height: 76px;
  position: relative;
  transform-style: preserve-3d;
}

/* 3D 굴리기 애니메이션 3종 */
.die-cube.tumble-a { animation: tumble-a var(--dur, 700ms) ease-out forwards; }
.die-cube.tumble-b { animation: tumble-b var(--dur, 700ms) ease-out forwards; }
.die-cube.tumble-c { animation: tumble-c var(--dur, 700ms) ease-out forwards; }

@keyframes tumble-a {
  0%   { transform: rotateX(0deg)    rotateY(0deg)    scale3d(1,   1,   1);   }
  20%  { transform: rotateX(130deg)  rotateY(90deg)   scale3d(.76,.76,.76);   }
  45%  { transform: rotateX(290deg)  rotateY(230deg)  scale3d(1.12,1.12,1.12);}
  70%  { transform: rotateX(460deg)  rotateY(390deg)  scale3d(.88,.88,.88);   }
  88%  { transform: rotateX(580deg)  rotateY(510deg)  scale3d(1.05,1.05,1.05);}
  100% { transform: rotateX(720deg)  rotateY(720deg)  scale3d(1,   1,   1);   }
}
@keyframes tumble-b {
  0%   { transform: rotateY(0deg)    rotateX(0deg)    scale3d(1,   1,   1);   }
  20%  { transform: rotateY(110deg)  rotateX(80deg)   scale3d(.74,.74,.74);   }
  45%  { transform: rotateY(265deg)  rotateX(210deg)  scale3d(1.13,1.13,1.13);}
  70%  { transform: rotateY(430deg)  rotateX(370deg)  scale3d(.87,.87,.87);   }
  88%  { transform: rotateY(565deg)  rotateX(490deg)  scale3d(1.04,1.04,1.04);}
  100% { transform: rotateY(720deg)  rotateX(720deg)  scale3d(1,   1,   1);   }
}
@keyframes tumble-c {
  0%   { transform: rotateX(0deg)    rotateZ(0deg)    rotateY(0deg)    scale3d(1,   1,   1);   }
  20%  { transform: rotateX(100deg)  rotateZ(40deg)   rotateY(120deg)  scale3d(.75,.75,.75);   }
  45%  { transform: rotateX(250deg)  rotateZ(80deg)   rotateY(280deg)  scale3d(1.14,1.14,1.14);}
  70%  { transform: rotateX(410deg)  rotateZ(270deg)  rotateY(440deg)  scale3d(.89,.89,.89);   }
  88%  { transform: rotateX(540deg)  rotateZ(340deg)  rotateY(580deg)  scale3d(1.04,1.04,1.04);}
  100% { transform: rotateX(720deg)  rotateZ(360deg)  rotateY(720deg)  scale3d(1,   1,   1);   }
}

/* ── 주사위 면 (6개) ── */
.die-face {
  position: absolute; width: 76px; height: 76px;
  border-radius: 12px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 9px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face-1 { transform: translateZ(38px);              background: #f5f0e8; border: 1.5px solid #cec6b4; }
.face-6 { transform: rotateY(180deg)  translateZ(38px); background: #ede8df; border: 1.5px solid #c8bfad; }
.face-2 { transform: rotateY(90deg)   translateZ(38px); background: #eee9e0; border: 1.5px solid #cabfad; }
.face-5 { transform: rotateY(-90deg)  translateZ(38px); background: #e9e4db; border: 1.5px solid #c6bba8; }
.face-3 { transform: rotateX(-90deg)  translateZ(38px); background: #f8f4ed; border: 1.5px solid #d0c8b6; }
.face-4 { transform: rotateX(90deg)   translateZ(38px); background: #dedad0; border: 1.5px solid #bdb4a2; }

/* ── 점 ── */
.die-cell { display: flex; align-items: center; justify-content: center; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: #1a1830; box-shadow: inset 0 1px 2px rgba(0,0,0,.45); }
.dot.hidden { visibility: hidden; }

/* ── Hold ── */
.hold-label { font-size: 0.7rem; font-weight: 700; color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; opacity: 0; transition: opacity 0.15s; height: 14px; }
.die-wrapper.held .hold-label { opacity: 1; }

/* ── Hint & Roll Button ── */
.hint { color: var(--text2); font-size: 0.9rem; text-align: center; }

.roll-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 36px;
  background: linear-gradient(135deg, var(--purple), var(--purple2));
  color: #fff; border: none; border-radius: 50px;
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s; font-family: inherit;
}
.roll-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(124,92,252,0.45); }
.roll-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.rolls-badge { background: rgba(255,255,255,0.2); padding: 3px 10px; border-radius: 50px; font-size: 0.8rem; }

/* ── Score ── */
.score-section { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.score-col { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.score-col-title { background: var(--bg3); padding: 10px 16px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text2); border-bottom: 1px solid var(--border); }
.score-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.score-row:last-child { border-bottom: none; }
.score-row.available { cursor: pointer; background: rgba(124,92,252,0.06); }
.score-row.available:hover { background: rgba(124,92,252,0.15); }
.score-row.scored { opacity: 0.45; }
.score-row.bonus-row { background: rgba(255,210,0,0.05); cursor: default; }
.row-name { font-size: 0.85rem; font-weight: 500; }
.row-name em { font-style: normal; color: var(--text2); font-size: 0.78rem; }
.row-score { font-size: 0.9rem; font-weight: 700; color: var(--text2); min-width: 36px; text-align: right; }
.score-row.available .row-score { color: var(--purple2); }
.score-row.scored .row-score    { color: var(--green); }
.bonus-row .row-score           { color: var(--gold) !important; }

/* ── Game Over ── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 100; }
.overlay.hidden { display: none; }
.gameover-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 24px; padding: 48px 56px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,0.6); }
.gameover-emoji { font-size: 3.5rem; margin-bottom: 12px; }
.gameover-card h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 24px; }
.gameover-score { font-size: 5rem; font-weight: 900; background: linear-gradient(135deg, var(--gold), #ff9f43); -webkit-background-clip: text; -webkit-text-fill-color: transparent; line-height: 1; }
.gameover-label { color: var(--text2); margin-bottom: 12px; font-size: 1.1rem; }
.gameover-rank { font-size: 1.2rem; font-weight: 700; margin-bottom: 28px; min-height: 1.5rem; }

/* ── Responsive ── */
@media (max-width: 600px) {
  .game-header { padding: 16px 20px; }
  .game-container { padding: 20px 16px; }
  .die-container, .die-flat, .die-3d, .die-cube { width: 60px; height: 60px; }
  .die-face { width: 60px; height: 60px; border-radius: 10px; padding: 7px; }
  .face-1 { transform: translateZ(30px); }
  .face-6 { transform: rotateY(180deg)  translateZ(30px); }
  .face-2 { transform: rotateY(90deg)   translateZ(30px); }
  .face-5 { transform: rotateY(-90deg)  translateZ(30px); }
  .face-3 { transform: rotateX(-90deg)  translateZ(30px); }
  .face-4 { transform: rotateX(90deg)   translateZ(30px); }
  .dot { width: 9px; height: 9px; }
  .score-section { grid-template-columns: 1fr; }
  .gameover-card { padding: 36px 28px; }
  .gameover-score { font-size: 4rem; }
}
