/* Game-specific controls, flags, editor, and short event animations. */
:root {
  --ink: var(--theme-text, #372817);
  --sand: var(--theme-accent, #a56a29);
  --wine: var(--theme-danger, #a23c2e);
  --plum: #65526c;
  --coral: var(--wine);
  --lime: #8caa52;
  --teal: #43847e;
  --navy: #384c65;
  --blue: #4571a1;
  --sky: #669cc7;
  --cyan: #7bbfb9;
  --white: #fff9ea;
  --steel: var(--theme-muted, #6f604e);
  --slate: var(--theme-muted, #6f604e);
  --dusk: var(--theme-raised, #eadbc2);
  --num: var(--theme-ui-font, system-ui, sans-serif);
}
img.ui-icon { vertical-align: -.17em; display: inline-block; }
img.ui-icon.px { image-rendering: pixelated; }
img.illustrated-icon { image-rendering: auto; object-fit: contain; }
.event-badge img.illustrated-icon {
  width: max(16px, 1.16em);
  height: max(16px, 1.16em);
}
.game .log img.illustrated-icon {
  width: max(14px, 1.08em);
  height: max(14px, 1.08em);
}
/* ---------- kingdom flag editor ---------- */
.flag-modal { width: min(760px, 100%); }
.flag-layout { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: start; }
@media (max-width: 700px) { .flag-layout { grid-template-columns: 1fr; } }
.flag-grid { display: grid; grid-template-columns: repeat(12, 26px); grid-template-rows: repeat(12, 26px); box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--sand); width: max-content; touch-action: none; cursor: crosshair; margin: 8px 6px 14px; }
@media (max-width: 480px) { .flag-grid { grid-template-columns: repeat(12, 22px); grid-template-rows: repeat(12, 22px); } }
.flag-grid .fc { box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.flag-grid .fc:hover { box-shadow: inset 0 0 0 2px #fff; }
.flag-pal { display: grid; grid-template-columns: repeat(8, 30px); gap: 6px; margin: 6px 4px 10px; }
.sw { width: 30px; height: 30px; border: 1px solid var(--line); cursor: pointer; padding: 0; }
.sw.on { box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--sand); transform: translateY(-2px); }
.sw.big { width: 28px; height: 28px; margin: 3px; }
.castle-color { width: 44px !important; height: 34px; padding: 0 !important; margin: 3px; cursor: pointer; }
.flag-preview { background: var(--panel2); border-radius: var(--radius); display: grid; place-items: center; padding: 14px; }
img.flag-img { image-rendering: pixelated; box-shadow: 0 0 0 2px var(--ink); background: var(--ink); vertical-align: middle; }
.flag-btn { padding: 0 !important; width: 40px; height: 36px; display: grid; place-items: center; }
.pcard.retired { opacity: .45; filter: grayscale(.8); }
.pcard .conn { font-size: 11px; font-weight: 700; }
.pcard .conn.off { color: var(--coral); animation: blink 1s steps(2) infinite; }
.player-row { grid-template-columns: 36px 40px minmax(0, 1fr) 150px 36px; }

.kingdom-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.board-wrap .labels-3d { z-index: 1; }
.board-wrap .zoom-ctrl { z-index: 6; }

/* ---------- Gartic-like paint editor ---------- */
.paint { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: start; margin-top: 6px; }
.paint-tools { display: grid; gap: 6px; }
.ptool, .psize { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel2); color: var(--text); cursor: pointer; }
.ptool { font-size: 22px; }
.ptool.on, .psize.on { background: color-mix(in srgb, var(--panel2), var(--gold) 25%); border-color: var(--gold); }
.ptool:disabled { opacity: .35; cursor: default; }
.psep { height: 6px; width: 6px; }
.paint-stage { position: relative; aspect-ratio: 3 / 2; width: 100%; max-width: 480px; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; background: #fff; justify-self: center; }
.paint-canvas, .paint-ghost { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.paint-ghost { pointer-events: none; }
.paint-pal { display: grid; gap: 8px; justify-items: center; }
.pcur { width: 34px; height: 34px; border-radius: 3px; box-shadow: 0 0 0 2px var(--line); }
.pgrid { display: grid; grid-template-columns: repeat(2, 24px); gap: 5px; }
.pcol { width: 24px; height: 24px; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; padding: 0; }
.pcol.on { outline: 2px solid var(--gold); outline-offset: 1px; }
.paint-custom { width: 46px !important; height: 30px; padding: 0 !important; cursor: pointer; }
.paint-sizes { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 16px 0 6px; flex-wrap: wrap; }
.psize { display: grid; place-items: center; }
.psize i { display: block; border-radius: 50% !important; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.flag-bottom { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; margin-top: 8px; }
@media (max-width: 700px) {
  .paint, .flag-bottom { grid-template-columns: minmax(0, 1fr); }
  .paint-tools, .paint-pal { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; }
  .paint-tools .psep { display: none; }
  .pgrid { order: 1; width: min(100%, 340px); grid-template-columns: repeat(auto-fit, minmax(26px, 1fr)); justify-items: center; }
  .pcol { width: 26px; height: 26px; }
}
img.flag-img.pixel { image-rendering: pixelated; }
img.flag-img:not(.pixel) { image-rendering: auto; }

/* ================= online hub ================= */
.online-hub { position: relative; min-height: 100vh; min-height: 100dvh; overflow: hidden; }
.hub-inner { position: relative; max-width: 1180px; margin: 0 auto; padding: 18px 16px 30px; }
.hub-head { display: flex; gap: 16px; align-items: center; margin-bottom: 8px; }
.hub-head h2 { font-size: clamp(24px, 4vw, 40px); color: var(--sand); text-shadow: 0 4px 0 var(--wine), 0 8px 0 var(--ink); }
.hub-sub { color: var(--steel); font-size: 15px; margin-top: 6px; text-shadow: 2px 2px 0 var(--ink); }
.hub-grid { display: grid; grid-template-columns: 1.05fr 1fr 1fr; gap: 6px; align-items: stretch; }
@media (max-width: 1000px) { .hub-grid { grid-template-columns: 1fr 1fr; } .kingdom-card { grid-column: 1 / -1; } }
@media (max-width: 680px) { .hub-grid { grid-template-columns: 1fr; } }
.hub-card { display: flex; flex-direction: column; gap: 10px; }
.hub-card p { color: var(--steel); margin: 0; line-height: 1.4; }
.hub-card > .btn.big { margin-top: auto; }
.kingdom-hero { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.kingdom-info { flex: 1; min-width: 160px; display: grid; gap: 6px; }
.hub-name { font-size: 20px !important; padding: 10px 12px !important; }
.castle-line { display: flex; gap: 10px; align-items: center; color: var(--steel); }
.castle-line .swatch { width: 24px; height: 24px; }
.hub-flag { position: relative; width: 130px; height: 120px; flex: none; }
.hub-flag .pole { position: absolute; left: 10px; top: 0; bottom: 0; width: 6px; background: #6b4a2f; box-shadow: 0 0 0 2px var(--ink); }
.hub-flag .pole::before { content: ""; position: absolute; left: -4px; top: -8px; width: 14px; height: 14px; background: var(--sand); box-shadow: 0 0 0 2px var(--ink); border-radius: 50% !important; }
.hub-flag img { position: absolute; left: 16px; top: 8px; }
.hub-flag.small { width: 76px; height: 64px; }
.hub-flag.small .pole { left: 6px; width: 4px; }
.hub-flag.small img { left: 10px; top: 4px; }
img.flag-img.wave {  transform-origin: left center; }
@keyframes flagWave { 0%,100% { transform: skewY(0deg) scaleX(1); } 25% { transform: skewY(2deg) scaleX(.97); } 50% { transform: skewY(0deg) scaleX(1); } 75% { transform: skewY(-2deg) scaleX(.98); } }
.cap-row { display: flex; gap: 6px; flex-wrap: wrap; }
.cap { width: 40px; height: 40px; font-family: var(--num); font-size: 18px; cursor: pointer; }
.cap-people { display: flex; gap: 4px; flex-wrap: wrap; min-height: 26px; }
.cap-people span { font-size: 20px; }
.pins { display: flex; gap: 8px; justify-content: center; }
.pin { width: 52px !important; height: 62px; text-align: center; font-family: var(--num) !important; font-size: 30px !important; text-transform: uppercase; padding: 0 !important; }
@media (max-width: 420px) { .pin { width: 44px !important; height: 54px; font-size: 24px !important; } }
.hub-status { min-height: 28px; text-align: center; font-weight: 600; margin-top: 4px; text-shadow: 2px 2px 0 var(--ink); }
.hub-tips { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.hub-tips span { background: rgba(26,28,44,.85); padding: 6px 12px; box-shadow: 0 0 0 2px var(--dusk); color: var(--steel); font-size: 14px; }
/* waiting room (guest) */
.waiting-card { max-width: 820px; margin: 10px auto 0; }
.waiting-msg { color: var(--sand) !important; font-size: 18px; }
.room-code.inline { display: inline-block; font-size: 26px; letter-spacing: 6px; padding: 2px 12px; margin: 0 8px; }
.room-state { font-family: var(--font); font-size: 13px; padding: 3px 8px; margin-left: 6px; vertical-align: middle; border-radius: var(--radius); }
.room-state.on { background: color-mix(in srgb, var(--panel2), var(--green) 17%); color: var(--text); }
.room-state.off { background: color-mix(in srgb, var(--panel2), var(--red) 17%); color: var(--text); }
.seat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.seat { background: var(--panel2); border-radius: var(--radius); padding: 10px; display: grid; justify-items: center; gap: 4px; text-align: center; }
.seat.host, .seat.me { background: color-mix(in srgb, var(--panel2), var(--gold) 15%); }
.seat small { color: var(--steel); }
.seat.empty { opacity: .55; }
.seat-q { width: 60px; height: 60px; display: grid; place-items: center; font-family: var(--num); font-size: 30px; color: var(--slate); }
/* host room card */
.room-card .room-code { font-size: 46px; }
.room-share { justify-content: center; }
.room-toggles { margin-top: 4px; }
.guest-list { display: grid; gap: 6px; }
.guest { display: flex; gap: 10px; align-items: center; background: var(--panel2); border-radius: var(--radius); padding: 6px 10px; }
.guest b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guest.host { background: color-mix(in srgb, var(--panel2), var(--gold) 15%); }
.guest.empty { color: var(--steel); font-size: 14px; opacity: .8; }
.guest .kick { padding: 2px 8px !important; }
.close-room { margin-top: 12px; align-self: flex-start; }
.seat-name { background: var(--ink); box-shadow: inset 0 0 0 3px var(--dusk); padding: 9px 10px; color: var(--steel); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-name.taken { color: var(--lime); box-shadow: inset 0 0 0 3px #1d5a38; }

/* ================= design audit fixes ================= */
/* Keep dialogs within the viewport. */
.modal { width: min(560px, calc(100vw - 40px)); margin: 12px; }
.flag-modal { width: min(820px, calc(100vw - 40px)); }
@media (max-width: 600px) {
  .card { margin: 10px 10px 22px; padding: 12px; }
  .modal { padding: 16px; max-height: 88vh; }
  .modal h2 { font-size: 20px; }
  /* player rows: the name keeps its space, the selector goes below */
  .player-row { grid-template-columns: 36px 40px minmax(0, 1fr) 36px; }
  .player-row > select, .player-row > .pill { grid-column: 1 / -1; }
  .lobby-head h2 { font-size: 22px; }
  /* compact action buttons */
  .actions .btn { padding: 7px 9px; font-size: 13px; margin: 2px; }
  .actionbar { gap: 6px; }
  .hand .rcard { width: 38px; height: 50px; }
}
/* lobby modes: wider cards, flagship ones take two columns */
.modes { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
@media (min-width: 760px) { .mode.flag { grid-column: span 2; } }
.mode small { font-size: 13px; line-height: 1.35; }
.mode b { font-size: 15px; margin-bottom: 3px; }
/* map editor polish */
.editor-side { background: var(--panel); }
.editor .board-wrap { background: radial-gradient(ellipse at center, #1f4f6e 0%, #122b40 60%, #0b1624 100%); }
.slot { fill: rgba(255,255,255,.035); stroke: rgba(148,176,194,.25); }
.brush { background: var(--dusk); border: 1px solid transparent; }
.brush.on { background: color-mix(in srgb, var(--panel2), var(--gold) 25%); border-color: var(--gold); }
/* help: easier reading */
.help-body li { line-height: 1.45; margin-bottom: 6px; }
.help-body h3 { margin-top: 18px; }
.waiting-card h3, .room-card h3 { flex-wrap: wrap; row-gap: 8px; }
.room-card .room-code { margin-bottom: 14px; }
.player-row select { text-overflow: ellipsis; }
@media (max-width: 600px) {
  .player-row > select, .player-row > .pill { order: 10; }
  .modal .btn { white-space: normal; text-align: center; line-height: 1.25; }
  .hub-head { flex-wrap: wrap; }
}

/* ---------- resources flying from the tiles to the hands ---------- */
.fly-res { position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none; will-change: transform, opacity; filter: drop-shadow(3px 3px 0 var(--ink)); }
.fly-res img.ui-icon { width: 34px; height: 34px; display: block; }
.fly-res:not(.mine) img.ui-icon { width: 26px; height: 26px; }
/* a stolen card that you're not part of: you only see its back */
.fly-back { display: block; width: 22px; height: 30px; background: repeating-linear-gradient(45deg, var(--pc, #5d275d) 0 4px, #29366f 4px 8px); box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--ink); }
/* where the cards land: player cards and the bank counters give a little hop */
.pcard.bump { animation: bumpSm .45s; }
.bank-info > .bump { animation: bump .45s; }
@keyframes bumpSm { 40% { transform: translateY(-4px) scale(1.03) } }


/* settlement spots on a port corner carry an anchor badge */
.hot3d.v.port { position: relative; }
.hot3d.v.port::after { content: '⚓'; position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -3px); font-size: 12px; line-height: 1; padding: 1px 2px; background: var(--white); box-shadow: 0 0 0 2px var(--ink); pointer-events: none; }

/* the dice button: hold it and the bar fills with throwing power */
.roll-btn { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.roll-btn > span { position: relative; z-index: 1; }
.roll-fill { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--charge, 0) * 100%); background: repeating-linear-gradient(90deg, #f08a3a 0 8px, #e86a2a 8px 16px); opacity: 0; }
.roll-btn.charging .roll-fill { opacity: 1; }
.roll-btn.charging { animation: rollShake .12s steps(2) infinite; }
.roll-btn.full .roll-fill { background: repeating-linear-gradient(90deg, #e04040 0 8px, #b13e53 8px 16px); }
.roll-btn.full { animation-duration: .06s; }
@keyframes rollShake { 0% { transform: translate(-1px, 0); } 50% { transform: translate(1px, -1px); } 100% { transform: translate(-1px, 1px); } }

/* Dice history is newest first, with a marker in the thrower's colour. */
.roll-chip {
  flex: none;
  width: 28px;
  height: 24px;
  display: grid;
  place-items: center;
  font: 700 14px var(--num);
  border-inline-start: 3px solid var(--pc);
  border-radius: 3px;
  background: var(--panel2);
  color: var(--text);
}
.roll-chip.newest { width: 32px; height: 28px; font-size: 16px; background: color-mix(in srgb, var(--panel2), var(--gold) 12%); }
.roll-chip.seven { color: var(--red); }
@media (max-width: 720px) { .roll-chip { width: 24px; height: 20px; font-size: 12px; } }
