/*
 * Zyrcan board (game 26).
 *
 * The hexes are drawn with CSS only. MyMOO::Games::Zyrcan::board_for_template
 * gives every hex an integer (col, row) on a pointy-top grid, taken from the
 * same cube coordinates the engine moves on, and board_size reports the grid
 * as --z26-cols / --z26-rows.
 *
 * For a pointy-top hexagon of width W and height H:
 *   - columns are spaced W/2 apart (each row is offset half a hex)
 *   - rows are spaced 0.75*H apart
 * so the grid is sized from its own cell count and needs no measuring.
 */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700;900&display=swap');

/* Orbitron, for the retro sci-fi look, on the game panel only. The site
 * header, chat and footer stay on Open Sans, because .game26 is the panel
 * body and nothing outside it is affected.
 *
 * Orbitron is roughly 15% wider than Open Sans and its counters fill in at
 * small sizes, so the 11px flag, the 12px ship counts and the 12px deploy
 * buttons are the places to watch on a phone. */
.game26 {
  font-family: 'Orbitron', 'Open Sans', sans-serif;
}

.bg-26-top {
  padding-bottom: 12px;
}

/* --- the box background --- */

/* One picture over the whole game box. It sits on .bg-26-panel, which wraps
 * both the panel body and the panel footer, so the two share a single crop.
 * Putting a background on each half separately would scale each to its own
 * box and the join between them would not line up.
 *
 * The panel is fluid. .bg-pagebody caps it at 720px but a phone hands it
 * about 320px, which is why this is an SVG scaled with cover and not the
 * fixed 326x700 PNG that games 15, 16 and 19 use.
 *
 * Bump ?v= when the artwork changes. main.tt already cache-busts this file
 * by its mtime, so editing it is enough to reach every phone, and the query
 * here is what makes the browser fetch the new picture. */
.bg-26-panel {
  background-image: url('/26/zyrcan-bg-starfield.svg?v=1');
  background-repeat: no-repeat;
  background-position: center top;
  background-size: cover;
  border-color: rgba(111, 134, 201, .40);

  /* Bootstrap's body colour is #333, which disappears against a dark sky.
   * Anything that carries its own background keeps its own colour, and is
   * restated in the rules below. */
  color: #dbe3f2;
}

.bg-26-title {
  font-size: 26px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 10px;
  color: #eef2fb;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .85);
}

/* The footer sits on the same picture, so it has to stop painting
 * bootstrap's #f5f5f5, and its rule becomes a soft line instead of #ddd. */
.bg-26-footer {
  margin-top: 12px;
  background-color: transparent;
  border-top-color: rgba(111, 134, 201, .35);
}

/* The seat list is a white card per player, so its text goes back to dark.
 * The same grey also appears on the box itself, outside any card. */
.bg-26-panel .list-group-item {
  color: #333;
}

.bg-26-panel .list-group-item .bg-26-dim {
  color: #777;
}

.bg-26-panel .bg-26-dim {
  color: #aab6cc;
}

/* The turn log is a bootstrap table inside the footer. Its own rules put
 * #ddd borders and a #f5f5f5 row hover, which would be pale text on a pale
 * row once the footer text goes light. */
.bg-26-footer .table > tbody > tr > td {
  color: #dbe3f2;
  border-color: rgba(219, 227, 242, .18);
}

.bg-26-footer .table-hover > tbody > tr:hover > td {
  background-color: rgba(219, 227, 242, .10);
  color: #fff;
}

/* --- seat list --- */

.g26-player {
  margin-bottom: 12px;
}

.g26-player .list-group-item {
  padding: 6px 10px;
}

.bg-26-seat {
  display: inline-block;
  min-width: 22px;
  margin-right: 6px;
  color: #fff;
}

/* The same five colours the ships use, so a seat number in this list
 * matches the hexes that seat owns on the board. */
