:root{
  --paper: #efe7d8;
  --paper-dark: #e4dac4;
  --ink: #2b2a28;
  --red: #b3261e;
  --red-soft: #c65a4f;
  --accent-blue: #2f6f9e;
  --accent-green: #3f7d4f;
  --accent-purple: #7a4f9e;
  --gold: #d9a441;
  --shadow: rgba(43,42,40,0.18);
}

*{ box-sizing: border-box; }

html, body{
  margin:0;
  padding:0;
  min-height:100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Patrick Hand', cursive;
}

.paper-bg{
  min-height:100vh;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.35), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(0,0,0,0.05), transparent 40%);
  background-color: var(--paper);
}

.hidden{ display:none !important; }

.title{
  font-family:'Caveat', cursive;
  font-weight:700;
  font-size: 4rem;
  margin: 0 0 4px 0;
  color: var(--ink);
  text-align:center;
  transform: rotate(-1.5deg);
}
.title.small{
  font-size: 2.2rem;
  text-align:left;
  margin:0;
}
.subtitle{
  text-align:center;
  font-size:1.3rem;
  margin-top:0;
  color:#5c564a;
}

/* ---------- Setup screen ---------- */
.screen{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 24px;
}

.setup-card{
  background: var(--paper-dark);
  border: 3px solid var(--ink);
  border-radius: 18px 22px 20px 24px / 22px 18px 24px 20px;
  box-shadow: 6px 6px 0 var(--shadow);
  padding: 32px 36px 28px;
  max-width: 440px;
  width:100%;
}

.setup-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  font-size:1.4rem;
  margin: 18px 0 10px;
}

.stepper{
  display:flex;
  align-items:center;
  gap:14px;
  font-size:1.6rem;
}
.stepper span{ min-width: 24px; text-align:center; }

.pencil-btn{
  font-family:'Patrick Hand', cursive;
  font-size:1.3rem;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 10px 12px 10px 12px / 12px 10px 12px 10px;
  padding: 6px 14px;
  cursor:pointer;
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform .08s ease;
}
.pencil-btn:hover{ transform: translateY(-2px); }
.pencil-btn:active{ transform: translateY(1px); box-shadow: 1px 1px 0 var(--shadow); }

