/* Mobile-first. Board scales to the smaller of viewport width/height. */
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&display=swap');
@font-face {
  font-family: 'ByteBounce';
  src: url('../fonts/ByteBounce.ttf') format('truetype');
}

:root {
  --light: #eeeed2;
  --dark: #262942;
  --sel: #f6f669;
  --last: rgba(72, 133, 214, 0.45);
  --check: rgba(214, 46, 46, 0.86);
  --draw: rgba(120, 124, 140, 0.62);
  --bg: #312e2b;
  --panel: #3b3936;
  --text: #f2f2f2;
  --header-font: Helvetica, Arial, sans-serif;
  --body-font: "Open Sans", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body-font);
  touch-action: manipulation;
}

#app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 10px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* board + side panel sit in a row on wide screens; the panel wraps BELOW the
   board on narrow/phone screens so the board is never crowded. */
#play {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

#title {
  font-family: var(--header-font);
  font-size: 1.4rem;
  font-weight: 600;
  margin: 6px 0 2px;
  letter-spacing: 0.5px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.95rem;
}
.topbar select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #555;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--header-font);
  font-size: 0.9rem;
}

.status {
  font-size: 1.05rem;
  min-height: 1.4em;
  text-align: center;
  font-weight: 500;
}
.status.win { color: #ffd166; font-weight: 700; }

.conn {
  font-size: 0.78rem;
  opacity: 0.65;
  margin: 2px 0 8px;
  text-align: center;
}

/* transient Best/Great/Brilliant badge after a graded move */
.movequality {
  min-height: 0;
  height: 0;
  overflow: hidden;
  text-align: center;
  font-family: var(--header-font);
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s ease;
  margin: 0;
}
.movequality.show {
  height: auto;
  min-height: 1.2em;
  opacity: 1;
  margin: 0;
}
.movequality.book { color: #c9c2b4; }
.movequality.good { color: #9ecbff; }
.movequality.excellent { color: #7CFC9A; }
.movequality.best { color: #6fe0c8; }
.movequality.brilliant { color: #ff8df0; text-shadow: 0 0 8px rgba(255, 141, 240, 0.8); }

.powers {
  width: min(96vw, 560px);
  background: var(--panel);
  border: 1px solid #4a4744;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  line-height: 1.5;
}

#board-wrap {
  width: min(96vw, 96vh, 560px);
}

.board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 3px solid #20201d;
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  touch-action: none; /* let us drag pieces without the page scrolling */
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sq.light { background: var(--light); }
.sq.dark  { background: var(--dark); }

.sq.sel { background: var(--sel) !important; }
.sq.last::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--last);
  pointer-events: none;
}
/* king in check: the whole square goes red (the piece sits on top of it) */
.sq.check::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--check);
  pointer-events: none;
}
/* drawn game (stalemate / threefold / insufficient): grey both kings' squares */
.sq.draw::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--draw);
  pointer-events: none;
}
/* the enemy piece delivering check gets an orange frame */
.sq.checker::before {
  content: "";
  position: absolute;
  inset: 0;                 /* flush to the square edges */
  border: 5px solid #ff9d2e;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.5);
  z-index: 3;
  pointer-events: none;
}
/* the square currently under a dragged piece gets a bright inset ring */
.sq.dragover {
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.92),
              inset 0 0 0 6px rgba(0, 0, 0, 0.32);
}

/* the piece: a square sprite that fills its square */
.piece {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.piece .pcimg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;            /* keep pixel art crisp at any size */
  image-rendering: -webkit-optimize-contrast; /* Safari fallback */
}

/* legal-move indicator: a square frame inset around the square's perimeter.
   White for a quiet move, red for a capture. Drawn above the piece sprite so
   capture frames show over the enemy piece. The thin dark shadow keeps the
   white frame visible on the light (cream) squares too. */
