:root {
  font-family: "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  font-synthesis: none;
  --black: #010412;
  --title: #1c202d;
  --muted: #5d6271;
  --line: #e1e3eb;
  --primary: #3e62ff;
  --white: #fff;
}

* { box-sizing: border-box; font-family: inherit; }
html { min-width: 320px; min-height: 100%; background: #f8f7ff; }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--black);
  background: linear-gradient(165deg, #fff 8%, rgba(246, 240, 255, 0.7) 56%, #dfe8ff 98%), #fff;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.home-link {
  position: fixed;
  z-index: 20;
  top: 24px;
  left: 24px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: #3e62ff;
  background: rgba(255,255,255,.88);
  box-shadow: 2px 2px 8px rgba(0,0,0,.1);
  font-size: 22px;
  font-weight: 700;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.home-link:hover { transform: translateX(-2px); box-shadow: 2px 5px 14px rgba(62,98,255,.18); }
.home-link:focus-visible { outline: 3px solid rgba(62,98,255,.35); outline-offset: 3px; }

.game-shell {
  width: min(1100px, calc(100% - 48px));
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(46px, 7.4vh, 80px) 0 60px;
}

.game-header { text-align: center; }
h1 {
  margin: 0;
  color: var(--title);
  font-size: clamp(2.7rem, 3.15vw, 3.75rem);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.02em;
}
.rule { margin: 11px 0 0; color: var(--muted); font-size: 20px; font-weight: 500; line-height: 1.3; letter-spacing: -0.02em; }
.dice-workspace {
  display: grid;
  grid-template-columns: minmax(0, .92fr) minmax(360px, 1.08fr);
  gap: 12px;
  margin-top: 35px;
}
.dice-panel {
  min-width: 0;
  min-height: 520px;
  padding: 28px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--white);
  box-shadow: 2px 2px 4px rgba(0,0,0,.1);
}
.dice-panel h2 { margin: 0; color: var(--title); font-size: 24px; line-height: 1.3; letter-spacing: -.03em; }
.panel-helper { margin: 8px 0 22px; color: #777; font-size: 14px; line-height: 1.5; }
.setup {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 16px;
  border-radius: 14px;
  background: #f7f7fa;
}
.setup-label { color: #444; font-size: 15px; font-weight: 700; }
.name-helper { margin: 22px 0 9px; color: #444; font-size: 15px; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 20px; }
.stepper button {
  width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 8px;
  color: var(--black); background: var(--white); box-shadow: 2px 2px 4px rgba(0,0,0,.1); cursor: pointer;
  font-size: 23px; line-height: 1; transition: transform 160ms ease, box-shadow 160ms ease;
}
.stepper button:hover { box-shadow: 2px 5px 12px rgba(62,98,255,.16); }
.stepper button:active { transform: scale(.94); }
.stepper button:disabled { color: #b8bbc5; cursor: not-allowed; }
.stepper button:focus-visible, .player-name:focus-visible, .roll-button:focus-visible { outline: 3px solid rgba(62,98,255,.35); outline-offset: 3px; }
.stepper strong { min-width: 32px; color: #000; text-align: center; font-size: 20px; font-weight: 500; }

.players { width: 100%; margin: 0; padding: 12px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; border-radius: 14px; background: #f7f7fa; list-style: none; }
.player {
  width: auto; min-width: 0; min-height: 74px; padding: 10px 12px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; border: 2px solid transparent; border-radius: 10px; color: var(--black);
  background: var(--white); box-shadow: 2px 2px 4px rgba(0,0,0,.1);
  transition: opacity 240ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.player-name {
  width: 100%; min-width: 0; padding: 0; border: 0; border-radius: 4px; color: #5b5e6e; background: transparent;
  font-size: 16px; font-weight: 500; line-height: 1.3; letter-spacing: -0.02em; text-align: center; text-overflow: ellipsis;
}
.player-name::selection { color: white; background: var(--primary); }
.player-name::placeholder { color: #a6a9ba; font-size: 14px; font-weight: 400; opacity: 1; }
.player-name:disabled { opacity: 1; }
.player strong { min-height: 31px; color: var(--black); font-size: 24px; font-weight: 650; line-height: 1.3; letter-spacing: -0.02em; }
.player.is-current { border-color: var(--primary); box-shadow: 2px 2px 4px rgba(0,0,0,.1), 0 0 0 1px rgba(62,98,255,.08); }
.player.is-done { background: rgba(255,255,255,.94); }
body.is-finished .player.is-current { border-color: transparent; }
body.is-finished .player:not(.is-loser) { opacity: .3; }
.player.is-loser { border-color: var(--primary); box-shadow: 0 0 0 1px rgba(62,98,255,.12); }
.player.is-loser .player-name { font-size: 18px; }
.player.is-loser strong { font-size: 28px; }

.play-area {
  position: sticky;
  top: 24px;
  align-self: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
.play-area::before { display: none; }
.play-area > * { position: relative; z-index: 1; }
.play-heading { width: 100%; }
.turn-label { margin: 8px 0 0; color: #777; font-size: 14px; line-height: 1.5; }
.turn-label.is-result { color: var(--primary); font-weight: 800; }
.dice-stage { --die-size: 150px; position: relative; width: 100%; height: 300px; margin-top: 8px; isolation: isolate; }
.dice-floor-shadow {
  position: absolute; z-index: 0; left: 50%; bottom: 18px; width: 58%; height: 30px; border-radius: 50%;
  background: rgba(40,48,70,.1); filter: blur(18px); transform: translateX(-50%) scaleY(.52); pointer-events: none;
}
.die-rig { position: absolute; width: var(--die-size); height: var(--die-size); will-change: transform; }
.die-rig--one { z-index: 1; left: calc(50% - 162px); top: 62px; transform: rotate(-4deg); }
.die-rig--two { z-index: 2; left: calc(50% + 12px); top: 70px; transform: rotate(4deg); }
.die-cube {
  position: relative; width: 100%; height: 100%; overflow: hidden; border: 1px solid rgba(74,78,104,.1); border-radius: 38px;
  background: linear-gradient(145deg,#fff 0%,#fbfaff 52%,#eceeff 100%); box-shadow: none; will-change: transform;
}
.die-window {
  position: absolute; inset: 0; display: block; overflow: hidden; border-radius: inherit;
  -webkit-mask-image: linear-gradient(to bottom,transparent 0%,#000 16%,#000 84%,transparent 100%);
  mask-image: linear-gradient(to bottom,transparent 0%,#000 16%,#000 84%,transparent 100%);
}
.die-reel { display: grid; grid-auto-rows: 100%; width: 100%; height: 100%; will-change: transform; }
.slot-face { position: relative; display: block; width: 100%; height: 100%; }
.pip {
  position: absolute; width: 26px; height: 26px; border-radius: 50%; background: #252733;
  box-shadow: inset 0 3px 4px rgba(0,0,0,.22), 0 2px 0 rgba(255,255,255,.8); transform: translate(-50%,-50%);
}
.slot-face--1 .pip:nth-child(1) { left: 50%; top: 50%; }
.slot-face--2 .pip:nth-child(1) { left: 29%; top: 29%; }
.slot-face--2 .pip:nth-child(2) { left: 71%; top: 71%; }
.slot-face--3 .pip:nth-child(1) { left: 28%; top: 28%; }
.slot-face--3 .pip:nth-child(2) { left: 50%; top: 50%; }
.slot-face--3 .pip:nth-child(3) { left: 72%; top: 72%; }
.slot-face--4 .pip:nth-child(1) { left: 29%; top: 29%; }
.slot-face--4 .pip:nth-child(2) { left: 71%; top: 29%; }
.slot-face--4 .pip:nth-child(3) { left: 29%; top: 71%; }
.slot-face--4 .pip:nth-child(4) { left: 71%; top: 71%; }
.slot-face--5 .pip:nth-child(1) { left: 28%; top: 28%; }
.slot-face--5 .pip:nth-child(2) { left: 72%; top: 28%; }
.slot-face--5 .pip:nth-child(3) { left: 50%; top: 50%; }
.slot-face--5 .pip:nth-child(4) { left: 28%; top: 72%; }
.slot-face--5 .pip:nth-child(5) { left: 72%; top: 72%; }
.slot-face--6 .pip:nth-child(1) { left: 29%; top: 24%; }
.slot-face--6 .pip:nth-child(2) { left: 71%; top: 24%; }
.slot-face--6 .pip:nth-child(3) { left: 29%; top: 50%; }
.slot-face--6 .pip:nth-child(4) { left: 71%; top: 50%; }
.slot-face--6 .pip:nth-child(5) { left: 29%; top: 76%; }
.slot-face--6 .pip:nth-child(6) { left: 71%; top: 76%; }
.die-cube.is-spinning .slot-face { filter: blur(.7px); }
.die-rig--one.is-rolling { animation: slot-bounce-one 1.8s cubic-bezier(.12,.68,.1,1) both; }
.die-rig--two.is-rolling { animation: slot-bounce-two 1.8s cubic-bezier(.12,.68,.1,1) both; }

.roll-button {
  width: 100%; min-height: 56px; margin-top: auto; padding: 0 24px; display: grid; place-items: center; border: 0; border-radius: 10px;
  color: white; background: var(--primary); box-shadow: 0 8px 18px rgba(62,98,255,.18); cursor: pointer;
  font-size: 16px; font-weight: 650; letter-spacing: -0.02em; transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}
.roll-button:hover { filter: brightness(1.06); box-shadow: 0 11px 24px rgba(62,98,255,.25); transform: translateY(-2px); }
.roll-button:active { transform: translateY(1px) scale(.985); }
.roll-button:disabled { cursor: wait; filter: saturate(.72); }
.hint { margin: 13px 0 0; color: #858996; font-size: 13px; text-align: center; }

.dice-result-stage {
  width: 100%;
  min-height: 316px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
  text-align: center;
  animation: result-pop 620ms cubic-bezier(.18,.9,.25,1.2) both;
}
.dice-result-stage[hidden] { display: none; }
.result-kicker { margin-bottom: 12px; padding: 7px 12px; border-radius: 999px; color: var(--primary); background: #edf1ff; font-size: 14px; font-weight: 900; }
.dice-result-stage strong { color: var(--primary); font-size: clamp(40px,5vw,62px); line-height: 1.08; letter-spacing: -.04em; word-break: keep-all; }
.result-digit { margin-top: 16px; color: #1c202d; font-size: 20px; font-weight: 800; }
.dice-result-stage p { margin: 9px 0 0; color: #777; font-size: 14px; }
body.is-finished .dice-stage { display: none; }

@keyframes slot-bounce-one { 0% { transform: rotate(-4deg) translateY(0); } 38% { transform: rotate(-2deg) translateY(-9px); } 100% { transform: rotate(-4deg) translateY(0); } }
@keyframes slot-bounce-two { 0% { transform: rotate(4deg) translateY(0); } 44% { transform: rotate(2deg) translateY(-11px); } 100% { transform: rotate(4deg) translateY(0); } }
@keyframes result-pop { 0% { opacity: 0; transform: translateY(22px) scale(.86); } 72% { opacity: 1; transform: translateY(-4px) scale(1.04); } 100% { opacity: 1; transform: translateY(0) scale(1); } }

@media (min-width: 901px) {
  html,
  body { height: 100%; overflow: hidden; }
  .game-shell {
    height: 100vh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .game-header { flex: none; }
  .dice-workspace { min-height: 0; flex: 1; }
  .dice-panel { height: 100%; min-height: 0; }
  .settings-panel {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(62,98,255,.35) transparent;
  }
  .settings-panel::-webkit-scrollbar { width: 8px; }
  .settings-panel::-webkit-scrollbar-thumb { border-radius: 999px; background: rgba(62,98,255,.32); }
  .settings-panel::-webkit-scrollbar-track { background: transparent; }
  .play-area { position: relative; top: auto; align-self: stretch; }
}

@media (min-width: 901px) and (max-height: 720px) {
  .game-shell { padding: 24px 0; }
  h1 { font-size: 2.4rem; }
  .rule { margin-top: 6px; font-size: 16px; }
  .dice-workspace { margin-top: 18px; }
  .dice-stage { --die-size: 122px; height: 220px; }
  .die-rig--one { left: calc(50% - 132px); top: 38px; }
  .die-rig--two { left: calc(50% + 10px); top: 45px; }
  .die-cube { border-radius: 30px; }
  .pip { width: 21px; height: 21px; }
  .dice-result-stage { min-height: 236px; }
}

@media (max-width: 900px) {
  .game-shell { width: min(720px, calc(100% - 40px)); }
  .dice-workspace { grid-template-columns: 1fr; }
  .dice-panel { min-height: 0; }
  .play-area { position: relative; top: auto; min-height: 500px; }
  .players { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (max-width: 560px) {
  .home-link { top: 14px; left: 14px; width: 38px; height: 38px; }
  .game-shell { width: calc(100% - 32px); padding: 34px 0; }
  h1 { font-size: 2.35rem; }
  .rule { margin-top: 8px; font-size: 14px; }
  .dice-workspace { margin-top: 26px; }
  .dice-panel { padding: 22px; }
  .setup-label { font-size: 14px; }
  .stepper { gap: 14px; }
  .stepper strong { font-size: 17px; }
  .players { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .player { min-height: 68px; padding: 9px 7px; }
  .player-name { font-size: 13px; }
  .player strong { min-height: 24px; font-size: 18px; }
  .player.is-loser .player-name { font-size: 14px; }
  .player.is-loser strong { font-size: 20px; }
  .play-area { min-height: 450px; }
  .dice-stage { --die-size: 132px; height: 238px; margin-top: 4px; }
  .die-rig--one { left: calc(50% - 140px); top: 45px; }
  .die-rig--two { left: calc(50% + 8px); top: 51px; }
  .die-cube { border-radius: 30px; }
  .pip { width: 21px; height: 21px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
