/* Realms of Omnia - one look for every screen: white table, black frames, the cards' own pixel font.
   Layout idea: the board sits in the middle; everything else hangs off its edges. */
:root {
  --paper: #fff; /* background */
  --ink: #000; /* text, frames */
  --dim: #7a7a7a;
  --p1: #1c7fd6; /* player 1 */
  --p2: #d63a2a; /* player 2 */
  --mana: #1c7fd6;
  --select: #f5a300; /* the one highlight: whatever is selected or being asked for */
  --good: #6be675; /* raised number (on the black unit strip) */
  --bad: #ff6b6b; /* lowered number, damage */
  --card-w: 100px;
  color-scheme: light;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  /* Sizes are multiples of 5px so every font pixel lands on whole screen pixels. */
  font:
    15px/1.4 'Omnia Pixel',
    monospace;
  text-transform: uppercase;
  -webkit-font-smoothing: none;
  touch-action: manipulation; /* no double-tap zoom on phones */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  font-smooth: never;
}
[hidden] {
  display: none !important;
}
img {
  display: block;
  image-rendering: pixelated;
  user-select: none;
  -webkit-user-drag: none;
}
h1,
h2,
h3,
p {
  margin: 0;
  font-weight: normal;
}
h1 {
  font-size: 40px;
  line-height: 1.2;
}
h2 {
  font-size: 20px;
}
h3 {
  font-size: 20px;
  margin-bottom: 10px;
}
.note {
  color: var(--dim);
  font-size: 10px;
}
.p0-text {
  color: var(--p1);
}
.p1-text {
  color: var(--p2);
}

button,
select,
input {
  font: inherit;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 6px 10px;
}
button {
  cursor: pointer;
}
button:hover:not(:disabled),
button.on {
  background: var(--ink);
  color: var(--paper);
}
button:disabled {
  color: var(--dim);
  border-color: var(--dim);
  cursor: default;
}
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--select);
  outline-offset: 2px;
}
label {
  font-size: 10px;
  color: var(--dim);
}

.screen {
  height: 100%;
  box-sizing: border-box;
  position: relative;
}

/* ------------------------------------------------------------ menu and deck choice */
#screen-menu,
#screen-setup,
#screen-online {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 20px;
  text-align: center;
}
.title {
  font-size: 60px;
}
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.menu-buttons.row {
  flex-direction: row;
}
.menu-buttons button {
  font-size: 20px;
  padding: 12px 20px;
}
.setup-columns {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
  justify-content: center;
}
.deck-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 260px;
}

/* ------------------------------------------------------------ deck builder */
#screen-builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
}
.builder-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-bottom: 2px solid var(--ink);
}
.filters > button {
  align-self: flex-start;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.filter-row button,
.filter-row select,
.filter-row input {
  font-size: 10px;
  padding: 5px 8px;
}
.filter-row input {
  width: 140px;
}
.gallery {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, 200px);
  gap: 10px;
  padding: 10px;
  justify-content: center;
  align-content: start;
}
.gallery .card {
  position: relative;
  width: 200px;
  height: 280px;
  cursor: pointer;
}
.gallery .card img {
  width: 100%;
  height: 100%;
}
.copies {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--select);
  color: var(--ink);
  padding: 3px 5px;
  font-size: 20px;
  line-height: 1;
}
.copies:empty {
  display: none;
}
.builder-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-left: 2px solid var(--ink);
  overflow-y: auto;
}
.deck-count {
  font-size: 20px;
}
.deck-list {
  flex: 1;
  min-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.deck-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  border-left: 5px solid var(--dim);
  padding: 4px 6px;
  font-size: 10px;
  text-align: left;
}
.rarity-Uncommon {
  border-left-color: #64c864;
}
.rarity-Rare {
  border-left-color: #6464c8;
}
.rarity-Epic {
  border-left-color: #9632c8;
}
.rarity-Legendary {
  border-left-color: #ff9100;
}
.rarity-Mythic {
  border-left-color: #e6d200;
}
.deck-problems {
  font-size: 10px;
  color: var(--p2);
}
.side-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.side-buttons button {
  font-size: 10px;
  flex: 1;
}

