/* 5 Roll — soft Yatzy mockup, 1080×1920 (9:16) */

:root {
  --ink: #1e3a5f;
  --ink-dim: #7a93b0;
  --line: rgba(150, 180, 210, 0.4);
  --accent: #4a7cff;
  --font-en: "Nunito", system-ui, sans-serif;
  --font-km: "Noto Sans Khmer", "Nunito", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #8aafd8;
  color: var(--ink);
  font-family: var(--font-en);
  user-select: none;
  touch-action: manipulation;
}

body.lang-km {
  font-family: var(--font-km);
}

img {
  display: block;
  max-width: 100%;
  pointer-events: none;
  background: transparent;
}

button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  filter: grayscale(0.15) brightness(0.9);
  opacity: 0.72;
}

#viewport {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  overflow: hidden;
  container-type: size;
  container-name: stage;
  box-shadow: 0 18px 50px rgba(60, 90, 130, 0.25);
}

.stage-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
}

.screen.is-active {
  display: block;
}

/* —— buttons —— */
.ui-btn {
  position: relative;
  display: grid;
  place-items: center;
}

.ui-btn img {
  width: 100%;
  height: auto;
}

.ui-btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
}

.primary-btn,
.play-btn {
  width: 52cqw;
}

.primary-btn span,
.play-btn span {
  position: absolute;
  inset: 0 0 12% 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 6.5cqw;
  color: #fff;
  text-shadow: 0 1px 0 rgba(40, 50, 120, 0.25);
}

.roll-btn {
  width: 100%;
}

.roll-btn .roll-copy {
  position: absolute;
  inset: 0 0 10% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35cqh;
  color: #fff;
  text-shadow: 0 1px 0 rgba(40, 50, 120, 0.25);
  pointer-events: none;
  line-height: 1.05;
}

.roll-btn .roll-copy strong {
  font-size: 4.8cqw;
  font-weight: 800;
}

.roll-btn .roll-copy small {
  font-size: 2.15cqw;
  font-weight: 700;
  opacity: 0.95;
  max-width: 88%;
  text-align: center;
}

.icon-btn {
  position: relative;
  width: 9.2cqw;
  height: 9.2cqw;
  display: grid;
  place-items: center;
  pointer-events: auto;
}

.icon-btn img {
  width: 100%;
  pointer-events: none;
}

.icon-btn:active {
  transform: scale(0.94);
}

.lang-chip {
  position: absolute;
  right: -0.6cqw;
  bottom: -0.3cqw;
  font-size: 2.1cqw;
  font-weight: 800;
  color: #2a5080;
  background: #e8f1fa;
  border-radius: 999px;
  padding: 0.15cqw 0.7cqw;
  line-height: 1.2;
}

/* —— home (hero + Start + bottom nav) —— */
#screen-home.is-active {
  display: block;
  background: linear-gradient(180deg, #b8d4f0 0%, #9ec0e8 38%, #88b0de 72%, #7aa6d8 100%);
}

.home-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 85% 50% at 50% 26%, rgba(255, 255, 255, 0.22) 0%, transparent 65%),
    radial-gradient(ellipse 75% 45% at 50% 92%, rgba(50, 90, 150, 0.18) 0%, transparent 72%);
}

.home-hero {
  position: absolute;
  left: 0;
  right: 0;
  top: 6cqh;
  height: 56cqh;
  z-index: 1;
  pointer-events: none;
}

.home-float {
  position: absolute;
  left: 50%;
  top: 2cqh;
  width: 78cqw;
  height: 28cqh;
  transform: translateX(-50%);
}

.float-die {
  position: absolute;
  width: 22cqw;
  filter: drop-shadow(0 1.2cqh 1cqh rgba(40, 50, 70, 0.28));
  animation: float-die 3.6s ease-in-out infinite;
}

.float-die.d1 {
  left: 2%;
  top: 38%;
  transform: rotate(-18deg);
  animation-delay: 0s;
}

