:root {
  color-scheme: light;
  --ink: #172c34;
  --muted: #415962;
  --paper: #f6faf9;
  --white: #fff;
  --accent: #096e60;
  --accent-dark: #074b44;
  --accent-pale: #e2f1eb;
  --line: #cddedb;
  --square-light: #fbfdfd;
  --square-dark: #d8e5e8;
  --board-edge: #c8d8d8;
  --mint: #c6ebdf;
  --yellow: #ffdc79;
  --pink: #f5d8db;
  font-family: "Nunito", ui-rounded, system-ui, sans-serif;
  font-size: 100%;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); }
a { color: inherit; }
button, select, .button { font: inherit; font-weight: 750; }
button, select, .button {
  appearance: none; min-height: 44px; border: 1px solid var(--line);
  border-radius: .75rem; padding: .58rem .9rem; color: var(--ink);
  background: var(--white);
}
button, .button { cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { cursor: default; opacity: .48; }
button.primary, .button.primary { background: var(--accent); color: white; border-color: var(--accent); box-shadow: 0 3px 0 var(--accent-dark); }
button.primary:hover, .button.primary:hover { background: var(--accent-dark); }
:focus-visible { outline: 3px solid #a94b06; outline-offset: 3px; }
p { line-height: 1.55; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 6vw, 4.5rem); line-height: .99; letter-spacing: -.065em; margin-bottom: .7rem; }
h1 span { color: var(--accent); }
h2 { font-size: 1.35rem; letter-spacing: -.025em; margin-bottom: .6rem; }
label { display: block; font-weight: 750; margin-bottom: .3rem; }
select { padding-right: 2.35rem; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 51%), linear-gradient(135deg, var(--ink) 50%, transparent 51%); background-size: 6px 6px; background-repeat: no-repeat; background-position: calc(100% - 19px) center, calc(100% - 13px) center; }
a, button { -webkit-tap-highlight-color: transparent; }
.skip { position: fixed; top: .5rem; left: .5rem; z-index: 5; background: white; padding: .65rem; transform: translateY(-160%); }
.skip:focus { transform: none; }
.sr-only { clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; position: absolute; white-space: nowrap; }
.masthead {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .8rem; padding: .7rem max(1rem, calc((100vw - 74rem) / 2));
  border-bottom: 1px solid var(--line); background: white;
}
.brand { display: inline-flex; align-items: center; gap: .48rem; width: max-content; text-decoration: none; font-size: 1.05rem; font-weight: 900; letter-spacing: -.03em; }
.stud { display: grid; place-items: center; background: var(--yellow); border-radius: .5rem; width: 2rem; height: 2rem; font-size: 1.2rem; }
nav { display: flex; gap: .25rem; }
nav a { align-content: center; min-height: 44px; border-radius: .55rem; padding: .35rem .7rem; font-weight: 750; text-decoration: none; white-space: nowrap; }
nav a[aria-current] { background: var(--accent-pale); color: var(--accent-dark); }
.rating { justify-self: end; font-weight: 850; text-align: right; white-space: nowrap; }
.rating small { display: block; font-size: .75rem; font-weight: 700; color: var(--muted); }
main { min-height: 70vh; }
.intro, .content { width: min(74rem, calc(100% - 2rem)); margin-inline: auto; }
.intro {
  margin-block: clamp(1rem, 3vw, 2.5rem) 2rem; display: grid; grid-template-columns: 1.15fr .85fr; overflow: hidden;
  color: var(--ink); background: #e7f3ee; border: 1px solid #cee3d9; border-radius: 1.5rem; min-height: 18rem;
}
.intro-copy { padding: clamp(1.25rem, 4.5vw, 3.6rem); align-self: center; z-index: 1; }
.intro-copy > p:not(.tag) { max-width: 32ch; color: var(--muted); font-size: 1.15rem; }
.tag { margin-bottom: .45rem; font-size: .85rem; font-weight: 800; letter-spacing: .065em; }
.intro .tag { color: var(--accent-dark); }
.actions { display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; }
.inverse { background: #fff; border-color: #b4cec5; color: var(--accent-dark); }
.hero-art { display: grid; place-items: center; min-width: 0; position: relative; isolation: isolate; background: radial-gradient(ellipse at 52% 72%, #c0dfd1 2%, transparent 71%); }
.hero-board {
  width: min(15rem, 75%); aspect-ratio: 1; display: flex; align-items: center; justify-content: center; gap: 8%;
  transform: rotate(-14deg) skew(7deg, 6deg); border: .5rem solid #bdcec9; border-radius: 1rem;
  background: repeating-conic-gradient(#fbfdfd 0 25%, #d3e1e4 0 50%) 50% / 30% 30%;
  box-shadow: -.48rem .62rem 0 #8fb5ab; font: 800 clamp(2rem, 6.5vw, 5.5rem) Georgia, serif; color: #2b4048;
}
.hero-board span { transform: skew(-7deg, -6deg) rotate(14deg) translateY(-.25em); text-shadow: 0 4px #fff5; }
.hero-board span:nth-child(2) { color: #eaf5f7; -webkit-text-stroke: 1px #47646e; transform: translateY(-.45em); }
.pete {
  position: relative; isolation: isolate; width: 3.5rem; aspect-ratio: 1;
  border: 2px solid #8c4d26; border-radius: 24%;
  background: linear-gradient(145deg, #fff0ad 0 26%, #ffd66d 27% 82%, #f0b051 83%);
  box-shadow: 0 .24rem 0 #ac612c;
}
.pete::before {
  content: ''; position: absolute; left: 24%; right: 24%; top: -16%; height: 20%;
  background: #ffd66d; border: 2px solid #8c4d26; border-bottom: 0; border-radius: .35rem .35rem 0 0;
}
.pete-face {
  position: absolute; inset: 0; border-radius: inherit;
  background: radial-gradient(circle at 33% 43%, #36434c 0 5%, transparent 6%),
    radial-gradient(circle at 67% 43%, #36434c 0 5%, transparent 6%),
    radial-gradient(ellipse at 22% 63%, #e89c67 0 7%, transparent 8%),
    radial-gradient(ellipse at 78% 63%, #e89c67 0 7%, transparent 8%);
}
.pete-face::after {
  content: ''; position: absolute; left: 41%; top: 52%; width: 18%; height: 13%;
  border: solid #36434c; border-width: 0 2px 2px; border-radius: 0 0 50% 50%;
}
.hero-pete { position: absolute; right: 13%; top: 15%; width: clamp(3.5rem, 6vw, 6rem); transform: rotate(13deg); }
.learn-grid { display: grid; grid-template-columns: minmax(0, 2.8fr) minmax(13rem, 1fr); gap: 1.25rem; align-items: start; }
.section-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; }
.section-heading span, .quiet { color: var(--muted); }
.side-card, .setup, .coach { background: white; border: 1px solid var(--line); border-radius: 1rem; padding: 1rem; }
.side-card select { width: 100%; margin-bottom: .65rem; }
.section { background: white; border: 1px solid var(--line); border-radius: 1rem; margin-bottom: .65rem; }
.section summary, .unit summary { cursor: pointer; list-style: none; color: var(--ink); }
.section summary::-webkit-details-marker, .unit summary::-webkit-details-marker { display: none; }
.section > summary { padding: .8rem; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .7rem; }
.section summary::after { content: '+'; justify-self: end; font-size: 1.25rem; font-weight: 750; color: var(--accent); }
.section[open] > summary::after, .unit[open] > summary::after { content: '−'; }
.section-number { padding: .25rem .5rem; background: var(--mint); border-radius: .55rem; font-weight: 850; white-space: nowrap; }
.section-number.yellow { background: var(--yellow); }
.section-number.pink { background: var(--pink); }
.section-info { display: grid; gap: .12rem; }
.section-info small, .unit-meta { color: var(--muted); font-size: .85rem; }
.section-body { padding: 0 .8rem .8rem; }
.unit { margin: .35rem 0; border: 1px solid var(--line); border-radius: .65rem; overflow: hidden; }
.unit > summary { min-height: 44px; padding: .45rem .7rem; display: flex; gap: .45rem; justify-content: space-between; align-items: center; flex-wrap: wrap; font-weight: 750; }
.unit > summary:focus-visible { outline-offset: -3px; }
.unit > summary span:first-child { flex: 1 0 60%; }
.unit-body { padding: .65rem; background: #f4f9f7; }
.activity-list { display: grid; gap: .35rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); margin: 0 0 .6rem; padding: 0; list-style: none; }
.activity-list button { width: 100%; text-align: left; }
.activity-list button.done { border-color: #71baab; background: #edfbf7; }
.simple { max-width: 42rem; margin-block: clamp(1.75rem, 5vw, 4rem); }
.setup { display: grid; gap: .8rem; }
.setup select { width: min(100%, 20rem); }
.setup p { margin-bottom: 0; }
.game { max-width: 68rem; padding-block: 1.15rem 2rem; }
.lesson-progress { display: flex; align-items: center; gap: .65rem; margin-bottom: .9rem; }
.lesson-exit {
  display: grid; place-items: center; flex: 0 0 auto; width: 44px; height: 44px;
  border-radius: 50%; color: #6f7c82; font: 400 2rem/1 system-ui, sans-serif; text-decoration: none;
}
.lesson-exit:hover { background: #edf3f1; color: var(--ink); }
.lesson-progress-track { position: relative; flex: 1; height: 16px; border-radius: 999px; background: #e5e5e5; }
#lesson-progress-fill {
  display: block; width: 0; height: 100%; border-radius: inherit; background: #58cc02;
}
#lesson-progress-fill.perfect { background: #ffc800; }
#lesson-progress-streak {
  position: absolute; bottom: calc(100% + .12rem); left: 0; transform: translateX(-50%);
  color: #58cc02; font: 900 .62rem/1 "Nunito", ui-rounded, system-ui, sans-serif;
  letter-spacing: .055em; text-transform: uppercase; white-space: nowrap; pointer-events: none;
}
#lesson-progress-streak.perfect { color: #d9a400; }
.game-top, .board-label { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .45rem; }
.game-top { margin-bottom: 1rem; }
.game-top p, .board-label p { margin: 0; }
.game-top .tag { border-radius: 999px; background: var(--accent-pale); color: var(--accent-dark); padding: .45rem .75rem; }
.game-grid { display: grid; grid-template-columns: minmax(0, 1.34fr) minmax(16rem, .8fr); gap: clamp(1rem, 4vw, 3rem); align-items: start; }
.game-info { min-width: 0; padding-block: .9rem; }
.game-info h1 { font-size: clamp(1.7rem, 4vw, 3rem); letter-spacing: -.045em; }
.board-panel { min-width: 0; width: min(100%, clamp(19rem, calc(100svh - 18rem), 40rem)); }
.board-label { margin: .55rem 0 .45rem; font-weight: 800; }
.board-label p { flex: 1 1 8rem; }
.board-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; }
#hint { color: var(--accent-dark); border-color: #a5ccbf; background: #e9f5ee; }
#hint:hover { border-color: var(--accent); }
#sound[aria-pressed="true"] { color: var(--accent-dark); border-color: #a5ccbf; background: #e9f5ee; }
.board-frame {
  position: relative; container-type: inline-size; overflow: hidden;
  border: clamp(3px, 1vw, 5px) solid var(--board-edge); border-radius: 1.15rem;
  box-shadow: 0 .5rem 0 #b9ccca, 0 .95rem 1.8rem #233a3c10; background: var(--square-light);
}
#board {
  display: grid; grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr));
  aspect-ratio: 1; touch-action: manipulation;
}
.square {
  display: grid; place-items: center; position: relative; padding: 0; border: 0; border-radius: 0;
  font: 400 clamp(1.55rem, 10.25cqw, 5.25rem)/1 "DejaVu Sans", "Segoe UI Symbol", "Apple Symbols", serif;
  min-width: 0; min-height: 0; user-select: none; background: var(--square-light);
}
.square.dark { background: var(--square-dark); }
.square:focus-visible { outline: 3px solid #a94b06; outline-offset: -4px; z-index: 2; }
.square.last { background-image: linear-gradient(#f1d96d7f, #f1d96d7f); }
.square.checked { background-image: linear-gradient(#ee94a09c, #ee94a09c); }
.square.mistake {
  z-index: 1; background-color: #f3a1a2; background-image: linear-gradient(#ed6b7270, #ed6b7270);
  box-shadow: inset 0 0 0 4px #c53b49;
}
.square.selected { box-shadow: inset 0 0 0 4px #174f74; }
.square.selected .piece {
  transform: translateY(-18%) scale(1.12);
  filter: drop-shadow(0 .32rem .15rem #172c3445);
}
.square.arrival-pending .piece { opacity: 0; }
.square.hint-origin::before, .square.hint-target::before {
  content: ''; position: absolute; inset: 3px; border-radius: .32rem; pointer-events: none; border: 3px solid #097363;
}
.square.hint-target::before { border-style: dashed; background: #27a68622; }
.square.legal::after { content: ''; position: absolute; border-radius: 50%; width: 20%; aspect-ratio: 1; background: #1a46568c; pointer-events: none; }
.square.legal.occupied::after { width: 88%; background: none; border: 3px solid #2a5864; }
.star {
  position: absolute; pointer-events: none; color: #f4c542; font: 800 clamp(1.5rem, 9cqw, 4.5rem)/1 system-ui, sans-serif;
  text-shadow: 0 .045em #b8860b, 0 .08em .06em #00000026;
}
.piece {
  position: relative; display: block; width: 82%; height: 88%; overflow: visible;
  pointer-events: none; transform-origin: 50% 80%;
  filter: drop-shadow(0 .12rem .08rem #172c3440);
  transition: transform .16s cubic-bezier(.2,.8,.25,1), filter .16s ease, opacity .12s ease;
}
.piece.white { --plastic: #f6f4e9; --shade: #c7d2cf; --line: #526d76; --shine: #fff; --stud: #fffefa; }
.piece.black { --plastic: #314b55; --shade: #1e343c; --line: #13272e; --shine: #70858a; --stud: #82969a; }
.piece.returning { opacity: 0; }
.piece.mistake-return, .piece.in-flight { transition: none; }
.coord { font: 800 clamp(.55rem, 2.25cqw, .85rem)/1 system-ui, sans-serif; position: absolute; color: #334e5b; pointer-events: none; }
.coord.file { right: 3px; bottom: 3px; }
.coord.rank { left: 3px; top: 3px; }
.hint-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
#hint-arrow {
  position: absolute; height: clamp(14px, 4.4cqw, 32px); transform-origin: left center;
  background: #087c68; clip-path: polygon(0 36%, calc(100% - .75em) 36%, calc(100% - .75em) 0, 100% 50%, calc(100% - .75em) 100%, calc(100% - .75em) 64%, 0 64%);
}
.coach { display: flex; align-items: center; gap: .75rem; padding: .5rem .15rem; background: transparent; border: 0; }
.coach-bubble {
  display: grid; gap: .15rem; flex: 1; min-width: 0; position: relative;
  background: #fff; padding: .47rem .72rem; border: 1px solid var(--line); border-radius: .9rem;
}
.coach-bubble::before {
  content: ''; position: absolute; left: -.3rem; top: 1.02rem; width: .5rem; height: .5rem;
  border: solid var(--line); border-width: 0 0 1px 1px; background: white; transform: rotate(45deg);
}
.coach strong { color: var(--accent-dark); font-size: .81rem; }
.coach p { margin: 0; line-height: 1.35; }
.mini-pete { flex: 0 0 auto; width: clamp(2.35rem, 6vw, 3.6rem); }
#pete-voice { flex: 0 0 auto; align-self: center; }
#pete-voice[aria-pressed="true"], #commentary[aria-pressed="true"] { background: var(--accent-pale); color: var(--accent-dark); border-color: #a5ccbf; }
.voice-status { margin: .15rem 0 .45rem; color: var(--muted); font-size: .9rem; }
#feedback { margin: .65rem 0 .75rem; color: var(--accent-dark); font-weight: 750; }
#feedback:empty { display: none; }
.game-actions { margin-bottom: .75rem; }
#moves-panel { background: white; border-radius: .75rem; padding: .7rem; }
#moves { display: grid; grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr)); gap: .15rem .5rem; max-height: 9rem; overflow: auto; margin-bottom: 0; }
dialog { width: min(28rem, calc(100% - 2rem)); border: 0; border-radius: 1rem; padding: 1.25rem; box-shadow: 0 12px 65px #18383f38; color: var(--ink); }
dialog::backdrop { background: #132c3685; }
.footer { width: min(74rem, calc(100% - 2rem)); margin: 1.25rem auto .65rem; border-top: 1px solid var(--line); padding: 1rem 0; display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: .55rem 1rem; color: var(--muted); }
#chess-account { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
@media (max-width: 770px) {
  .learn-grid { grid-template-columns: 1fr; }
  .game-grid { display: flex; flex-direction: column; align-items: stretch; }
  .board-panel { width: min(100%, 36rem); margin: auto; order: -2; }
  .game-info { display: contents; }
  .game-info h1 { order: -5; margin-bottom: 0; }
  #objective { order: -4; margin-bottom: 0; }
  #lesson-tip { order: -3; margin-bottom: 0; }
  #feedback { order: -1; }
  #moves-panel { order: 2; }
  #feedback, .game-actions { margin-block: 0; }
}
@media (max-width: 550px) {
  .intro { grid-template-columns: 1fr; position: relative; }
  .intro-copy { padding-right: 1rem; }
  .hero-art { position: absolute; inset: 0 0 0 52%; opacity: .26; pointer-events: none; }
  .hero-pete { display: none; }
  .game { padding-block-start: .65rem; }
  .lesson-progress { gap: .4rem; margin-bottom: .55rem; }
  .lesson-progress-track { height: 14px; }
  .game-top { margin-bottom: .55rem; }
  .game-grid { gap: .55rem; }
  .coach { gap: .5rem; align-items: center; }
  .coach-bubble { padding-inline: .55rem; }
  #pete-voice { padding-inline: .45rem; font-size: .88rem; }
  .board-label { margin-top: .3rem; }
  .game-top .tag { font-size: .78rem; }
}
@media (prefers-reduced-motion: no-preference) {
  button, .button { transition: background-color .12s, border-color .12s; }
  #lesson-progress-fill { transition: width .25s ease, background-color .18s; }
}
@media (prefers-reduced-motion: reduce) {
  .piece { transition: none; }
}

.player-tools { display: flex; align-items: center; justify-content: end; gap: .65rem; min-width: 0; }
#player-menu { display: flex; align-items: center; gap: .45rem; min-width: 0; max-width: 10rem; }
#player-menu::after { content: ''; flex: 0 0 .35rem; height: .35rem; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg) translateY(-.15rem); }
#active-player {
  display: block; flex: 1 1 auto; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; text-align: left;
}
#player-select, #player-name { width: 100%; }
#player-name { min-height: 44px; padding: .58rem .9rem; border: 1px solid var(--line); border-radius: .75rem; color: var(--ink); font: inherit; }
#player-form { margin-top: 1rem; }
.profile-actions { margin-top: .65rem; }
#player-status { margin: .35rem 0 0; }
#player-status:empty { display: none; }
@media (max-width: 1024px) {
  .masthead { grid-template-columns: auto minmax(0, 1fr); gap: .2rem .5rem; }
  nav { grid-row: 2; grid-column: 1 / -1; justify-content: center; }
  .player-tools { grid-row: 3; grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr); gap: .3rem; }
  #player-menu { width: 100%; max-width: none; flex: none; justify-content: space-between; padding-inline: .5rem; }
  #active-player { overflow: visible; text-overflow: clip; font-size: clamp(.7rem, 3.5vw, 1rem); }
  .rating { justify-self: end; margin-left: 0; }
  .rating small { white-space: normal; max-width: 5rem; }
}
