/* Anarchy Chess (web): black, blood red and silver, matching the logo */
:root {
  --bg: #0b0b12;
  --surface: #15151f;
  --ink: #ecebef;
  --muted: #a3a2ae;
  --line: #2c2b38;
  --accent: #e0262f;        /* buttons, links, selected states */
  --accent-ink: #ffffff;
  --accent-soft: #ff5a61;   /* links and outlines on dark surfaces */
  --tint: #2a1418;
  --focus: #ffcf4d;

  --sq-light: #e4e1da;
  --sq-dark: #5b5a66;
  --move: #2984ff;
  --anarchy: #c740f2;
  --gold: #ffd133;
  --check: #e5484d;

  --card-top: #b3141c;
  --card-bottom: #3a0609;

  --font-display: "Oswald", "Arial Narrow", Impact, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 14px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); min-height: 100vh;
  background: radial-gradient(ellipse 90% 55% at 50% 0%, #2a0a10 0%, rgb(42 10 16 / 0) 70%) no-repeat, var(--bg);
  font-family: var(--font-body); font-size: 1.0625rem; line-height: 1.55;
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.15; margin: 0; text-transform: uppercase; letter-spacing: 0.02em; }
p { margin: 0 0 0.75em; }
a { color: var(--accent-soft); text-underline-offset: 3px; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 34rem; margin: 0 auto; padding: 1.25rem 16px 2rem; }
.masthead { text-align: center; margin-bottom: 1.25rem; }
.masthead h1 { line-height: 0; }
.logo { display: block; width: 100%; max-width: 20rem; height: auto; margin: 0 auto; filter: drop-shadow(0 10px 28px rgb(224 38 47 / 0.25)); transition: max-width 0.25s ease; }
body:has(#game:not([hidden])) .logo { max-width: 8.5rem; }
body:has(#game:not([hidden])) .tagline { display: none; }
body:has(#game:not([hidden])) .masthead { margin-bottom: 0.5rem; }
.tagline { color: var(--muted); margin: 0.35rem 0 0; }

/* Buttons */
.btn {
  font: inherit; font-family: var(--font-display); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; cursor: pointer;
  border: 1.5px solid #6d6c7a; color: var(--ink); background: transparent;
  border-radius: 999px; padding: 0.6rem 1.2rem; min-height: 44px;
}
.btn:hover:not(:disabled) { background: var(--tint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }

/* Start screen */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.start { display: grid; gap: 1.25rem; }
.start-option h3 { font-size: 1.3rem; margin-bottom: 0.25rem; }
.start-option .btn { width: 100%; margin-top: 0.5rem; }
.start-option + .start-option { border-top: 1px solid var(--line); padding-top: 1.25rem; }
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; margin: 0.75rem 0 0.25rem; }
.level {
  font: inherit; cursor: pointer; text-align: left;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink);
  padding: 0.55rem 0.75rem; min-height: 44px;
}
.level strong { display: block; }
.level span { color: var(--muted); font-size: 0.875rem; }
.level[aria-checked="true"] { border-color: var(--accent); background: var(--tint); box-shadow: inset 0 0 0 1px var(--accent); }
.how summary { cursor: pointer; font-weight: 700; color: var(--accent-soft); }
.how p { margin-top: 0.6rem; color: var(--muted); }
.key { font-weight: 700; padding: 0 0.3em; border-radius: 4px; }
.key-normal { color: #fff; background: var(--move); }
.key-card { color: #fff; background: var(--anarchy); box-shadow: 0 0 8px var(--anarchy); }

/* Card */
.game { display: grid; gap: 0.5rem; }
.card {
  position: relative; color: #fff; text-align: center;
  background: linear-gradient(180deg, var(--card-top), var(--card-bottom));
  border-radius: 18px; padding: 0.7rem 1rem 0.9rem; min-height: 8.6rem;
  box-shadow: 0 8px 22px rgb(0 0 0 / 0.4), inset 0 0 0 1px rgb(255 255 255 / 0.08);
}
.card-pills { display: flex; justify-content: space-between; min-height: 1.4rem; }
.pill {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0.15rem 0.55rem; border-radius: 999px; background: rgb(0 0 0 / 0.28);
}
.pill.owner { margin-left: auto; }
.pill.cat-teleport { background: #d194ff; color: #2a0d3d; }
.pill.cat-special { background: #ffcc4d; color: #3a2a00; }
.pill.cat-resurrection { background: var(--gold); color: #3a2a00; }
.card-title { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; font-size: 1.45rem; line-height: 1.2; margin-top: 0.1rem; }
.card-art { display: flex; align-items: center; justify-content: center; gap: 0.6rem; height: 2.6rem; margin: 0.25rem 0; }
.card-art img { height: 2.4rem; width: auto; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.4)); }
.card-art .sym { font-size: 1.5rem; opacity: 0.9; }
.card-desc { font-size: 0.95rem; opacity: 0.92; }
.card.flash { animation: card-in 0.35s ease-out; }
@keyframes card-in { from { transform: scale(0.96); opacity: 0.6; } to { transform: none; opacity: 1; } }

.status { text-align: center; color: var(--muted); font-weight: 700; margin: 0.15rem 0 0; min-height: 1.5em; }

.player { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 1.8rem; font-size: 0.95rem; }
.player-name { font-weight: 700; }
.captured { display: flex; flex-wrap: wrap; justify-content: flex-end; }
.captured img { height: 1.3rem; width: auto; margin-left: -0.25rem; }

/* Board */
.board {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: 6px; overflow: visible;
  box-shadow: 0 0 0 4px #1e1d29, 0 10px 30px rgb(0 0 0 / 0.55); touch-action: none; user-select: none; -webkit-user-select: none;
  container-type: inline-size; /* effects size themselves in cqw */
}
.board.busy { pointer-events: none; }
.sq {
  position: absolute; width: 12.5%; height: 12.5%; border: 0; padding: 0; margin: 0;
  background: var(--sq-light); cursor: pointer; font: inherit;
}
.sq.dark { background: var(--sq-dark); }
.sq:first-child { border-top-left-radius: 6px; }
.sq:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: 2px; }
.coord { position: absolute; font-size: 0.6rem; font-weight: 700; pointer-events: none; line-height: 1; }
.coord.rank { top: 3px; left: 3px; }
.coord.file { bottom: 3px; right: 4px; }
.sq .coord { color: rgb(0 0 0 / 0.5); }
.sq.dark .coord { color: rgb(255 255 255 / 0.85); }

/* Highlights sit inside each square, under the pieces */
.hl { position: absolute; inset: 0; pointer-events: none; }
.hl.last { background: rgb(255 214 10 / 0.3); }
.hl.sel { background: rgb(255 214 10 / 0.42); }
.hl.check { background: rgb(229 72 77 / 0.45); box-shadow: inset 0 0 0 3px var(--check); }
.hl.move { background: rgb(41 132 255 / 0.35); box-shadow: inset 0 0 0 2px rgb(41 132 255 / 0.9); }
.hl.card {
  /* Undo the rule-card styles that the shared .card class would otherwise give this square
     (its min-height made highlights on the bottom rows run off the board) */
  min-height: 0; padding: 0; border-radius: 0;
  /* Glow is inset so squares on the board's edge don't spill a purple halo outside the board */
  background: rgb(199 64 242 / 0.3); box-shadow: inset 0 0 0 2px rgb(199 64 242 / 0.9), inset 0 0 14px 3px rgb(199 64 242 / 0.8);
  animation: breathe 1.8s ease-in-out infinite; z-index: 1;
}
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.piece {
  position: absolute; width: 12.5%; height: 12.5%; padding: 0.7%;
  object-fit: contain; pointer-events: none; z-index: 3;
  transition: left 0.3s ease, top 0.3s ease, opacity 0.3s ease;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.25));
}
.piece.instant { transition: none; }
.piece.dragging { transition: none; z-index: 20; transform: scale(1.15); }
.piece.selected { opacity: 0.6; }
.piece.flipped { rotate: 180deg; }

/* Effects layer */
.twinkle { position: absolute; pointer-events: none; z-index: 13; line-height: 1; translate: -50% -50%; }
.fx { position: absolute; pointer-events: none; z-index: 10; }
.fx.below { z-index: 2; }
.ghost { position: absolute; width: 12.5%; height: 12.5%; padding: 0.7%; object-fit: contain; pointer-events: none; z-index: 12; }

/* Online play */
.online { display: grid; gap: 0.5rem; }
.invite { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; display: grid; gap: 0.6rem; }
.invite p { margin: 0; }
.invite-row { display: flex; gap: 0.5rem; }
.invite-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 0.95rem; color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 0.5rem 0.7rem; min-height: 44px;
}
.online-note { margin: 0; text-align: center; color: var(--muted); font-size: 0.95rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem 0.75rem; }
.online > .btn { justify-self: center; }

/* Black's online view: the board turns around, the pieces and labels stay upright */
.board.flip { transform: rotate(180deg); }
.board.flip .piece, .board.flip .ghost, .board.flip .coord { rotate: 180deg; }
.coord.alt, .board.flip .coord:not(.alt) { display: none; }
.board.flip .coord.alt { display: block; }
/* In square coordinates these corners land top-left / bottom-right once the board is turned */
.coord.rank.alt { top: auto; left: auto; bottom: 3px; right: 3px; }
.coord.file.alt { bottom: auto; right: auto; top: 3px; left: 4px; }

.controls { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0.5rem; margin-top: 0.5rem; }
.controls .btn { padding-inline: 0.5rem; }

.foot { text-align: center; margin-top: 2rem; font-size: 0.95rem; }
.credits { margin-top: 1rem; font-size: 0.75rem; color: var(--muted); }
.credits a { color: inherit; }

/* Dialogs */
.dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  padding: 1.25rem 1.25rem 1rem; max-width: min(24rem, calc(100vw - 32px)); text-align: center;
}
.dialog::backdrop { background: rgb(0 0 0 / 0.65); }
.dialog h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.dialog-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 0.75rem; flex-wrap: wrap; }
.promo-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-top: 0.75rem; }
.promo-choices button {
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; padding: 0.4rem; min-height: 64px;
}
.promo-choices button:hover { border-color: var(--accent); }
.promo-choices img { height: 2.8rem; width: auto; margin: 0 auto; display: block; }

@media (prefers-reduced-motion: reduce) {
  .logo { transition: none; }
  .piece { transition: none; }
  .hl.card { animation: none; }
  .card.flash { animation: none; }
}