.float-die.d2 {
  left: 38%;
  top: 0%;
  width: 24cqw;
  transform: rotate(8deg);
  animation-delay: 0.4s;
}

.float-die.d3 {
  right: 0;
  top: 28%;
  transform: rotate(16deg);
  animation-delay: 0.8s;
}

.home-mascot {
  position: absolute;
  left: 50%;
  top: 26cqh;
  width: 64cqw;
  transform: translateX(-50%);
  filter: drop-shadow(0 1.5cqh 1.2cqh rgba(40, 50, 70, 0.2));
}

.start-btn {
  position: absolute;
  left: 50%;
  top: 66cqh;
  transform: translateX(-50%);
  width: 58cqw;
  z-index: 3;
}

.start-btn span {
  position: absolute;
  inset: 0 0 10% 0;
  display: grid;
  place-items: center;
  font-size: 7cqw;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 rgba(120, 20, 30, 0.35);
}

.start-btn:active:not(:disabled) {
  transform: translateX(-50%) translateY(2px) scale(0.98);
}

.home-nav {
  position: absolute;
  left: 4cqw;
  right: 4cqw;
  bottom: 3.5cqh;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2cqw;
  align-items: start;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8cqh;
  pointer-events: auto;
}

.nav-item img {
  width: 14cqw;
  height: 14cqw;
  object-fit: contain;
  filter: drop-shadow(0 0.5cqh 0.4cqh rgba(40, 50, 70, 0.2));
}

.nav-item span {
  font-size: 2.8cqw;
  font-weight: 800;
  color: #2a2a2a;
  text-align: center;
  line-height: 1.15;
}

.nav-item:active {
  transform: scale(0.94);
}

.nav-item.is-muted img {
  filter: grayscale(0.35) brightness(0.95) drop-shadow(0 0.5cqh 0.4cqh rgba(40, 50, 70, 0.2));
}

@keyframes float-die {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -1.2cqh;
  }
}

/* —— play header (mockup) —— */
.play-header {
  position: absolute;
  top: 1.8cqh;
  left: 4cqw;
  right: 3.2cqw;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2cqw;
}

.brand-title {
  margin: 0;
  font-size: 7cqw;
  font-weight: 800;
  color: #1e3a5f;
  letter-spacing: 0.02em;
  line-height: 1;
  cursor: pointer;
}

.brand-tag {
  margin: 0.5cqh 0 0;
  font-size: 2.9cqw;
  font-weight: 700;
  color: var(--ink-dim);
}

.top-tools {
  display: flex;
  gap: 1.8cqw;
  align-items: center;
  flex-shrink: 0;
  padding-top: 0.3cqh;
}

.play-layout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 9.5cqh 2.6cqw 1.4cqh;
  gap: 0.85cqh;
  z-index: 1;
  min-height: 0;
}

/* —— dice table —— */
.table-area {
  position: relative;
  flex: 0 0 22%;
  min-height: 0;
  background: #fff;
  border-radius: 0;
  box-shadow: none;
}

.play-panel {
  display: none;
}

.table-inner {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 0;
}