.name-inputs{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin: 14px 0 20px;
}
.name-input-row{
  display:flex;
  align-items:center;
  gap:10px;
}
.swatch{
  width:20px;
  height:20px;
  border-radius:50%;
  border: 2px solid var(--ink);
  flex-shrink:0;
}
.name-input-row input{
  flex:1;
  font-family:'Patrick Hand', cursive;
  font-size:1.2rem;
  padding: 7px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.big-btn{
  width:100%;
  font-family:'Caveat', cursive;
  font-weight:700;
  font-size:1.7rem;
  background: var(--red);
  color: #fff8ee;
  border: 3px solid var(--ink);
  border-radius: 16px 20px 16px 20px / 20px 16px 20px 16px;
  padding: 10px 16px;
  cursor:pointer;
  box-shadow: 4px 4px 0 var(--shadow);
  transition: transform .08s ease;
}
.big-btn:hover{ transform: translateY(-2px); }
.big-btn:active{ transform: translateY(1px); box-shadow: 2px 2px 0 var(--shadow); }
.big-btn:disabled{ opacity:.5; cursor:default; transform:none; }

.link-btn{
  background:none;
  border:none;
  font-family:'Patrick Hand', cursive;
  font-size:1.1rem;
  color: var(--accent-blue);
  text-decoration: underline;
  text-decoration-style: wavy;
  cursor:pointer;
  padding: 4px 8px;
}
.setup-footer{
  display:flex;
  justify-content:center;
  align-items:center;
  gap: 6px;
  margin-top: 4px;
}
.sound-btn{
  text-decoration: none;
  font-size: 1.3rem;
  line-height: 1;
}

/* ---------- Modal ---------- */
.modal{
  position:fixed;
  inset:0;
  background: rgba(30,28,24,0.45);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index: 50;
  padding: 20px;
}
.modal-card{
  background: var(--paper-dark);
  border: 3px solid var(--ink);
  border-radius: 20px 16px 22px 18px / 18px 22px 16px 20px;
  box-shadow: 6px 6px 0 var(--shadow);
  padding: 26px 30px;
  max-width: 420px;
  width:100%;
  text-align:center;
}
.modal-card h2{
  font-family:'Caveat', cursive;
  font-size:2.4rem;
  margin: 0 0 10px;
}
.modal-card ul{
  text-align:left;
  font-size: 1.1rem;
  line-height:1.5;
  padding-left: 20px;
}
.red-word{ color: var(--red); font-weight:bold; }

.confirm-buttons{
  display:flex;
  gap: 12px;
  justify-content:center;
  margin-top: 14px;
}
.confirm-buttons .pencil-btn{ flex:1; }

.choice-buttons{
  display:flex;
  flex-direction:column;
  gap: 10px;
  margin-top: 14px;
}
.choice-buttons .choice-option{
  text-align:left;
  font-size: 1.2rem;
}

.scoreboard{
  display:flex;
  flex-direction:column;
  gap: 6px;
  margin: 14px 0;
  text-align:left;
}
.scoreboard-row{
  display:flex;
  align-items:center;
  gap: 8px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 8px 10px 8px 10px / 10px 8px 10px 8px;
  padding: 6px 10px;
  font-size: 1.1rem;
}
.scoreboard-row.winner-row{
  border-width: 3px;
  box-shadow: 2px 2px 0 var(--shadow);
}
.scoreboard-row .sb-score{
  margin-left:auto;
  font-family:'Caveat', cursive;
  font-weight:700;
  font-size: 1.3rem;
}

.support-box{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap: 8px;
  margin: 16px 0 6px;
  padding: 14px;
  background: var(--paper);
  border: 2.5px dashed var(--ink);
  border-radius: 14px;
}
.support-text{
  font-size: 1.05rem;
  text-align:center;
  margin: 0;
  line-height:1.35;
}
#support-qr{
  width: 160px;
  height: 160px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  display: block;
}

/* ---------- Game screen ---------- */
#game-screen.screen{
  height: 100vh;
  min-height: 100vh;
  display:flex;
  flex-direction:column;
  align-items:stretch;
  justify-content:flex-start;
  padding: 14px 18px;
  gap: 10px;
  overflow:hidden;
}

.game-header{
  display:flex;
  align-items:center;
  gap:14px;
  flex: 0 0 auto;
}
.game-header .title.small{ flex:1; }

.round-tag{
  font-size: .95rem;
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 3px 10px;
  font-family: 'Patrick Hand', cursive;
}

.game-layout{
  flex: 1 1 auto;
  min-height: 0;
  display:flex;
  gap: 16px;
}

.board-wrap{
  flex: 1 1 auto;
  min-width: 0;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 6px 6px 0 var(--shadow);
  padding: 8px;
  display:flex;
  align-items:center;
  justify-content:center;
  perspective: 1400px;
}
#board-svg{
  width:100%;
  height:100%;
  display:block;
  transition: transform .38s ease-in-out;
}

.side-panel{
  flex: 0 0 280px;
  min-width: 0;
  display:flex;
  flex-direction:column;
  gap: 8px;
  min-height: 0;
}

