:root {
  --ink: #4a2c12;
  --wood: #c48a52;
  --wood-d: #8f5a2c;
  --cream: #fff7e6;
  --green: #6fb35a;
  --gold: #f2c14e;
  --red: #d9534f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(180deg, #a9dcf7 0%, #d6efff 38%, #fbf0d6 72%, #e8f3d2 100%);
  color: var(--ink);
  font-family: Rubik, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1; min-height: 0; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#c:active { cursor: grabbing; }
.view-btns { position: absolute; z-index: 5; top: max(10px, env(safe-area-inset-top)); inset-inline-end: 10px; display: flex; flex-direction: column; gap: 8px; }
.view-btns .round { width: 40px; height: 40px; font-size: 17px; }
.drag-hint {
  position: absolute; z-index: 4; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(255, 250, 238, 0.88); padding: 5px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  pointer-events: none; white-space: nowrap; transition: opacity 0.6s; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.drag-hint.gone { opacity: 0; }

.corner { position: absolute; top: max(10px, env(safe-area-inset-top)); inset-inline-start: 10px; display: flex; gap: 8px; z-index: 5; }
.round {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255, 250, 238, 0.92); box-shadow: 0 3px 0 rgba(120, 75, 30, 0.35), 0 4px 12px rgba(0, 0, 0, 0.12);
  font-size: 20px; display: grid; place-items: center;
}
.round.lang { width: auto; padding: 0 14px; border-radius: 22px; font-size: 15px; font-weight: 600; }
.round.pill { width: auto; padding: 0 14px 0 10px; border-radius: 22px; gap: 6px; display: flex; align-items: center; font-size: 14px; font-weight: 700; }
.round.pill .eye-icon { font-size: 19px; }
.toast {
  position: absolute; z-index: 7; top: 66px; left: 50%; transform: translate(-50%, -8px); opacity: 0;
  background: #fffaf0; border: 3px solid #e2b13f; border-radius: 16px; padding: 8px 16px; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15); transition: opacity 0.3s, transform 0.3s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.round[aria-pressed="true"] { background: #ffd970; box-shadow: 0 3px 0 #c9961a, 0 0 0 3px rgba(255, 255, 255, 0.9); }
.round:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(120, 75, 30, 0.35); }

/* ---------- side / bottom panel ---------- */
#panel {
  background: linear-gradient(180deg, #f3d6a4, #e7bd80);
  border-top: 4px solid var(--wood-d);
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 -6px 18px rgba(80, 45, 10, 0.18);
  z-index: 4;
}
.brand { display: none; font-family: "Secular One", Rubik, sans-serif; font-size: 26px; text-align: center; line-height: 1.1; }
.brand small { display: block; font-family: Rubik, sans-serif; font-size: 14px; font-weight: 600; opacity: 0.75; }

#players { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
#players li {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 250, 238, 0.8); border-radius: 999px; padding: 4px 10px 4px 6px;
  border: 3px solid transparent; font-weight: 600; font-size: 14px; transition: transform 0.2s;
}
#players li .av { width: 28px; height: 28px; border-radius: 50%; background: var(--pc); display: grid; place-items: center; font-size: 17px; }
#players li .ps { background: var(--pc); color: #fff; border-radius: 999px; padding: 0 8px; min-width: 30px; text-align: center; font-weight: 800; }
#players li.active { border-color: var(--pc); transform: scale(1.06); background: #fffdf6; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12); }

.controls { display: flex; align-items: center; gap: 14px; justify-content: center; }
.roll-col { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 0; flex: 0 1 260px; }
#status { font-weight: 700; font-size: 16px; text-align: center; min-height: 1.3em; }

