.chess-page {
  background: radial-gradient(ellipse at 38% 4%, #482925, #1d1115 52%, #0b0708);
}
.chess-page .puzzle-main { width: min(calc(100% - 28px), 1040px); padding-block: 16px 36px; }
.chess-page .puzzle-heading { margin: 6px 0 16px; }
.chess-page h1 { color: #ffecd1; }
.chess-layout {
  display: grid;
  grid-template-columns: minmax(0, 670px) minmax(210px, 1fr);
  align-items: start;
  gap: clamp(12px, 2vw, 24px);
}
.chess-stage, .chess-panel {
  min-width: 0;
  border: 1px solid #694638;
  border-radius: 15px;
  background: #211416;
  padding: clamp(9px, 1.6vw, 18px);
  box-shadow: 0 14px 36px #0005;
}
.chess-status {
  margin: 0 0 10px;
  min-height: 1.5em;
  color: #ffedd3;
  font-weight: 700;
}
.chess-frame {
  padding: clamp(6px, 1.2vw, 14px);
  border-radius: 9px;
  background: repeating-linear-gradient(174deg, #704225 0 2px, #512a19 3px 5px, #68351f 6px 9px);
  border: 1px solid #a4774d;
  box-shadow: inset 0 0 8px #26100e, 0 4px 0 #2c1612;
}
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border: 1px solid #2f180f;
  aspect-ratio: 1;
  background: #b7825e;
}
.chess-square {
  display: grid;
  place-items: center;
  position: relative;
  border: 0;
  padding: 0;
  min-width: 0;
  background: repeating-linear-gradient(175deg, #fff0 0 3px, #7331120d 4px, #fff0 6px), #e7bb89;
  color: #462513;
  touch-action: manipulation;
}
.chess-square.is-dark { background-color: #9b6245; color: #fff3d7; }
.chess-square.is-last { box-shadow: inset 0 0 0 3px #f4d581b0; }
.chess-square.is-selected { box-shadow: inset 0 0 0 3px #ffe7a0, inset 0 0 22px #855620ba; }
.chess-square.in-check { box-shadow: inset 0 0 0 3px #fa4d46, inset 0 0 14px #982119; }
.chess-square:focus-visible { outline: 2px solid #fff3c9; outline-offset: -3px; z-index: 2; }
.chess-square.is-target::after {
  content: "";
  position: absolute;
  width: 23%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #33190e99;
  pointer-events: none;
}
.chess-square.is-capture::after {
  width: 86%;
  background: none;
  border: 3px solid #542b20cf;
}
.chess-piece {
  --sprite: url("platform-assets/miharo-chess-pieces.webp");
  display: block;
  position: relative;
  width: 94%;
  aspect-ratio: 1;
  background-image: var(--sprite);
  background-repeat: no-repeat;
  background-size: 600% 100%;
  background-position: var(--piece-position) 50%;
  filter: drop-shadow(0 1px 1px #49240f9e);
  pointer-events: none;
}
.chess-piece.is-charcoal {
  filter: grayscale(.86) brightness(.34) contrast(1.05) drop-shadow(0 0 .65px #fce5cbbb) drop-shadow(0 1px 1px #25140f99);
}
.chess-coordinate {
  position: absolute;
  z-index: 1;
  font-size: clamp(.47rem, 1.25vw, .72rem);
  font-weight: 750;
  pointer-events: none;
}
.chess-rank { top: 2px; left: 3px; }
.chess-file { right: 3px; bottom: 2px; }
.chess-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chess-actions label, .chess-actions select { grid-column: 1 / -1; }
.chess-actions label { font-weight: 700; color: #ffedd3; }
.chess-guide { margin-top: 15px; border-top: 1px solid #694638; padding-top: 10px; }
.chess-guide summary { cursor: pointer; min-height: 32px; }
.chess-guide ul { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 4px; padding: 0; margin: 6px 0; list-style: none; text-align: center; }
.chess-guide li { display: grid; justify-items: center; font-size: .82rem; color: #fbe5c6; }
.chess-guide .chess-piece { width: min(100%, 100px); }
#chess-promotion { width: min(calc(100% - 30px), 400px); border: 1px solid #a87550; border-radius: 14px; background: #2c1b1c; color: #fff0d5; padding: 16px; }
#chess-promotion::backdrop { background: #080505b8; }
#chess-promotion h2 { margin: 0 0 12px; font: 1.5rem Georgia, serif; }
.chess-promotion-options { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
@media (max-width: 740px), (pointer: coarse) and (orientation: portrait) {
  .chess-layout { grid-template-columns: minmax(0, 1fr); }
  .chess-actions { grid-template-columns: minmax(0, 1.2fr) 1fr 1fr; }
  .chess-actions label { grid-column: 1 / -1; }
  .chess-actions select { grid-column: auto; min-width: 0; }
}

/* Private online match controls */
.chess-actions [hidden], .chess-online [hidden] { display: none !important; }
.chess-online { margin-top: 14px; padding: 14px; border: 1px solid #88644c; border-radius: 12px; background: #301d1f; color: #ffe8cd; }
.chess-online label { display: block; font-weight: 700; font-size: .9rem; margin: 12px 0 6px; }
.chess-online input { box-sizing: border-box; width: 100%; min-width: 0; padding: 10px; color: #221416; background: #fff6e8; border: 2px solid #cda578; border-radius: 8px; font-size: 1rem; }
.chess-online input:focus { outline: 3px solid #ffe7a0; outline-offset: 2px; }
.chess-online .puzzle-button { width: 100%; min-height: 42px; margin-top: 9px; }
.chess-online-actions { display: flex; gap: 8px; }
.chess-online-actions .puzzle-button { flex: 1; }
.chess-online-note { min-height: 1.5em; font-size: .95rem; line-height: 1.45; }
.chess-online-safety { color: #e3c5a6; font-size: .8rem; }

.chess-learning {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .85rem;
  margin-bottom: .7rem;
  color: #ffedd3;
}
.chess-learning[hidden] { display: none; }
.chess-online .chess-learning { margin-block: 0 0.8rem; }
.chess-learning label { font-weight: 700; }
.chess-learning select { max-width: 100%; min-height: 44px; }
.chess-suggestions[hidden] { display: none; }
.chess-suggestions {
  margin-top: 1rem;
  padding: .8rem;
  border: 1px solid #88644c;
  border-radius: 9px;
  background: #301d1f;
  color: #ffedd3;
}
.chess-suggestions h2 { margin: 0; font: 1.4rem Georgia, serif; }
.chess-suggestions p { margin: .35rem 0 .65rem; font-size: .9rem; }
.chess-suggestions ol { margin: 0; padding-left: 1.5rem; }
.chess-suggestions li + li { margin-top: .35rem; }
.chess-suggestions button { min-height: 44px; width: 100%; text-align: left; }

/* Bilingual piece identification in every mode; local board rotation is automatic. */
.chess-piece-info[hidden], .chess-local-note[hidden] { display: none !important; }
.chess-piece-info {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .9rem;
  margin-top: .65rem; padding: .65rem .85rem;
  border: 1px solid #a47e52; border-radius: 9px;
  background: #39231f; color: #fff1d9; line-height: 1.4;
}
.chess-piece-info strong { font-size: 1.05rem; }
.chess-piece-info span { color: #edd1b4; font-size: .87rem; }
.chess-local-note { color: #eacbaa; font-size: .86rem; margin: .65rem 0 0; }

/* Polished pounamu-inspired board: layered jade tones without a heavy image asset. */
.chess-frame {
  background:
    radial-gradient(ellipse at 24% 7%, #c4e0bd4d, transparent 50%),
    repeating-linear-gradient(164deg, #174737 0 5px, #255744 7px 15px, #194a3c 17px 23px);
  border-color: #a9c2ad;
  box-shadow: inset 0 0 7px #b4d6b86b, 0 4px 0 #143b32;
}
.chess-board { background-color: #6a9d84; }
.chess-square {
  background:
    radial-gradient(ellipse at 20% 15%, #ffffff55 0, #ffffff00 59%),
    repeating-linear-gradient(163deg, #20594500 0 5px, #2059450c 6px, #20594500 12px),
    linear-gradient(132deg, #d4e7c8, #b0ceb7);
  color: #244e3e;
}
.chess-square.is-dark {
  background:
    radial-gradient(ellipse at 17% 14%, #edffe42c 0, #edffe400 62%),
    repeating-linear-gradient(154deg, #123e3000 0 8px, #123e3016 9px, #123e3000 16px),
    linear-gradient(134deg, #679f83, #477e69);
  color: #f5f5da;
}
.chess-piece.is-charcoal {
  filter: grayscale(.86) brightness(.34) contrast(1.05)
    drop-shadow(0 0 1.25px #e5f4db) drop-shadow(0 1px 1px #f1f7e9);
}
.chess-square.is-dark .chess-piece.is-charcoal {
  filter: grayscale(.95) brightness(.3) contrast(1.12)
    drop-shadow(0 0 1.75px #f2f8e8) drop-shadow(0 1px 1px #f2f8e8);
}
/* Keep the selected character's name in sight above the board on phones. */
.chess-piece-info {
  margin: 0 0 .55rem;
  padding: .55rem .7rem;
  border-color: #88b599;
  background: #234d3e;
  color: #f5f7e6;
  line-height: 1.35;
}
.chess-piece-info span { color: #d4e8d0; }



/* v4: mobile-first pounamu set — restrained materials, clear playable board.
   The decorative border stays outside all 64 squares. */
.chess-page {
  background:
    radial-gradient(ellipse 85% 27% at 42% 0%, #65472d44, transparent 80%),
    radial-gradient(ellipse 70% 43% at 87% 82%, #1c302638, transparent 75%),
    linear-gradient(180deg, #190f0c, #0e0a09 70%, #090706);
}
.chess-page .puzzle-main {
  width: min(calc(100% - 22px), 1100px);
  padding-block: clamp(14px, 2vw, 23px) 48px;
}
.chess-page .puzzle-back { color: #d8bd98; }
.chess-page .puzzle-heading {
  padding: 7px 1px 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid #76543b59;
}
.chess-page .puzzle-heading h1 {
  font-size: clamp(2.1rem, 6.6vw, 3.8rem);
  color: #f4dfb7;
  text-shadow: 0 1px 3px #090706, 0 0 16px #dbad6420;
  letter-spacing: -.04em;
}
.chess-layout {
  grid-template-columns: minmax(0, 710px) minmax(240px, 1fr);
  gap: clamp(12px, 2vw, 20px);
}
.chess-stage, .chess-panel {
  padding: clamp(9px, 1.3vw, 16px);
  border: 1px solid #604637;
  border-radius: 14px;
  background: linear-gradient(165deg, #211714, #130e0c 75%);
  box-shadow: inset 0 1px 0 #b88c5930, 0 16px 36px #0008;
}
.chess-learning, .chess-status, .chess-actions label { color: #edd7b7; }
.chess-status { margin-bottom: 11px; }
.chess-page .puzzle-button {
  min-height: 44px;
  color: #f0dfc3;
  border: 1px solid #7e5940;
  border-radius: 9px;
  background: linear-gradient(160deg, #382922, #261c18);
  box-shadow: inset 0 1px 0 #fce4b41c;
}
.chess-page .puzzle-button:hover:not(:disabled) { filter: brightness(1.12); }
.chess-page .puzzle-primary {
  color: #22170e;
  border-color: #eac48d;
  background: linear-gradient(160deg, #f6dcad, #dfac69 65%, #bd8249);
  box-shadow: inset 0 1px 0 #fff4dc94;
}
/* Real woodgrain is kept thin and entirely around, never on top of, squares. */
.chess-frame {
  position: relative;
  isolation: isolate;
  padding: clamp(8px, 1.5vw, 14px);
  border: 2px solid #987047;
  border-radius: 14px;
  background:
    linear-gradient(180deg, #d5a56e46, transparent 20%, #27150c70 85%),
    repeating-linear-gradient(171deg,
      #402515 0 3px, #57361f 4px 6px,
      #351e12 7px 11px, #684128 12px 13px,
      #422616 14px 20px);
  box-shadow:
    inset 0 1px 1px #ffdb9e9c,
    inset 0 -3px 5px #170a08a8,
    0 4px 0 #1b0d08,
    0 9px 20px #0008;
}
/* A narrow etched border — no decorative layer can obscure a character. */
.chess-frame::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid #d7a56a73;
  border-radius: 9px;
  pointer-events: none;
}
.chess-frame::after { content: none; }
.chess-board {
  position: relative;
  z-index: 1;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid #18382c;
  border-radius: 3px;
  background: #46795e url("platform-assets/chess-greenstone-marble.svg") center / cover no-repeat;
  box-shadow: inset 0 0 8px #15352878, 0 0 0 1px #dcc18c8c;
}
/* Readable jewel tones. Translucency reveals gentle stone veining, not stripes. */
.chess-square {
  background:
    radial-gradient(circle at 20% 13%, #f6ffdf80, transparent 75%),
    linear-gradient(142deg, #cce5cae9, #a9c7b0ed);
  color: #234e3a;
  box-shadow: inset 1px 1px 0 #fcfff22d;
}
.chess-square.is-dark {
  background:
    radial-gradient(circle at 19% 10%, #d1f3c942, transparent 72%),
    linear-gradient(143deg, #64977eea, #3c795fe8);
  color: #f4e8c6;
  box-shadow: inset 1px 1px 0 #e8ffdd22;
}
.chess-square.is-last { box-shadow: inset 0 0 0 2px #f3d597aa; }
.chess-square.is-selected {
  box-shadow: inset 0 0 0 3px #ffe2a2, inset 0 0 15px #e3b56869;
  z-index: 2;
}
.chess-square.in-check { box-shadow: inset 0 0 0 3px #f97869, inset 0 0 14px #9a2c21; }
.chess-square.is-target::after {
  width: 24%;
  background: #523f26a6;
}
.chess-square.is-capture::after {
  width: 82%;
  border: 3px solid #f5dfb6;
  background: none;
}
/* Preserve the original charcoal pieces — never hue-shift them into green. */
.chess-piece {
  width: 100%;
  --piece-scale: 1.075;
  transform: scale(var(--piece-scale));
  transform-origin: 50% 67%;
  filter: saturate(1.04) contrast(1.10)
    drop-shadow(0 0 1px #5d351c9c)
    drop-shadow(0 2px 2px #133025bb);
  transition: transform .16s ease;
}
.chess-piece[data-role="k"], .chess-piece[data-role="q"] { --piece-scale: 1.1; }
.chess-piece[data-role="p"] { --piece-scale: 1.055; }
.chess-piece.is-charcoal,
.chess-square.is-dark .chess-piece.is-charcoal {
  filter: grayscale(1) brightness(.32) contrast(1.19)
    drop-shadow(0 0 1.1px #f7f0dd)
    drop-shadow(0 2px 1.2px #edf7e4a8);
}
.chess-square.is-selected .chess-piece {
  transform: translateY(-2%) scale(calc(var(--piece-scale) * 1.04));
}
.chess-coordinate {
  font-size: clamp(.5rem, 1.3vw, .72rem);
  color: #fdf3d9;
  text-shadow: 0 1px 2px #123125;
}
.chess-square:not(.is-dark) .chess-coordinate {
  color: #204e35;
  text-shadow: 0 1px 1px #f4ffe4;
}
.chess-piece-info {
  margin: 0 0 .6rem;
  padding: .6rem .7rem;
  border: 1px solid #9c8158;
  border-radius: 9px;
  background: #273629;
  color: #f6e6c2;
}
.chess-piece-info span { color: #d4ddc7; }
.chess-local-note { color: #deccaf; }
.chess-guide { border-color: #624a34; }
.chess-guide summary { color: #e9d1a5; }
.chess-guide li { color: #ecd9b8; line-height: 1.4; }
/* Controls remain large enough for mobile fingers. */
@media (max-width: 740px), (pointer: coarse) and (orientation: portrait) {
  .chess-layout { grid-template-columns: minmax(0, 1fr); }
  .chess-frame { padding: clamp(7px, 1.8vw, 11px); }
  .chess-stage, .chess-panel { padding: 9px; }
  .chess-page .puzzle-heading h1 { font-size: clamp(2.05rem, 6.5vw, 3rem); }
}
@media (max-width: 380px) {
  .chess-frame { padding: 7px; }
  .chess-page .puzzle-main { width: min(calc(100% - 14px), 1100px); }
  .chess-stage, .chess-panel { padding: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  .chess-piece { transition: none; }
}

/* Clear bilingual identity and easy-level moves, without altering board styling. */
.chess-piece-info-label {
  color: #e8d0a4;
  font-size: .81rem;
  font-weight: 700;
  letter-spacing: .015em;
}
.chess-piece-moves {
  flex-basis: 100%;
  width: 100%;
  margin: .28rem 0 0;
  padding-top: .45rem;
  border-top: 1px solid #bdbb9952;
  font-size: .89rem;
  line-height: 1.55;
  color: #f7ecd1;
  overflow-wrap: anywhere;
}
