/* Shared Andrew game theme. Works with a plain HTML stylesheet link. */
@font-face {
  font-family: 'Andrew Pixel';
  src: url('./andrew-pixel.ttf') format('truetype');
  font-weight: 100 900;
  font-display: swap;
}
:root {
  color-scheme: dark;
  --ink: #251d30;
  --paper: #efe8f5;
  --line: #b39bc5;
  --rule: #756184;
  --gold: #f1cc76;
  --panel: #352a42;
  --control: #493853;
  --muted: #c9b9d4;
  --shadow: #140f1c;
  --square-light: #e1d3e9;
  --square-dark: #9480a5;
  --pixel-font: 'Andrew Pixel', monospace;
  --reading-font: 'Segoe UI', system-ui, sans-serif;
  --page-width: 840px;
  font-family: var(--pixel-font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--paper);
  background: var(--ink);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
h1,
h2,
h3,
h4,
p,
figure {
  margin: 0;
}
h1,
h2,
h3,
h4 {
  font-weight: 400;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button,
select,
.panel,
dialog {
  border: 2px solid var(--line);
  border-radius: 0;
}
button,
select {
  cursor: pointer;
  background-color: var(--control);
  box-shadow: 0 3px var(--shadow);
  padding: 8px 12px;
}
button:hover {
  background-color: #614c70;
  color: #fff3c9;
}
button:active {
  translate: 0 1px;
}
button:disabled,
select:disabled {
  opacity: 0.5;
  cursor: default;
}
button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
button svg {
  flex: none;
}
button.primary,
.active {
  color: var(--ink);
  background: var(--gold);
  border-color: var(--gold);
}
button.primary:hover,
.active:hover {
  background: #ffdc8d;
  color: var(--ink);
}
button.secondary,
.text-button,
.primary,
.answer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
a {
  color: var(--gold);
}
select {
  width: 100%;
  min-height: 42px;
  padding-right: 32px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath fill='%23efe8f5' d='M0 0h10v2H8v2H6v2H4V4H2V2H0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
::selection {
  color: var(--ink);
  background: var(--gold);
}
.topbar {
  max-width: var(--page-width);
  width: 100%;
  margin: 0 auto;
  padding: 14px 20px;
  border-bottom: 2px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand {
  background: transparent;
  color: var(--gold);
  border: 0;
  box-shadow: none;
  padding: 4px 0;
  font: 18px var(--pixel-font);
  white-space: nowrap;
}
.brand:hover {
  background: transparent;
  color: #ffe1a2;
}
.header-actions,
.actions,
.console-actions,
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.actions,
.console-actions,
.row {
  flex-wrap: wrap;
}
.tool {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 5px;
}
.tool svg {
  width: 20px;
  height: 20px;
}
#menu-tool {
  width: 84px;
}
.install-tool {
  color: var(--gold);
}
.menu-icon {
  width: 17px;
  height: 10px;
  background: repeating-linear-gradient(to bottom, currentColor 0 2px, transparent 2px 4px);
}
.panel,
dialog,
.coach-card {
  background: var(--panel);
  box-shadow: 4px 4px var(--shadow);
}
.panel {
  padding: 20px;
}
.panel h2,
dialog h2 {
  color: var(--gold);
}
.full-page,
.game-main {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 16px 20px 22px;
}
.page-title h1 {
  font: 23px/1.4 var(--pixel-font);
  color: var(--gold);
}
.page-title {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin: 5px 0 20px;
}
.board-layout {
  height: 100vh;
  height: 100dvh;
  min-height: 570px;
  display: flex;
  flex-direction: column;
}
.game-main {
  flex: 1;
  min-height: 0;
}
.game-screen {
  display: grid;
  height: 100%;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) clamp(145px, 22dvh, 184px);
  gap: 14px;
}
.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}
.player-row,
.board-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
}
.player-row {
  min-height: 26px;
}
.player-row > div {
  min-width: 0;
  display: flex;
  gap: 12px;
  align-items: baseline;
}
.player-row strong {
  font-weight: normal;
  color: var(--gold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-row small,
.muted {
  color: var(--muted);
}
.player-row small {
  font-size: 13px;
  white-space: nowrap;
}
.status {
  white-space: nowrap;
  text-align: right;
}
.board-space {
  min-width: 0;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  padding-left: 16px;
}
#live-board {
  width: min(calc(100cqw - 24px), calc(100cqh - 32px), 592px);
  aspect-ratio: 1;
  margin-bottom: 18px;
}
.board-frame {
  position: relative;
  padding: 6px;
  border: 2px solid var(--line);
  background: #1c1525;
  box-shadow: 4px 4px var(--shadow);
  user-select: none;
}
.squares {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  isolation: isolate;
}
.rank-labels,
.file-labels {
  position: absolute;
  display: grid;
  color: var(--muted);
  font: 14px/1 var(--pixel-font);
}
.rank-labels {
  left: -22px;
  top: 6px;
  bottom: 6px;
  grid-template-rows: repeat(8, 1fr);
}
.file-labels {
  bottom: -21px;
  left: 6px;
  right: 6px;
  grid-template-columns: repeat(8, 1fr);
}
.rank-labels span,
.file-labels span {
  display: grid;
  place-items: center;
}
.square {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  position: relative;
  padding: 0;
  border: 0;
  box-shadow: none;
  touch-action: manipulation;
}
.square.light {
  background: var(--square-light);
}
.square.dark {
  background: var(--square-dark);
}
.square.last {
  background: #c5a4af;
}
#live-board .square.last-from::after {
  content: '';
  position: absolute;
  inset: 8%;
  border: 3px solid #573371;
  pointer-events: none;
}
.square.selected {
  background: var(--gold);
  box-shadow: inset 0 0 0 3px #51405a;
}
.square.hint-from {
  box-shadow: inset 0 0 0 3px var(--gold), inset 0 0 0 4px var(--ink);
}
.square i {
  width: 16%;
  height: 16%;
  background: #4f365f;
  position: absolute;
  pointer-events: none;
  z-index: 3;
}
.square.hint-to i {
  background: var(--gold);
  outline: 2px solid var(--ink);
}
.square:has(.piece).legal i,
.square:has(.piece).hint-to i {
  inset: 3%;
  width: auto;
  height: auto;
  background: none;
  border: 3px solid #574164;
}
.square:has(.piece).hint-to i {
  border-color: var(--gold);
}
.square:active {
  translate: none;
}
.square:focus-visible {
  outline-offset: -3px;
  z-index: 4;
}
.square .piece,
.square img {
  width: 80%;
  height: 80%;
  z-index: 2;
  pointer-events: none;
}
.piece {
  stroke: #503d5d;
  stroke-width: 2;
  paint-order: stroke fill;
  fill: currentColor;
  image-rendering: pixelated;
  overflow: visible;
}
.white-piece {
  color: #fff2cc;
}
.black-piece {
  color: #2b2038;
  stroke: #1b1423;
}
.black-piece > path:first-child {
  stroke: #9e92a7;
  stroke-width: 0.65;
  paint-order: stroke fill;
}
.piece-eye,
.piece-detail {
  fill: #756380;
  stroke: none;
}
.black-piece .piece-eye,
.black-piece .piece-detail {
  fill: #baa7c8;
}
.board-strip {
  font-size: 12px;
  color: var(--muted);
  height: 24px;
}
.board-strip button {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  padding: 1px 4px;
  border: 0;
  box-shadow: none;
  background: transparent;
  color: inherit;
}
.moves {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  font-variant-numeric: tabular-nums;
}
.coach-card {
  display: grid;
  grid-template-columns: clamp(120px, 18vw, 176px) minmax(0, 1fr);
  border: 2px solid var(--line);
  min-height: 0;
}
.coach-card.no-portrait {
  grid-template-columns: 1fr;
}
.coach-stage {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #281c35;
  border-right: 2px solid var(--line);
  padding: 5px 4px 20px;
}
.coach-stage img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.coach-stage > span {
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: var(--gold);
}
.coach-copy {
  min-width: 0;
  overflow: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.speech {
  line-height: 1.5;
}
.console-actions {
  margin-top: auto;
}
.console-actions button,
.actions button {
  font: 13px/1.45 var(--pixel-font);
  min-height: 34px;
}
dialog {
  width: min(460px, calc(100vw - 26px));
  max-height: 90dvh;
  margin: auto;
  padding: 0;
  color: var(--paper);
}
dialog::backdrop {
  background: #150e1cdd;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--panel);
  padding: 9px 15px;
  border-bottom: 2px solid var(--rule);
  color: var(--gold);
  font: 14px var(--pixel-font);
}
.modal-body {
  padding: 18px;
}
@media (max-width: 520px) {
  .topbar {
    padding: 11px 12px;
  }
  .brand {
    font-size: clamp(13px, calc(5vw - 3px), 16px);
  }
  .header-actions {
    gap: 6px;
  }
  .game-main,
  .full-page {
    padding: 10px 12px 15px;
  }
  .game-screen {
    gap: 10px;
    grid-template-rows: minmax(0, 1fr) clamp(166px, 22dvh, 196px);
  }
  .coach-card {
    grid-template-columns: clamp(88px, 29vw, 140px) minmax(0, 1fr);
  }
  .coach-copy {
    padding: 10px;
    gap: 6px;
  }
  .speech {
    font-size: 14px;
  }
  .console-actions {
    gap: 5px;
  }
  .console-actions button {
    font-size: 11px;
    padding: 5px 7px;
    min-height: 32px;
  }
  .console-actions svg {
    width: 13px;
    height: 13px;
  }
  .player-row {
    font-size: 14px;
  }
  .player-row > div {
    display: block;
  }
  .player-row small {
    display: none;
  }
  .status {
    font-size: 12px;
  }
  .rank-labels,
  .file-labels {
    font-size: 12px;
  }
  .board-strip {
    font-size: 10px;
  }
}
@media (max-width: 360px) {
  .topbar {
    padding-inline: 8px;
    gap: 6px;
  }
  #menu-tool {
    width: 72px;
  }
}
@media screen and (orientation: landscape) {
  .board-layout, .board-layout ~ dialog.study[open] {
    --rail-min: clamp(188px, 28%, 320px);
    display: grid;
    grid-template-columns: minmax(0, min(100dvh, calc(100% - var(--rail-min)))) minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    gap: 6px clamp(8px, 1.5vw, 24px);
    max-width: calc(100dvh + 540px);
    min-height: 0;
    margin-inline: auto;
    padding: max(4px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }
  .board-layout .topbar {
    grid-area: 1 / 2;
    z-index: 1;
    padding: 2px 0 8px;
    gap: 6px;
    container-type: inline-size;
  }
  .board-layout .brand {
    min-width: 0;
    white-space: normal;
    text-align: left;
    font-size: clamp(13px, 4cqi, 18px);
  }
  .board-layout .header-actions { gap: 6px; }
  .board-layout #menu-tool { width: 40px; }
  .board-layout .install-tool { display: none; }
  .board-layout .game-main {
    grid-area: 1 / 1 / -1 / -1;
    display: grid;
    grid-template: subgrid / subgrid;
    padding: 0;
    max-width: none;
  }
  .game-main .game-screen, .game-main .play-area { display: contents; }
  .game-main .board-space {
    grid-area: 1 / 1 / -1 / 2;
    padding: 0 4px 18px 21px;
  }
  #live-board {
    width: min(100cqw, 100cqh);
    margin: 0;
  }
  #live-board .rank-labels { left: -19px; }
  #live-board .file-labels { bottom: -17px; }
  .game-main .player-row { grid-area: 2 / 2; }
  .game-main .board-strip { grid-area: 3 / 2; }
  .game-main .coach-card {
    grid-area: 4 / 2;
    grid-template-columns: clamp(48px, 21%, 100px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-self: start;
    min-height: min(100%, 108px);
    max-height: 100%;
  }
  .game-main .coach-card.no-portrait { grid-template-columns: minmax(0, 1fr); }
  .game-main .coach-copy {
    min-height: 0;
    padding: 8px 10px;
    overscroll-behavior: contain;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    animation: none !important;
  }
}
