:root {
  --ink: #2a2620;
  --paper: #fbf6ec;
  --paper-2: #ece2cf;
  --accent: #2e8b57;
  --accent-dark: #1d5c39;
  --warn: #e2731c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: #1d2b22;
  overflow: hidden;
}
.hidden { display: none !important; }
.error { color: #b3261e; font-weight: 700; min-height: 1.2em; font-size: 14px; }
.btn {
  border: none; border-radius: 12px; padding: 10px 18px;
  font: inherit; font-weight: 900; font-size: 15px;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark);
  cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: var(--paper-2); color: var(--ink); box-shadow: 0 4px 0 #c4b18f; }
.btn.warn { background: var(--warn); box-shadow: 0 4px 0 #a24d0c; }
.icon-btn {
  width: 40px; height: 40px; border: none; border-radius: 12px; cursor: pointer;
  background: rgba(251, 246, 236, 0.92); font-weight: 900; font-size: 18px; color: var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.mini { border: none; border-radius: 8px; padding: 3px 8px; font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; background: var(--paper-2); color: var(--ink); }

/* ------------------------------------------------------------- lobby */
#lobby { height: 100%; overflow: auto; padding: 18px 16px 90px; background: linear-gradient(180deg, #e9e2d3, #cdbf9f); }
.lobby-head { width: min(980px, 100%); margin: 0 auto 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.lobby-head h1 { margin: 0; flex: 1; font-size: clamp(24px, 6vw, 34px); }
.link-btn { text-decoration: none; font-weight: 800; color: var(--ink); background: var(--paper); padding: 8px 12px; border-radius: 12px; box-shadow: 0 3px 0 #c4b18f; }
.user-chip { font-weight: 800; background: var(--paper); padding: 8px 12px; border-radius: 999px; }
.lobby-grid { width: min(980px, 100%); margin: 0 auto; display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
.card { background: var(--paper); border-radius: 20px; padding: 16px 18px; box-shadow: 0 6px 0 #c4b18f; }
.card h2 { margin: 0 0 12px; font-size: 20px; }
.card h3 { margin: 14px 0 6px; font-size: 15px; opacity: 0.8; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; font-weight: 800; }
.seg { display: flex; background: var(--paper-2); border-radius: 12px; padding: 3px; }
.seg button { border: none; background: transparent; font: inherit; font-weight: 900; width: 44px; padding: 7px 0; border-radius: 9px; cursor: pointer; color: var(--ink); }
.seg button.sel { background: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
select, #join-code { font: inherit; font-weight: 800; padding: 8px 10px; border-radius: 10px; border: 2px solid #d7c7a8; background: #fff; color: var(--ink); }
#join-code { flex: 1; text-transform: uppercase; letter-spacing: 3px; font-size: 18px; min-width: 0; }
.row { display: flex; gap: 8px; }
details { margin: 10px 0 14px; background: var(--paper-2); border-radius: 12px; padding: 8px 12px; }
summary { font-weight: 800; cursor: pointer; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; font-size: 14px; font-weight: 600; line-height: 1.3; }
.check input { margin-top: 2px; }
.game-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--paper-2); margin-bottom: 6px; font-size: 14px; }
.game-row .who { flex: 1; font-weight: 700; }
.game-row b { letter-spacing: 1px; }
.empty { opacity: 0.6; font-size: 14px; }

/* ------------------------------------------------------------- partida */
#game, #stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: max(10px, env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.code-chip { background: rgba(251, 246, 236, 0.92); border-radius: 999px; padding: 6px 8px 6px 14px; font-weight: 700; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.code-chip b { letter-spacing: 2px; font-size: 16px; }
#status-line { color: #fff; font-weight: 800; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); font-size: 15px; }

#players {
  position: fixed; z-index: 5; left: 12px; top: 64px;
  display: flex; flex-direction: column; gap: 8px; width: 230px;
}
.pl {
  background: rgba(251, 246, 236, 0.94); border-radius: 14px; padding: 8px 10px;
  border-left: 8px solid var(--c); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  display: grid; grid-template-columns: 26px 1fr auto; gap: 2px 8px; align-items: center;
  transition: transform 0.2s;
}
.pl.turn { transform: translateX(6px); box-shadow: 0 0 0 3px #fff27a, 0 3px 0 rgba(0, 0, 0, 0.25); }
.pl .av { font-size: 20px; }
.pl .nm { font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .conn { width: 10px; height: 10px; border-radius: 50%; background: #3bb54a; }
.pl .conn.off { background: #999; }
.pl .meta { grid-column: 1 / -1; display: flex; gap: 10px; font-size: 12px; font-weight: 800; opacity: 0.85; }
.pl .badge { grid-column: 1 / -1; font-size: 11px; font-weight: 900; background: #2a2620; color: #fff27a; border-radius: 8px; padding: 2px 6px; justify-self: start; }
.pl .timer { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.12); overflow: hidden; }
.pl .timer i { display: block; height: 100%; background: var(--accent); }
.pl .timer i.low { background: #e2392b; }

#log {
  position: fixed; z-index: 4; right: 12px; top: 110px; width: 250px;
  display: flex; flex-direction: column; gap: 4px; pointer-events: none;
}
#log div { background: rgba(20, 30, 24, 0.72); color: #fff; border-radius: 10px; padding: 5px 9px; font-size: 13px; font-weight: 700; animation: fadein 0.3s; }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px); } }

#actionbar {
  position: fixed; z-index: 5; left: 50%; transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(640px, calc(100vw - 24px));
  background: rgba(251, 246, 236, 0.95); border-radius: 18px; padding: 10px 12px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
}
#dice-chips { display: flex; gap: 6px; }
.die {
  width: 40px; height: 40px; border-radius: 10px; background: #fff; border: 2px solid #d7c7a8;
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 900;
}
.die.used { opacity: 0.35; text-decoration: line-through; }
.die.double { border-color: var(--warn); }
#hint { flex: 1; font-weight: 800; font-size: 14px; min-width: 120px; }
.actions { display: flex; gap: 8px; }

#move-menu {
  position: fixed; z-index: 8; background: var(--paper); border-radius: 14px; padding: 8px;
  display: flex; flex-direction: column; gap: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
#move-menu button { white-space: nowrap; }

.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(10, 18, 12, 0.55); backdrop-filter: blur(2px);
}
.panel { width: min(420px, 100%); background: var(--paper); border-radius: 20px; padding: 20px; text-align: center; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4); }
.panel h2 { margin: 0 0 10px; }
.panel p { font-weight: 700; line-height: 1.4; }
.big-code { font-size: 26px; letter-spacing: 4px; background: var(--paper-2); padding: 2px 10px; border-radius: 10px; }
.panel-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.wait-pl { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--paper-2); margin: 6px 0; font-weight: 800; border-left: 8px solid var(--c); }
.wait-pl.empty { opacity: 0.5; font-weight: 600; }
.note { font-size: 13px; opacity: 0.75; }

#loading { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: #1d2b22; color: #fbf6ec; font-weight: 800; font-size: 20px; }

@media (max-width: 760px) {
  #players { top: auto; bottom: 120px; left: 8px; right: 8px; width: auto; flex-direction: row; overflow-x: auto; gap: 6px; }
  .pl { min-width: 150px; padding: 6px 8px; }
  .pl.turn { transform: translateY(-4px); }
  #log { top: 104px; right: 8px; width: 60vw; }
  #log div:nth-child(n + 3) { display: none; }
  #actionbar { gap: 8px; }
  #hint { order: 3; flex-basis: 100%; font-size: 13px; }
}