.active-dice {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.drop-hint {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  width: 46cqw;
  z-index: 2;
  pointer-events: none;
  opacity: 1;
  background: transparent;
  border: 2px dashed rgba(90, 140, 200, 0.65);
  border-radius: 0;
  box-shadow: none;
  padding: 1.4cqh 2.5cqw;
}

.drop-hint img {
  display: none;
}

.drop-hint span {
  position: static;
  display: block;
  text-align: center;
  font-size: 2.8cqw;
  font-weight: 700;
  color: #4a6f96;
  padding: 0;
  line-height: 1.2;
}

.drop-hint.is-hidden {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.die {
  width: 15cqw;
  cursor: grab;
  filter: drop-shadow(0 0.55cqh 0.45cqh rgba(60, 90, 130, 0.28));
  background: transparent;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

.die.is-scattered {
  position: absolute;
  width: 15.5cqw;
  margin: 0;
  transform-origin: center center;
  z-index: 4;
}

.die.is-dragging-src {
  opacity: 0.3;
}

.die.is-rolling {
  animation: jig 0.1s linear infinite;
}

.die.is-jump-in {
  animation: die-jump-in 0.58s cubic-bezier(0.22, 1.25, 0.36, 1) both;
  animation-delay: var(--jump-delay, 0ms);
}

.die.is-jump-in.is-rolling {
  animation:
    die-jump-in 0.58s cubic-bezier(0.22, 1.25, 0.36, 1) both,
    jig 0.09s linear infinite;
  animation-delay: var(--jump-delay, 0ms), var(--jump-delay, 0ms);
}

.die-ghost {
  position: fixed;
  width: min(17vw, 84px);
  transform: translate(-50%, -50%) rotate(-8deg) scale(1.08);
  filter: drop-shadow(0 10px 14px rgba(40, 70, 110, 0.35));
  pointer-events: none;
  z-index: 9999;
}

/* —— roll + holds —— */
.tray-row {
  display: flex;
  align-items: flex-end;
  gap: 2.5cqw;
  position: relative;
  z-index: 6;
  flex: 0 0 auto;
}

.roll-wrap {
  width: 38cqw;
  flex-shrink: 0;
}

.holds-block {
  flex: 1;
  min-width: 0;
}

.holds-label {
  margin: 0 0 0.55cqh 0.4cqw;
  font-size: 3.2cqw;
  font-weight: 800;
  color: #2a5080;
}

.tray-wrap {
  position: relative;
  width: 100%;
  min-height: 11cqw;
  transition: filter 0.15s ease;
}

.tray-wrap.is-drop-target {
  filter: brightness(1.04);
}

.tray-wrap.is-drop-hot {
  filter: brightness(1.08) saturate(1.08);
}

.locked-dice {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1.4cqw;
  align-items: center;
  justify-items: center;
}

.locked-dice .slot-empty {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  pointer-events: none;
}

.locked-dice .die {
  width: 100%;
  max-width: none;
  pointer-events: auto;
  cursor: grab;
}

/* —— scorecard —— */
.score-area {
  position: relative;
  flex: 1 1 58%;
  min-height: 0;
  width: 100%;
  background: #fff;
  border-radius: 4.2cqw;
  box-shadow: 0 0.55cqh 1.6cqh rgba(40, 70, 110, 0.14);
}

.score-panel {
  display: none;
}

.score-ui {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 1.1cqh 1.6cqw 1cqh;
}

.score-head {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) repeat(3, minmax(0, 1fr));
  align-items: center;
  height: 4.8cqh;
  font-size: 4.8cqw;
  font-weight: 800;
  color: #4a6f96;
  text-align: center;
  background: rgba(240, 247, 255, 0.9);
  border: 1px solid rgba(150, 180, 210, 0.45);
  border-radius: 1.4cqw 1.4cqw 0 0;
}

.score-head span + span {
  border-left: 1px solid var(--line);
  height: 100%;
  display: grid;
  place-items: center;
}

.score-rows {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid rgba(150, 180, 210, 0.45);
  border-top: 0;
  border-radius: 0 0 1.4cqw 1.4cqw;
}

.score-row {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) repeat(3, minmax(0, 1fr));
  align-items: stretch;
  border-top: 1px solid var(--line);
  min-height: 0;
}

.score-row:first-child {
  border-top: 0;
}

.score-row.is-sep {
  border-top-width: 2px;
  border-top-color: rgba(120, 160, 200, 0.5);
}

.cat-label {
  display: flex;
  align-items: center;
  gap: 1cqw;
  padding: 0 0.8cqw;
  min-width: 0;
  font-size: 3.9cqw;
  font-weight: 800;
  color: #2a5080;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-right: 1px solid var(--line);
}

.cat-pip {
  width: 4.4cqw;
  height: 4.4cqw;
  border-radius: 28%;
  flex-shrink: 0;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.12);
}

