:root {
  --bg: #e9dcc6;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: #c9b79c;
  --text: #2b2b2b;
  --muted: #6d6252;
  --blue: #4871b6;
  --blue-dark: #2f5596;
  --gray: #8a8a8a;
  --red: #c4372e;
  --topbar: #1a2d4a;
  --sea: #2f7fbf;
  --sea-dark: #1f5f96;
  --brick: #c4562c;
  --lumber: #2e7a34;
  --wool: #8fcb4b;
  --grain: #e8bb35;
  --ore: #8c96a3;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    repeating-linear-gradient(90deg, rgba(120, 85, 40, 0.04) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(0deg, rgba(120, 85, 40, 0.03) 0 1px, transparent 1px 13px);
  min-height: 100vh;
}
button { font-family: inherit; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 16px;
  background: linear-gradient(#22395c, var(--topbar));
  color: #fff; padding: 6px 16px; height: 46px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  position: sticky; top: 0; z-index: 20;
}
.logo { font-family: 'Roboto Slab', serif; font-weight: 800; font-size: 20px; letter-spacing: 0.5px; }
.logo-hex { color: #f2a33a; }
.table-info { opacity: 0.8; font-size: 13px; flex: 1; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.speed { font-size: 12px; opacity: 0.9; }
.speed select { margin-left: 4px; border-radius: 4px; border: 0; padding: 2px 4px; }
.topbtn {
  background: rgba(255, 255, 255, 0.12); color: #fff; border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px; padding: 5px 10px; cursor: pointer; font-size: 13px;
}
.topbtn:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- status bar (BGA "page title") ---------- */
#page-title {
  position: sticky; top: 46px; z-index: 15;
  margin: 10px 12px 0; padding: 9px 14px; min-height: 44px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
  font-size: 16px; font-weight: 700;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
}
#status-text .pname { font-weight: 700; }
#status-buttons { display: inline-flex; flex-wrap: wrap; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; border-radius: 6px; padding: 6px 12px;
  font-size: 13px; font-weight: 700; cursor: pointer; color: #fff;
  background: linear-gradient(#5b86cf, var(--blue)); box-shadow: 0 2px 0 var(--blue-dark);
  transition: transform 0.05s, filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn.gray { background: linear-gradient(#a6a6a6, var(--gray)); box-shadow: 0 2px 0 #666; }
.btn.red { background: linear-gradient(#d9554b, var(--red)); box-shadow: 0 2px 0 #8d2620; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.4); }

/* ---------- layout ---------- */
#game { display: flex; gap: 12px; padding: 12px; align-items: flex-start; }
#left { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
#right { width: 300px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 110px; }

.panel {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 8px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); padding: 10px;
}
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); font-weight: 700; margin-bottom: 6px; }

/* ---------- board ---------- */
#board-wrap {
  position: relative; border-radius: 10px; overflow: hidden;
  background: radial-gradient(ellipse at center, #3d93d1 0%, #2a73b1 55%, #1d5687 100%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  border: 3px solid #6b4a26;
}
#board { width: 100%; height: auto; display: block; max-height: max(420px, calc(100vh - 300px)); }
.tile-poly { stroke: #f2e2b8; stroke-width: 3; }
.hex-hit { fill: transparent; cursor: pointer; }
.hex-hit:hover { fill: rgba(255, 255, 255, 0.28); }
.hex-target { fill: rgba(255, 255, 255, 0.12); stroke: #fff; stroke-width: 3; stroke-dasharray: 8 6; pointer-events: none; animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -28; } }

.hint-vertex { fill: rgba(255, 255, 255, 0.85); stroke: #1a2d4a; stroke-width: 2; cursor: pointer; animation: pulse 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.hint-vertex:hover { fill: #ffe066; }
.hint-edge { stroke: rgba(255, 255, 255, 0.75); stroke-width: 9; stroke-linecap: round; cursor: pointer; animation: fadepulse 1.1s ease-in-out infinite; }
.hint-edge:hover { stroke: #ffe066; }
@keyframes pulse { 50% { transform: scale(1.25); } }
@keyframes fadepulse { 50% { stroke: rgba(255, 255, 255, 0.35); } }

.building { filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, 0.55)); }
.placed { animation: drop 0.35s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes drop { from { transform: translateY(-14px) scale(1.3); opacity: 0; } }
.robber { filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.6)); transition: transform 0.4s ease; }
.token-text { font-family: 'Roboto Slab', serif; font-weight: 800; }

#floaters { position: absolute; inset: 0; pointer-events: none; }
.floater {
  position: absolute; transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.95); border-radius: 12px; padding: 2px 8px;
  font-weight: 700; font-size: 13px; white-space: nowrap; border: 2px solid;
  animation: floatup 1.6s ease-out forwards;
}
@keyframes floatup { 0% { opacity: 0; margin-top: 8px; } 15% { opacity: 1; margin-top: 0; } 75% { opacity: 1; } 100% { opacity: 0; margin-top: -26px; } }

/* ---------- hand ---------- */
#hand-panel { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.hand-section { min-width: 0; }
.build-section { margin-left: auto; }
.cards { display: flex; flex-wrap: wrap; gap: 8px; min-height: 84px; align-items: flex-end; }
.empty-note { color: var(--muted); font-style: italic; font-size: 12px; align-self: center; }

.rcard {
  position: relative; width: 54px; height: 78px; border-radius: 6px;
  border: 2px solid #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; user-select: none;
}
.rcard .ico { font-size: 26px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4)); }
.rcard .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; margin-top: 4px; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5); }
.rcard .cnt {
  position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; border-radius: 11px;
  background: #1a2d4a; color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; padding: 0 4px;
}
.rcard.zero { opacity: 0.35; }
.rcard.bump { animation: bump 0.5s ease; }
@keyframes bump { 40% { transform: translateY(-8px) scale(1.06); } }
.r-brick { background: linear-gradient(160deg, #d9703f, #a8401b); }
.r-lumber { background: linear-gradient(160deg, #3f9645, #1f5a24); }
.r-wool { background: linear-gradient(160deg, #a9db6a, #6ba32e); }
.r-grain { background: linear-gradient(160deg, #f4cf55, #c8941a); }
.r-ore { background: linear-gradient(160deg, #a6afba, #66707c); }

.dcard {
  position: relative; width: 76px; height: 78px; border-radius: 6px; padding: 5px;
  border: 2px solid #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  background: linear-gradient(160deg, #f6ecd4, #e0caa0); color: #3b2a12;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  font-size: 10.5px; font-weight: 700; cursor: default;
}
.dcard .ico { font-size: 22px; }
.dcard.knight { border-color: #7d4ea8; }
.dcard.vp { border-color: #e08a1e; }
.dcard.progress { border-color: #2e8b57; }
.dcard.playable { cursor: pointer; box-shadow: 0 0 0 3px #ffd84a, 0 2px 4px rgba(0, 0, 0, 0.35); }
.dcard.playable:hover { transform: translateY(-3px); }
.dcard.new::after { content: 'NEW'; position: absolute; top: -7px; left: -6px; background: var(--red); color: #fff; font-size: 9px; padding: 1px 4px; border-radius: 4px; }

#build-bar { display: grid; grid-template-columns: repeat(2, minmax(150px, 1fr)); gap: 6px; }
.buildbtn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; border-radius: 6px; border: 1px solid var(--panel-border);
  background: #fff; cursor: pointer; font-weight: 700; font-size: 13px; color: var(--text);
}
.buildbtn:hover:not(:disabled) { border-color: var(--blue); background: #eef3fb; }
.buildbtn:disabled { opacity: 0.45; cursor: not-allowed; }
.buildbtn.active { background: #ffe9a8; border-color: #e0a400; }
.cost { display: inline-flex; gap: 2px; }
.mini { display: inline-flex; width: 18px; height: 22px; border-radius: 3px; align-items: center; justify-content: center; font-size: 12px; border: 1px solid rgba(255, 255, 255, 0.7); }

/* ---------- player panels ---------- */
.pboard { position: relative; padding: 8px 10px 8px 12px; }
.pboard.active { box-shadow: 0 0 0 3px #f2a33a, 0 1px 3px rgba(0, 0, 0, 0.2); }
.pboard.active::before {
  content: '▶'; position: absolute; left: -16px; top: 14px; color: #f2a33a; font-size: 14px;
  animation: nudge 1s ease-in-out infinite;
}
@keyframes nudge { 50% { transform: translateX(3px); } }
.phead { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #fff; border: 2px solid rgba(0, 0, 0, 0.25); flex-shrink: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.pname { font-weight: 700; font-size: 15px; text-shadow: 0 0 1px rgba(0, 0, 0, 0.25); }
.ptag { font-size: 11px; color: var(--muted); font-weight: 400; }
.pscore { margin-left: auto; font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 3px; }
.pscore .star { color: #f2a33a; }
.pscore .hidden { font-size: 11px; color: var(--muted); font-weight: 500; }
.pstats { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; font-size: 13px; }
.pstat { display: inline-flex; align-items: center; gap: 3px; }
.pstat .ic { font-size: 14px; }
.pieces { font-size: 11px; color: var(--muted); margin-top: 4px; }
.badges { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; background: #eee; color: #999; border: 1px solid #ddd; }
.badge.on { background: #fff4d6; color: #8a5a00; border-color: #e0a400; }
.pboard.flash { animation: flash 0.8s ease; }
@keyframes flash { 30% { background: #fff6cc; } }

/* ---------- dice & bank ---------- */
#dice-bank { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
#dice-box { display: flex; gap: 6px; align-items: center; }
.die { width: 40px; height: 40px; }
.die.rolling { animation: roll 0.5s ease-out; }
@keyframes roll { 0% { transform: rotate(-200deg) scale(0.6); } 100% { transform: rotate(0) scale(1); } }
.dice-sum { font-weight: 800; font-size: 20px; margin-left: 4px; }
#bank-box { font-size: 12px; display: grid; grid-template-columns: repeat(3, auto); gap: 2px 8px; }
#bank-box .bk { display: inline-flex; align-items: center; gap: 2px; }

/* ---------- log ---------- */
#log { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.logline { background: #fff; border-radius: 4px; padding: 4px 6px; font-size: 12.5px; line-height: 1.35; border-left: 3px solid #ddd; }
.logline.sys { background: transparent; border: 0; color: var(--muted); font-style: italic; text-align: center; }
.logname { font-weight: 700; }

/* ---------- modals ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 20, 35, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal {
  background: #fbf6ec; border-radius: 10px; border: 1px solid var(--panel-border);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
}
.modal h2 { margin: 0; padding: 12px 16px; font-family: 'Roboto Slab', serif; font-size: 18px; border-bottom: 1px solid var(--panel-border); background: rgba(255, 255, 255, 0.6); border-radius: 10px 10px 0 0; }
.modal .body { padding: 14px 16px; }
.modal .foot { padding: 10px 16px 14px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal p { margin: 0 0 10px; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 700; font-size: 13px; }
.field input, .field select { padding: 7px 8px; border-radius: 5px; border: 1px solid var(--panel-border); font-size: 14px; }
.picker { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.pick { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pick .rcard { width: 50px; height: 70px; cursor: pointer; }
.pick .ctrl { display: flex; align-items: center; gap: 4px; }
.pick .ctrl button { width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--panel-border); background: #fff; cursor: pointer; font-weight: 700; padding: 0; }
.pick .ctrl span { min-width: 16px; text-align: center; font-weight: 700; }
.row-label { font-weight: 700; font-size: 13px; }
.note { font-size: 12px; color: var(--muted); }
.responses { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.resp { display: flex; align-items: center; gap: 8px; background: #fff; padding: 6px 8px; border-radius: 6px; }
.resp .who { flex: 1; }
.rules-body h3 { margin: 12px 0 4px; font-size: 14px; }
.rules-body ul { margin: 0; padding-left: 18px; line-height: 1.5; }
.winner-big { font-size: 46px; text-align: center; }
.final-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.final-table td { padding: 4px 6px; border-bottom: 1px solid #eadfcb; }

/* ---------- online ---------- */
.hidden { display: none !important; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--panel-border); }
.tab { border: 0; background: transparent; padding: 8px 12px; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--blue-dark); border-bottom-color: var(--blue); }
.online-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.online-box { background: #fff; border: 1px solid var(--panel-border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; }
.online-box .btn { align-self: flex-start; margin-top: auto; }
.code { background: #2b2b2b; color: #e8e8e8; padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.room-code { font-size: 15px; margin-bottom: 8px; }
.room-code b { font-family: 'Roboto Slab', serif; font-size: 26px; letter-spacing: 4px; color: var(--blue-dark); margin-left: 6px; }
.invite { display: flex; gap: 6px; margin-bottom: 12px; }
.invite input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--panel-border); border-radius: 5px; font-size: 13px; }
.seats { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.seat { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 6px; padding: 7px 10px; border: 1px solid #eadfcb; }
.seat.open { color: var(--muted); border-style: dashed; background: transparent; }
.seat .dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.4); background: #ddd; }
.offer-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; background: #f3efe6; border-radius: 6px; padding: 4px 8px; }
#chat-form { display: none; margin-bottom: 6px; }
body.online #chat-form { display: block; }
#chat-input { width: 100%; padding: 6px 8px; border-radius: 5px; border: 1px solid var(--panel-border); font-size: 13px; }
.logline.chat { background: #eef3fb; border-left-color: var(--blue); }
body.online .speed { display: none; }
.toast { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); background: #1a2d4a; color: #fff; padding: 8px 14px; border-radius: 6px; z-index: 100; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); font-weight: 500; animation: toast 3.5s ease forwards; }
@keyframes toast { 0% { opacity: 0; } 8% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }

@media (max-width: 960px) {
  .online-grid { grid-template-columns: 1fr; }
  #game { flex-direction: column; padding: 8px 16px; }
  #right { width: 100%; position: static; }
  #page-title { margin: 8px 16px 0; font-size: 14px; }
  .build-section { margin-left: 0; }
  #build-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .speed { display: none; }
  .table-info { display: none; }
}
