/* Family board-game look: a wooden table, a mint game board, cream cardboard panels, candy buttons */
:root {
  --wood-a: #e2b077;
  --wood-b: #cf975a;
  --board-a: #a6e0c4;
  --board-b: #7fcaa6;
  --rev-a: #f7c1d0;
  --rev-b: #e796b4;
  --cream: #fffaf0;
  --card: #fff3df;
  --line: #5a3e2b;
  --ink: #4a3426;
  --muted: #8a7462;
  --on-board: #24503e;
  --coral: #ff7a59;
  --coral-d: #d9573a;
  --sun: #ffc93c;
  --sun-d: #e0a400;
  --sky: #5aa9e6;
  --sky-d: #3b86c2;
  --leaf: #5cc28a;
  --leaf-d: #3e9c69;
  --ui: "Segoe UI", "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --display: "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--ui);
  user-select: none;
  /* Wooden table planks */
  background:
    repeating-linear-gradient(180deg, rgb(0 0 0 / 0%) 0 118px, rgb(110 60 20 / 22%) 118px 121px),
    repeating-linear-gradient(90deg, rgb(255 255 255 / 4%) 0 3px, rgb(0 0 0 / 3%) 3px 9px),
    linear-gradient(180deg, var(--wood-a), var(--wood-b));
}

/* The game board lying on the table */
#felt {
  position: fixed;
  inset: 20px 20px 28px;
  border-radius: 36px;
  background:
    radial-gradient(circle, rgb(255 255 255 / 22%) 2.5px, transparent 3px) 0 0 / 34px 34px,
    radial-gradient(ellipse at 50% 42%, var(--board-a) 0%, var(--board-b) 85%);
  box-shadow:
    0 0 0 10px var(--cream),
    0 8px 0 10px #e3cca3,
    0 16px 28px 10px rgb(80 40 10 / 35%);
}
/* Revolution: the board blushes pink */
#felt::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle, rgb(255 255 255 / 25%) 2.5px, transparent 3px) 0 0 / 34px 34px,
    radial-gradient(ellipse at 50% 42%, var(--rev-a) 0%, var(--rev-b) 85%);
  opacity: 0;
  transition: opacity 0.6s ease;
}
body.revolution #felt::before { opacity: 1; }
/* A dashed "track" printed around the board edge */
#felt::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 26px;
  border: 4px dashed rgb(255 255 255 / 65%);
  pointer-events: none;
}

/* Play area printed in the middle of the board */
#fieldMark {
  position: fixed;
  transform: translate(-50%, -50%);
  border: 3px dashed rgb(255 255 255 / 85%);
  border-radius: 28px;
  background: rgb(255 255 255 / 22%);
  pointer-events: none;
}
#fieldMark span {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 14px;
  border-radius: 999px;
  background: var(--cream);
  border: 2px solid var(--line);
  font-family: var(--display);
  font-size: 13px;
  white-space: nowrap;
  color: var(--ink);
  box-shadow: 0 3px 0 rgb(90 62 43 / 25%);
  transition: color 0.2s, background 0.2s;
}
#fieldMark span.held.cut { background: #c9f5e6; color: #11624c; }
#fieldMark span.held.clear { background: #e3f1ff; color: #28608f; }
#discardMark {
  position: fixed;
  transform: translate(-50%, 0);
  padding: 1px 10px;
  border-radius: 999px;
  background: rgb(255 250 240 / 80%);
  font-size: 12px;
  font-weight: 700;
  color: #3d4a44;
  pointer-events: none;
  white-space: nowrap;
}

#table {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

/* Candy buttons: chunky, rounded, with a pressable bottom edge */
button {
  font-family: var(--display);
  font-size: 15px;
  border-radius: 999px;
  padding: 8px 20px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s, background 0.15s, box-shadow 0.1s;
}
button:active:not(:disabled) { transform: translateY(2px); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary {
  background: var(--coral);
  color: #fff;
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 var(--coral-d);
  font-weight: 700;
  min-width: 96px;
}
button.primary:active:not(:disabled) { box-shadow: 0 2px 0 var(--coral-d); }
button.ghost {
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 #d9c4a0;
}
button.ghost:active:not(:disabled) { box-shadow: 0 2px 0 #d9c4a0; }
button.small { font-size: 13px; padding: 6px 12px; white-space: nowrap; }
button.small.off { color: var(--muted); }

/* Top bar: strength ladder + round + rules */
#topbar {
  position: fixed;
  top: 26px;
  left: 34px;
  right: 34px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#ladder {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 16px;
  background: var(--cream);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 rgb(90 62 43 / 25%);
}
#ladder.flip { animation: ladderFlip 0.5s ease; }
@keyframes ladderFlip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
.ladder-end { font-size: 11px; font-weight: 700; color: var(--muted); }
#ladderChips { display: flex; gap: 3px; }
.chip {
  min-width: 24px;
  height: 26px;
  padding: 0 4px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  background: #fff;
  border: 1.5px solid #e3cca3;
  color: var(--ink);
  transition: opacity 0.2s;
}
.chip.eight { box-shadow: inset 0 -3px 0 var(--coral); }
.chip.joker { background: var(--sun); border-color: var(--sun-d); font-size: 11px; }
.chip.weaker { opacity: 0.3; }
.chip.current { outline: 2px solid var(--coral); outline-offset: 1px; opacity: 0.6; }
.chip.beats { background: #fff3c4; border-color: var(--sun-d); box-shadow: 0 0 0 1px var(--sun); }
#revBadge {
  margin-left: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #e2559a;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}
#revBadge[hidden] { display: none; }
.top-right { display: flex; align-items: center; gap: 12px; }
#roundLabel {
  font-family: var(--display);
  font-size: 15px;
  color: var(--ink);
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--sun);
  border: 2px solid var(--line);
}