.sq .movehint {
  position: absolute;
  inset: 0;                 /* flush to the square edges, like a thick cell border */
  border: 5px solid #ffffff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.5);
  z-index: 3;
  pointer-events: none;
}
.sq .movehint.capture { border-color: #ff2e2e; }

/* a square you can target with an active ability (distinct from move hints) */
.sq .movehint.abil {
  border-color: #b46bff;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.55), 0 0 8px rgba(180, 107, 255, 0.7);
}

/* a checkmated king topples over */
.piece.fallen .pcimg { transform: rotate(90deg); }

/* a stunned piece is rotated 90° (and dimmed) until it recovers */
.piece.stunned .pcimg { transform: rotate(90deg); filter: grayscale(0.5) brightness(0.85); }

/* skill-indicator dots in the top-left corner of a square */
.sq .badges {
  position: absolute; top: 2px; left: 2px;
  display: flex; gap: 2px; z-index: 4; pointer-events: none;
}
.sq .badge {
  width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.7);
}
.sq .badge.passive { background: #36c24a; }                       /* green: passive applied */
.sq .badge.active  { background: #ffffff; border: 1.5px solid #000; } /* white: bought, unused */
.sq .badge.armed   { background: #2f86ff; }                       /* blue: armed reaction */
.sq .badge.used    { background: #4a4a4a; }                       /* dark gray: skill spent */
.sq .badge.spell   { background: #b46bff; }                       /* purple: under a spell */

/* coordinate labels in corners */
.sq .coord {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  opacity: 0.6;
  z-index: 1;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

.controls {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #555;
  border-radius: 8px;
  padding: 12px 13px;
  font-family: 'ByteBounce', monospace;
  font-size: 1.2rem;
  line-height: 1.3;
  letter-spacing: 0.5px;
  cursor: pointer;
}
button:active { background: #4a4744; }
button.danger { border-color: #7a4040; color: #ffb3b3; }
button.danger:active { background: #5a3030; }

.captured {
  display: none;
}
.cap-row { min-height: 30px; line-height: 30px; letter-spacing: 2px; }

/* ── Power Chess side panel ─────────────────────────────────────────── */
.side {
  width: min(96vw, 500px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* points tally — shows ONLY the viewing player's points (opponent hidden) */
.points {
  background: var(--panel);
  border: 1px solid #4a4744;
  border-radius: 10px;
  padding: 4px 8px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.points .pts-label { font-family: 'ByteBounce', var(--header-font); font-size: 1.2rem; opacity: 0.8; font-weight: 600; }
.points .pts-captured-rows { display: flex; flex-direction: column; gap: 1.5px; align-items: flex-start; }
.points .pts-captured { display: flex; flex-direction: row; gap: 1.5px; align-items: center; min-width: 60px; }
.points .pts-captured .swatch { width: 31px; height: 31px; margin-left: -6px; margin-right: -6px; }
.points .pts-val { font-family: 'ByteBounce', monospace; font-size: 5.7rem; font-weight: 800; color: #ffd166; margin-left: auto; line-height: 1; }
.points .pts-unit { font-family: 'ByteBounce', monospace; font-size: 2rem; opacity: 0.7; align-self: flex-end; margin-bottom: 60px; }
/* spectator view: White at the left end, Black at the right end */
.points.both { justify-content: space-between; }
.points.both .pts-side { display: flex; align-items: center; gap: 6px; }
.points.both .pts-val { font-size: 1.6rem; margin: 0; }
.points.both .dot { width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 0 2px #000; }
.points.both .dot.w { background: #f2f2f2; }
.points.both .dot.b { background: #2b2b2b; border: 1px solid #888; }

/* transient explanation when a shop click can't do anything */
.shophint {
  height: 0; overflow: hidden; opacity: 0;
  background: #4a3f2a; color: #ffe2a8; border-radius: 8px;
  font-size: 0.78rem; transition: opacity 0.15s ease;
}
.shophint.show { height: auto; opacity: 1; padding: 8px 12px; }

.shop {
  background: var(--panel);
  border: 1px solid #4a4744;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 60px;
  font-size: 0.86rem;
}
.shop-empty { opacity: 0.6; font-size: 0.82rem; line-height: 1.5; }
.shop-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid #4a4744;
}
.shop-head .pcimg { width: 30px; height: 30px; }
.shop-head .shop-title { font-family: var(--header-font); font-size: 1rem; font-weight: 600; }

/* modifiers/effects display (stun, shield, spells, etc.) */
.shop-modifiers {
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px 0; margin-bottom: 8px; border-bottom: 1px solid #4a4744;
  font-size: 0.8rem;
}
.modifier {
  display: flex; align-items: center; gap: 6px;
}
.mod-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.modifier.stun .mod-dot { background: #6b5a5a; }
.modifier.spell .mod-dot { background: #9d7fd0; }
.modifier.passive .mod-dot { background: #7cb342; }
.modifier.active .mod-dot { background: #e0e0e0; }
.modifier.armed .mod-dot { background: #42a5f5; }

/* grid: one row per path, T1 left / T2 right */
.shop-grid { display: flex; flex-direction: column; gap: 6px; }
.shop-prow { display: flex; flex-direction: column; gap: 3px; }
.shop-pname {
  font-family: var(--header-font); font-size: 0.9rem; font-weight: 600; opacity: 0.95; color: #ffd9a0;
  border-bottom: 1px solid #5a554f; padding-bottom: 5px; margin-top: 4px;
}
.shop-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-items: stretch; }
@media (max-width: 720px) { .shop-pair { grid-template-columns: 1fr; } }
.shop-tier-header { text-align: center; font-weight: 600; font-size: 0.9rem; padding: 4px 0; opacity: 0.9; }

/* an ability tile */
.tile {
  border: 1px solid #55514d;
  border-radius: 8px;
  padding: 6px 8px;
  line-height: 1.22;
  display: flex;
  flex-direction: column;
}
.tile.empty { border-style: dashed; opacity: 0.25; }
.tile .tile-top { display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; }
.tile .tile-name { font-weight: 700; font-size: 0.86rem; }
.tile .tile-tier { font-size: 0.56rem; opacity: 0.55; }
.tile .tile-cost { margin-left: auto; font-weight: 800; color: #ffd166; font-size: 0.8rem; }
.tile .tile-desc { font-size: 0.68rem; opacity: 0.82; margin-top: 3px; flex: 1; }
.tile .tile-tag { font-size: 0.62rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; margin-top: 4px; align-self: flex-start; }

/* states */
.tile.buyable { cursor: pointer; border-color: #6f8f5a; background: rgba(120, 170, 90, 0.10); }
.tile.buyable:active { background: rgba(120, 170, 90, 0.22); }
.tile.usable { cursor: pointer; border-color: #b46bff; background: rgba(150, 100, 220, 0.12); }
.tile.usable:active { background: rgba(150, 100, 220, 0.26); }
.tile.owned { border-color: #4a4744; background: rgba(255, 255, 255, 0.03); }
.tile.owned .tile-tag { background: #3a5a3a; color: #bfe9bf; }
.tile.unaffordable { opacity: 0.55; }
.tile.unaffordable .tile-tag { background: #5a5040; color: #e9d9b0; }
.tile.locked { opacity: 0.3; }
.tile.locked .tile-tag { background: #444; color: #ccc; }

.shop-targeting {
  border: 1px solid #b46bff; border-radius: 8px; padding: 8px 10px; margin-bottom: 8px;
  background: rgba(150, 100, 220, 0.14); font-size: 0.8rem;
}
.shop-targeting button { margin-top: 6px; padding: 6px 10px; }

/* ── Rooms lobby ─────────────────────────────────────────────────────── */
.lobby { max-width: 1100px; margin: 0 auto; padding: 14px 12px 40px; }
.lobby h1 { text-align: center; font-size: 1.5rem; margin: 8px 0 14px; }
.lobby-hint {
  text-align: center; min-height: 1.2em; margin-bottom: 10px;
  color: #ffd166; font-size: 0.85rem; opacity: 0; transition: opacity 0.15s ease;
}
.lobby-hint.show { opacity: 1; }
.lobby-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.room-card {
  background: var(--panel); border: 1px solid #4a4744; border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.room-head { display: flex; align-items: baseline; gap: 8px; }
.room-name { font-family: var(--header-font); font-size: 0.95rem; font-weight: 600; }
.room-status {
  margin-left: auto; font-size: 0.68rem; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
}
.room-status.live { background: #2e5a32; color: #bff0c0; }
.room-status.open { background: #3a3836; color: #b7b1aa; }
.room-status.wait { background: #5a4a28; color: #ffe0a0; }
.room-turn { font-size: 0.82rem; min-height: 1.1em; opacity: 0.92; }
.room-turn .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: middle; box-shadow: 0 0 2px #000; }
.room-turn .dot.w { background: #f2f2f2; }
.room-turn .dot.b { background: #2b2b2b; border: 1px solid #888; }
.room-material { font-size: 0.8rem; opacity: 0.85; }
.room-material .mat-cap { margin-top: 3px; min-height: 18px; display: flex; flex-wrap: wrap; gap: 1px; }
.room-material .mat-cap .pcimg { width: 16px; height: 16px; }
.seat { display: flex; align-items: center; gap: 6px; }
.seat label { font-size: 0.72rem; width: 42px; opacity: 0.8; }
.seat-name {
  flex: 1; min-width: 0; background: #2b2926; color: var(--text);
  border: 1px solid #555; border-radius: 6px; padding: 6px 8px; font-size: 0.85rem;
}
.seat-name:disabled { opacity: 0.85; }
.seat.claimed .seat-name { border-color: #6f8f5a; }
.seat-name.needs-name { border-color: #e05a5a; box-shadow: 0 0 0 2px rgba(224, 90, 90, 0.4); }
.seat-btn { font-size: 1.2rem; padding: 7px 8px; white-space: nowrap; }
.spectate-btn { font-size: 2.2rem; padding: 7px 8px; margin-top: 2px; }
.to-lobby { color: #9ecbff; text-decoration: none; font-size: 0.85rem; margin-right: 6px; }
.to-lobby:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* small piece icon, used in the captured tray and promotion picker */
.swatch { display: inline-block; width: 28px; height: 28px; vertical-align: middle; }
.swatch .pcimg { width: 100%; height: 100%; object-fit: contain; display: block; margin-top: -16px }
.promo .swatch { width: 52px; height: 52px; }

/* the floating piece while dragging (shares .piece, so reset its layout) */
.drag-ghost {
  position: fixed;
  inset: auto;
  z-index: 200;
  transform: translate(-50%, -60%) scale(1.12);
  transform-origin: center;
  pointer-events: none;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.5));
}
.drag-ghost .pcimg { width: 100%; height: 100%; object-fit: contain; display: block; }

/* floating points animation when a move earns points */
@keyframes float-up {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) translateY(0) scale(1);
  }
  31% {
    opacity: 1;
    transform: translate(-50%, -50%) translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) translateY(-60px) scale(0.8);
  }
}

.floating-points {
  position: fixed;
  z-index: 150;
  font-family: 'ByteBounce', monospace;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0px;
  transform: translate(-50%, -50%);
  line-height: 0.6;
}

.floating-points.quality .floating-word {
  font-size: 80px;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(0,0,0,0.7);
}

.floating-points.kill .floating-word {
  font-size: 100px;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(0,0,0,0.7);
}

.floating-points.quality .floating-word { color: #9ecbff; }
.floating-points.quality.book .floating-word { color: #c9c2b4; }
.floating-points.quality.excellent .floating-word { color: #7CFC9A; }
.floating-points.quality.best .floating-word { color: #6fe0c8; }
.floating-points.quality.brilliant .floating-word { color: #ff8df0; text-shadow: 0 0 8px rgba(255, 141, 240, 0.8); }
.floating-points.kill .floating-word { color: #ff2e2e; text-shadow: 0 0 4px rgba(0,0,0,0.7); }

.floating-points.quality .floating-number {
  font-size: 120px;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(0,0,0,0.7);
}
.floating-points.quality.book .floating-number { color: #c9c2b4; }
.floating-points.quality.good .floating-number { color: #9ecbff; }
.floating-points.quality.excellent .floating-number { color: #7CFC9A; }
.floating-points.quality.best .floating-number { color: #6fe0c8; }
.floating-points.quality.brilliant .floating-number { color: #ff8df0; text-shadow: 0 0 8px rgba(255, 141, 240, 0.8); }

.floating-points.kill .floating-number {
  font-size: 120px;
  color: #ff2e2e;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(0,0,0,0.7);
}

.floating-points.animate {
  animation: float-up 1.6s ease-out forwards;
}

/* promotion picker overlay */
.promo {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.promo-inner {
  background: var(--panel);
  padding: 18px;
  border-radius: 12px;
  text-align: center;
}
.promo-label { margin-bottom: 14px; font-family: var(--header-font); font-size: 0.95rem; font-weight: 600; }
.promo-choices { display: flex; gap: 6px; }
.promo-choices button {
  font-size: 40px;
  width: 64px;
  height: 64px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
