:root {
  --ink: #2f2418;
  --ink-soft: #6b5a45;
  --parch: #f4ead3;
  --parch-2: #e9dbb8;
  --wood: #3b2f22;
  --wood-2: #4d3d2b;
  --accent: #b5482f;
  --accent-2: #8e3622;
  --ok: #2e7d3b;
  --line: #c9b48a;
  --shadow: 0 10px 30px rgba(30, 20, 10, .35);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 30% 20%, #5a4a35, var(--wood) 60%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input {
  font: inherit; color: var(--ink); background: #fffaf0; border: 1.5px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }

/* ---------- telas de menu ---------- */
.screen { position: fixed; inset: 0; }
#menu, #lobby { overflow-y: auto; padding: 24px 16px 40px; }
.menu-wrap { max-width: 760px; margin: 0 auto; }
.logo {
  font-family: 'Cinzel', serif; font-weight: 800; font-size: clamp(38px, 9vw, 68px);
  color: var(--parch); text-align: center; margin: 12px 0 0; letter-spacing: .04em;
  text-shadow: 0 3px 0 #1d150d, 0 8px 24px rgba(0, 0, 0, .4);
}
.logo.small { font-size: 40px; }
.tagline { text-align: center; color: #d9c79f; margin: 4px 0 26px; }
.field-label { display: block; color: var(--parch); font-weight: 700; margin-bottom: 6px; }
#name { max-width: 360px; margin-bottom: 18px; }
.exp-card { margin-bottom: 16px; }
.exp-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; }
.kind-bar, .extra-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.kind-bar:empty, .extra-bar:empty { display: none; }
.chip {
  border: 1.5px solid var(--line); background: #fffaf0; color: var(--ink); font-weight: 800; font-size: 13px;
  padding: 6px 10px; border-radius: 999px;
}
.chip small { color: var(--ink-soft); font-weight: 700; }
.chip.on { background: var(--wood-2); color: #fff; border-color: var(--wood); }
.chip.on small { color: #e7d3a5; }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.small.on { background: var(--wood-2); color: #fff; border-color: var(--wood); }
.pchip .pextras { font-size: 12px; display: flex; gap: 4px; align-items: center; color: var(--ink-soft); font-weight: 800; }
.opt.cap circle { fill: rgba(214, 58, 47, .35); stroke: #d63a2f; stroke-dasharray: none; stroke-width: 3; }
.opt.cap.sel circle { fill: rgba(214, 58, 47, .75); }
.opt.tw circle { fill: rgba(120, 110, 95, .5); stroke: #fff; }
.opt.fairy circle { fill: rgba(246, 167, 216, .55); stroke: #fff; }
.opt.dragon circle { fill: rgba(192, 43, 43, .22); stroke: #c02b2b; stroke-width: 4; stroke-dasharray: 8 5; }
.opt.dragon:hover circle { fill: rgba(192, 43, 43, .45); }
.opt.sel circle { fill: rgba(255, 255, 255, .95); stroke-dasharray: none; stroke-width: 3; }
.dragon-fig { filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .35)); }
.exp { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 8px 10px; border-radius: 8px; background: var(--parch-2); }
.exp input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.exp span { display: flex; flex-direction: column; }
.exp small { color: var(--ink-soft); font-size: 13px; }
.lobby-exp { display: grid; gap: 6px; margin: 12px 0 0; }
.lobby-exp .exp { background: var(--parch); }
.lobby-exp.readonly .exp { cursor: default; opacity: .9; }
.big-toggle.on { background: var(--accent); color: #fff; border-color: var(--accent-2); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card {
  background: var(--parch); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  border: 2px solid var(--parch-2); display: flex; flex-direction: column; gap: 12px;
}
.card h2, .modal-card h2 { font-family: 'Cinzel', serif; margin: 0; font-size: 22px; }
.card p { margin: 0; color: var(--ink-soft); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.join input { text-transform: uppercase; letter-spacing: .2em; font-weight: 800; }
.mini-label { width: 44px; font-weight: 700; color: var(--ink-soft); font-size: 14px; }
.seg { display: inline-flex; background: var(--parch-2); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 6px; font-weight: 700; color: var(--ink-soft); }
.seg button.on { background: #fffaf0; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.btn {
  border: 1.5px solid var(--line); background: #fffaf0; color: var(--ink); font-weight: 800;
  padding: 10px 16px; border-radius: 8px; transition: transform .08s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; color: var(--parch); border-color: #8b7555; }
.btn:disabled { opacity: .45; cursor: default; }
.link { display: block; margin: 22px auto 0; background: none; border: 0; color: #e7d3a5; text-decoration: underline; font-weight: 700; }
.hint { color: var(--ink-soft); font-size: 14px; }
#lobby .hint { color: #d9c79f; text-align: center; }

/* sala */
.code-box {
  display: flex; gap: 12px; align-items: center; justify-content: center; margin: 12px 0 6px;
}
#roomCode {
  font-family: 'Cinzel', serif; font-size: 40px; font-weight: 800; letter-spacing: .25em;
  color: var(--parch); background: rgba(0, 0, 0, .25); padding: 4px 18px; border-radius: 10px;
}
#seats { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 8px; }
#seats li {
  display: flex; align-items: center; gap: 10px; background: var(--parch); border-radius: 10px; padding: 10px 12px;
}
#seats .who { flex: 1; font-weight: 800; }
#seats .tag { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
#seats .off { color: #b33; }
#seats select { font: inherit; border-radius: 6px; border: 1px solid var(--line); background: #fffaf0; padding: 4px; }
.x-btn { border: 0; background: none; font-size: 20px; color: #a33; padding: 0 6px; }
#hostControls { margin-bottom: 14px; justify-content: center; }
#lobby .row:last-of-type { justify-content: center; }
.dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); flex: none; }

/* chat */
.chat { margin-top: 16px; background: rgba(0, 0, 0, .18); border-radius: 10px; padding: 8px; }
#panel .chat { background: var(--parch-2); }
.chat-log { max-height: 140px; overflow-y: auto; font-size: 14px; color: var(--parch); padding: 2px 4px 6px; }
#panel .chat-log { color: var(--ink); max-height: 100px; }
.chat-log b { margin-right: 4px; }
.chat-form { display: flex; gap: 6px; }
.chat-form input { padding: 7px 10px; }
.chat-form .btn { padding: 7px 12px; }

/* ---------- jogo ---------- */
#game { background: #4a6a2c radial-gradient(circle, #577a33 0%, #3a5524 100%); }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#board.dragging { cursor: grabbing; }
#board3d { position: absolute; inset: 0; touch-action: none; }
#playersBar, #boardTools, #panel { z-index: 2; }
#board3d canvas { display: block; width: 100%; height: 100%; }
.fx3d-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.fx3d {
  position: absolute; transform: translate(-50%, -50%); font-family: 'Cinzel', serif; font-weight: 800; font-size: 34px;
  -webkit-text-stroke: 1.5px #fff; text-shadow: 0 3px 10px rgba(0, 0, 0, .35); animation: floatUp3d 1.8s ease-out forwards;
}
@keyframes floatUp3d { 0% { opacity: 0; margin-top: 10px; } 15% { opacity: 1; } 100% { opacity: 0; margin-top: -60px; } }
.icon-btn.small-txt { font-size: 14px; }
.hint-cell { fill: rgba(255, 250, 220, .22); stroke: #fff6cf; stroke-width: 2.5; stroke-dasharray: 8 6; cursor: pointer; }
.hint-cell:hover { fill: rgba(255, 250, 220, .45); }
.ghost-tile { opacity: .92; cursor: pointer; }
.ghost-frame { fill: none; stroke: #fff; stroke-width: 4; }
.last-frame { fill: none; stroke-width: 4; }
.opt { cursor: pointer; }
.opt circle { fill: rgba(255, 255, 255, .55); stroke: #fff; stroke-width: 2; stroke-dasharray: 4 3; }
.opt:hover circle { fill: rgba(255, 255, 255, .85); }
.fx-text {
  font-family: 'Cinzel', serif; font-weight: 800; font-size: 34px; paint-order: stroke; stroke: #fff; stroke-width: 6px;
  animation: floatUp 1.8s ease-out forwards; text-anchor: middle; pointer-events: none;
}
.fx-area { fill: rgba(255, 255, 255, .35); animation: fadeOut 1.4s ease-out forwards; pointer-events: none; }
@keyframes floatUp { 0% { transform: translateY(10px); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(-40px); opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }

#playersBar {
  position: absolute; top: 10px; left: 10px; right: 340px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none;
}
.pchip {
  display: flex; align-items: center; gap: 8px; background: rgba(244, 234, 211, .94); border-radius: 10px;
  padding: 6px 10px; box-shadow: 0 3px 10px rgba(0, 0, 0, .25); border: 2px solid transparent; pointer-events: auto;
}
.pchip.turn { border-color: #fff; box-shadow: 0 0 0 3px var(--c), 0 3px 10px rgba(0, 0, 0, .3); }
.pchip .pname { font-weight: 800; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .pscore { font-family: 'Cinzel', serif; font-weight: 800; font-size: 20px; min-width: 28px; text-align: right; }
.pchip .pmeeples { display: flex; align-items: center; font-size: 13px; font-weight: 800; color: var(--ink-soft); gap: 2px; }
.pchip .bigtag { font-size: 10px; margin-left: 2px; color: var(--accent); }
.pchip .bot { font-size: 11px; background: var(--parch-2); border-radius: 4px; padding: 1px 5px; color: var(--ink-soft); font-weight: 800; }
.pchip .offline { font-size: 11px; color: #b33; font-weight: 800; }

#boardTools { position: absolute; left: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 10px; border: 0; background: rgba(244, 234, 211, .94);
  font-size: 20px; font-weight: 800; color: var(--ink); box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
}

#panel {
  position: absolute; top: 10px; right: 10px; bottom: 10px; width: 320px; background: var(--parch);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 10px;
  overflow: hidden;
}
.turn-box { display: flex; gap: 12px; align-items: center; }
#tilePreview { width: 96px; height: 96px; flex: none; border-radius: 6px; background: var(--parch-2); display: grid; place-items: center; }
#tilePreview svg { border-radius: 4px; box-shadow: 0 3px 8px rgba(0, 0, 0, .25); }
.turn-info { flex: 1; min-width: 0; }
#status { font-weight: 800; font-size: 16px; line-height: 1.25; }
#deckLeft { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }
#meepleHint { min-height: 20px; }
#logBox { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#logBox summary { font-weight: 800; cursor: pointer; color: var(--ink-soft); }
#log { margin: 6px 0 0; padding: 0 0 0 4px; list-style: none; overflow-y: auto; font-size: 13.5px; max-height: calc(100vh - 360px); }
#log li { padding: 3px 0; border-bottom: 1px dashed var(--line); }
#log li .c { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

/* modais */
.modal { position: fixed; inset: 0; background: rgba(20, 14, 8, .6); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card {
  background: var(--parch); border-radius: var(--radius); padding: 22px; max-width: 560px; width: 100%;
  max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.rules ol { padding-left: 20px; margin: 0; display: grid; gap: 8px; }
.rules table, .end-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.rules th, .rules td, .end-table th, .end-table td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; }
.end-table td.num, .end-table th.num { text-align: right; }
.end-table tr.win td { font-weight: 800; }
.end-title { font-family: 'Cinzel', serif; font-size: 26px; text-align: center; margin: 0; }
.end-sub { text-align: center; color: var(--ink-soft); margin: 0; }
.modal-card .row { justify-content: center; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--wood);
  color: var(--parch); padding: 10px 16px; border-radius: 10px; font-weight: 700; opacity: 0; transition: .25s; z-index: 30;
  pointer-events: none; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- celular ---------- */
@media (max-width: 760px) {
  #playersBar { right: 10px; top: 8px; left: 8px; gap: 5px; }
  .pchip { padding: 4px 7px; gap: 5px; }
  .pchip .pname { max-width: 64px; font-size: 13px; }
  .pchip .pscore { font-size: 16px; min-width: 20px; }
  #panel {
    top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; padding: 10px; gap: 8px;
  }
  #tilePreview { width: 72px; height: 72px; }
  #tilePreview svg { width: 68px; height: 68px; }
  #logBox { display: none; }
  #panel .chat-log { max-height: 60px; }
  #boardTools { bottom: auto; top: 50%; transform: translateY(-50%); left: 8px; }
  .icon-btn { width: 38px; height: 38px; font-size: 18px; }
  #roomCode { font-size: 30px; }
}