/* Player tokens: animal face + name card */
.plate {
  position: fixed;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 8px;
  /* Every token is the same size, whatever its text (keep in sync with PLATE_W in layout.js) */
  width: 184px;
  height: 60px;
  padding: 5px 14px 5px 5px;
  white-space: nowrap;
  border-radius: 999px;
  text-align: left;
  background: var(--cream);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 rgb(90 62 43 / 30%);
  pointer-events: none;
  transition: box-shadow 0.2s, background 0.2s, transform 0.2s;
  z-index: 5;
}
.plate.active {
  background: #fff3c4;
  box-shadow: 0 4px 0 var(--sun-d), 0 0 0 4px rgb(255 201 60 / 55%);
  transform: translate(-50%, -50%) scale(1.07);
}
.plate.active::before {
  content: "▼";
  position: absolute;
  top: -20px;
  left: 29px;
  transform: translateX(-50%);
  color: var(--coral);
  font-size: 14px;
  text-shadow: 0 2px 0 var(--cream);
  animation: bob 0.9s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translate(-50%, -4px); } }
.plate.active .plate-avatar { animation: hop 0.9s ease-in-out infinite; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-4px) rotate(-6deg); } }
.plate-body { display: flex; flex-direction: column; align-items: flex-start; flex: 1; min-width: 0; }
.plate-name, .plate-count { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.plate-name { font-family: var(--display); font-weight: 700; font-size: 16px; line-height: 1.25; color: var(--ink); }
.plate-count { font-size: 13px; font-weight: 600; color: #6e5848; line-height: 1.35; }
/* Status badge ("Pass", "1st Tycoon") sits on the token's bottom edge so every token stays two lines */
.plate-tag {
  position: absolute;
  right: 10px;
  bottom: -12px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  border-radius: 999px;
  padding: 0 9px;
  border: 2px solid var(--line);
}
.plate-tag[hidden] { display: none; }
.plate-tag.pass { background: #e6ddd0; color: var(--muted); }
.plate-tag.done { background: var(--sun); color: var(--ink); }

/* Round animal faces (plates, lobby, results, title) */
.avatar {
  display: inline-block;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--line);
  background: #fff;
  line-height: 0;
}
.avatar svg { width: 100%; height: 100%; display: block; }
.plate-avatar { width: 44px; height: 44px; }
.avatar.mini { width: 26px; height: 26px; border-width: 1.5px; vertical-align: middle; margin-right: 8px; }

/* Log under the field */
#log {
  position: fixed;
  transform: translate(-50%, 0);
  width: min(520px, 80vw);
  text-align: center;
  pointer-events: none;
  z-index: 4;
}
/* Every line sits on its own cream strip so it reads clearly on the board; older lines are smaller and paler */
.log-line {
  width: fit-content;
  max-width: 100%;
  margin: 3px auto;
  padding: 1px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
  color: #3d4a44;
  background: rgb(255 250 240 / 62%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-line.newest {
  font-size: 15px;
  padding: 2px 14px;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 rgb(90 62 43 / 22%);
}
.log-line.rev { color: #a3215c; }
.log-line.flow { color: #17607a; }
.log-line.finish { color: #8a5600; }

/* Hint + buttons above the hand */
#actionBar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 8px 8px 18px;
  border-radius: 999px;
  background: var(--cream);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 rgb(90 62 43 / 25%);
  z-index: 6;
  max-width: calc(100vw - 260px);
}
#actionBar[hidden] { display: none; }
#actionBar.my-turn { background: #fff3c4; box-shadow: 0 4px 0 var(--sun-d), 0 0 0 4px rgb(255 201 60 / 50%); }
#hint { font-size: 14px; font-weight: 600; color: var(--muted); }
#actionBar.my-turn #hint { color: var(--ink); }
#hint.ok { color: #2e8b57 !important; }
#hint.warn { color: var(--coral-d) !important; }
.buttons { display: flex; gap: 8px; flex-shrink: 0; }
.buttons button[hidden] { display: none; }

/* Event banner: big bubbly sticker text */
#banner {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  z-index: 15;
  opacity: 0;
}
#banner.show { animation: bannerIn 1.5s ease forwards; }
.banner-main {
  font-family: var(--display);
  font-weight: 700;
  font-size: 64px;
  letter-spacing: 0.04em;
  color: #fff;
  -webkit-text-stroke: 3px var(--line);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--coral);
  white-space: nowrap;
}
.banner-sub {
  margin-top: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--line);
  padding: 4px 16px;
  border-radius: 999px;
  display: inline-block;
}
.banner-sub:empty { display: none; }
#banner.rev .banner-main { color: #ffe0ef; text-shadow: 0 6px 0 #e2559a; }
#banner.cut .banner-main { color: #e9fff8; text-shadow: 0 6px 0 #2bb38d; }
#banner.round .banner-main { font-size: 44px; text-shadow: 0 5px 0 var(--sky); }
#banner.finish .banner-main { color: #fff6cc; text-shadow: 0 6px 0 var(--sun-d); }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  20% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(0.98); }
}

/* Panels: cream cardboard */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgb(60 35 15 / 45%);
}
.overlay[hidden] { display: none; }
.panel {
  width: min(540px, 92vw);
  max-height: 84vh;
  overflow-y: auto;
  padding: 22px 28px;
  border-radius: 24px;
  background: var(--cream);
  border: 3px solid var(--line);
  box-shadow: 0 8px 0 #d9c4a0, 0 18px 40px rgb(60 30 10 / 35%);
  color: var(--ink);
  line-height: 1.75;
  user-select: text;
}
.panel h2 { margin: 0 0 8px; font-family: var(--display); color: var(--coral-d); }
.panel h3 { margin: 14px 0 2px; font-size: 15px; font-family: var(--display); color: var(--sky-d); }
.panel ul { margin: 0; padding-left: 20px; }
.panel button { margin-top: 16px; }
#resultHead { font-size: 18px; font-weight: 700; margin: 4px 0 10px; }
#resultTable { width: 100%; border-collapse: collapse; }
#resultTable th { font-size: 12px; font-weight: 400; color: var(--muted); text-align: left; padding: 0 8px 4px; }
#resultTable td { padding: 8px; }
#resultBody tr:nth-child(odd) td { background: rgb(227 204 163 / 22%); }
#resultBody tr.me td { background: #fff3c4; }
#resultBody tr.me td:first-child { box-shadow: inset 4px 0 0 var(--sun); }
.res-place { color: var(--muted); white-space: nowrap; }
.res-title { font-weight: 700; white-space: nowrap; }
.res-name { font-weight: 700; white-space: nowrap; }
.res-tag {
  margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; background: var(--coral); color: #fff;
}
.res-move { font-size: 12px; color: var(--muted); }
.res-move.up { color: #2e8b57; }
.res-move.down { color: var(--coral-d); }
.res-pts { color: #a86b00; font-weight: 700; }
.res-total { font-weight: 700; white-space: nowrap; }
.res-hist { white-space: nowrap; }
.hist-chip {
  width: 24px; height: 24px; display: inline-grid; place-items: center;
  margin-right: 4px;
  border-radius: 8px; font-size: 13px; font-weight: 700;
  background: #ece2d2; color: var(--muted);
}
#resultNote { white-space: pre-line; color: var(--muted); font-size: 14px; margin: 14px 0 0; }

/* Rank colours shared by plates, results and history chips */
.r1 { color: #c98a00; }
.r2 { color: #8a6a4a; }
.r3 { color: #5f7894; }
.r4 { color: var(--coral-d); }
.hist-chip.r1 { background: var(--sun); color: var(--ink); }
.hist-chip.r2 { background: #f1dfc0; color: var(--ink); }

/* Rank badge (last round's title) on the token's top edge, so it never adds a line */
.plate-rank {
  position: absolute;
  top: -11px;
  left: 54px;
  padding: 0 8px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.5;
}
.plate-rank.r1 { background: var(--sun); color: var(--ink); }
.plate-rank[hidden] { display: none; }
.plate-tag.fallen { background: var(--coral); color: #fff; }

/* AI speech bubbles, attached to the nameplate */
.bubble {
  position: absolute;
  top: 50%;
  width: max-content;
  max-width: 220px;
  padding: 7px 12px;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 4px 0 rgb(90 62 43 / 25%);
  z-index: 8;
}
.bubble[hidden] { display: none; }
.bubble::after {
  content: "";
  position: absolute;
  top: 50%;
  border: 7px solid transparent;
  transform: translateY(-50%);
}
.plate[data-side="left"] .bubble, .plate[data-side="top"] .bubble { left: calc(100% + 12px); transform: translateY(-50%); }
.plate[data-side="left"] .bubble::after, .plate[data-side="top"] .bubble::after { right: 100%; border-right-color: var(--line); }
.plate[data-side="right"] .bubble { right: calc(100% + 12px); transform: translateY(-50%); }
.plate[data-side="right"] .bubble::after { left: 100%; border-left-color: var(--line); }
.bubble.pop { animation: bubblePop 0.22s ease-out; }
@keyframes bubblePop {
  from { opacity: 0; scale: 0.85; }
  to { opacity: 1; scale: 1; }
}

/* Card exchange panel, shown on the empty field */
#exchangePanel {
  position: fixed;
  transform: translate(-50%, -50%);
  min-width: 340px;
  padding: 12px 18px;
  border-radius: 20px;
  background: var(--cream);
  border: 2px solid var(--line);
  box-shadow: 0 5px 0 rgb(90 62 43 / 25%);
  pointer-events: none;
  z-index: 4;
}
#exchangePanel[hidden] { display: none; }
.ex-title { font-family: var(--display); color: var(--coral-d); font-size: 16px; text-align: center; margin-bottom: 6px; }
#exchangeSteps { list-style: none; margin: 0; padding: 0; }
#exchangeSteps li {
  display: grid;
  grid-template-columns: 1fr auto 44px;
  gap: 12px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--muted);
}
#exchangeSteps li.now { color: var(--ink); font-weight: 700; background: #fff3c4; }
#exchangeSteps li.done { opacity: 0.6; }
.ex-what { font-size: 12px; }
.ex-status { text-align: right; color: var(--leaf-d); font-weight: 700; }

/* ---- Special-rule effects ---- */
/* Revolution: a pink flash over the whole table, and the table shakes */
#fx {
  position: fixed;
  inset: 0;
  z-index: 14;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 45%, rgb(255 180 210 / 75%) 0%, rgb(226 85 154 / 40%) 35%, rgb(226 85 154 / 0%) 75%);
}
#fx.rev { animation: revFlash 0.75s ease-out 0.15s; }
@keyframes revFlash {
  0% { opacity: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; }
}
body.shake #felt, body.shake #table { animation: shake 0.36s ease-in-out 0.15s; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-7px, 2px); }
  40% { transform: translate(6px, -3px); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(2px, -1px); }
}

/* Eight Cut: a white-and-teal swish across the field */
#slash {
  position: fixed;
  width: 0;
  height: 0;
  z-index: 13;
  pointer-events: none;
}
#slash::before {
  content: "";
  position: absolute;
  left: calc(var(--len, 300px) / -2);
  top: -4px;
  width: var(--len, 300px);
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgb(43 179 141 / 0%), #fff 45%, #2bb38d 60%, rgb(43 179 141 / 0%));
  box-shadow: 0 0 14px #fff;
  transform: rotate(-24deg) scaleX(0);
  opacity: 0;
}
#slash.go::before { animation: slashIn 0.5s ease-out 0.2s; }
@keyframes slashIn {
  0% { transform: rotate(-24deg) scaleX(0); opacity: 1; transform-origin: left center; }
  45% { transform: rotate(-24deg) scaleX(1); opacity: 1; transform-origin: left center; }
  100% { transform: rotate(-24deg) scaleX(1); opacity: 0; transform-origin: left center; }
}

