* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #fbeff4;
  background: radial-gradient(circle at 50% 0%, #5a2c5e 0%, #2a1534 55%, #140a1c 100%) fixed;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
:lang(zh-Hant) body, :lang(zh-Hant) button { font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

#app { height: 100%; display: flex; justify-content: center; }
.screen { width: 100%; max-width: 560px; height: 100%; display: flex; flex-direction: column; align-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }

/* Menu */
#menu { position: relative; overflow-y: auto; justify-content: safe center; gap: 14px; }
.logo { font-size: clamp(56px, 16vw, 92px); margin: 0; letter-spacing: -2px; font-weight: 900;
  background: linear-gradient(90deg, #ffe08a, #ff9f5a, #f45d8a, #a66be0, #4f95f2);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.tag { margin: -8px 0 18px; opacity: .7; letter-spacing: 3px; text-transform: uppercase; font-size: 13px; }
.big { width: min(360px, 90%); padding: 16px 20px; border-radius: 16px; border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.05)); font-size: 22px; font-weight: 700;
  text-align: left; transition: transform .1s, background .2s; }
.big:hover { background: linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,.08)); }
.big:active { transform: scale(.98); }
.big small { display: block; font-size: 13px; font-weight: 400; opacity: .78; margin-top: 4px; }
.big small b { font-weight: 700; color: #ffe08a; }
.link { background: none; border: none; opacity: .75; text-decoration: underline; text-underline-offset: 3px; font-size: 15px; padding: 8px; }
.lang { position: absolute; top: 12px; right: 12px; padding: 6px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); font-size: 14px; }

/* Top bar + HUD */
.topbar { width: 100%; display: flex; align-items: center; gap: 8px; }
.topbar h2 { margin: 0; font-size: 18px; text-align: center; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08); font-size: 20px; line-height: 1; display: grid; place-items: center; flex: none; }
.icon.off { opacity: .4; }
#hud { width: 100%; display: flex; justify-content: center; gap: 10px; margin: 12px 0; }
.box { min-width: 86px; padding: 6px 12px; border-radius: 12px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1);
  display: flex; flex-direction: column; align-items: center; }
.box small { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; opacity: .6; }
.box b { font-size: 22px; font-variant-numeric: tabular-nums; }
.box.next { min-width: 64px; }
#next { width: 30px; height: 30px; margin-top: 2px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 15px;
  transition: background .2s; }

/* Board: square, as large as fits. Tiles are positioned with transforms in % of their own size. */
#boardWrap { flex: 1 1 0; min-height: 0; width: 100%; display: grid; place-items: center; touch-action: none; }
#board { position: relative; width: min(100%, var(--fit, 100%)); aspect-ratio: 1; border-radius: 4.5%; overflow: hidden;
  background: rgba(10,4,16,.55); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 18px 50px rgba(0,0,0,.35);
  container-type: inline-size; }
.cell, .tile { position: absolute; left: 3%; top: 3%; width: 21.25%; height: 21.25%; }
.cell { border-radius: 14%; background: rgba(255,255,255,.06); }
.tile { transition: transform 110ms ease-in-out; will-change: transform; }
.face { width: 100%; height: 100%; border-radius: 14%; display: grid; place-items: center; font-weight: 800; line-height: 1;
  box-shadow: inset 0 -0.9cqw 0 rgba(0,0,0,.18), inset 0 0.5cqw 0 rgba(255,255,255,.35);
  font-size: 9cqw; font-variant-numeric: tabular-nums; }
.face.d3 { font-size: 7.4cqw; }
.face.d4 { font-size: 6cqw; }
.face.d5 { font-size: 4.9cqw; }
.face.pop { animation: pop 180ms ease-out; }
.face.appear { animation: appear 160ms ease-out; }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.16); } 100% { transform: scale(1); } }
@keyframes appear { 0% { transform: scale(0); } 100% { transform: scale(1); } }
#board.shake { animation: shake 160ms; }
@keyframes shake { 25% { translate: -1.2% 0; } 75% { translate: 1.2% 0; } }
.hint { opacity: .45; font-size: 13px; margin: 10px 0 0; }

/* Modal */
#modal { position: fixed; inset: 0; background: rgba(12,4,18,.65); display: grid; place-items: center; z-index: 10; padding: 16px; }
.card { width: min(420px, 100%); max-height: 90%; overflow-y: auto; background: linear-gradient(180deg, #4a2552, #2c1636);
  border: 1px solid rgba(255,255,255,.18); border-radius: 20px; padding: 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.card h2 { margin: 0 0 12px; font-size: 26px; }
.card .body { font-size: 16px; line-height: 1.5; opacity: .92; }
.card .body p { margin: 0 0 10px; }
.card .body.left { text-align: left; font-size: 14.5px; }
.card .actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.card .actions button { padding: 10px 20px; border-radius: 12px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08); font-size: 16px; font-weight: 600; }
.card .actions button.primary { background: linear-gradient(180deg, #f45d8a, #c93d6c); border-color: transparent; }
