:root {
  color-scheme: light;
  --bg: #faf5ea;
  --card: #fffdf8;
  --ink: #2b2118;
  --muted: #7a6d5f;
  --line: #e4d9c3;
  --accent: #7a2e3f;
  --accent-soft: #f6e8ea;
  --sea: #cfe6ea;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3 { font-family: var(--serif); margin: 0; }
h2 { font-size: 21px; }
h3 { font-size: 15px; margin: 14px 0 6px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.refused { color: #b3261e; }
.muted:has(.refused) { color: var(--ink); animation: nudge .35s ease; }
@keyframes nudge { 0%, 100% { transform: none; } 30% { transform: translateX(-5px); } 70% { transform: translateX(5px); } }
.ic { flex: none; vertical-align: -0.22em; }

.dot {
  display: inline-block; flex: none;
  width: 11px; height: 11px; margin-right: 6px;
  border-radius: 50%;
  background: var(--c);
  border: 1.5px solid rgba(43, 33, 24, .6);
}
.dot.huge { width: 52px; height: 52px; margin: 0 0 10px; border-width: 3px; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 16px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: none; border-color: transparent; color: var(--accent); }
.btn.wide { width: 100%; }
.btn.big { width: 100%; padding: 15px; font-size: 17px; }
.btn:disabled, .abtn:disabled { opacity: .42; }
.btn:not(:disabled):active, .abtn:not(:disabled):active { transform: translateY(1px); }
.iconbtn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: none;
  font-weight: 700; font-size: 18px;
}
.row { display: flex; gap: 8px; margin-top: 14px; }
.row .btn { flex: 1; }
.list { display: grid; gap: 8px; margin-top: 12px; }

/* ---------- inicio ---------- */
.menu {
  min-height: 100%;
  display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.menu-card { width: 100%; max-width: 460px; display: grid; gap: 10px; }
.menu-card h2 { font-size: 16px; margin-top: 10px; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.brand-mark { width: 64px; height: 64px; flex: none; }
.brand h1 { font-size: 34px; line-height: 1.05; color: var(--accent); }
.brand p { margin: 4px 0 0; color: var(--muted); }
.modes { display: grid; gap: 8px; }
.levels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
#level-hint { margin: 0; min-height: 2.8em; }
.mode {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--card);
  cursor: pointer;
}
.mode input { margin: 3px 0 0; accent-color: var(--accent); }
.mode small { display: block; color: var(--muted); font-size: 13px; }
.mode:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.slots { display: grid; gap: 8px; }
.slot { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 8px; }
.slot .dot { width: 18px; height: 18px; margin: 0; }
.slot input, .slot select {
  height: 42px; padding: 0 10px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff;
  font-size: 16px;
  user-select: text; -webkit-user-select: text;
}
.slot.off input, .slot.off .dot { opacity: .35; }

/* ---------- partida ---------- */
.game {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.topbar { display: flex; align-items: center; gap: 6px; padding: 4px 6px; }
.topbar-title { flex: 1; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.topbar-title b { flex: none; white-space: nowrap; font-family: var(--serif); font-size: 19px; color: var(--accent); }
.topbar-title span { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.players { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; padding: 0 8px 8px; }
.pchip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1px 8px;
  padding: 6px 8px;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--card);
  text-align: left; font-size: 12.5px;
  min-width: 0;
}
.pchip.on { border-color: var(--ink); box-shadow: inset 0 -4px 0 var(--c); }
.pname { flex: 1 1 100%; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname .dot { vertical-align: -1px; margin-right: 5px; }
.ppts b { font-size: 16px; }
.pmeta { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.pmeta .ic + .ic, .pmeta .ic:not(:first-child) { margin-left: 4px; }
.pbadges em {
  font-style: normal; font-size: 10px; font-weight: 700;
  padding: 1px 5px; margin-right: 3px;
  border-radius: 6px;
  background: #f2d48a; color: #5c4108;
}

.board-wrap {
  position: relative;
  min-height: 0;
  margin: 0 8px;
  border-radius: 16px;
  background: var(--sea);
  overflow: hidden;
}
#board { display: block; width: 100%; height: 100%; }
.dice { position: absolute; top: 8px; left: 8px; display: flex; align-items: center; gap: 4px; pointer-events: none; }
.die { width: 30px; height: 30px; animation: pop .35s ease-out; }
.die rect { fill: #fff; stroke: var(--ink); stroke-width: 1.5; }
.die circle { fill: var(--ink); }
.dice b { margin-left: 4px; font-size: 20px; font-family: var(--serif); }

.panel { display: grid; gap: 8px; padding: 8px; align-content: start; min-height: 0; }
.status { display: flex; align-items: center; min-height: 24px; font-weight: 600; }
.rcards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.rcard {
  display: grid; justify-items: center;
  padding: 5px 2px 4px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff;
}
.rcard b { font-size: 17px; line-height: 1.15; }
.rcard small { font-size: 10px; color: var(--muted); }
.rcard.zero { opacity: .45; }
.dcards { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dcard {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: #fff;
  font-size: 13px; font-weight: 600;
}
.dcard.ready { border-color: var(--accent); background: var(--accent-soft); }

.actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.actions > .btn { grid-column: 1 / -1; }
.abtn {
  display: grid; justify-items: center; align-content: center; gap: 2px;
  min-height: 50px; padding: 5px 4px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff;
  font-weight: 600; font-size: 14px;
}
.abtn .cost { display: flex; gap: 1px; min-height: 14px; font-size: 10.5px; font-weight: 500; color: var(--muted); }
.abtn.sel { border-color: var(--accent); background: var(--accent-soft); }
.abtn.end { background: var(--accent); border-color: var(--accent); color: #fff; }
.actions.five .abtn.end { grid-column: span 2; }

.log { max-height: 38px; overflow-y: auto; font-size: 12.5px; color: var(--muted); }
.log p { margin: 0 0 1px; }
.log .dot { width: 8px; height: 8px; margin-right: 5px; }

@media (min-width: 860px), (orientation: landscape) and (min-width: 620px) {
  .game {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "top top" "board players" "board panel";
  }
  .topbar { grid-area: top; }
  .players { grid-area: players; grid-auto-flow: row; grid-template-columns: 1fr 1fr; padding: 0 10px 8px; }
  .board-wrap { grid-area: board; margin: 0 0 10px 10px; }
  .panel { grid-area: panel; padding: 0 10px 10px; overflow-y: auto; grid-template-rows: auto auto auto minmax(0, 1fr); }
  .log { max-height: none; }
}

/* ---------- tablero (SVG) ---------- */
.beach polygon { fill: #f3e2b8; stroke: #f3e2b8; stroke-width: 16; stroke-linejoin: round; }
.hex polygon { stroke: #fffaf0; stroke-width: 3; stroke-linejoin: round; }
.hex .blocked { fill: rgba(44, 42, 51, .3); stroke: none; }
.token { fill: #fff8e7; stroke: #cdb98c; stroke-width: 1.5; }
.hex.hot .token { fill: #fff; stroke: #d8432f; stroke-width: 3.5; }
.num { font: 700 17px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; fill: var(--ink); }
.num.red, .pip.red { fill: #c0392b; }
.pip { fill: var(--ink); }
.terrain { font: 700 10px system-ui, sans-serif; text-anchor: middle; fill: #8a7444; letter-spacing: .1em; text-transform: uppercase; }
.port path { fill: none; stroke: #a88756; stroke-width: 3; stroke-dasharray: 1 6; stroke-linecap: round; }
.port circle { fill: #fff8e7; stroke: #a88756; stroke-width: 1.5; }
.port text { font: 700 8.5px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; fill: #5c4526; }
.port text.big { font-size: 12px; }
.road-bg { stroke: var(--ink); stroke-width: 11; stroke-linecap: round; }
.road { stroke-width: 7; stroke-linecap: round; }
.critic { pointer-events: none; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .45)); }
.th { fill: transparent; pointer-events: all; cursor: pointer; }
.tring { fill: none; stroke: #2c2a33; stroke-width: 3; stroke-dasharray: 6 4; pointer-events: none; animation: blink 1s ease-in-out infinite alternate; }
.th:hover { fill: rgba(44, 42, 51, .18); }
.te { stroke-width: 9; stroke-linecap: round; filter: drop-shadow(0 0 1.5px #2b2118); animation: blink 1s ease-in-out infinite alternate; }
.tv { fill: #fff; stroke-width: 4; filter: drop-shadow(0 0 1.5px #2b2118); animation: blink 1s ease-in-out infinite alternate; }
.tv.ring { fill: none; }
.hit { fill: transparent; stroke: transparent; stroke-width: 26; pointer-events: all; cursor: pointer; }
@keyframes blink { from { opacity: .55; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.4) rotate(-40deg); } to { transform: none; } }

/* ---------- diálogos ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(43, 33, 24, .5);
}
.backdrop.cover { background: var(--accent); }
.modal {
  width: min(440px, 100%);
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 18px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 12px 40px rgba(43, 33, 24, .3);
}
.modal h2 { display: flex; align-items: center; margin-bottom: 10px; }
.modal .steps, .modal .pickrow { margin-bottom: 12px; }
.center h2 { justify-content: center; }
.steps, .pickrow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.step { display: grid; justify-items: center; gap: 3px; }
.step small { font-size: 10px; color: var(--muted); }
.step div { display: grid; justify-items: center; gap: 3px; }
.step div button {
  width: 40px; height: 32px;
  border: 1.5px solid var(--line); border-radius: 9px;
  background: #fff;
  font-size: 18px; font-weight: 700; line-height: 1;
}
.step div button:last-child { order: -1; }
.step div button:first-child { order: 1; }
.step b { font-size: 15px; white-space: nowrap; }
.pickrow button {
  display: grid; justify-items: center; gap: 1px;
  padding: 7px 2px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff;
}
.pickrow button.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.pickrow button:disabled { opacity: .35; }
.pickrow small { font-size: 10px; color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 10px; padding: 4px; border-radius: 12px; background: #f0e7d6; }
.tabs button { padding: 8px; border: 0; border-radius: 9px; background: none; font-weight: 600; }
.tabs button.on { background: #fff; }
.deal { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 12px 0; }
.deal > div { display: grid; justify-items: center; gap: 4px; }
.deal small { color: var(--muted); }
.deal > span { font-size: 20px; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 9px; margin: 0 2px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: #fff;
  font-weight: 700;
}
.facts { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.facts td { padding: 7px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.facts td:last-child { text-align: right; font-weight: 600; white-space: nowrap; }
.facts small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.rules { font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.legend span { white-space: nowrap; }
.rank { display: flex; align-items: center; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; }
.rank span { flex: 1; }

.toasts {
  position: fixed; z-index: 60;
  top: calc(env(safe-area-inset-top) + 52px); left: 0; right: 0;
  display: grid; justify-items: center; gap: 6px;
  pointer-events: none;
}
.toast {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ink); color: #fff;
  font-weight: 600; font-size: 14px;
  animation: toast 3.2s ease both;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .te, .tv, .tring, .die { animation: none; }
}

/* ---------- red ---------- */
.netrow { margin-top: 0; }
.tc { text-align: center; }
.field { display: grid; gap: 4px; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  height: 46px; padding: 0 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
  font-size: 17px;
  user-select: text; -webkit-user-select: text;
}
.field .codein { font-size: 26px; font-weight: 800; letter-spacing: .35em; text-transform: uppercase; text-align: center; }
.roomcode {
  justify-self: center;
  margin: 4px 0 0; padding: 10px 22px;
  border: 2px dashed var(--accent); border-radius: 14px;
  font: 800 44px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .25em; text-indent: .25em;
  color: var(--accent);
  user-select: text; -webkit-user-select: text;
}
.lslots { display: grid; gap: 8px; }
.lslot { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); }
.lslot .dot { width: 18px; height: 18px; margin: 0; }
.lname { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ltag { color: var(--muted); font-size: 13px; }
.lslot .iconbtn { width: 32px; height: 32px; font-size: 15px; }
.netbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  background: #7d1d12; color: #fff; text-align: center; font-size: 14px; font-weight: 600;
}