.score-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 100%;
  font-size: 5.4cqw;
  font-weight: 800;
  color: #1e3a5f;
  border-left: 1px solid var(--line);
  cursor: pointer;
  background: transparent;
  border-radius: 0;
  margin: 0;
  padding: 0;
}

.score-cell .val {
  position: relative;
  z-index: 1;
}

.score-cell.is-preview {
  color: #4a7cff;
  background: rgba(90, 150, 255, 0.12);
}

.score-cell.is-filled {
  color: #1e3a5f;
  background: rgba(245, 248, 252, 0.95);
  cursor: default;
}

.score-cell.is-zero-preview {
  color: rgba(90, 120, 150, 0.38);
}

.score-cell:active:not(.is-filled) {
  background: rgba(90, 150, 255, 0.16);
}

/* —— total —— */
.total-bar {
  position: relative;
  flex: 0 0 8.5cqh;
  width: 100%;
  background: #fff;
  border-radius: 3.8cqw;
  box-shadow: 0 0.55cqh 1.6cqh rgba(40, 70, 110, 0.14);
}

.total-bar > img {
  display: none;
}

.total-ui {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5cqw;
  font-weight: 800;
  font-size: 4.8cqw;
  color: #2a5080;
}

.total-ui strong {
  font-size: 9.5cqw;
  color: #1e3a5f;
}

/* —— overlays —— */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(40, 70, 110, 0.35);
}

.overlay[hidden] {
  display: none !important;
}

.overlay-card {
  position: relative;
  width: 82cqw;
}

.overlay-body {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 5cqw 5.5cqw 4cqw;
  text-align: left;
  overflow: hidden;
}

.overlay-body h2 {
  margin: 0 0 1.2cqh;
  font-size: 5.5cqw;
  color: #1e3a5f;
  text-align: center;
  flex-shrink: 0;
}

.overlay-body p {
  margin: 0 0 2cqh;
  white-space: pre-line;
  font-size: 2.85cqw;
  font-weight: 700;
  color: var(--ink-dim);
  line-height: 1.45;
  overflow-y: auto;
  max-height: 52cqh;
  width: 100%;
  padding-right: 1cqw;
}

.overlay-close {
  width: 42cqw;
}

#screen-result.is-active {
  display: grid;
  place-items: center;
  background: rgba(40, 70, 110, 0.28);
}

.result-card {
  position: relative;
  width: 82cqw;
}

.result-body {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6cqw;
  text-align: center;
}

.result-body h2 {
  margin: 0;
  font-size: 6cqw;
  color: #1e3a5f;
}

.result-cap {
  margin: 1.2cqh 0 0;
  font-size: 3.4cqw;
  color: var(--ink-dim);
  font-weight: 700;
}

.result-score {
  margin: 0.8cqh 0;
  font-size: 16cqw;
  font-weight: 800;
  line-height: 1;
  color: #1e3a5f;
}

.result-best,
.result-note {
  margin: 0.4cqh 0;
  font-size: 3.5cqw;
  font-weight: 700;
  color: #4a6f96;
}

.result-note {
  color: #4a7cff;
  min-height: 3cqh;
}

.result-body .primary-btn {
  margin-top: 2cqh;
  width: 50cqw;
}

@keyframes jig {
  from {
    transform: rotate(-8deg) translateY(-2%);
  }
  to {
    transform: rotate(8deg) translateY(2%);
  }
}

@keyframes die-jump-in {
  0% {
    opacity: 0;
    transform: translate(var(--jump-x, 0), -32cqh) scale(0.3) rotate(var(--jump-from-rot, -40deg));
  }
  58% {
    opacity: 1;
    transform: translate(0, 1.2cqh) scale(1.1) rotate(var(--land-rot, 0deg));
  }
  78% {
    transform: translate(0, -0.5cqh) scale(0.95) rotate(var(--land-rot, 0deg));
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(var(--land-rot, 0deg));
  }
}
