/* طاولة ٣١ — flat orange-red board, user's chosen reference (original art) */
:root {
  --wood-hi: #d84e23;
  --wood: #c33f16;
  --wood-lo: #a03110;
  --frame-hi: #6e2c12;
  --frame: #52200c;
  --frame-lo: #341204;
  --pt-a-hi: #fbf4e4;
  --pt-a: #f1e3c1;
  --pt-b-hi: #efcb93;
  --pt-b: #e2b573;
  --gold: #e8c86a;
  --gold-deep: #b8860b;
  --shell: #241009;
  --shell-2: #33170c;
  --cream: #f6e9dc;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Cairo', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background:
    radial-gradient(1100px 550px at 75% -10%, rgba(232,200,106,.14), transparent 60%),
    radial-gradient(800px 500px at 8% 110%, rgba(210,105,30,.12), transparent 60%),
    linear-gradient(165deg, #2e1408, #241009 45%, #180a05);
  color: var(--cream);
  min-height: 100vh;
  display: flex; flex-direction: column; overflow-x: hidden;
}
@supports (height: 100dvh) { body { min-height: 100dvh; } }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: rgba(0,0,0,.3);
  border-bottom: 1px solid rgba(232,200,106,.18);
  backdrop-filter: blur(6px);
}
#topbar h1 {
  font-size: 20px; font-weight: 900; letter-spacing: .5px;
  background: linear-gradient(90deg, #ffe9c9, #e8c86a 55%, #f7ecd2);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#conn { display: flex; align-items: center; gap: 6px; font-size: 12px; min-width: 92px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; transition: background .3s; }
.dot.ok { background: #4ade80; box-shadow: 0 0 10px #4ade80; }
.dot.mid { background: #facc15; box-shadow: 0 0 10px #facc15; }
.dot.bad { background: #f87171; box-shadow: 0 0 10px #f87171; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.topbtns { display: flex; gap: 6px; }
#btn-rules, #btn-sound {
  background: rgba(255,255,255,.06); border: 1px solid rgba(232,200,106,.3); color: var(--cream);
  border-radius: 10px; padding: 5px 11px; font-family: inherit; font-size: 13px; cursor: pointer;
}

main { flex: 1; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- home / lobby ---------- */
.home-card {
  margin: auto; max-width: 420px; width: 92%;
  background: linear-gradient(165deg, rgba(255,235,200,.09), rgba(255,235,200,.03));
  border: 1px solid rgba(232,200,106,.22);
  border-radius: 22px; padding: 28px 22px; text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.08);
  animation: rise .4s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.big-emoji { font-size: 44px; margin-bottom: 8px; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
.home-card h2 { font-weight: 900; margin-bottom: 8px; font-size: 24px; }
.sub { color: #ecd9bd; font-size: 14px; margin-bottom: 20px; line-height: 1.8; }
#inp-name {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1.5px solid rgba(232,200,106,.35);
  background: rgba(0,0,0,.35); color: #fff; font-family: inherit; font-size: 17px; text-align: center;
  margin-bottom: 14px; outline: none; transition: border-color .2s, box-shadow .2s;
}
#inp-name:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(232,200,106,.18); }
button.primary {
  width: 100%; padding: 14px; border: none; border-radius: 14px; cursor: pointer;
  background: linear-gradient(160deg, #e8a13c, #c2670f 60%, #a84f08);
  color: #fff; font-family: inherit; font-weight: 900; font-size: 17px;
  margin-bottom: 10px; text-shadow: 0 1px 2px rgba(0,0,0,.35);
  box-shadow: 0 8px 22px rgba(194,103,15,.42), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform .12s, box-shadow .2s;
}
button.primary:active { transform: scale(.96); box-shadow: 0 3px 10px rgba(194,103,15,.35); }
button.primary.big { font-size: 20px; padding: 16px; border-radius: 16px; }
button.ghost {
  background: rgba(255,255,255,.05); border: 1px solid rgba(232,200,106,.35); color: var(--cream);
  border-radius: 12px; padding: 8px 16px; font-family: inherit; font-size: 14px; cursor: pointer;
}
.hint { color: #c9a885; font-size: 12px; margin-top: 6px; }
#home-options { animation: rise .3s ease; }
#join-row { display: flex; gap: 8px; margin-bottom: 10px; }
#inp-code {
  flex: 1; padding: 12px; border-radius: 14px; border: 1.5px solid rgba(232,200,106,.35);
  background: rgba(0,0,0,.35); color: var(--gold); font-family: inherit; font-size: 18px; font-weight: 900;
  text-align: center; letter-spacing: 6px; text-transform: uppercase; direction: ltr; outline: none;
}
#inp-code:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(232,200,106,.18); }
#join-row .primary { flex: 1; margin-bottom: 0; }
.err { color: #ff9d9d; font-size: 12px; margin: -4px 0 8px; font-weight: 700; }
.code-box {
  background: rgba(0,0,0,.42); border: 1px dashed rgba(232,200,106,.5);
  border-radius: 12px; padding: 12px; font-size: 19px; margin-bottom: 12px;
}
.code-box strong { letter-spacing: 5px; color: var(--gold); font-size: 24px; }
.link-box {
  background: rgba(0,0,0,.42); border-radius: 12px; padding: 10px; font-size: 11px;
  word-break: break-all; color: #d9bb96; margin-bottom: 14px; direction: ltr; text-align: left;
  border: 1px solid rgba(232,200,106,.15);
}
a.wa {
  display: block; color: #7ee2a8; font-size: 15px; font-weight: 700; text-decoration: none;
  border: 1.5px solid rgba(126,226,168,.45); border-radius: 14px; padding: 12px; margin-bottom: 10px;
}
.waiting-dots::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- score bar ---------- */
#scorebar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 6px; }
.chip {
  flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center;
  background: rgba(255,240,215,.07); border: 1.5px solid rgba(232,200,106,.2);
  border-radius: 14px; padding: 7px 10px; font-size: 14px; font-weight: 700; position: relative;
  transition: border-color .3s, box-shadow .3s, background .3s;
}
.chip b { font-size: 21px; color: var(--gold); }
.chip.me { border-color: rgba(232,200,106,.65); }
.chip.turn { background: rgba(232,200,106,.14); border-color: var(--gold); box-shadow: 0 0 14px rgba(232,200,106,.3); }
.chip.turn::after {
  content: '▼'; position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%);
  color: var(--gold); font-size: 11px; animation: bob 1s infinite;
}
@keyframes bob { 50% { transform: translateX(-50%) translateY(2px); } }
#round-no { font-size: 11px; color: #d9bb96; text-align: center; min-width: 88px; line-height: 1.5; }
#status-line {
  text-align: center; font-weight: 900; font-size: 16px; padding: 6px 10px 8px;
  color: #ffedd6; text-shadow: 0 2px 8px rgba(0,0,0,.4);
}
#notice {
  margin: 0 auto 8px; background: linear-gradient(135deg, #f5dfa8, #e8c86a); color: #4a2a08; font-weight: 700;
  padding: 6px 18px; border-radius: 22px; font-size: 13px; width: fit-content;
  box-shadow: 0 6px 18px rgba(232,200,106,.3); animation: rise .25s ease;
}

/* ---------- the board: unified landscape layout (reference style) ---------- */
#board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2px 6px 6px; }
#board {
  position: relative; display: flex; flex-direction: column; direction: rtl;
  width: min(97vw, 640px, calc((100dvh - 235px) * 1.3));
  aspect-ratio: 13 / 10; flex: none;
  border-radius: 14px; overflow: hidden;
  border: 8px solid var(--frame);
  outline: 2px solid rgba(255,220,170,.14);
  box-shadow:
    inset 0 2px 0 rgba(255,220,170,.2),
    inset 0 -3px 6px rgba(0,0,0,.5),
    0 18px 40px rgba(0,0,0,.55);
  background: var(--wood);
}
/* flat felt rows */
.row {
  flex: none; height: 37%; display: flex; flex-direction: row; direction: rtl;
  background:
    repeating-linear-gradient(0deg, rgba(255,235,200,.04) 0 2px, transparent 2px 11px, rgba(60,15,0,.05) 11px 13px, transparent 13px 26px),
    linear-gradient(180deg, var(--wood-hi), var(--wood) 40%, var(--wood-lo));
}
/* open field band between the triangle rows: dice live here */
#field {
  position: relative; flex: none; height: 26%; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  background:
    repeating-linear-gradient(0deg, rgba(255,235,200,.04) 0 2px, transparent 2px 11px, rgba(60,15,0,.05) 11px 13px, transparent 13px 26px),
    linear-gradient(180deg, var(--wood), var(--wood-lo));
}
/* thin dark center divider across the whole board */
#cbar {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 16px; transform: translateX(-50%);
  background: linear-gradient(90deg, #381405, #52200c 50%, #381405);
  border-left: 2px solid var(--frame-lo); border-right: 2px solid var(--frame-lo);
  box-shadow: inset 2px 0 4px rgba(0,0,0,.4), inset -2px 0 4px rgba(0,0,0,.4);
  z-index: 3; pointer-events: none;
}
.point { position: relative; flex: 1; display: flex; flex-direction: column; cursor: pointer; }
/* make room for the center divider between the 6th and 7th point */
.row .point:nth-child(6) { margin-left: 16px; }
.tri { position: absolute; inset: 1px 0; pointer-events: none; transition: opacity .15s, background .15s;
  filter: drop-shadow(0 2px 1px rgba(58,22,4,.28)); }
/* top row: bases on top edge, tips point down */
#row-top .point { align-items: flex-start; justify-content: flex-start; }
#row-top .tri { clip-path: polygon(0 0, 100% 0, 50% 100%); }
#row-top .point.even .tri { background: linear-gradient(180deg, var(--pt-a-hi), var(--pt-a) 70%); }
#row-top .point.odd .tri { background: linear-gradient(180deg, var(--pt-b-hi), var(--pt-b) 70%); }
#row-top .stack { flex-direction: column; }
#row-top .chk { margin: 0; margin-top: -18%; }
/* bottom row: bases on bottom edge, tips point up */
#row-bot .point { align-items: flex-end; justify-content: flex-start; }
#row-bot .tri { clip-path: polygon(50% 0, 0 100%, 100% 100%); }
#row-bot .point.even .tri { background: linear-gradient(0deg, var(--pt-a-hi), var(--pt-a) 70%); }
#row-bot .point.odd .tri { background: linear-gradient(0deg, var(--pt-b-hi), var(--pt-b) 70%); }
#row-bot .stack { flex-direction: column-reverse; }
#row-bot .chk { margin: 0; margin-bottom: -18%; }
.stack {
  position: relative; z-index: 2; height: 100%; width: 100%;
  display: flex; align-items: center; padding: 0 2px;
}
.chk {
  position: relative; flex: none; width: 84%; max-width: 34px; aspect-ratio: 1; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 900;
}
.chk::after { /* carved inner ring */
  content: ''; position: absolute; inset: 24%; border-radius: 50%;
  border: 2px solid rgba(90,55,15,.4);
}
.chk.a {
  background: radial-gradient(circle at 38% 32%, #fdf7e8, #f2e3c2 55%, #dec593 84%, #c9a971);
  border: 1.5px solid #96733a; color: #7a5c22;
  box-shadow: 0 2px 3px rgba(0,0,0,.45), inset 0 1px 2px rgba(255,255,255,.65);
}
.chk.b {
  background: radial-gradient(circle at 38% 32%, #6d4523, #4c2c12 56%, #301505);
  border: 1.5px solid #1e0c03; color: #e8c86a;
  box-shadow: 0 2px 3px rgba(0,0,0,.5), inset 0 1px 2px rgba(255,220,170,.22);
}
.chk.b::after { border-color: rgba(232,200,106,.35); }
.chk.mine { outline: 2px solid rgba(232,200,106,.55); outline-offset: -1px; }
/* movable glow: front (top) checker of the stack */
.point.movable .stack .chk:last-child {
  box-shadow: 0 0 0 3px rgba(74,222,128,.8), 0 0 16px #4ade80;
  animation: glow 1.2s ease-in-out infinite;
}
@keyframes glow { 50% { box-shadow: 0 0 0 2px rgba(74,222,128,.4), 0 0 7px #4ade80; } }
.point.sel { background: rgba(74,222,128,.22); }
.point.sel .tri { opacity: .75; }
.point.target .tri { opacity: 1; filter: drop-shadow(0 0 10px rgba(232,200,106,.9)) brightness(1.18); animation: targetPulse 1s infinite; }
@keyframes targetPulse { 50% { filter: drop-shadow(0 0 4px rgba(232,200,106,.5)) brightness(1.02); } }

/* tiny bear-off chips at the right edge of the field */
.tray {
  position: absolute; right: 5px; z-index: 4;
  text-align: center; background: rgba(0,0,0,.42); border-radius: 8px;
  padding: 2px 7px; cursor: pointer; border: 1px solid rgba(232,200,106,.25);
  font-size: 8px; color: #ecd9bd; transition: all .2s;
}
#off-b { top: 5px; }
#off-a { bottom: 5px; }
.tray b { display: block; font-size: 13px; color: #fff; }
.tray.target { border-color: var(--gold); background: rgba(232,200,106,.3); animation: targetPulse 1s infinite; }
#center { display: flex; align-items: center; justify-content: center; gap: 10px; }
#dice-box { display: flex; flex-direction: row; align-items: center; gap: 6px; }
.die {
  width: 38px; height: 38px; border-radius: 8px; padding: 5px;
  background: linear-gradient(150deg, #ffffff, #f2efe9);
  display: grid; grid-template: repeat(3,1fr)/repeat(3,1fr);
  box-shadow: 0 3px 7px rgba(0,0,0,.5), inset 0 1px 0 #fff;
  animation: pop .3s cubic-bezier(.2,1.6,.4,1);
}
.die.rolling { animation: shake .5s ease; }
@keyframes shake {
  0% { transform: rotate(0) scale(.55); } 22% { transform: rotate(30deg) scale(1.08); }
  48% { transform: rotate(-26deg); } 74% { transform: rotate(15deg); } 100% { transform: rotate(0); }
}
@keyframes pop { 0% { transform: scale(.3) rotate(50deg); opacity: 0; } }
.die span { width: 7px; height: 7px; border-radius: 50%; place-self: center; }
.die span.on { background: #1c1c1c; box-shadow: inset 0 1px 1px rgba(255,255,255,.25); }
.die-mini { width: 19px; height: 19px; border-radius: 5px; padding: 3px; animation: none; }
.die-mini span { width: 4px; height: 4px; }
.dice-left { display: flex; gap: 4px; align-items: center; }
.dim { color: #c9a885; }
#btn-roll {
  width: auto; height: auto; border-radius: 999px; padding: 9px 20px; font-size: 14px; line-height: 1.2;
  margin: 0; border: 2px solid rgba(255,240,200,.5);
  animation: rise .25s ease;
}
#btn-roll.pulse { animation: rollPulse 1.3s infinite; }
@keyframes rollPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,200,106,.55), 0 8px 22px rgba(194,103,15,.42); }
  50% { box-shadow: 0 0 0 12px rgba(232,200,106,0), 0 8px 22px rgba(194,103,15,.42); }
}
#btn-undo { font-size: 12px; padding: 6px 10px; }

#you-are { text-align: center; padding: 6px 10px 2px; font-size: 12px; color: #d9bb96; }
#rotate-hint { display: none; text-align: center; font-size: 11px; color: #c9a885; padding: 2px 0 6px; }
@media (max-aspect-ratio: 1/1) { #rotate-hint { display: block; } }

/* flying checker (slide animation) */
.chk.fly {
  position: fixed; z-index: 80; pointer-events: none;
  margin: 0 !important; animation: none !important;
}

/* bigger board when the phone is landscape */
@media (min-aspect-ratio: 1/1) {
  main, .screen { overflow-y: auto; }
  #you-are { display: none; }
  #scorebar { padding: 6px 12px 3px; }
  #status-line { padding: 3px 10px 4px; }
  #board { width: min(98vw, calc((100dvh - 172px) * 1.3)); }
}

/* ---------- overlays ---------- */
#overlay, #rules {
  position: fixed; inset: 0; background: rgba(15,6,2,.8);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
  backdrop-filter: blur(4px);
}
.overlay-card {
  background: linear-gradient(160deg, #4a2408, #241009);
  border: 1px solid rgba(232,200,106,.35); border-radius: 22px;
  padding: 30px 24px; text-align: center; max-width: 380px; width: 100%;
  box-shadow: 0 24px 70px rgba(0,0,0,.65), inset 0 1px 0 rgba(255,255,255,.1);
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
.overlay-card h2 { font-weight: 900; margin-bottom: 12px; font-size: 24px; }
.overlay-card p { color: #ecd9bd; margin-bottom: 18px; line-height: 1.9; font-size: 15px; }
.rules-card { text-align: right; max-height: 86vh; overflow-y: auto; }
.rules-card h2 { text-align: center; }
.rules-card ul { padding-right: 18px; margin-bottom: 18px; }
.rules-card li { font-size: 13px; line-height: 2; color: #f0e0cc; }

.heart-fall { position: fixed; top: -30px; font-size: 22px; z-index: 60; pointer-events: none; animation: heartFall linear forwards; }
@keyframes heartFall { to { transform: translateY(110vh) rotate(340deg); opacity: .1; } }

/* ---------- splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 100;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(232,200,106,.22), transparent 60%),
    linear-gradient(160deg, #2e1408, #241009 45%, #180a05);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .5s ease; opacity: 1;
}
#splash.gone { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; animation: splashIn .7s cubic-bezier(.2,1.4,.4,1); }
@keyframes splashIn { from { transform: scale(.6); opacity: 0; } }
.logo-art { width: 132px; height: 132px; filter: drop-shadow(0 14px 30px rgba(0,0,0,.5)); animation: float 3.2s ease-in-out infinite; }
.logo-art.small { width: 76px; height: 76px; margin-bottom: 10px; }
.splash-title {
  font-size: 40px; font-weight: 900; margin-top: 14px;
  background: linear-gradient(90deg, #ffe9c9, #e8c86a 50%, #f7ecd2);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.splash-sub { color: #ecd9bd; font-size: 14px; margin-top: 4px; }

@media (max-height: 700px) {
  .home-card { padding: 20px 18px; }
  .big-emoji { font-size: 32px; }
  .logo-art { width: 100px; height: 100px; }
}
