/* Night at the Zoo — night-time zoo theme */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg1: #150d33;
  --bg2: #2b1a55;
  --panel: rgba(255, 255, 255, 0.055);
  --panel2: rgba(255, 255, 255, 0.10);
  --line: rgba(255, 255, 255, 0.14);
  --ink: #efeaff;
  --dim: #b6a9e0;
  --accent: #f0a13c;
  --glow: #ffd166;
  --good: #6ee7a0;
  --cell: #6a5fb5;
  --cell-dark: #4a4090;
  --rocks: #c9432e;
  --grass: #3e7d3c;
  --sand: #e8a13d;
}

html { color-scheme: dark; -webkit-tap-highlight-color: transparent; }
body {
  font-family: "Segoe UI", "Noto Sans", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1px 1px at 12% 22%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 34% 8%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 56% 30%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 12%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 40%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 22% 55%, #fff4 50%, transparent 51%),
    radial-gradient(1px 1px at 66% 70%, #fff4 50%, transparent 51%),
    radial-gradient(1px 1px at 44% 88%, #fff5 50%, transparent 51%),
    linear-gradient(160deg, var(--bg1), var(--bg2) 60%, #1c1240);
  background-attachment: fixed;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}

/* snappier taps on touch devices (no double-tap zoom delay) */
button, select, .tile, .cell, .critter, .score-chip { touch-action: manipulation; }

h1, h2, h3 { font-weight: 700; letter-spacing: 0.02em; }
button {
  font: inherit;
  color: var(--ink);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
button:hover { background: rgba(255, 255, 255, 0.18); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: #2a1500; border-color: transparent; font-weight: 600; }
button.primary:hover { background: var(--glow); }
button.danger { background: #7c2d2d; }
input[type="text"], select {
  font: inherit; color: var(--ink);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
}

#app { max-width: 1500px; margin: 0 auto; padding: 12px 16px 40px; }

/* ---------- menu ---------- */
.menu {
  max-width: 620px; margin: 6vh auto; padding: 28px 32px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
}
.menu h1 { font-size: 2rem; margin-bottom: 2px; }
.menu .tagline { color: var(--dim); margin-bottom: 22px; }
.menu .row { display: flex; gap: 10px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.menu label { min-width: 110px; color: var(--dim); }
.menu .animal-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.menu .animal-pick button { padding: 4px 10px; display: inline-flex; align-items: center; gap: 5px; }
.menu .animal-pick button.sel { background: var(--accent); color: #2a1500; }
.menu .start-row { margin-top: 22px; display: flex; gap: 12px; }
.menu .note { color: var(--dim); font-size: 0.85rem; margin-top: 16px; line-height: 1.5; }
.moons { color: var(--glow); }

/* ---------- game layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 14px; margin-bottom: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.topbar .title { font-weight: 700; color: var(--glow); white-space: nowrap; }
.topbar .roundinfo { color: var(--dim); }
.topbar .spacer { flex: 1; }
.score-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25); cursor: pointer;
}
.score-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.score-chip.active { outline: 2px solid var(--glow); }
.score-chip.viewed { background: rgba(255, 255, 255, 0.14); }
.first-star { color: var(--glow); }

.gamegrid { display: grid; grid-template-columns: 460px 1fr; gap: 14px; align-items: start; }
@media (max-width: 1100px) {
  /* single column: actions first, reading material (runaways, log) at the bottom */
  .gamegrid { display: flex; flex-direction: column; gap: 0; }
  .gamegrid > .col { display: contents; }
  .p-board { order: 1; }
  .p-hand { order: 2; }
  .p-market { order: 3; }
  .p-animals { order: 4; }
  .p-log { order: 5; }
  /* while drafting, the market is the thing to tap */
  .gamegrid.phase-draft .p-market { order: 0; }
  .prompt {
    position: sticky; top: 6px; z-index: 30;
    background: linear-gradient(rgba(240, 161, 60, 0.16), rgba(240, 161, 60, 0.16)), #241546;
    box-shadow: 0 4px 14px rgba(5, 2, 15, 0.55);
  }
}

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 14px;
}
.panel h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--dim); margin-bottom: 8px; }

/* prompt */
.prompt {
  border: 1px solid rgba(240, 161, 60, 0.5);
  background: rgba(240, 161, 60, 0.1);
  border-radius: 14px; padding: 10px 14px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  min-height: 52px;
}
.prompt .msg { flex: 1; min-width: 220px; }
.prompt .msg.with-tile { display: flex; align-items: center; gap: 12px; }
.prompt .msg.with-tile .tile-wrap { flex: none; }
.prompt .msg b { color: var(--glow); }
.prompt .notice {
  flex-basis: 100%;
  color: var(--glow);
  background: rgba(255, 209, 102, 0.09);
  border: 1px solid rgba(255, 209, 102, 0.4);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

/* ---------- tiles ---------- */
.tile {
  --tc: #888;
  position: relative;
  width: 74px; height: 74px; flex: none;
  background: var(--tc);
  border-radius: 21% 29% 25% 25% / 27% 24% 26% 23%;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
.tile.rocks { --tc: var(--rocks); }
.tile.grass { --tc: var(--grass); }
.tile.sand  { --tc: var(--sand); }
.tile.small { width: 52px; height: 52px; font-size: 1rem; }
.tile .sym { display: flex; gap: 2px; align-items: center; font-weight: 700; }
.tile .slash { opacity: 0.8; font-size: 0.9em; }
.tile.clickable { cursor: pointer; outline: 2px dashed rgba(255, 209, 102, 0.55); outline-offset: 2px; }
.tile.clickable:hover { outline: 3px solid var(--glow); outline-offset: 0; }
.tile.selected { outline: 3px solid var(--glow); }
.tilebtnrow { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
.tilebtnrow button { padding: 2px 8px; font-size: 0.78rem; border-radius: 7px; }
.tile-wrap { display: flex; flex-direction: column; align-items: center; }
.tile-wrap .cap { font-size: 0.72rem; color: var(--dim); margin-top: 4px; }

.tilerow { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.empty-slot {
  width: 74px; height: 74px; flex: none; border-radius: 21% 29% 25% 25% / 27% 24% 26% 23%;
  border: 2px dashed var(--line);
}
.smallrow .empty-slot { width: 52px; height: 52px; }

.star { color: #fff; font-weight: 700; }
.vpstar {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em;
}

/* ---------- player board ---------- */
.boardwrap { display: flex; justify-content: center; }
.board {
  display: grid;
  grid-template-columns: repeat(7, var(--cs, 84px));
  grid-template-rows: repeat(7, var(--cs, 84px));
  gap: 5px;
  padding: 12px;
  background: rgba(20, 10, 45, 0.55);
  border: 1px solid var(--line);
  border-radius: 16px;
  position: relative;
}
@media (max-width: 760px) { .board { --cs: clamp(32px, calc((100vw - 84px) / 7), 46px); gap: 4px; padding: 8px; } }
@media (min-width: 761px) and (max-width: 1300px) { .board { --cs: 64px; } }

.cell {
  position: relative;
  border-radius: 19% 26% 22% 24% / 24% 22% 26% 20%;
  background: var(--cell);
  display: flex; align-items: center; justify-content: center;
}
.cell.dark { background: var(--cell-dark); }
.cell.offgrid { background: transparent; border-radius: 0; }
.cell.entrance { box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25); }
.cell.entrance.rocks { background: var(--rocks); }
.cell.entrance.grass { background: var(--grass); }
.cell.entrance.sand { background: var(--sand); }
.cell.zoo {
  background: linear-gradient(180deg, #241a52, #171040);
  box-shadow: inset 0 0 12px rgba(255, 209, 102, 0.35), inset 0 0 0 2px rgba(255, 209, 102, 0.4);
  flex-direction: column; display: flex;
}
.cell.zoo .arch { color: var(--glow); font-weight: 800; font-size: 0.72rem; letter-spacing: 0.2em; }
.cell.zoo .gate svg { display: block; margin: 1px auto; }
.cell.zoo .homecount { font-size: 0.7rem; color: var(--dim); }

.cell .space-sym {
  color: rgba(255, 255, 255, 0.85); font-weight: 700; font-size: 1rem;
  display: flex; gap: 2px; align-items: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.cell .placed {
  position: absolute; inset: 0;
  border-radius: inherit;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
  font-weight: 700;
}
.cell .placed.rocks { background: var(--rocks); }
.cell .placed.grass { background: var(--grass); }
.cell .placed.sand { background: var(--sand); }

.cell .shield {
  position: absolute; top: -3px; left: 50%; transform: translateX(-50%);
  z-index: 3;
  background: #251a4e; border: 1px solid var(--line);
  border-radius: 0 0 7px 7px; padding: 0 4px 2px;
  font-size: 0.68rem; line-height: 1.25;
  display: flex; align-items: center; gap: 2px;
}
.shield .tsq { display: inline-block; width: 9px; height: 9px; border-radius: 3px; }
.tsq.rocks { background: var(--rocks); }
.tsq.grass { background: var(--grass); }
.tsq.sand { background: var(--sand); }
.tsq.multi { background: linear-gradient(180deg, var(--sand) 33%, var(--grass) 33% 66%, var(--rocks) 66%); }

.pair-badge {
  position: absolute; z-index: 4;
  width: 30px; height: 30px; border-radius: 50%;
  background: #221847; border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.66rem; font-weight: 700; color: #fff;
  pointer-events: none;
}
.pair-badge.h { right: -19px; top: 50%; transform: translateY(-50%); }
.pair-badge.v { bottom: -19px; left: 50%; transform: translateX(-50%); }
.pair-badge.done { opacity: 0.35; }

.cell.sel-place { cursor: pointer; outline: 3px dashed rgba(255, 209, 102, 0.8); outline-offset: -2px; }
.cell.sel-place.cond-ok { outline-color: var(--good); outline-style: solid; }
.cell.sel-dest { cursor: pointer; outline: 3px solid var(--good); outline-offset: -2px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { outline-color: rgba(110, 231, 160, 0.35); } }

/* animals */
.cell .critters {
  position: absolute; bottom: 1px; left: 2px; right: 2px; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 1px; justify-content: center;
  pointer-events: none;
}
.critter {
  pointer-events: auto;
  position: relative;
  width: 29px; height: 29px; border-radius: 50%;
  background: rgba(15, 8, 35, 0.85);
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
  display: inline-flex; align-items: center; justify-content: center;
}
.critter svg, .ani { display: block; }
.critter .ani-wrap { display: flex; }
.critter .badge {
  position: absolute; top: -7px; right: -7px;
  font-size: 0.62rem; background: #221847; border: 1px solid var(--line);
  border-radius: 999px; padding: 0 3px; line-height: 1.3;
}
.critter.undiscovered { opacity: 0.5; filter: grayscale(0.8); border-style: dashed; }
.critter.asleep { transform: rotate(75deg); }
.critter.sel-animal { cursor: pointer; border-color: var(--good); box-shadow: 0 0 8px var(--good); animation: pulse2 1.2s infinite; }
@keyframes pulse2 { 50% { box-shadow: 0 0 2px var(--good); } }
.critter.active-mover { border-color: var(--glow); box-shadow: 0 0 10px var(--glow); }
.critter.on-edge { position: absolute; z-index: 6; }
.critter.on-edge.eN { top: -14px; left: 50%; transform: translateX(-50%); }
.critter.on-edge.eS { bottom: -14px; left: 50%; transform: translateX(-50%); }
.critter.on-edge.eW { left: -14px; top: 50%; transform: translateY(-50%); }
.critter.on-edge.eE { right: -14px; top: 50%; transform: translateY(-50%); }

/* market/leftover board */
.zoneicon { font-size: 1.1rem; margin-right: 4px; }
.marketrow { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }

.animal-cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
.animal-card {
  background: rgba(0, 0, 0, 0.22); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; font-size: 0.78rem; line-height: 1.35;
}
.animal-card .head { display: flex; align-items: center; gap: 6px; font-size: 0.95rem; font-weight: 700; flex-wrap: wrap; min-width: 0; }
.animal-card .head .em { display: flex; align-items: center; }
.animal-card .vp { color: var(--glow); }
.animal-card .rule { color: var(--dim); margin-top: 4px; }
.animal-card .letter {
  margin-left: auto; background: var(--panel2); border-radius: 6px;
  padding: 0 6px; font-size: 0.75rem; color: var(--dim);
}

.solo-tile { display: flex; gap: 6px; align-items: center; }
.solo-tile .slot {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.solo-tile .slot.p1 { border-color: var(--glow); color: var(--glow); }
.solo-tile .slot.p2 { border-color: var(--dim); color: var(--dim); }

.supplies { display: flex; gap: 14px; flex-wrap: wrap; color: var(--dim); font-size: 0.85rem; align-items: center; }
.supplies .pill { display: inline-flex; align-items: center; gap: 5px; }

/* hand & warehouse */
.handrow { display: flex; gap: 22px; flex-wrap: wrap; }

/* log */
.log { max-height: 180px; overflow-y: auto; font-size: 0.8rem; color: var(--dim); line-height: 1.5; }
.log div:last-child { color: var(--ink); }

/* modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(5, 2, 15, 0.7); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px;
}
.modal {
  background: #221650; border: 1px solid var(--line); border-radius: 16px;
  max-width: 760px; width: 100%; max-height: 88vh; overflow-y: auto;
  padding: 24px 28px;
}
.modal h2 { margin-bottom: 12px; color: var(--glow); }
.modal h3 { margin: 16px 0 6px; }
.modal p, .modal li { line-height: 1.55; font-size: 0.92rem; color: var(--ink); }
.modal ul { padding-left: 20px; }
.modal .closebtn { float: right; }

/* results */
.results { max-width: 860px; margin: 4vh auto; }
.results .tablewrap { overflow-x: auto; }
.results table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.results th, .results td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.results .total-row td { font-weight: 700; color: var(--glow); border-top: 2px solid var(--line); }
.results .winner { color: var(--good); font-weight: 700; }
.rank-banner {
  font-size: 1.3rem; padding: 14px; text-align: center;
  background: var(--panel2); border-radius: 12px; margin-bottom: 14px;
}


/* ---------- terrain textures ---------- */
.tile.grass, .cell .placed.grass, .cell.entrance.grass {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18'><path d='M4 15 q1.2 -4.5 0 -8 M9 16 q2 -5.5 1 -9 M14 15 q1.2 -3.5 0 -6.5' stroke='rgba(10,40,12,0.30)' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
}
.tile.rocks, .cell .placed.rocks, .cell.entrance.rocks {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22'><path d='M2 6 l6 3 5 -2.5 M10 14 l5 4 M4 18 l4 -3.5 M16 4 l3 4' stroke='rgba(60,10,5,0.28)' stroke-width='1.4' fill='none' stroke-linecap='round'/></svg>");
}
.tile.sand, .cell .placed.sand, .cell.entrance.sand {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><circle cx='3.5' cy='4.5' r='1.1' fill='rgba(90,50,5,0.25)'/><circle cx='11.5' cy='8.5' r='1.1' fill='rgba(90,50,5,0.25)'/><circle cx='6.5' cy='13' r='1.1' fill='rgba(90,50,5,0.25)'/><circle cx='13.5' cy='2.5' r='0.9' fill='rgba(90,50,5,0.2)'/></svg>");
}

/* ---------- phone-size tweaks ---------- */
@media (max-width: 760px) {
  #app { padding: 8px 8px 28px; }
  .panel { padding: 10px; margin-bottom: 10px; border-radius: 12px; }
  .prompt { padding: 8px 10px; margin-bottom: 10px; }
  .prompt .msg { min-width: 160px; font-size: 0.92rem; }
  .prompt button { padding: 9px 14px; }

  .topbar { gap: 8px; padding: 6px 8px; margin-bottom: 10px; }
  .topbar .title { display: none; }
  .topbar button { padding: 6px 10px; font-size: 0.85rem; }
  .topbar .roundinfo { font-size: 0.85rem; }

  .boardwrap { overflow-x: auto; justify-content: flex-start; }
  .board { margin: 0 auto; }
  .critter { width: 24px; height: 24px; }
  .critter svg { width: 17px; height: 17px; }
  .critter .badge { top: -6px; right: -6px; font-size: 0.56rem; }
  .critter.on-edge.eN { top: -12px; }
  .critter.on-edge.eS { bottom: -12px; }
  .critter.on-edge.eW { left: -12px; }
  .critter.on-edge.eE { right: -12px; }
  .cell .space-sym { font-size: 0.8rem; }
  .cell .placed { font-size: 0.85rem; }
  .cell .shield { font-size: 0.6rem; }
  .cell.zoo .arch { font-size: 0.56rem; }
  .cell.zoo .homecount { font-size: 0.6rem; }
  .cell.zoo .gate svg { width: 22px; height: 22px; }
  .pair-badge { width: 24px; height: 24px; font-size: 0.56rem; }
  .pair-badge.h { right: -14px; }
  .pair-badge.v { bottom: -14px; }

  .tilebtnrow button { padding: 6px 10px; font-size: 0.85rem; }
  .tilerow { gap: 8px; }
  .handrow { gap: 14px; }
  .log { max-height: 120px; }

  .menu { margin: 2vh auto; padding: 20px 16px; }
  .menu h1 { font-size: 1.6rem; }
  .menu label { min-width: 90px; }
  .modal-back { padding: 2vh 8px; }
  .modal { padding: 18px 14px; }
  .results { margin: 1vh auto; }
}