/* ------------------------------------------------------------ the table */
.table {
  height: 100%;
  display: grid;
  column-gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: var(--foe-hand-h, 156px) var(--board-h, auto) calc(var(--card-w) * 1.4 + 16px);
  align-content: center; /* centred on tall screens */
}
.hand {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 8px;
} /* hands span the full width so they never push the board sideways */
.hand .card {
  width: var(--card-w);
  flex: none;
  position: relative;
}
.hand .card img,
.pile img,
.modal-cards .card img,
.cast img {
  width: 100%;
  aspect-ratio: 5 / 7;
}
/* The opponent's hand: same size as yours, upside down. */
.hand.foe {
  grid-row: 1;
  align-items: center;
}
.hand.foe .card {
  transform: rotate(180deg);
}
.hand.mine {
  grid-row: 3;
  align-items: flex-start;
  padding-top: 10px;
}
.hand.mine .card {
  transition: transform 0.1s;
}
.hand.mine .card {
  cursor: pointer;
}
.hand.mine .card.selected {
  transform: translateY(-8px);
  z-index: 3;
  outline: 3px solid var(--select);
}
.new-cost {
  position: absolute;
  left: 0;
  top: 0;
  background: var(--mana);
  color: var(--paper);
  font-size: 20px;
  line-height: 1;
  padding: 3px 5px;
}

.board {
  grid-column: 2;
  grid-row: 2;
  position: relative;
}
.board-image {
  width: 100%;
  height: 100%;
}
#tiles,
#floaters {
  position: absolute;
  inset: 0;
}
#floaters {
  pointer-events: none;
}

/* Your deck and mana sit bottom-left, your discard bottom-right; the opponent's are the same, turned half a circle. */
.side {
  grid-row: 2;
  display: grid;
  min-height: 0;
}
.side.left {
  grid-column: 1;
  justify-self: end;
  grid-template-rows: 1fr 1fr;
  justify-items: end;
}
.side.right {
  grid-column: 3;
  justify-self: start;
  grid-template-rows: 1fr auto 1fr;
  justify-items: start;
}
.bottom-group,
#my-discard {
  align-self: end;
}
#my-deck,
#my-discard,
#foe-deck,
#foe-discard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: var(--pile-w, var(--card-w));
}
.pile {
  width: var(--pile-w, var(--card-w));
  aspect-ratio: 5 / 7;
  box-sizing: border-box;
}
#foe-deck img,
#foe-discard img {
  transform: rotate(180deg);
}
.pile.discard {
  cursor: pointer;
}
.pile.discard.empty {
  border: 2px dashed var(--dim);
}
.pile-count {
  font-size: 20px;
  line-height: 1;
}
.mana {
  width: var(--pile-w, var(--card-w));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  color: var(--mana);
}
.mana span {
  font-size: 10px;
}
.mana b {
  font-size: 40px;
  line-height: 1;
  font-weight: normal;
}