.turn-card, .dice-area, .players-list, .log-box, .mini-box{
  background: var(--paper-dark);
  border: 3px solid var(--ink);
  border-radius: 12px 16px 12px 16px / 16px 12px 16px 12px;
  box-shadow: 3px 3px 0 var(--shadow);
}
.turn-card{ text-align:center; flex: 0 0 auto; padding: 8px 12px; }
.turn-label{ font-size: .85rem; color:#5c564a; }
.turn-player{
  font-family:'Caveat', cursive;
  font-weight:700;
  font-size: 1.5rem;
}

.jail-draw-row{ display:flex; gap:8px; flex: 0 0 auto; }
.mini-box{ flex:1; padding: 4px 6px 6px; text-align:center; }
.mini-box svg{ width:100%; height:56px; display:block; }
.mini-label{ font-size:.8rem; color:#5c564a; margin-top:2px; }

.dice-area{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 8px;
  flex: 0 0 auto;
}
#dice-svg{ flex: 0 0 auto; }
.roll-btn{
  flex:1;
  font-family:'Caveat', cursive;
  font-weight:700;
  font-size:1.25rem;
  background: var(--red);
  color: #fff8ee;
  border: 3px solid var(--ink);
  border-radius: 12px 16px 12px 16px / 16px 12px 16px 12px;
  padding: 7px 8px;
  cursor:pointer;
  transition: transform .08s ease;
}
.roll-btn:hover{ transform: translateY(-2px); }
.roll-btn:active{ transform: translateY(1px); }
.roll-btn:disabled{ opacity:.5; cursor:default; transform:none; }

.players-list{
  flex: 0 0 auto;
  display:flex;
  flex-direction:column;
  gap: 4px;
  padding: 6px 8px;
  max-height: 40vh;
  overflow-y:auto;
}
.player-row{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap: 6px;
  padding: 5px 4px;
  border-bottom: 1px dashed #c9bfa8;
}
.player-row:last-child{ border-bottom:none; }
.player-row.active{ background: rgba(255,255,255,0.45); border-radius:8px; }
.player-row .swatch{ width:14px; height:14px; }
.player-name{ font-size: .98rem; }
.player-score{
  margin-left:auto;
  font-family:'Caveat', cursive;
  font-weight:700;
  font-size: 1.15rem;
}
.player-icons{ display:flex; gap:3px; flex-basis:100%; padding-left:22px; }
.player-status-line{ font-size:.82rem; color:#5c564a; flex-basis:100%; padding-left:22px; }
.player-status-line.jailed-text{ color: var(--red); }
.player-status-line.frozen-text{ color: var(--accent-blue); }
.player-status-line.eliminated-text{ color: #999; font-style:italic; }

.log-box{
  padding: 8px 12px;
  flex: 1 1 auto;
  min-height: 0;
  display:flex;
  flex-direction:column;
}
.log-title{ font-size:.8rem; color:#5c564a; margin-bottom:4px; }
.log{
  overflow-y:auto;
  font-size: .95rem;
  line-height:1.32;
  flex:1;
}
.log div{ margin-bottom: 2px; }

/* ---- card draw animation ---- */
.card-backdrop{
  position:fixed; inset:0;
  background: rgba(30,28,24,0.35);
  z-index:498;
  opacity:1;
  transition: opacity .4s ease;
  pointer-events:none;
}
.flying-card{
  position:fixed;
  z-index: 500;
  border-radius: 12px;
  perspective: 1000px;
  transition: left .5s ease, top .5s ease, width .5s ease, height .5s ease, opacity .4s ease;
}
.card-inner{
  position:relative;
  width:100%;
  height:100%;
  transform-style: preserve-3d;
  transition: transform .5s ease;
}
.card-face{
  position:absolute;
  inset:0;
  backface-visibility:hidden;
  border-radius: 12px;
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--shadow);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  padding: 10px;
  text-align:center;
}
.card-back{ font-size: 3rem; color: var(--red); font-family:'Caveat', cursive; font-weight:700; }
.card-front{ transform: rotateY(180deg); }
.card-inner.flipped{ transform: rotateY(180deg); }
.card-front .card-kind{ font-size: .85rem; color:#5c564a; margin-bottom: 4px; }
.card-front .card-name{ font-family:'Caveat', cursive; font-weight:700; font-size: 1.7rem; color: var(--ink); margin-bottom: 6px; }
.card-front .card-desc{ font-size: .95rem; color: var(--ink); line-height:1.3; margin-bottom: 14px; }
.card-continue-btn{
  font-family:'Patrick Hand', cursive;
  font-size:1rem;
  background: var(--paper-dark);
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  padding: 5px 16px;
  cursor:pointer;
}

/* ---- big on-board dice roll ---- */
.big-dice{
  position:fixed;
  z-index: 480;
  opacity:1;
  transition: opacity .4s ease;
  pointer-events:none;
}
#dice-svg, .big-dice svg{ -webkit-tap-highlight-color: transparent; outline: none; }

@media (max-width: 900px){
  .side-panel{ flex-basis: 230px; }
  .turn-player{ font-size:1.3rem; }
  .title{ font-size: 3rem; }
}

/* ---- playful FX overlays: freeze / jail / shields ---- */
.fx-overlay{
  position:fixed; top:50%; left:50%;
  width:220px; height:220px;
  transform: translate(-50%,-50%) scale(0.3) rotate(-10deg);
  opacity:0;
  z-index:600;
  pointer-events:none;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .2s ease;
}
.fx-overlay.show{ transform: translate(-50%,-50%) scale(1) rotate(0deg); opacity:1; }
.fx-overlay.fade{ transform: translate(-50%,-50%) scale(1.2) rotate(6deg); opacity:0; transition: transform .35s ease, opacity .35s ease; }

.fx-burst-shape{ position:absolute; inset:0; }
.fx-burst-sq{
  position:absolute; inset:0;
  border: 4px solid var(--ink);
  border-radius: 18%;
}

.fx-icon{ position:relative; font-size: 4rem; z-index:1; line-height:1; }
.fx-label{
  position:relative; z-index:1;
  font-family:'Caveat', cursive; font-weight:700; font-size:1.7rem;
  color: var(--ink);
  margin-top: 2px;
}

.fx-stamp{
  position:fixed; top:50%; left:50%; z-index:600; pointer-events:none;
  transform: translate(-50%,-50%) scale(1.8) rotate(-14deg);
  opacity:0;
  font-family:'Caveat', cursive; font-weight:700; font-size: 3.2rem;
  color: var(--red);
  background: var(--paper);
  border: 6px solid var(--red);
  border-radius: 14px;
  padding: 10px 26px;
  box-shadow: 5px 5px 0 var(--shadow);
  transition: transform .28s cubic-bezier(.34,1.8,.64,1), opacity .2s ease;
}
.fx-stamp.slam{ transform: translate(-50%,-50%) scale(1) rotate(-8deg); opacity:1; }
.fx-stamp.fade{ opacity:0; transition: opacity .35s ease; }

.fx-flying-token{
  position:fixed; z-index:590; pointer-events:none;
  border: 2px solid var(--ink); border-radius:50%;
  transition: left .5s ease, top .5s ease, width .5s ease, height .5s ease, opacity .5s ease;
}

.fx-sparkle{
  position:fixed; z-index:600; pointer-events:none;
  font-size: 1.6rem;
  transform: translate(-50%,-50%) scale(1);
  transition: left .45s ease, top .45s ease, opacity .45s ease, transform .45s ease;
}

.fx-bubble{
  position:fixed; z-index:600; pointer-events:none;
  transform: translate(-50%,-100%) scale(0.4);
  opacity:0;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 8px 14px;
  font-family:'Caveat', cursive; font-weight:700; font-size:1.25rem;
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--shadow);
  white-space: nowrap;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .2s ease;
}
.fx-bubble::after{
  content:'';
  position:absolute; left:50%; bottom:-9px; transform:translateX(-50%);
  border-width:10px 8px 0 8px; border-style:solid;
  border-color: var(--ink) transparent transparent transparent;
}
.fx-bubble.show{ transform: translate(-50%,-100%) scale(1); opacity:1; }
.fx-bubble.fade{ transform: translate(-50%,-120%) scale(1.05); opacity:0; transition: transform .35s ease, opacity .35s ease; }
