/*
 * Shakin ulkoasu (DESIGN.md, kohta 2). Vain .hdp-shakki-luokat ja .hdpeli[data-game="shakki"]-valitsimet.
 * Mitat tulevat JS:stä: --hdp-shakki-board (laudan sivu) ja --hdp-shakki-sq (ruutu). Lauta on aina ltr.
 */
.hdp-shakki {
  --hdp-shakki-board: 320px;
  --hdp-shakki-sq: 40px;
  --hdp-shakki-light: #f0e4cf;
  --hdp-shakki-dark: #b98b5e;
  --hdp-shakki-last-light: #f2d58a;
  --hdp-shakki-last-dark: #d9ae5c;
  --hdp-shakki-dot: rgba(19, 33, 43, .22);
  display: grid;
  grid-template-columns: var(--hdp-shakki-board);
  grid-template-areas: "top" "board" "bottom" "moves";
  justify-content: center;
  row-gap: 4px;
}
/* Tietokone: lauta vasemmalla, paneeli oikealla laudan korkuisena. */
.hdp-shakki.is-side {
  grid-template-columns: var(--hdp-shakki-board) minmax(180px, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "board top" "board moves" "board bottom";
  justify-content: stretch;
  column-gap: 16px;
  row-gap: 8px;
  height: var(--hdp-shakki-board);
}
.hdp-shakki-row { grid-area: top; display: flex; align-items: center; gap: 8px; min-height: 36px; min-width: 0; font-size: 14px; line-height: 1.3; }
.hdp-shakki-row.is-bottom { grid-area: bottom; }
.hdp-shakki.is-narrow .hdp-shakki-row { min-height: 28px; padding: 0 8px; font-size: 13px; gap: 6px; }
.hdp-shakki.is-side .hdp-shakki-row { flex-wrap: wrap; row-gap: 2px; align-content: center; }
.hdp-shakki-turn { flex: none; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--hdp-line); }
.hdp-shakki-turn.is-on { background: var(--hdp-primary); border-color: var(--hdp-primary); }
.hdp-shakki-turn.is-thinking { animation: hdp-shakki-pulse 1s ease-in-out infinite; }
@keyframes hdp-shakki-pulse { 50% { transform: scale(.55); opacity: .5; } }
.hdp-shakki-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdp-shakki-name strong { font: 600 14px/1.3 var(--hdp-font-display); }
.hdp-shakki.is-narrow .hdp-shakki-name strong { font-size: 13px; }
.hdpeli[data-game="shakki"] .hdp-shakki-level {
  margin: 0; padding: 4px 0; border: 0; background: none; color: var(--hdp-fg); cursor: pointer; min-height: 28px;
  font: 600 14px/1.3 var(--hdp-font-display); text-decoration: underline dotted var(--hdp-muted); text-underline-offset: 3px;
}
.hdp-shakki.is-narrow .hdp-shakki-level { font-size: 13px; }
.hdpeli[data-game="shakki"] .hdp-shakki-level:hover { color: var(--hdp-primary); }
.hdp-shakki-caps { display: inline-flex; align-items: center; flex-wrap: nowrap; min-width: 0; overflow: hidden; }
.hdp-shakki-caps b { margin-inline-start: 4px; color: var(--hdp-muted); font: 600 12px/1 var(--hdp-font-body); font-variant-numeric: tabular-nums; }
.hdp-shakki-mini { display: inline-block; flex: none; width: 18px; height: 18px; margin-inline-end: -6px; background: center / contain no-repeat; }
.hdp-shakki.is-narrow .hdp-shakki-mini { width: 15px; height: 15px; margin-inline-end: -5px; }
.hdp-shakki-status { margin-inline-start: auto; color: var(--hdp-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdp-shakki.is-side .hdp-shakki-status { margin-inline-start: 18px; flex-basis: 100%; }

/* ---------- lauta ---------- */
.hdp-shakki-boardbox { grid-area: board; position: relative; width: var(--hdp-shakki-board); height: var(--hdp-shakki-board); }
.hdp-shakki-board {
  position: relative; width: 100%; height: 100%; border-radius: 6px; overflow: hidden; outline: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .15), 0 6px 20px rgba(16, 36, 52, .12);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.hdp-shakki-board:focus-visible { box-shadow: 0 0 0 3px var(--hdp-primary-2), 0 6px 20px rgba(16, 36, 52, .12); }
.hdp-shakki-rank { display: contents; }
.hdp-shakki-sq {
  position: absolute; left: 0; top: 0; width: var(--hdp-shakki-sq); height: var(--hdp-shakki-sq);
  background-color: var(--hdp-shakki-light); touch-action: manipulation;
}
.hdp-shakki-sq.is-dark { background-color: var(--hdp-shakki-dark); }
.hdp-shakki-sq.is-light.is-last { background-color: var(--hdp-shakki-last-light); }
.hdp-shakki-sq.is-dark.is-last { background-color: var(--hdp-shakki-last-dark); }
.hdp-shakki-sq.is-mine { touch-action: none; cursor: grab; }
.hdp-shakki-sq.is-sel { background-image: linear-gradient(rgba(22, 132, 184, .55), rgba(22, 132, 184, .55)); }
.hdp-shakki-sq.is-check { background-image: radial-gradient(circle, rgba(214, 48, 49, .9) 0%, rgba(214, 48, 49, .55) 45%, rgba(214, 48, 49, 0) 72%); }
.hdp-shakki-sq.is-flash { animation: hdp-shakki-flash .6s ease-out 2; }
@keyframes hdp-shakki-flash { 50% { box-shadow: inset 0 0 0 999px rgba(214, 48, 49, .55); } }
.hdp-shakki-sq.is-target, .hdp-shakki-sq.is-capture { cursor: pointer; }
.hdp-shakki-sq.is-target::after {
  content: ""; position: absolute; left: 34%; top: 34%; width: 32%; height: 32%; border-radius: 50%; background: var(--hdp-shakki-dot);
}
.hdp-shakki-sq.is-capture::after {
  content: ""; position: absolute; inset: 2%; border-radius: 50%; box-shadow: inset 0 0 0 calc(var(--hdp-shakki-sq) * .09) var(--hdp-shakki-dot);
}
.hdp-shakki-sq.is-hover { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .85); background-image: linear-gradient(rgba(22, 132, 184, .25), rgba(22, 132, 184, .25)); }
.hdp-shakki-sq.is-hint { box-shadow: inset 0 0 0 3px var(--hdp-okra); }
.hdp-shakki-sq.is-cursor { box-shadow: inset 0 0 0 3px var(--hdp-primary-2); z-index: 1; }
.hdp-shakki-cf, .hdp-shakki-cr {
  position: absolute; display: none; pointer-events: none;
  font: 600 max(9px, calc(var(--hdp-shakki-sq) * .17))/1 var(--hdp-font-body);
}
.hdp-shakki-cf { right: 4%; bottom: 3%; }
.hdp-shakki-cr { left: 5%; top: 4%; }
.hdp-shakki-sq.is-light .hdp-shakki-cf, .hdp-shakki-sq.is-light .hdp-shakki-cr { color: var(--hdp-shakki-dark); }
.hdp-shakki-sq.is-dark .hdp-shakki-cf, .hdp-shakki-sq.is-dark .hdp-shakki-cr { color: var(--hdp-shakki-light); }
.hdp-shakki-sq.has-file .hdp-shakki-cf, .hdp-shakki-sq.has-rank .hdp-shakki-cr { display: block; }
.hdp-shakki.no-coords .hdp-shakki-cf, .hdp-shakki.no-coords .hdp-shakki-cr { display: none; }
.hdp-shakki-pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.hdp-shakki-pc {
  position: absolute; left: 0; top: 0; width: var(--hdp-shakki-sq); height: var(--hdp-shakki-sq);
  background: center / 100% 100% no-repeat; will-change: transform;
}
.hdp-shakki-pc.is-lifted { z-index: 10; scale: 1.08; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .35)); }
.hdp-shakki-pc.is-lifted.is-touch { scale: 1.3; }
.hdp-shakki-arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.hdp-shakki-arrows line { stroke: #f4ba6c; stroke-linecap: round; opacity: .9; }
.hdp-shakki-arrows polygon { fill: #f4ba6c; opacity: .9; }

/* ---------- korotusvalitsin ---------- */
.hdp-shakki-promo { position: absolute; inset: 0; z-index: 20; background: rgba(19, 33, 43, .35); border-radius: 6px; }
.hdp-shakki-promo-col {
  position: absolute; width: var(--hdp-shakki-sq); display: grid; background: #ffffff; border-radius: 8px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .15), 0 10px 30px rgba(0, 0, 0, .35);
}
.hdpeli[data-game="shakki"] .hdp-shakki-promo-btn {
  width: var(--hdp-shakki-sq); height: var(--hdp-shakki-sq); margin: 0; padding: 0; border: 0; border-radius: 0; cursor: pointer;
  background: #ffffff center / 86% 86% no-repeat;
}
.hdpeli[data-game="shakki"] .hdp-shakki-promo-btn:hover, .hdpeli[data-game="shakki"] .hdp-shakki-promo-btn:focus-visible { background-color: #e3f1f8; outline: none; box-shadow: inset 0 0 0 3px var(--hdp-primary-2); }

/* ---------- siirtolista ja napit ---------- */
.hdp-shakki-movesbox { grid-area: moves; display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 40px; }
.hdp-shakki.is-narrow .hdp-shakki-movesbox { min-height: 36px; padding: 0 8px; }
.hdpeli[data-game="shakki"] .hdp-shakki-moves {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 10px; margin: 0; padding: 0 2px; list-style: none;
  overflow-x: auto; overflow-y: hidden; white-space: nowrap; scrollbar-width: none; font: 500 14px/1.4 var(--hdp-font-body);
  font-variant-numeric: tabular-nums;
}
.hdp-shakki-moves::-webkit-scrollbar { display: none; }
.hdpeli[data-game="shakki"] .hdp-shakki-moves li { display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 0; }
.hdp-shakki-no { color: var(--hdp-muted); }
.hdp-shakki-mv { padding: 1px 3px; border-radius: 4px; }
.hdp-shakki-mv.is-last { background: rgba(244, 186, 108, .4); }
.hdp-shakki-fig { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -.25em; background: center / contain no-repeat; }
.hdp-shakki-acts { flex: none; display: flex; gap: 4px; }
.hdpeli[data-game="shakki"] .hdp-shakki-act {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; width: 40px; height: 40px; margin: 0; padding: 0;
  border: 1px solid var(--hdp-line); border-radius: 10px; background: var(--hdp-surface); color: var(--hdp-fg); cursor: pointer;
  font: 600 13px/1 var(--hdp-font-display);
}
.hdpeli[data-game="shakki"] .hdp-shakki-act:hover:not(:disabled) { border-color: var(--hdp-primary); }
.hdpeli[data-game="shakki"] .hdp-shakki-act:disabled { opacity: .4; cursor: default; }
.hdp-shakki-act svg { width: 18px; height: 18px; flex: none; }
.hdp-shakki-act span { display: none; }
.hdpeli[data-game="shakki"] .hdp-shakki.is-narrow .hdp-shakki-act { width: 36px; height: 36px; }

/* Paneeli tietokoneella: kaksisarakkeinen siirtolista, napit alla. */
.hdp-shakki.is-side .hdp-shakki-movesbox {
  display: grid; grid-template-rows: minmax(0, 1fr) auto; align-items: stretch; gap: 0; min-height: 0;
  border: 1px solid var(--hdp-line); border-radius: 10px; background: var(--hdp-surface); overflow: hidden;
}
.hdpeli[data-game="shakki"] .hdp-shakki.is-side .hdp-shakki-moves { display: block; overflow-x: hidden; overflow-y: auto; white-space: normal; padding: 4px 0; scrollbar-width: thin; }
.hdpeli[data-game="shakki"] .hdp-shakki.is-side .hdp-shakki-moves li { display: grid; grid-template-columns: 2.6em minmax(0, 1fr) minmax(0, 1fr); gap: 2px; padding: 2px 8px; }
.hdpeli[data-game="shakki"] .hdp-shakki.is-side .hdp-shakki-moves li:nth-child(even) { background: var(--hdp-bg); }
.hdp-shakki.is-side .hdp-shakki-acts { display: flex; justify-content: space-between; padding: 6px; border-top: 1px solid var(--hdp-line); }

/* ---------- dialogit (liitetty bodyyn) ---------- */
.hdp-shakki-newgame { display: grid; gap: 14px; }
.hdp-shakki-fs { border: 0; padding: 0; margin: 0; min-width: 0; display: grid; gap: 6px; }
.hdp-shakki-fs legend { padding: 0; margin-bottom: 6px; font: 600 12px/1.2 var(--hdp-font-display); letter-spacing: .06em; text-transform: uppercase; color: var(--hdp-muted); }
.hdp-shakki-fs .hdpeli-seg span { padding: 9px 4px; color: var(--hdp-fg); }
.hdp-shakki-fs .hdpeli-seg input:checked + span { color: var(--hdp-primary-ink); }
.hdp-shakki-help { margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: var(--hdp-muted); }
.hdp-shakki-note { margin: 0; font-size: 13px; line-height: 1.45; color: var(--hdp-okra-dark); }
.hdp-shakki-statswrap { overflow-x: auto; }
.hdp-shakki-stats { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.hdp-shakki-stats th, .hdp-shakki-stats td { padding: 6px 4px; border-bottom: 1px solid var(--hdp-line); text-align: end; white-space: nowrap; }
.hdp-shakki-stats th[scope="row"], .hdp-shakki-stats thead th:first-child { text-align: start; font-weight: 600; }
.hdp-shakki-stats thead th { font: 600 11px/1.3 var(--hdp-font-display); text-transform: uppercase; letter-spacing: .04em; color: var(--hdp-muted); }
.hdp-shakki-sr { position: absolute !important; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .hdp-shakki-turn.is-thinking, .hdp-shakki-sq.is-flash { animation: none; }
}