.controls {
  width: var(--side-w, 200px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.controls .turn {
  font-size: 10px;
}
.controls {
  position: relative;
}
.controls .extra {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}
.end-turn {
  font-size: 20px;
  padding: 12px 8px;
}
.minor {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.minor button {
  font-size: 10px;
  padding: 4px 6px;
  border-width: 1px;
  border-color: var(--dim);
  color: var(--dim);
}

/* ------------------------------------------------------------ tiles, units, bases */
.tile,
.base {
  position: absolute;
  box-sizing: border-box;
}
.tile.move {
  background: rgba(28, 127, 214, 0.35);
  cursor: pointer;
}
.tile.attack::after,
.tile.choice::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tile.attack {
  cursor: crosshair;
}
.tile.attack::after {
  border: 3px solid var(--p2);
  background: rgba(214, 58, 42, 0.35);
}
.tile.choice {
  cursor: pointer;
}
.tile.choice::after {
  border: 3px solid var(--select);
  background: rgba(245, 163, 0, 0.3);
}

/* A unit is a small black card: picture on top, attack/health underneath. No outline - the opponent's are simply upside down. */
.unit {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}
.unit.foe {
  transform: rotate(180deg);
}
.unit.foe .numbers,
.unit.foe .gear {
  transform: rotate(180deg);
} /* ...but their numbers stay readable */
.unit.selected {
  outline: 3px solid var(--select);
  z-index: 1;
}
/* Shows only the picture from the card: the art box is 768x512 at (16,128) on the 800x1120 image. */
.unit .art {
  aspect-ratio: 3 / 2;
  overflow: hidden;
  flex: none;
}
.unit .art img {
  width: 104.1667%;
  margin: -16.6667% 0 0 -2.0833%;
}
.numbers {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
}
.numbers b {
  font-weight: normal;
}
.numbers .up {
  color: var(--good);
}
.numbers .down {
  color: var(--bad);
}
.small-tiles .numbers {
  font-size: 10px;
}
.gear {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--ink);
  color: var(--select);
  font-size: 10px;
  line-height: 1;
  padding: 1px 2px;
}

.base {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid transparent;
  color: var(--paper);
  cursor: default;
}
.base-health {
  font-size: 40px;
  line-height: 1;
}
.small-tiles .base-health {
  font-size: 30px;
}
.base.attack {
  border-color: var(--p2);
  background: rgba(214, 58, 42, 0.5);
  cursor: crosshair;
}
.base.choice {
  border-color: var(--select);
  background: rgba(245, 163, 0, 0.45);
  cursor: pointer;
}

.floater {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  text-shadow: 3px 3px 0 var(--ink);
  animation: rise 0.9s forwards;
}
.floater.damage {
  color: var(--bad);
}
.floater.heal {
  color: var(--good);
}
@keyframes rise {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-40px);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .floater,
  .cast {
    animation-duration: 0.01s;
  }
  .hand.mine .card {
    transition: none;
  }
}

/* ------------------------------------------------------------ pop-ups */
.modal,
.curtain {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal {
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
}
.modal.open,
.curtain.open {
  display: flex;
}
.modal-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 96%;
  max-height: 94%;
  box-sizing: border-box;
  overflow-y: auto;
  padding: 16px;
  background: var(--paper);
  border: 3px solid var(--ink);
  text-align: center;
}
.modal-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 4px;
}
/* Pop-up cards have no close-up, so they are drawn large enough to read: five fit across, up to 280px wide. */
.modal-cards .card {
  width: clamp(140px, 17vw, 280px);
  max-width: calc((88vh - 150px) / 1.4); /* ...and never taller than the pop-up leaves room for */
  cursor: pointer;
}
.modal-cards .card.picked {
  outline: 4px solid var(--select);
}
.modal-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.modal-buttons.column {
  flex-direction: column;
}
.log {
  width: min(560px, 80vw);
  max-height: 50vh;
  overflow-y: auto;
  text-align: left;
  font-size: 10px;
  border: 1px solid var(--dim);
  padding: 8px;
}
.curtain {
  z-index: 30;
  flex-direction: column;
  gap: 20px;
  background: var(--paper);
  text-align: center;
  padding: 20px;
}
.curtain.see-through {
  background: rgba(255, 255, 255, 0.85);
}
.end-buttons {
  display: flex;
  gap: 15px;
}
/* The win screen folded away: only a small bar at the top, and the board underneath can be clicked. */
.curtain.peeking {
  background: none;
  pointer-events: none;
  justify-content: flex-start;
  padding: 5px;
}
.end-bar {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 20px;
}
.curtain .end-bar button {
  font-size: 10px;
  padding: 5px 10px;
}
.curtain button {
  font-size: 20px;
  padding: 12px 20px;
}

/* Card close-up. With equipment, the other cards of the stack peek out behind; click to bring the next one forward. */
.preview {
  position: fixed;
  z-index: 40;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  aspect-ratio: 5 / 7;
  width: var(--preview-w, 400px);
}
.preview img {
  position: absolute;
  aspect-ratio: 5 / 7;
}
.preview.clickable {
  pointer-events: auto;
  cursor: pointer;
}
.preview.at-left {
  left: 10px;
}

@media (max-width: 760px) {
  .title {
    font-size: 30px;
  }
  #screen-builder {
    grid-template-columns: minmax(0, 1fr) 220px;
  }
  .gallery {
    grid-template-columns: repeat(auto-fill, 100px);
  }
  .gallery .card {
    width: 100px;
    height: 140px;
  }
  .controls {
    width: 120px;
  }
  .end-turn {
    font-size: 10px;
  }
}

/* Short screens: smaller mana number and End Turn button so the side columns fit the board's height. */
.compact .mana {
  padding: 3px 0;
}
.compact .mana b {
  font-size: 30px;
}
.compact .pile-count {
  font-size: 15px;
}
.compact .controls {
  width: 130px;
  gap: 4px;
}
.compact .end-turn {
  font-size: 10px;
  padding: 6px;
}
.compact .minor {
  margin-top: 0;
}

/* Inputs are the one place text may be selected. */
input {
  user-select: text;
  -webkit-user-select: text;
}

