:root {
  --chess-navy: #17324d;
  --chess-teal: #2b7a78;
  --chess-cream: #fff7df;
  --chess-gold: #e2ad36;
  --chess-coral: #d96955;
}

.chess-shell { width: min(100%, 46rem); }
.chess-shell .game-stage { place-items: stretch; touch-action: manipulation; }
.chess-shell .game-profile { display: none; }
.header-buttons { display: flex; gap: .4rem; }
.header-buttons .icon-button { min-width: 0; padding-inline: .65rem; }
.chess-app { width: 100%; min-height: 0; display: grid; place-items: center; }
.chess-app > [hidden] { display: none !important; }
.start-card, .queue-card {
  width: min(100%, 35rem);
  max-height: 100%;
  padding: clamp(1rem, 3vw, 1.75rem);
  overflow: auto;
  border: 1px solid #c9c0b2;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 8px 9px 0 #e8dfcf;
}
.start-card h2, .queue-card h2, .rules-dialog h2, .promotion-dialog h2, .concede-dialog h2 {
  margin: .15rem 0 .65rem;
  color: var(--chess-navy);
  font: 750 clamp(1.8rem, 7vw, 2.8rem)/.98 Georgia, "Times New Roman", serif;
  letter-spacing: -.035em;
}
.start-card > p:not(.eyebrow), .queue-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.48; }
.eyebrow { margin: 0 0 .55rem; color: var(--chess-teal); font-size: .67rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.mini-board {
  width: 5.5rem; height: 5.5rem; position: relative; display: grid; grid-template-columns: 1fr 1fr;
  margin-bottom: .8rem; overflow: hidden; border: 2px solid var(--chess-navy); border-radius: 10px;
  background: conic-gradient(from 90deg, #e6d7b8 25%, var(--chess-teal) 0 50%, #e6d7b8 0 75%, var(--chess-teal) 0);
  background-size: 50% 50%;
}
.mini-board span, .mini-board strong { position: absolute; font: 2.8rem/1 Georgia, serif; filter: drop-shadow(2px 3px 0 rgba(0,0,0,.18)); }
.mini-board span { left: .25rem; bottom: .2rem; color: var(--chess-navy); }
.mini-board strong { right: .3rem; top: .2rem; color: var(--chess-cream); }
.start-actions { display: flex; margin: .9rem 0; }
.start-actions .action-button { min-width: 0; width: 100%; white-space: normal; }
.difficulty-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; margin: 0; padding: 0; border: 0; }
.difficulty-picker legend { width: 100%; margin-bottom: .5rem; color: var(--chess-navy); font-size: .72rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.difficulty-picker .action-button { min-width: 0; min-height: 4.25rem; display: grid; align-content: center; gap: .2rem; padding: .5rem; white-space: normal; }
.difficulty-picker small { color: var(--muted); font-size: .58rem; font-weight: 700; line-height: 1.2; }
.no-account { margin: .8rem 0 0; font-size: .75rem; }
.queue-card { text-align: center; }
.search-knight {
  width: 6rem; height: 6rem; display: grid; place-items: center; margin: 0 auto .8rem;
  border: 2px dashed #9eb3ad; border-radius: 50%; color: var(--chess-teal);
  font: 3.7rem/1 Georgia, serif; animation: knight-search 2.4s ease-in-out infinite;
}
@keyframes knight-search { 50% { transform: translateY(-.35rem) rotate(-7deg); } }

.chess-statusbar { gap: .75rem; }
.status-copy { min-width: 0; flex: 1; overflow: hidden; color: var(--muted); font-size: .75rem; font-weight: 750; line-height: 1.25; text-align: center; text-overflow: ellipsis; }
.timer-value.warning { color: #a93f2f; }
.board-view { width: min(100%, 38rem); height: 100%; min-height: 0; max-height: 100%; display: grid; grid-template-rows: auto 4px minmax(0, 1fr) auto auto; gap: .4rem; }
.player-strip {
  min-height: 2.65rem; display: flex; align-items: center; justify-content: space-between; gap: .7rem;
  padding: .35rem .55rem; border: 1px solid #c9c0b2; border-radius: 9px; background: var(--panel);
}
.player-identity { min-width: 0; display: flex; align-items: center; gap: .45rem; }
.player-identity img { width: 1.85rem; height: 1.85rem; flex: none; border: 1px solid var(--chess-navy); border-radius: 50%; object-fit: cover; }
.player-identity span { min-width: 0; display: grid; line-height: 1.05; }
.player-identity strong { overflow: hidden; color: var(--chess-navy); font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.player-identity small, .strike-status { color: var(--muted); font-size: .57rem; font-weight: 800; }
.player-strip.active { border-color: var(--chess-gold); box-shadow: 0 0 0 2px rgba(226,173,54,.2); }
.player-strip.active img { animation: active-seat-pulse 2.4s ease-in-out infinite; }
@keyframes active-seat-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(226,173,54,.15); }
  50% { transform: scale(1.1); box-shadow: 0 0 0 .24rem rgba(226,173,54,.22); }
}
.turn-meter { height: 4px; overflow: hidden; border-radius: 10px; background: #d8d0c3; }
.turn-meter span { display: block; width: 100%; height: 100%; transform-origin: left; background: var(--chess-gold); }
.chess-board-frame {
  min-width: 0; min-height: 0; display: grid; place-items: center; container-type: size;
}
.chess-board {
  width: min(100cqw, 100cqh); height: min(100cqw, 100cqh); min-height: 0; aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  overflow: hidden;
  container-type: inline-size;
  border: 3px solid var(--chess-navy); border-radius: 8px; background: #eadfc7;
  box-shadow: 5px 6px 0 rgba(23,50,77,.17);
}
.chess-square {
  position: relative; min-width: 0; min-height: 0; aspect-ratio: 1; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 0; background: #eadfc7; color: var(--chess-navy);
  font: clamp(.72rem, 9cqw, 3.55rem)/1 "Times New Roman", Georgia, serif; cursor: default;
}
.chess-square.dark { background: #4f8a7c; }
.chess-square.selectable { cursor: pointer; }
.chess-square.selected { box-shadow: inset 0 0 0 4px var(--chess-gold); }
.chess-square.target::after {
  content: ""; position: absolute; width: 24%; aspect-ratio: 1; border-radius: 50%;
  background: rgba(23,50,77,.38); pointer-events: none;
}
.chess-square.target.occupied::after { width: 82%; background: transparent; border: 4px solid rgba(217,105,85,.78); }
.chess-square.last-move { background-image: linear-gradient(rgba(226,173,54,.34), rgba(226,173,54,.34)); }
.chess-square.bot-last-move {
  background-image: linear-gradient(rgba(70,154,214,.68), rgba(70,154,214,.68));
  box-shadow: inset 0 0 0 2px rgba(23,50,77,.42);
}
.chess-square.in-check { background: var(--chess-coral); }
.chess-piece {
  position: relative; z-index: 1; display: block;
  width: 1em; height: 1em; text-align: center;
  font-variant-emoji: text;
  filter: drop-shadow(1px 2px 0 rgba(0,0,0,.18));
}
.chess-piece.black {
  color: #142c43;
  -webkit-text-fill-color: #142c43;
  -webkit-text-stroke: 0;
}
.chess-piece.white {
  color: #fff8e7;
  -webkit-text-fill-color: #fff8e7;
  -webkit-text-stroke: 1px #17324d;
  paint-order: stroke fill;
}
.coordinate { position: absolute; z-index: 2; color: rgba(23,50,77,.7); font: 800 clamp(.42rem, 1.8cqw, .62rem)/1 system-ui, sans-serif; pointer-events: none; }
.coordinate.file { right: 3px; bottom: 2px; }
.coordinate.rank { left: 3px; top: 2px; }
.dark .coordinate { color: rgba(255,250,240,.8); }
.match-notice { min-height: 1.2rem; margin: 0; color: var(--muted); font-size: .65rem; font-weight: 750; line-height: 1.3; text-align: center; }

.rules-dialog, .promotion-dialog, .concede-dialog {
  width: min(calc(100% - 2rem), 32rem); max-height: calc(100dvh - 2rem); padding: 0;
  border: 2px solid var(--chess-navy); border-radius: 14px; background: var(--panel); color: var(--text);
  box-shadow: 8px 9px 0 rgba(0,0,0,.2);
}
.rules-dialog::backdrop, .promotion-dialog::backdrop, .concede-dialog::backdrop { background: rgba(16,38,58,.72); backdrop-filter: blur(5px); }
.rules-dialog form, .promotion-dialog form, .concede-dialog form { padding: 1.5rem; }
.rules-dialog h2, .promotion-dialog h2, .concede-dialog h2 { font-size: 2rem; }
.rules-dialog ol { padding-left: 1.25rem; }
.rules-dialog li, .rules-dialog p, .concede-dialog p { margin-bottom: .7rem; color: var(--muted); line-height: 1.48; }
.dialog-close { float: right; width: 2.5rem; height: 2.5rem; border: 0; border-radius: 50%; background: #ece5d9; color: var(--chess-navy); font-size: 1.5rem; cursor: pointer; }
.promotion-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; margin: 1rem 0; }
.promotion-choices button { aspect-ratio: 1; border: 2px solid var(--chess-navy); border-radius: 9px; background: #eadfc7; color: var(--chess-navy); font: 2.5rem/1 Georgia, serif; cursor: pointer; }
.dialog-actions { display: flex; gap: .65rem; }
.dialog-actions .action-button { flex: 1; }

@media (max-height: 760px) and (orientation: portrait) {
  .board-view { gap: .25rem; }
  .player-strip { min-height: 2.2rem; padding-block: .22rem; }
  .player-identity img { width: 1.55rem; height: 1.55rem; }
  .match-notice { min-height: .9rem; font-size: .58rem; }
}
@media (max-height: 620px) and (orientation: landscape) {
  .chess-shell { width: min(100%, 58rem); }
  .chess-shell .game-header h1 { font-size: 1rem; }
  .chess-app { height: 100%; }
  .start-card {
    height: 100%;
    padding: .55rem;
    display: grid;
    grid-template-columns: minmax(7rem, .62fr) minmax(15rem, 1.38fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: .25rem .55rem;
    overflow: hidden;
  }
  .start-card .mini-board { grid-column: 1; grid-row: 1 / span 2; width: 4.2rem; height: 4.2rem; margin: 0 auto; }
  .start-card .mini-board span, .start-card .mini-board strong { font-size: 2.05rem; }
  .start-card .eyebrow { grid-column: 2; grid-row: 1; align-self: end; margin: 0; }
  .start-card h2 { grid-column: 2; grid-row: 2; margin: 0; font-size: clamp(1.25rem, 5.7cqh, 1.7rem); }
  .start-card > p:not(.eyebrow), .start-card .no-account { display: none; }
  .start-card .start-actions { grid-column: 1; grid-row: 3; align-self: stretch; flex-direction: column; gap: .3rem; margin: 0; }
  .start-card .start-actions .action-button { min-width: 0; min-height: 0; padding: .35rem; white-space: normal; }
  .start-card .difficulty-picker { grid-column: 2; grid-row: 3; gap: .3rem; min-height: 0; }
  .start-card .difficulty-picker legend { margin-bottom: .2rem; }
  .start-card .difficulty-picker .action-button { min-height: 0; height: 100%; padding: .25rem; }
  .queue-card { padding: .65rem; overflow: hidden; }
  .queue-card .search-knight { width: 3.6rem; height: 3.6rem; margin-bottom: .3rem; font-size: 2.2rem; }
  .queue-card h2 { margin-bottom: .25rem; font-size: 1.45rem; }
  .queue-card > p:not(.eyebrow) { margin: .2rem 0; font-size: .75rem; line-height: 1.25; }
  .board-view { height: 100%; }
  .player-strip { min-height: 2rem; padding-block: .18rem; }
  .player-identity img { width: 1.45rem; height: 1.45rem; }
  .match-notice { display: none; }
}
@media (max-width: 480px) {
  .difficulty-picker { grid-template-columns: 1fr; }
  .difficulty-picker .action-button { min-height: 3.1rem; grid-template-columns: 5rem 1fr; align-items: center; text-align: left; }
  .header-buttons .icon-button { padding-inline: .45rem; font-size: .72rem; }
  .status-copy { font-size: .66rem; }
}
@media (max-width: 350px) {
  .chess-square { font-size: clamp(1.45rem, 10cqw, 3rem); }
  .player-identity strong { max-width: 7.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .search-knight, .player-strip.active img { animation: none; }
}