.bg-26-seat[data-seat="0"] { background-color: #c0392b; }
.bg-26-seat[data-seat="1"] { background-color: #2471a3; }
.bg-26-seat[data-seat="2"] { background-color: #1e8449; }
.bg-26-seat[data-seat="3"] { background-color: #b7950b; }
.bg-26-seat[data-seat="4"] { background-color: #7d3c98; }

/* Yellow is the one seat white text fails on: 2.87:1, against 4.72:1 or
 * better for the other four. This badge gets dark text, which is 6.06:1. */
.bg-26-seat[data-seat="3"] { color: #1a1a1a; }

/* Mark "you" with a ring, not a fill, so the seat colour stays visible. */
.bg-26-me > .bg-26-seat {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #337ab7;
}

/* The turn label. Only the turn is spelled out in words: the ring on your
 * own seat number already says which seat is yours, so a second label for it
 * would be noise. */
.bg-26-flag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 11px;
  line-height: 16px;
  vertical-align: 1px;
}

.bg-26-turn {
  background-color: #fcf8e3;
}

.bg-26-flag-turn {
  border-color: #e0d08a;
  background-color: #f6edb4;
  color: #7a6212;
  font-weight: bold;
}

.bg-26-out {
  opacity: 0.55;
}

.bg-26-dim {
  color: #777;
  font-size: 12px;
}

/* --- the hex grid --- */

.bg-z26-board-wrap {
  /* Size the hex to the width available, instead of picking one size and
   * hoping it fits.
   *
   * The board needs cols hex-widths, and the padding below adds a half-hex
   * on each side, so the total is hexw * (cols + 1). A fixed 46px hex needs
   * 506px for the 5-player board, which fits no phone and not even a window
   * between 481px and 567px on a desktop. Dividing by (cols + 1) is what
   * makes the hex fit the space that is actually there.
   *
   * 76px is the chrome around the board, plus room for a scrollbar: 15px of
   * .container padding and 15px of .panel-body padding each side, 1px of
   * .panel border each side, and 14px for a scrollbar. 100vw counts the
   * scrollbar but the panel does not, so it is wider and the difference has
   * to come off before dividing. The ceiling keeps the 46px look on a wide
   * screen and the floor keeps the hex tappable on a small phone. */
  --z26-hexw: clamp(26px, calc((100vw - 76px) / (var(--z26-cols) + 1)), 46px);
  --z26-hexh: calc(var(--z26-hexw) * 53 / 46);

  /* Derived steps, kept next to the size they depend on so changing the hex
   * above moves the whole grid with one pair of numbers. */
  --z26-half:   calc(var(--z26-hexw) / 2);
  --z26-rowsep: calc(var(--z26-hexh) * 0.75);

  /* Keep the whole board inside the panel on a narrow screen. The clamp
   * above should mean nothing has to scroll, but this stays as a safety
   * net for the 26px floor on a very narrow phone. */
  overflow-x: auto;
  text-align: center;

  /* Breathing room between the hexes and the panel edge. The hexes are
   * placed inside .bg-z26-board, so this no longer has to make room for any
   * overhang; it just keeps the board off the panel border. */
  padding: calc(var(--z26-hexh) / 2) calc(var(--z26-hexw) / 2);
}

.bg-z26-board {
  position: relative;
  margin: 0 auto;

  /* board_size reports columns = max_col/2 + 1, so the widest hex centre
   * sits on col 2*(cols-1). Columns step half a hex, so its right edge is at
   * W/2 * 2*(cols-1) + W = cols * W, which is exactly the width below.
   * Rows step 0.75H apart and the last row adds one whole hex, giving
   * (rows - 1) * 0.75H + H. */
  width:  calc(var(--z26-hexw) * var(--z26-cols));
  height: calc(var(--z26-hexh) * ((var(--z26-rows) - 1) * 0.75 + 1));
}

.bg-z26-hex {
  position: absolute;
  box-sizing: border-box;
  width:  var(--z26-hexw);
  height: var(--z26-hexh);

  /* A pointy-top hexagon, drawn without any image. */
  clip-path: polygon(
    50% 0%,
    100% 25%,
    100% 75%,
    50% 100%,
    0%   75%,
    0%   25%
  );

  background-color: #d9d9d9;
  border: 0;

  /* No negative margins here. Each hex is placed by left/top alone, so the
   * grid lines up with the edges of .bg-z26-board instead of hanging half a
   * hex past it. A negative margin here centres the hex on its grid point,
   * but it also shifts the whole grid half a cell up and left of a box that
   * keeps its full size, which left one dead hex on the right and one on the
   * bottom. board_size reports columns = max_col/2 + 1, so max_col is always
   * 2*(cols-1) and the rightmost hex lands exactly on the box edge; the same
   * holds for the last row and the box height. */

  /* Scale the digit with the hex. The chip around the engine count (see
   * .bg-z26-engines below) needs the text to stay clear of the hexagon
   * edges, and that ratio only holds if the text moves with the hex. */
  font-size: calc(var(--z26-hexw) * 0.33);
  text-align: center;

  /* Centre the digit with flexbox. Centring it with line-height instead
   * put it on the text baseline, so its height depended on the font
   * metrics of the browser and it could drift or clip. */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* No phone media query is needed for the hex size.
 *
 * There used to be one that dropped the hex to a flat 34px below 480px.
 * That still did not fit: the 5-player board needs hexw * (cols + 1) =
 * 374px, and a 375px phone leaves 313px inside the panel. The board
 * overflowed to the right, and because margin: 0 auto cannot centre a block
 * wider than its container, all the slack landed on the right while the
 * padding on the left stayed. That is the gap on the left and the cut cell
 * on the right.
 *
 * The clamp above now sizes the hex from the width, so no breakpoint is
 * needed to make the board fit. This override only lowers the ceiling from
 * 46px to 34px, so the 3-player and 4-player boards look exactly as they
 * did on a phone. They already fit, and the ceiling is what held them at
 * 34px before. Without it they would jump to about 40px. Only the
 * 5-player board is small enough to hit the clamp's own term. */
@media (max-width: 480px) {
  .bg-z26-board-wrap {
    /* Same formula, without the scrollbar: 15px of .container padding and
     * 15px of .panel-body padding each side, 1px of .panel border each
     * side, and 10px of slack so rounding cannot push it over. */
    --z26-hexw: clamp(26px, calc((100vw - 68px) / (var(--z26-cols) + 1)), 34px);
  }
}

/* --- deployment --- */

.bg-z26-empty {
  background-color: #a8c6dd;
  cursor: pointer;
}

.bg-z26-empty:hover {
  background-color: #7ba7c8;
}

.bg-z26-placing .bg-z26-empty {
  background-color: #8fb8d6;
}

.bg-z26-deploy {
  margin-top: 10px;
}

/* Attack hint, under the board. Same slot as the deploy instructions so the
 * two phases read the same way. */
.bg-z26-attack {
  margin-top: 10px;
}

.bg-z26-picks {
  margin-bottom: 6px;
}

/* How many ships this player still has to place, under the picker. */
.bg-z26-left {
  margin: 0;
  font-weight: bold;
}

/* The green from the seat palette is unreadable against the sky at 1.2:1,
 * so this message takes the same hue lifted until it clears the
 * background. It is text on the box, not a seat colour to match. */
.bg-z26-left-done {
  color: #5fd48b;
}

/* Bootstrap sets font-family on button, so these would inherit Orbitron from
 * .game26 anyway. Stating it here keeps the intent obvious and survives a
 * button being rendered outside the panel. */
.bg-z26-shipbtn,
.bg-z26-shipbtn .badge {
  font-family: 'Orbitron', 'Open Sans', sans-serif;
}

.bg-z26-shipbtn {
  margin: 0 4px 4px 0;
}

/* The selected ship button is drawn in the seat colour, so it previews the
 * colour that ship will take on the board. The digit inside keeps its dark
 * chip, because on the yellow seat the chip is what holds the contrast. */
.bg-z26-shipbtn.bg-z26-on {
  color: #fff;
}

.bg-z26-shipbtn.bg-z26-on[data-seat="0"] { background-color: #c0392b; }
.bg-z26-shipbtn.bg-z26-on[data-seat="1"] { background-color: #2471a3; }
.bg-z26-shipbtn.bg-z26-on[data-seat="2"] { background-color: #1e8449; }
.bg-z26-shipbtn.bg-z26-on[data-seat="3"] { background-color: #b7950b; }
.bg-z26-shipbtn.bg-z26-on[data-seat="4"] { background-color: #7d3c98; }

/* The yellow seat is the one colour white text fails on: 2.87:1, against
 * 4.72:1 or better for the other four. This button gets dark text instead,
 * which is 6.06:1 there. */
.bg-z26-shipbtn.bg-z26-on[data-seat="3"] { color: #1a1a1a; }

/* Fallback for the seat-less case, so a button is never left unselected
 * looking while it is in fact selected. */
.bg-z26-shipbtn.bg-z26-on:not([data-seat]),
.bg-z26-shipbtn.bg-z26-on[data-seat=""] {
  background-color: #337ab7;
}

/* --- ships and attacking --- */

.bg-z26-ship {
  background-color: #9c9c9c;
  color: #fff;
  font-weight: bold;
}

.bg-z26-ship[data-seat="0"] { background-color: #c0392b; }
.bg-z26-ship[data-seat="1"] { background-color: #2471a3; }
.bg-z26-ship[data-seat="2"] { background-color: #1e8449; }
.bg-z26-ship[data-seat="3"] { background-color: #b7950b; }
.bg-z26-ship[data-seat="4"] { background-color: #7d3c98; }

.bg-z26-movable {
  cursor: pointer;
  box-shadow: inset 0 0 0 3px #fff;
}

.bg-z26-selected {
  box-shadow: inset 0 0 0 4px #ffeb3b;
}

.bg-z26-target {
  background-color: #e74c3c;
  box-shadow: inset 0 0 0 3px #fff;
  cursor: pointer;
}

.bg-z26-engines {
  position: relative;
  top: -1px;
}

/* The engine count sits on a saturated seat colour, and a bare white
 * glyph there picks up the fill when it is antialiased. On a phone the
 * hex is small, so the smearing left the digit almost unreadable. Give it
 * its own dark chip and set the colour outright, so the digit never
 * depends on what colour the ship underneath is.
 *
 * The chip has to stay narrow. The hexagon tapers to a point at the top
 * and the bottom, so the room available shrinks with the chip height.
 * Keep line-height at 1.15 and the padding thin, or clip-path cuts the
 * corners off on a phone.
 *
 * The padding and the radius follow the hex width for the same reason the
 * font size does: a fixed 3px is a large share of a 26px hex and a small
 * share of a 46px one, and the pointy top and bottom leave the least room
 * exactly where the chip is widest. */
.bg-z26-hex .bg-z26-engines {
  display: inline-block;
  box-sizing: border-box;
  padding: 0 calc(var(--z26-hexw) * 0.065);
  border-radius: calc(var(--z26-hexw) * 0.09);
  background-color: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-weight: bold;
  line-height: 1.15;
}

.bg-z26-passform {
  margin-top: 12px;
}