.big {
  background: linear-gradient(180deg, #8fd27a, #5fae4a); color: #fff;
  font-family: "Secular One", Rubik, sans-serif; font-size: 21px;
  padding: 12px 22px; border-radius: 18px;
  box-shadow: 0 5px 0 #3f7f30, 0 8px 18px rgba(0, 0, 0, 0.18);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}
.big:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #3f7f30; }
.big:disabled { filter: grayscale(0.6) brightness(1.05); opacity: 0.6; cursor: default; }
#btnRoll { border: 3px solid var(--pc, transparent); }
.ghost { background: rgba(255, 255, 255, 0.7); padding: 10px 18px; border-radius: 14px; font-weight: 700; box-shadow: 0 3px 0 rgba(120, 75, 30, 0.25); }

/* ---------- CSS 3D dice ---------- */
.dice-wrap { width: 72px; height: 72px; perspective: 400px; flex: none; }
.dice {
  --s: 64px; width: var(--s); height: var(--s); margin: 4px; position: relative; transform-style: preserve-3d;
  transform: rotateX(-18deg) rotateY(24deg); transition: transform 0.95s cubic-bezier(0.2, 0.7, 0.25, 1); cursor: pointer;
}
.face {
  position: absolute; inset: 0; border-radius: 14px; background: linear-gradient(145deg, #fffaf0, #f1dcb6);
  border: 2px solid #d9b98a; display: grid; padding: 9px;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  box-shadow: inset 0 0 10px rgba(150, 100, 40, 0.25);
}
.face i { width: 12px; height: 12px; border-radius: 50%; background: #6b3e17; place-self: center; box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.35); }
.f1 { transform: translateZ(32px); }
.f6 { transform: rotateY(180deg) translateZ(32px); }
.f2 { transform: rotateY(90deg) translateZ(32px); }
.f5 { transform: rotateY(-90deg) translateZ(32px); }
.f3 { transform: rotateX(90deg) translateZ(32px); }
.f4 { transform: rotateX(-90deg) translateZ(32px); }
.f1 i { grid-area: 2 / 2; background: #c0392b; width: 16px; height: 16px; }
.f2 i:nth-child(1) { grid-area: 1 / 1; } .f2 i:nth-child(2) { grid-area: 3 / 3; }
.f3 i:nth-child(1) { grid-area: 1 / 1; } .f3 i:nth-child(2) { grid-area: 2 / 2; } .f3 i:nth-child(3) { grid-area: 3 / 3; }
.f4 i:nth-child(1) { grid-area: 1 / 1; } .f4 i:nth-child(2) { grid-area: 1 / 3; } .f4 i:nth-child(3) { grid-area: 3 / 1; } .f4 i:nth-child(4) { grid-area: 3 / 3; }
.f5 i:nth-child(1) { grid-area: 1 / 1; } .f5 i:nth-child(2) { grid-area: 1 / 3; } .f5 i:nth-child(3) { grid-area: 2 / 2; } .f5 i:nth-child(4) { grid-area: 3 / 1; } .f5 i:nth-child(5) { grid-area: 3 / 3; }
.f6 i:nth-child(1) { grid-area: 1 / 1; } .f6 i:nth-child(2) { grid-area: 2 / 1; } .f6 i:nth-child(3) { grid-area: 3 / 1; }
.f6 i:nth-child(4) { grid-area: 1 / 3; } .f6 i:nth-child(5) { grid-area: 2 / 3; } .f6 i:nth-child(6) { grid-area: 3 / 3; }

/* ---------- ladder / rope card ---------- */
.card {
  position: absolute; left: 50%; bottom: 14px; z-index: 6; width: min(340px, calc(100% - 32px));
  transform: translate(-50%, 0) scale(0.7); transform-origin: 50% 100%; opacity: 0; transition: transform 0.25s, opacity 0.25s;
  background: var(--cream); border-radius: 24px; padding: 18px 20px 16px; text-align: center;
  border: 5px solid var(--green); box-shadow: 0 14px 40px rgba(60, 30, 0, 0.3); cursor: pointer;
}
.card.show { transform: translate(-50%, 0) scale(1); opacity: 1; }
.card.rope { border-color: #c97b5a; background: #fff3ec; }
.card-icon { font-size: 56px; line-height: 1; margin-top: -48px; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2)); }
.card-head { font-weight: 700; font-size: 15px; opacity: 0.75; margin-top: 4px; }
.card-title { font-family: "Secular One", Rubik, sans-serif; font-size: 30px; margin: 2px 0 6px; color: #3f7f30; }
.card.rope .card-title { color: #b04a2a; }
.card-text { font-size: 17px; line-height: 1.45; }
.card-move { margin-top: 10px; display: inline-block; background: var(--green); color: #fff; font-weight: 800; padding: 4px 14px; border-radius: 999px; }
.card.rope .card-move { background: #c97b5a; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: rgba(255, 244, 222, 0.45); backdrop-filter: blur(3px); overflow-y: auto;
}
.sheet {
  width: min(520px, 100%); background: linear-gradient(180deg, #fffaf0, #fbecd0); border-radius: 28px;
  border: 5px solid var(--wood); box-shadow: 0 8px 0 var(--wood-d), 0 20px 50px rgba(60, 30, 0, 0.3);
  padding: 20px 20px 22px; text-align: center; margin: auto;
}
.hero { font-size: 54px; line-height: 1; }
.sheet h1 { font-family: "Secular One", Rubik, sans-serif; font-size: clamp(30px, 7vw, 42px); margin: 6px 0 0; color: #6b3e0a; }
.sheet .sub { margin: 0; font-weight: 700; font-size: 18px; color: #3f7f30; }
.intro { font-size: 16px; line-height: 1.5; margin: 10px 0; }
.legend { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.lg { padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.lg.up { background: #dff1d6; color: #2f6b22; }
.lg.down { background: #fbe0d6; color: #9a3a1c; }

#setupPlayers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.prow {
  display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 16px; padding: 8px;
  border: 3px solid var(--pc); flex-wrap: wrap;
}
.pdot { width: 14px; height: 14px; border-radius: 50%; background: var(--pc); flex: none; }
.seg { display: flex; background: #f3e6cf; border-radius: 12px; padding: 3px; flex: none; }
.seg button { padding: 6px 10px; border-radius: 9px; background: transparent; font-weight: 700; font-size: 15px; }
.seg button[aria-pressed="true"] { background: var(--pc); color: #fff; }
.pname { flex: 1 1 110px; min-width: 0; font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 10px; border: 2px solid #ead8b8; background: #fffdf8; color: var(--ink); }
.prow.is-ai { background: #eef2fb; }
.aitag { flex: 1 1 100%; text-align: start; font-size: 14px; font-weight: 700; color: #35508a; padding: 2px 4px 0; }
.ai { padding: 7px 10px; border-radius: 10px; background: #f3e6cf; font-weight: 700; font-size: 14px; flex: none; }
.ai.on { background: #e1e7f6; }
.del { width: 32px; height: 32px; border-radius: 50%; background: #f6e2dc; color: #9a3a1c; font-weight: 800; flex: none; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 12px; }
.sheet-actions .big { min-width: 220px; }

/* Footer of the home screen: contact, support, copyright */
.menu-footer { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.link-btn { background: none; color: #7a4a12; font-weight: 700; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; padding: 4px; }
.copyright { margin: 6px 0 0; font-size: 12px; opacity: 0.7; }
.small-sheet h2 { font-family: "Secular One", Rubik, sans-serif; margin: 0; color: #6b3e0a; }
.contact-form { display: flex; flex-direction: column; gap: 4px; text-align: start; }
.contact-form label { font-size: 13px; font-weight: 600; margin-top: 4px; }
.contact-form input, .contact-form select, .contact-form textarea {
  font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 10px; border: 2px solid #ead8b8; background: #fffdf8; color: var(--ink);
}
.contact-form textarea { resize: vertical; min-height: 90px; }
.contact-form .big { align-self: center; margin-top: 6px; }
.contact-status { margin: 4px 0 0; min-height: 1.3em; font-size: 14px; text-align: center; }
.contact-status.ok { color: #2f7a22; }
.contact-status.err { color: #b0331c; }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 9; }
#confetti i {
  position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translate(var(--x), 110vh) rotate(var(--r)); }
}

/* Wide screens: the panel stands at the side */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  #app { flex-direction: row; }
  #panel {
    width: 290px; flex: none; border-top: 0; border-inline-start: 4px solid var(--wood-d);
    justify-content: center; gap: 18px; padding: 20px 18px; box-shadow: 0 0 22px rgba(80, 45, 10, 0.2);
  }
  .brand { display: block; }
  #players { flex-direction: column; align-items: stretch; }
  #players li .nm { flex: 1; }
  .controls { flex-direction: column; }
  .roll-col { flex: none; width: 100%; }
  .dice-wrap { width: 96px; height: 96px; }
  .dice { --s: 86px; margin: 5px; }
  .f1 { transform: translateZ(43px); } .f6 { transform: rotateY(180deg) translateZ(43px); }
  .f2 { transform: rotateY(90deg) translateZ(43px); } .f5 { transform: rotateY(-90deg) translateZ(43px); }
  .f3 { transform: rotateX(90deg) translateZ(43px); } .f4 { transform: rotateX(-90deg) translateZ(43px); }
  .face i { width: 15px; height: 15px; } .f1 i { width: 20px; height: 20px; }
  .face { padding: 12px; border-radius: 18px; }
}
@media (max-height: 560px) and (max-aspect-ratio: 1/1) {
  .dice-wrap { width: 56px; height: 56px; }
  .dice { --s: 50px; }
  .f1 { transform: translateZ(25px); } .f6 { transform: rotateY(180deg) translateZ(25px); }
  .f2 { transform: rotateY(90deg) translateZ(25px); } .f5 { transform: rotateY(-90deg) translateZ(25px); }
  .f3 { transform: rotateX(90deg) translateZ(25px); } .f4 { transform: rotateX(-90deg) translateZ(25px); }
  .face i { width: 9px; height: 9px; }
}