/* ------------------------------------------------------------ play online */
#screen-menu,
#screen-setup,
#screen-online {
  overflow-y: auto;
}
.online-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.online-actions button {
  font-size: 20px;
  padding: 10px 16px;
}
.online-join {
  display: flex;
  align-items: center;
  gap: 8px;
}
.online-join input {
  width: 110px;
  font-size: 20px;
  text-align: center;
}
.online-status {
  min-height: 3em;
  white-space: pre-line;
  color: var(--p1);
}

/* ------------------------------------------------------------ phones
   .narrow = upright phone: thin side columns, LOG/MENU move to the top-left corner, END TURN shrinks to fit.
   .short  = sideways phone: the opponent's hand shows only its lower half. */
.narrow .table {
  column-gap: 6px;
}
.narrow .controls {
  width: var(--side-w);
  gap: 3px;
}
.narrow .controls .turn {
  font-size: 5px;
  line-height: 1.6;
}
.narrow .end-turn {
  font-size: 10px;
  padding: 6px 2px;
}
.narrow .minor {
  position: fixed; /* LOG and MENU sit in the bottom corner, below your hand */
  left: 4px;
  bottom: 4px;
  margin: 0;
  z-index: 5;
}
.narrow .controls .extra button,
.narrow .controls .extra p {
  font-size: 5px;
  padding: 4px 2px;
}
.narrow .mana span {
  font-size: 5px;
}
.narrow .mana b {
  font-size: 20px;
}
.short .hand.foe {
  align-items: flex-end;
  overflow: hidden;
}
.preview.tap-away {
  pointer-events: auto;
  transform: translateY(-50%);
}
@media (max-width: 700px) {
  h1 {
    font-size: 30px;
  }
  .modal-box {
    padding: 8px;
  }
  .modal-cards .card {
    width: clamp(120px, 44vw, 200px);
  }
  .menu-buttons button,
  .curtain button {
    font-size: 15px;
  }
  .setup-columns {
    gap: 16px;
  }
  .deck-choices {
    min-width: 0;
  }
  /* Deck builder: cards on top, deck panel underneath. */
  #screen-builder {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 44%;
  }
  .builder-side {
    border-left: 0;
    border-top: 2px solid var(--ink);
  }
  .gallery {
    grid-template-columns: repeat(auto-fill, 150px);
  }
  .gallery .card {
    width: 150px;
    height: 210px;
  }
  .deck-list {
    min-height: 60px;
  }
}

/* ------------------------------------------------------------ counters, mana per turn, concede, opponent's turn */
/* A green number just above the stats: counters a card has collected. */
.numbers {
  position: relative;
}
.counter {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  background: var(--good);
  color: var(--ink);
  font-size: 10px;
  line-height: 1;
  padding: 2px 3px;
  min-width: 6px;
  text-align: center;
}
.unit.foe .counter {
  bottom: auto;
  top: 100%; /* the opponent's units are turned round, so "above the stats" is the other way */
}
.mana-rate {
  font-size: 10px;
  color: var(--mana);
}
.concede {
  color: var(--p2) !important;
  border-color: var(--p2) !important;
}
.concede:hover:not(:disabled) {
  background: var(--p2) !important;
  color: var(--paper) !important;
}
/* Over your hand while the opponent is playing. Clicks pass through it. */
.turn-banner {
  /* Sits in the middle of the board while the opponent plays; clicks pass through to the board. */
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  pointer-events: none;
  display: none;
  padding: 20px 30px;
  color: var(--paper);
  font-size: 40px;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 0 0 5px var(--paper);
}
.turn-banner.shown {
  display: block;
  animation: pulse 1.6s ease-in-out infinite;
}
.p0-banner {
  background: var(--p1);
}
.p1-banner {
  background: var(--p2);
}
@keyframes pulse {
  0%,
  100% {
    opacity: 0.9;
  }
  50% {
    opacity: 0.6;
  }
}
@media (prefers-reduced-motion: reduce) {
  .turn-banner.shown {
    animation: none;
  }
}
.compact .turn-banner {
  font-size: 25px;
  padding: 12px 18px;
}
.narrow .turn-banner,
.short .turn-banner {
  font-size: 15px;
  padding: 8px 12px;
  box-shadow: 0 0 0 3px var(--paper);
}
.narrow .mana-rate {
  font-size: 5px;
}