/* ---- Tips ---- */
.coach {
  position: fixed;
  z-index: 12;
  width: min(360px, calc(100vw - 40px));
  padding: 10px 14px 10px 16px;
  border-radius: 16px;
  border: 2px solid var(--line);
  border-left: 7px solid var(--sky);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 5px 0 rgb(90 62 43 / 25%), 0 10px 24px rgb(60 30 10 / 25%);
}
.coach[hidden] { display: none; }
.coach.top { top: 82px; left: 34px; }
.coach.bar { left: 50%; transform: translateX(-50%); }
.coach::after {
  content: "";
  position: absolute;
  border: 8px solid transparent;
}
.coach.top::after { bottom: 100%; left: 40px; border-bottom-color: var(--line); }
.coach.bar::after { top: 100%; left: 50%; margin-left: -8px; border-top-color: var(--line); }
.coach.pop { animation: coachPop 0.24s ease-out; }
.coach.bar.pop { animation: coachPopBar 0.24s ease-out; }
@keyframes coachPop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes coachPopBar { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translateX(-50%); } }
.coach-tag { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; color: var(--sky-d); }
.coach-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }
.coach-actions button { padding: 4px 12px; font-size: 12px; }
.coach-off { background: transparent; color: var(--muted); border: none; }
.coach-ok { background: var(--sky); color: #fff; border: 2px solid var(--line); box-shadow: 0 3px 0 var(--sky-d); }

/* Welcome panel and tips toggle */
.welcome-panel { max-width: 560px; }
#welcomeLead { margin: 0 0 8px; font-size: 16px; }
#welcomeList { margin: 0 0 12px; padding-left: 22px; }
#welcomeList li { margin-bottom: 6px; }
.welcome-buttons { display: flex; justify-content: flex-end; gap: 10px; }
/* Round icon buttons (gear, globe) */
button.gear {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 #d9c4a0;
  flex-shrink: 0;
}
button.gear svg { width: 22px; height: 22px; transition: transform 0.3s ease; }
button.gear:hover svg { transform: rotate(45deg); }
button.gear.lang-btn:hover svg { transform: none; }
button.gear.lang-btn svg { width: 21px; height: 21px; }
.top-right .lang-btn { margin-right: -4px; }

/* Language list under the globe button */
.lang-menu {
  position: fixed;
  z-index: 45;
  display: flex;
  flex-direction: column;
  min-width: 132px;
  padding: 6px;
  border-radius: 14px;
  background: var(--cream);
  border: 2px solid var(--line);
  box-shadow: 0 5px 0 rgb(90 62 43 / 25%);
}
.lang-menu[hidden] { display: none; }
.lang-menu button {
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
}
.lang-menu button:hover { background: #fff3c4; }
.lang-menu button.on { color: var(--coral-d); font-weight: 700; }
.lang-menu button.on::after { content: ' ✓'; }

/* Title screen: the box lid of the game, sitting on the table */
.title-screen {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  overflow-y: auto;
  background:
    repeating-linear-gradient(180deg, rgb(0 0 0 / 0%) 0 118px, rgb(110 60 20 / 22%) 118px 121px),
    repeating-linear-gradient(90deg, rgb(255 255 255 / 4%) 0 3px, rgb(0 0 0 / 3%) 3px 9px),
    linear-gradient(180deg, var(--wood-a), var(--wood-b));
}
.title-screen[hidden] { display: none; }
#titleSettingsBtn { position: fixed; top: 22px; right: 28px; z-index: 1; }
#titleLangBtn { position: fixed; top: 22px; right: 80px; z-index: 1; }
.title-box {
  position: relative;
  margin: auto;
  width: min(500px, 90vw);
  padding: 28px 30px 26px;
  text-align: center;
  border-radius: 32px;
  background:
    radial-gradient(circle, rgb(255 255 255 / 25%) 2.5px, transparent 3px) 0 0 / 30px 30px,
    linear-gradient(180deg, var(--board-a), var(--board-b));
  border: 3px solid var(--line);
  box-shadow: 0 0 0 8px var(--cream), 0 8px 0 8px #e3cca3, 0 18px 36px 8px rgb(80 40 10 / 35%);
}
.title-animals { display: flex; justify-content: center; gap: 10px; }
.title-avatar { width: 54px; height: 54px; border-width: 2.5px; animation: hop 1.8s ease-in-out infinite; }
.title-avatar:nth-child(2) { animation-delay: 0.2s; }
.title-avatar:nth-child(3) { animation-delay: 0.4s; }
.title-avatar:nth-child(4) { animation-delay: 0.6s; }
.title-badge {
  display: inline-block;
  margin-top: 14px;
  padding: 3px 14px;
  border: 2px dashed var(--line);
  border-radius: 999px;
  background: rgb(255 250 240 / 70%);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--ink);
}
.title-box h1 {
  margin: 10px 0 0;
  font-family: var(--display);
  font-size: clamp(34px, 6.5vw, 54px);
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: #fff;
  -webkit-text-stroke: 3px var(--line);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--coral);
}
.title-sub { margin-top: 8px; font-family: var(--display); font-size: 17px; color: var(--on-board); letter-spacing: 0.06em; }
.title-lead { margin: 10px auto 20px; font-size: 14px; line-height: 1.7; color: var(--on-board); }
.title-modes { display: flex; flex-direction: column; gap: 12px; }
button.mode-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 24px;
  border-radius: 20px;
  text-align: left;
  background: var(--leaf);
  color: #fff;
  border: 2.5px solid var(--line);
  box-shadow: 0 5px 0 var(--leaf-d);
}
button.mode-btn:hover { filter: brightness(1.05); }
button.mode-btn:active { box-shadow: 0 2px 0 var(--leaf-d); }
button.mode-tutorial { background: var(--sky); box-shadow: 0 5px 0 var(--sky-d); }
button.mode-tutorial:active { box-shadow: 0 2px 0 var(--sky-d); }
button.mode-single { background: var(--coral); box-shadow: 0 5px 0 var(--coral-d); }
button.mode-single:active { box-shadow: 0 2px 0 var(--coral-d); }
button.mode-analytics { background: #a98bdb; box-shadow: 0 5px 0 #7d61b5; }
button.mode-analytics:active { box-shadow: 0 2px 0 #7d61b5; }
.mode-label { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; text-shadow: 0 2px 0 rgb(0 0 0 / 15%); }
.mode-tag {
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--sun);
  color: var(--ink);
  text-shadow: none;
}
.mode-desc { font-family: var(--ui); font-size: 13px; color: rgb(255 255 255 / 92%); }
.title-msg {
  margin-top: 14px;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  background: var(--cream);
  border: 2px solid var(--line);
  color: var(--ink);
}
.title-msg[hidden] { display: none; }
.title-note { margin: 18px 0 0; font-size: 12px; color: rgb(36 80 62 / 80%); }
/* Short windows: tighten the spacing so everything fits without scrolling */
@media (max-height: 760px) {
  .title-box { padding: 18px 26px; }
  .title-avatar { width: 44px; height: 44px; }
  .title-badge { margin-top: 8px; }
  .title-lead { margin: 6px auto 14px; }
  .title-modes { gap: 10px; }
  button.mode-btn { padding: 7px 24px; }
  .mode-label { font-size: 17px; }
  .title-note { margin-top: 12px; }
}

/* Multiplayer lobby (inside the title screen) */
.title-box[hidden] { display: none; }
.lobby-box { text-align: left; }
.lobby-box h2 {
  margin: 0 0 14px; text-align: center; font-family: var(--display); font-size: 30px; color: #fff;
  -webkit-text-stroke: 2.5px var(--line); paint-order: stroke fill; text-shadow: 0 4px 0 var(--coral);
}
.lobby-label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 700; color: var(--on-board); }
.lobby-input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.lobby-input:focus { outline: 3px solid var(--sun); }
.lobby-link { display: flex; gap: 8px; }
.lobby-link .lobby-input { font-size: 13px; color: var(--muted); }
.lobby-local { margin-top: 6px; font-size: 12px; color: var(--on-board); }
.lobby-local[hidden] { display: none; }
.lobby-seats { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 8px; }
.lobby-seats li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--cream);
  border: 2px solid var(--line);
}
.lobby-seats li.me { background: #fff3c4; box-shadow: 0 0 0 3px var(--sun); }
.lobby-seats li.cpu { opacity: 0.7; }
.seat-no { width: 18px; color: var(--muted); font-size: 13px; font-weight: 700; }
.seat-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-tag { padding: 1px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #ece2d2; color: var(--muted); }
.seat-tag.host { background: var(--sun); color: var(--ink); }
.lobby-status { min-height: 1.4em; margin: 14px 0 0; text-align: center; font-size: 13px; font-weight: 600; color: var(--on-board); }
.lobby-status.err { color: #b3261e; }
.lobby-buttons { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; }
.lobby-buttons button { flex: 1; }

/* Multiplayer in-game: CPU seats and connection trouble */
.plate.cpu .plate-name::after {
  content: 'CPU';
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 9px;
  vertical-align: 2px;
  background: #ece2d2;
  color: var(--muted);
}
#netBadge {
  color: #fff; font-size: 13px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; background: var(--coral); border: 2px solid var(--line);
}
#netBadge[hidden] { display: none; }

/* Settings window */
.settings-overlay { z-index: 40; }
.settings-panel { width: min(460px, 92vw); }
.set-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 2px dashed #e3cca3;
}
.set-row.off { opacity: 0.45; }
.set-label { font-size: 15px; font-weight: 600; }
.seg { display: flex; flex-shrink: 0; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.settings-panel .seg button {
  margin: 0;
  padding: 5px 14px;
  border: none;
  border-radius: 0;
  font-size: 13px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  box-shadow: none;
}
.settings-panel .seg button:active { transform: none; }
.settings-panel .seg button + button { border-left: 2px solid #e3cca3; }
.settings-panel .seg button.on { background: var(--sun); color: var(--ink); font-weight: 700; }
.set-range { display: flex; align-items: center; gap: 10px; }
.set-range input { width: 150px; accent-color: var(--coral); }
.set-value { width: 28px; text-align: right; font-size: 13px; color: var(--muted); }
.settings-game { margin-top: 4px; }
.settings-game[hidden] { display: none; }
.settings-buttons { display: flex; justify-content: flex-end; }

/* ---- Playtest analytics dashboard (over the title screen) ---- */
.dash-overlay { z-index: 30; }
.dash-panel {
  width: min(1120px, 96vw);
  max-height: 92vh;
  padding: 22px 26px 16px;
  line-height: 1.5;
  background:
    radial-gradient(circle, rgb(90 62 43 / 5%) 1.5px, transparent 2px) 0 0 / 22px 22px,
    var(--cream);
}
.dash-panel button { margin-top: 0; }
.dash-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dash-titles h2 { margin: 0; font-size: 26px; }
.dash-titles p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.dash-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dash-tools button.on { background: #efe4ff; }
.dash-filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0 6px; }
.dash-seg { display: flex; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.dash-seg button {
  border: 0; border-radius: 0; box-shadow: none; padding: 6px 14px; font-size: 13px;
  background: transparent; color: var(--ink);
}
.dash-seg button + button { border-left: 2px solid var(--line); }
.dash-seg button.on { background: var(--sun); font-weight: 700; }
.dash-seg button:active:not(:disabled) { transform: none; }
.dash-select {
  font: 13px var(--ui); padding: 6px 10px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; color: var(--ink); max-width: 100%;
}
.dash-count { font-size: 12px; color: var(--muted); }

.dash-sec { margin-top: 18px; }
.dash-h { margin: 0 !important; font-size: 18px !important; color: var(--ink) !important; }
.dash-hsub { margin: 2px 0 8px; font-size: 12.5px; color: var(--muted); }
.dash-sec > .dash-h + :not(.dash-hsub) { margin-top: 8px; }

.dash-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.dash-tiles.col { grid-template-columns: 1fr; min-width: 200px; align-content: start; }
.dash-tile {
  padding: 10px 14px; border-radius: 16px; background: #fff; border: 2px solid var(--line);
  box-shadow: 0 3px 0 #e3cca3;
}
.dash-tile-v { font: 700 26px var(--display); color: var(--coral-d); line-height: 1.2; }
.dash-tile-l { font-size: 12.5px; font-weight: 700; }
.dash-tile-s { font-size: 11px; color: var(--muted); }
.dash-tile.warn { background: #fff1e8; border-color: var(--coral-d); }

.dash-row { display: flex; gap: 12px; flex-wrap: wrap; }
.dash-row > .grow { flex: 1 1 380px; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.dash-stackcol { display: flex; flex-direction: column; gap: 12px; }
.dash-card {
  padding: 12px 14px; border-radius: 16px; background: #fff; border: 2px solid var(--line);
  box-shadow: 0 3px 0 #e3cca3;
}
.dash-card-t { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.dash-note { font-size: 11px; color: var(--muted); margin-top: 4px; }

.dash-bar { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 8px; margin: 6px 0; font-size: 12.5px; }
.dash-bar-l { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-bar-v { white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.dash-track { position: relative; height: 16px; border-radius: 999px; background: #f1e6d3; overflow: hidden; }
.dash-fill { height: 100%; border-radius: 999px; }
.dash-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--line); opacity: 0.55; }
.dash-track.dumb { overflow: visible; background: #f6efe2; }
.dash-track.dumb i {
  position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  border: 2px solid var(--line);
}
.dash-track.dumb i.pre { background: #b9a690; }
.dash-track.dumb i.post { background: var(--sky); }
.dumb-line { position: absolute; top: 50%; height: 4px; margin-top: -2px; border-radius: 2px; }
.dash-stack { display: flex; height: 22px; border-radius: 999px; overflow: hidden; background: #f1e6d3; grid-column: span 2; }
.dash-part {
  display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap;
  font-size: 11px; font-weight: 700; color: #3c2a1d;
}
.dash-none { padding-left: 10px; font-size: 12px; color: var(--muted); align-self: center; }
.dash-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; margin-top: 6px; }
.dash-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 4px; border-radius: 3px; border: 1px solid var(--line); }

.dash-cols { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.dash-colwrap { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; }
.dash-colwrap span { font-size: 10.5px; font-weight: 700; margin-top: 2px; }
.dash-colpair { flex: 1; width: 100%; display: flex; align-items: flex-end; gap: 1px; border-bottom: 2px solid var(--line); }
.dash-col { flex: 1; min-height: 1px; border-radius: 3px 3px 0 0; }

.dash-heat { display: grid; grid-template-columns: auto repeat(4, 1fr); gap: 4px; font-size: 13px; }
.dash-heat-corner { font-size: 10.5px; color: var(--muted); align-self: end; padding: 0 6px 2px 0; }
.dash-heat-head { text-align: center; font-weight: 700; padding: 2px 0; }
.dash-heat-row { font-weight: 700; padding-right: 8px; align-self: center; white-space: nowrap; }
.dash-heat-cell {
  text-align: center; padding: 10px 0; border-radius: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums; border: 1.5px solid rgb(90 62 43 / 25%);
}
.dash-heat-cell.hot { color: #fff; text-shadow: 0 1px 0 rgb(0 0 0 / 25%); }

.dash-ins-list { display: flex; flex-direction: column; gap: 8px; }
.dash-ins {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; font-size: 13.5px;
}
.dash-ins-i { font-size: 18px; line-height: 1.3; }
.dash-ins-t { font-weight: 600; }
.dash-ins-tune { margin-top: 4px; font-size: 12px; color: #5d4a3b; }
.dash-ins-tune b { color: var(--sky-d); }
.ins-warn { background: #fff0e6; border-color: var(--coral-d); }
.ins-idea { background: #fff9dc; }
.ins-good { background: #ecf8f0; border-color: var(--leaf-d); }

.dash-tablewrap { overflow-x: auto; border: 2px solid var(--line); border-radius: 16px; background: #fff; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.dash-table th, .dash-table td { padding: 7px 10px; text-align: right; white-space: nowrap; }
.dash-table th { background: #f6ead6; font-size: 12px; }
.dash-table th:first-child, .dash-table td:first-child { text-align: left; }
.dash-table tbody tr + tr td { border-top: 1px solid #efe2cc; }
.dash-table tr.me td { background: #fff7e0; }
.dash-table.compare tbody tr { cursor: pointer; }
.dash-table.compare tbody tr:hover td { background: #f7f1ff; }
.dash-table tr.now .dash-rule { font-weight: 700; }
.dash-table tr.sel td { background: #efe4ff; }
.dash-who { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.dash-avatar { width: 28px; height: 28px; border-width: 2px; flex: none; }
.dash-avatar.big { width: 56px; height: 56px; border-width: 2.5px; animation: hop 1.8s ease-in-out infinite; }
.dash-avatar.big:nth-child(2) { animation-delay: 0.2s; }
.dash-avatar.big:nth-child(3) { animation-delay: 0.4s; }
.dash-avatar.big:nth-child(4) { animation-delay: 0.6s; }

.dash-sim {
  margin-top: 14px; padding: 14px 16px; border-radius: 18px;
  background: #f4eeff; border: 2px dashed #7d61b5;
}
.dash-sim-t { font: 700 15px var(--display); color: #5b3f94; }
.dash-fields { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.dash-field-l { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.dash-chips { display: flex; gap: 6px; flex-wrap: wrap; }
button.dash-chip {
  padding: 4px 12px; font-size: 13px; border: 2px solid var(--line); background: #fff; color: var(--ink);
  box-shadow: 0 2px 0 #d9c4a0;
}
button.dash-chip.on { background: #a98bdb; color: #fff; font-weight: 700; }
.dash-sim-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.dash-sim-foot button.primary { background: #a98bdb; box-shadow: 0 4px 0 #7d61b5; }
.dash-progress { flex: 1 1 200px; height: 14px; border-radius: 999px; background: #fff; border: 2px solid var(--line); overflow: hidden; }
.dash-progress-fill { height: 100%; width: 0; background: #a98bdb; transition: width 0.2s; }
.dash-sim-msg { font-size: 13px; font-weight: 700; }
.dash-sim-msg.done { color: var(--leaf-d); }

.dash-empty { margin: 22px 0 6px; padding: 26px 20px; text-align: center; border-radius: 20px; background: #fff; border: 2px dashed var(--line); }
.dash-empty-animals { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.dash-empty h3 { margin: 6px 0 !important; font-size: 20px !important; color: var(--ink) !important; }
.dash-empty p { margin: 0 auto 14px; max-width: 560px; font-size: 13.5px; color: var(--muted); }
button.dash-big { font-size: 17px; padding: 12px 26px; background: #a98bdb; box-shadow: 0 5px 0 #7d61b5; }
.dash-footer { margin: 18px 0 0; font-size: 11.5px; color: var(--muted); text-align: center; }

/* ================================================================
   Phones and touch screens
   The table switches to a phone layout when the window is under 700px wide or 500px tall
   (body.compact, plus .portrait or .landscape). Positions come from layout.js; these rules only shrink things.
   ================================================================ */

/* iOS: 100vh is taller than what is visible, so size the canvas to the real window */
#table { width: 100%; height: 100%; }
html, body { height: 100%; height: 100dvh; }
body {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.panel { max-height: min(84vh, 84dvh); }
.panel, .lobby-input { -webkit-user-select: text; }
/* iOS zooms into any text box under 16px */
@media (pointer: coarse) {
  .lobby-input, .lobby-link .lobby-input { font-size: 16px; }
  button.gear:hover svg { transform: none; }
}

/* ---- The table, phone size ---- */
body.compact #felt {
  inset: calc(env(safe-area-inset-top) + 4px) calc(env(safe-area-inset-right) + 4px) calc(env(safe-area-inset-bottom) + 4px) calc(env(safe-area-inset-left) + 4px);
  border-radius: 22px;
  background-size: 26px 26px, auto;
  box-shadow: 0 0 0 4px var(--cream), 0 4px 0 4px #e3cca3;
}
body.compact #felt::before { background-size: 26px 26px, auto; }
body.compact #felt::after { inset: 6px; border-radius: 17px; border-width: 2px; }

/* Player tokens (keep in sync with PLATE_W / PLATE_H in layout.js) */
body.compact .plate {
  width: 120px;
  height: 42px;
  gap: 5px;
  padding: 3px 10px 3px 3px;
  border-width: 1.5px;
  box-shadow: 0 3px 0 rgb(90 62 43 / 30%);
}
body.compact .plate.active { box-shadow: 0 3px 0 var(--sun-d), 0 0 0 3px rgb(255 201 60 / 60%); transform: translate(-50%, -50%) scale(1.05); }
body.compact .plate.active::before { top: -15px; left: 19px; font-size: 10px; }
body.compact .plate-avatar { width: 32px; height: 32px; border-width: 1.5px; }
body.compact .plate-name { font-size: 13px; line-height: 1.2; }
body.compact .plate-count { font-size: 11px; line-height: 1.25; }
body.compact .plate-rank { top: -9px; left: 34px; padding: 0 6px; font-size: 9px; border-width: 1.5px; letter-spacing: 0; }
body.compact .plate-tag { right: 6px; bottom: -10px; padding: 0 6px; font-size: 10px; border-width: 1.5px; }
body.compact .plate.cpu .plate-name::after { margin-left: 3px; padding: 0 3px; font-size: 8px; }

/* Speech bubbles hang under the token instead of beside it (there is no room beside it) */
body.compact .bubble {
  top: calc(100% + 12px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  max-width: min(200px, 46vw);
  padding: 5px 9px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.35;
}
body.compact .bubble::after {
  top: auto;
  bottom: 100%;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: var(--line);
}
body.compact .plate[data-side="left"] .bubble { left: 0; transform: none; }
body.compact .plate[data-side="left"] .bubble::after { left: 30px; }
body.compact .plate[data-side="right"] .bubble { left: auto; right: 0; transform: none; }
body.compact .plate[data-side="right"] .bubble::after { left: auto; right: 30px; transform: none; }
body.compact .plate[data-side="bottom"] .bubble { top: auto; bottom: calc(100% + 12px); left: 0; transform: none; }
body.compact .plate[data-side="bottom"] .bubble::after { bottom: auto; top: 100%; left: 30px; border-bottom-color: transparent; border-top-color: var(--line); }

/* Log: only the latest two lines, left-aligned next to my token */
body.compact #log { text-align: left; }
body.compact .log-line { margin: 2px 0; padding: 0 9px; font-size: 11.5px; line-height: 1.5; }
body.compact .log-line.newest { padding: 0 10px; font-size: 13px; border-width: 1.5px; box-shadow: 0 2px 0 rgb(90 62 43 / 22%); }
body.compact .log-line:not(:nth-last-child(-n+2)) { display: none; }

/* Field labels */
body.compact #fieldMark { border-width: 2px; border-radius: 18px; }
body.compact #fieldMark span { top: -11px; padding: 1px 10px; font-size: 11px; border-width: 1.5px; }
body.compact #discardMark { padding: 0 7px; font-size: 10px; }

/* Hint + buttons */
body.compact #actionBar {
  gap: 8px;
  padding: 4px 5px 4px 12px;
  border-width: 1.5px;
  border-radius: 22px;
  box-shadow: 0 3px 0 rgb(90 62 43 / 25%);
}
body.compact #actionBar.my-turn { box-shadow: 0 3px 0 var(--sun-d), 0 0 0 3px rgb(255 201 60 / 50%); }
body.compact #hint { flex: 1; min-width: 0; font-size: 12.5px; line-height: 1.3; }
body.compact .buttons { gap: 6px; }
body.compact .buttons button { padding: 8px 14px; font-size: 14px; min-width: 70px; }

/* Banners */
body.compact .banner-main { font-size: clamp(30px, 10vw, 46px); -webkit-text-stroke: 2px var(--line); text-shadow: 0 4px 0 var(--coral); }
body.compact #banner.round .banner-main { font-size: clamp(24px, 7.5vw, 34px); text-shadow: 0 4px 0 var(--sky); }
body.compact #banner.rev .banner-main { text-shadow: 0 4px 0 #e2559a; }
body.compact #banner.cut .banner-main { text-shadow: 0 4px 0 #2bb38d; }
body.compact #banner.finish .banner-main { text-shadow: 0 4px 0 var(--sun-d); }
body.compact .banner-sub { font-size: 13px; padding: 2px 12px; }

/* Card exchange list */
body.compact #exchangePanel { min-width: 0; width: min(380px, calc(100vw - 16px)); padding: 6px 8px; border-radius: 16px; }
body.compact .ex-title { font-size: 13px; margin-bottom: 2px; }
body.compact #exchangeSteps li { gap: 6px; padding: 2px 6px; font-size: 12px; line-height: 1.4; grid-template-columns: minmax(0, 1fr) auto 22px; }
body.compact .ex-who, body.compact .ex-what { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.compact .ex-what { font-size: 11px; }
body.compact.landscape #exchangePanel { padding: 4px 10px; width: min(440px, 54vw); }
body.compact.landscape .ex-title { font-size: 12px; margin-bottom: 0; }
body.compact.landscape #exchangeSteps li { padding: 0 6px; font-size: 11px; line-height: 1.35; }

/* Tips */
body.compact .coach { width: min(340px, calc(100vw - 16px)); padding: 8px 10px 8px 12px; font-size: 13px; line-height: 1.5; border-left-width: 5px; }
body.compact .coach.top::after { left: 26px; }
body.compact .coach-actions button { padding: 6px 12px; }
/* Sideways: the top tip and the bar tip can be up at once, so keep them on opposite sides */
body.compact.landscape .coach { width: min(300px, 38vw); font-size: 12.5px; }
body.compact.landscape .coach.bar { left: auto; right: calc(env(safe-area-inset-right) + 8px); transform: none; }
body.compact.landscape .coach.bar::after { left: 40px; margin-left: 0; }
body.compact.landscape .coach.bar.pop { animation: coachPop 0.24s ease-out; }

/* ---- Top bar, phone held upright: buttons on the first row, the ladder full-width under them ---- */
body.compact #topbar { gap: 6px; }
body.compact.portrait #topbar {
  top: calc(env(safe-area-inset-top) + 6px);
  left: calc(env(safe-area-inset-left) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  flex-wrap: wrap;
}
body.compact.portrait .top-right { order: -1; width: 100%; gap: 6px; }
body.compact #roundLabel { margin-right: auto; padding: 3px 10px; font-size: 13px; border-width: 1.5px; }
body.compact #netBadge { font-size: 11px; padding: 2px 8px; }
body.compact #rulesBtn { font-size: 13px; padding: 6px 12px; box-shadow: 0 3px 0 #d9c4a0; }
body.compact .top-right button.gear { width: 36px; height: 36px; box-shadow: 0 3px 0 #d9c4a0; }
body.compact .top-right button.gear svg { width: 19px; height: 19px; }
body.compact .top-right .lang-btn { margin-right: 0; }
body.compact #ladder { position: relative; gap: 3px; height: 34px; padding: 4px 6px; border-width: 1.5px; border-radius: 12px; box-shadow: 0 3px 0 rgb(90 62 43 / 25%); }
body.compact.portrait #ladder { width: 100%; }
body.compact .ladder-end { font-size: 10px; }
body.compact #ladderChips { gap: 2px; }
body.compact.portrait #ladderChips { flex: 1; min-width: 0; }
body.compact .chip { min-width: 0; height: 22px; padding: 0 1px; border-radius: 6px; font-size: 12px; }
body.compact.portrait .chip { flex: 1; }
body.compact.landscape .chip { width: 21px; }
body.compact .chip.joker { font-size: 9px; }
body.compact #revBadge {
  position: absolute;
  top: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 1px 8px;
  font-size: 10px;
  white-space: nowrap;
}
body.compact.portrait #actionBar {
  left: calc(env(safe-area-inset-left) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  transform: none;
  max-width: none;
}

/* ---- Top bar, phone held sideways: everything on one row ---- */
body.compact.landscape #topbar {
  top: calc(env(safe-area-inset-top) + 6px);
  left: calc(env(safe-area-inset-left) + 10px);
  right: calc(env(safe-area-inset-right) + 10px);
}
body.compact.landscape #roundLabel { margin-right: 0; }
/* The bar sits between my token (left) and the discard pile (right) */
body.compact.landscape #actionBar { max-width: calc(100vw - 2 * (max(env(safe-area-inset-left), env(safe-area-inset-right)) + 140px)); }

/* ---- Panels on small screens ---- */
@media (max-width: 699px), (max-height: 499px) {
  .panel { width: 94vw; padding: 16px 16px; border-radius: 18px; line-height: 1.6; }
  .panel h2 { font-size: 20px; }
  .panel button { margin-top: 12px; }
  #result .panel { overflow-x: auto; }
  #resultHead { font-size: 16px; }
  #resultTable td { padding: 6px 4px; font-size: 13px; }
  #resultTable th { padding: 0 4px 4px; }
  .hist-chip { width: 20px; height: 20px; margin-right: 2px; font-size: 11px; }
  .res-tag { margin-left: 4px; padding: 1px 5px; font-size: 10px; }
  .avatar.mini { width: 22px; height: 22px; margin-right: 5px; }
  #resultNote { font-size: 13px; }
  .welcome-buttons { flex-wrap: wrap; }
  .set-row { flex-wrap: wrap; gap: 6px 12px; padding: 9px 0; }
  .set-label { font-size: 14px; }
  .set-range input { width: 120px; }
  .settings-panel .seg button { padding: 6px 11px; }

  /* Title screen and lobby: clear the corner buttons and the notch */
  .title-screen {
    padding: calc(env(safe-area-inset-top) + 62px) calc(env(safe-area-inset-right) + 10px) calc(env(safe-area-inset-bottom) + 18px) calc(env(safe-area-inset-left) + 10px);
  }
  #titleSettingsBtn { top: calc(env(safe-area-inset-top) + 10px); right: calc(env(safe-area-inset-right) + 12px); }
  #titleLangBtn { top: calc(env(safe-area-inset-top) + 10px); right: calc(env(safe-area-inset-right) + 64px); }
  .title-box { width: min(500px, 100%); padding: 18px 16px; border-radius: 24px; box-shadow: 0 0 0 6px var(--cream), 0 6px 0 6px #e3cca3; }
  .title-box h1 { -webkit-text-stroke: 2.5px var(--line); }
  .title-avatar { width: 42px; height: 42px; }
  .title-lead { margin: 6px auto 14px; font-size: 13px; }
  .title-modes { gap: 10px; }
  button.mode-btn { padding: 9px 18px; border-radius: 16px; }
  .mode-label { font-size: 16px; }
  .mode-desc { font-size: 12px; }
  .lobby-box h2 { font-size: 26px; }
  .lobby-seats li { padding: 5px 12px; }
  .lobby-buttons { gap: 8px; }
}
/* Sideways phone: very little height, so shrink the title further */
@media (max-height: 499px) {
  .title-screen { padding-top: calc(env(safe-area-inset-top) + 14px); padding-right: calc(env(safe-area-inset-right) + 70px); padding-left: calc(env(safe-area-inset-left) + 70px); }
  .title-animals { display: none; }
  .title-badge { margin-top: 0; }
  .title-box h1 { margin-top: 6px; font-size: 32px; }
  .title-sub { margin-top: 4px; font-size: 14px; }
  .title-lead { display: none; }
  .title-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
  button.mode-btn { padding: 7px 14px; }
  .mode-desc { display: none; }
  .title-note { margin-top: 10px; }
  #titleLangBtn { top: calc(env(safe-area-inset-top) + 64px); right: calc(env(safe-area-inset-right) + 12px); }
}

/* ---- Analytics on a phone: a notice that it is built for big screens ---- */
.dash-mobile-warn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff3c4;
  border: 2px solid var(--sun-d);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
}
.dash-mobile-warn b { display: block; color: var(--coral-d); font-size: 14.5px; }
.dash-mobile-warn-icon { font-size: 22px; line-height: 1.2; }
.dash-mobile-warn p { flex: 1; margin: 0; }
.dash-mobile-warn button { flex-shrink: 0; align-self: center; }