.pgn-shell { margin: auto; }
h1 { margin-bottom: .2rem; } h2 { font-size: 1.1rem; }
a { color: inherit; }
.info-panel { background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 16px; padding: 1rem; }
.privacy, .help { font-size: .85rem; }
.pgn-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; }
.board-wrap { box-sizing: border-box; width: 100%; padding: .6rem; }
g-chess-board { display: block; width: 100%; }
.controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .7rem 0; }
button, select, input { font: inherit; color: var(--ink); }
button:not(.icon-btn), select, input[type=search] { border: 1px solid var(--panel-border); border-radius: 8px; background: #fffaf0; padding: .55rem; }
button { cursor: pointer; min-height: 42px; } button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid #007f86; outline-offset: 3px; }
.moves { position: relative; max-height: 240px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: .3rem; padding: .3rem; }
.comment {
  margin: 1.1rem 0 .5rem;
  padding: 0;
  font-family: "PGN Notation", Georgia, serif;
  font-size: 1.1rem;
  font-weight: 400;
  line-height: 1.7;
  color: var(--ink);
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#status, #storage-status { overflow-wrap: anywhere; }
#status[data-error=true], #storage-status { color: #8c361a; }
.last-move { position: absolute; width: 12.5%; height: 12.5%; box-sizing: border-box; background: #ecbc2860; pointer-events: none; }
#trial { border-top: 1px solid var(--panel-border); } .analysis { border-top: 1px solid var(--panel-border); }
dialog { max-width: min(400px, 85vw); border-radius: 15px; border: 1px solid var(--panel-border); background: #fffaf0; }
#trial-moves, #analysis-result { overflow-wrap: anywhere; }
.piece-glyph { display: inline-block; width: 24px; height: 24px; vertical-align: middle; }
@media (max-width: 760px) { .pgn-layout { grid-template-columns: minmax(0, 1fr); } body { padding: .75rem; } }
/* The library and game picker use the same cards as the home page. */
.pgn-browser { color-scheme: light; }
.pgn-browser .welcome { margin-top: .5rem; }
.pgn-browser .welcome h1 { overflow-wrap: anywhere; }
.library-actions { text-align: center; margin-bottom: 24px; }
.upload { position: relative; cursor: pointer; margin-top: 0; }
.upload input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.upload:focus-within { outline: 3px solid #a45b20; outline-offset: 5px; }
.pgn-browser .privacy { color: var(--hero-muted); margin-top: 12px; }
.pgn-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pgn-card { min-height: 150px; justify-content: center; gap: 10px; padding-right: 42px; }
.pgn-card h2 { overflow-wrap: anywhere; }
.pgn-card p { margin: 0; color: #7c765f; font-size: .85rem; line-height: 1.6; overflow-wrap: anywhere; }
.file-card { position: relative; min-width: 0; }
.file-card .pgn-card { padding-bottom: 46px; height: 100%; box-sizing: border-box; }
.delete-file { position: absolute; bottom: 10px; left: 22px; border: 0; background: transparent; font-size: .8rem; min-height: 30px; color: #8a7f5e; }
.delete-file:hover { color: #8c361a; text-decoration: underline; }
.search-label { display: block; color: var(--hero-ink); }
.search-label input { display: block; width: min(440px, 100%); box-sizing: border-box; margin: 8px auto 0; padding: .8rem 1rem; border-radius: 999px; }
.empty-state { text-align: center; padding: 40px 20px; border-radius: 24px; background: #fffaf0ef; color: #7c765f; }
.pgn-browser #status { text-align: center; color: var(--hero-ink); }
.pgn-browser #status[data-error=true] { color: #8c361a; background: #fffaf0; border-radius: 12px; }
.pgn-shell { max-width: calc(min(1000px, 100dvh - 110px) + 336px); width: 100%; }
.player-header h1 { font-size: clamp(1.3rem, 3vw, 2rem); margin: .3rem 0; }
.player-header { margin-bottom: 1.25rem; padding-right: 3rem; }
.player-header p { color: var(--muted); font-size: .85rem; }
.board-panel > .controls { justify-content: center; }
#play { background: linear-gradient(#dc9a4c, #c9762f); color: #fffaf0; border-color: var(--accent-dark); min-width: 44px; font-weight: 700; }
#position-label { text-align: center; color: var(--muted); font-size: .85rem; }
summary { cursor: pointer; font-weight: 650; padding: .6rem 0; }
.analysis { margin-top: 1rem; padding-top: .3rem; }
.info-panel { border-radius: 24px; padding: 1.25rem; }
.comment:empty, #status:empty, #storage-status:empty { display: none; }
@media (max-width: 820px) { .pgn-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .pgn-cards { grid-template-columns: minmax(0, 1fr); } .pgn-card { min-height: 125px; } .pgn-shell { padding: 0; } .player-header { margin-bottom: .75rem; } }

.pgn-layout { align-items: start; }
.player-header h1 { overflow-wrap: anywhere; }

#analysis-result { min-height: 1.25rem; margin: .4rem 0; font-size: .8rem; color: var(--muted); }
.analysis { position: relative; }
.analysis-toolbar { position: absolute; left: 46px; top: .4rem; display: flex; align-items: center; gap: .4rem; }
.analysis-toggle { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; box-sizing: border-box; padding: .3rem; border-radius: 8px; color: var(--ink); }
.analysis-toggle::-webkit-details-marker { display: none; }
.analysis-toggle::marker { content: ""; }
#analysis[open] > .analysis-toggle { background: #d4eacc; }
.analysis-toggle:hover { background: #e8ddba80; }
.analysis-toolbar > span { margin-right: auto; color: var(--muted); font-size: .85rem; }
.analysis-toolbar button { width: 36px; min-height: 36px; padding: .2rem; font-size: 1.1rem; }
.analysis-line { display: flex; align-items: baseline; gap: .75rem; min-height: 2.8rem; box-sizing: border-box; padding: .85rem 0; border-bottom: 1px solid var(--panel-border); }
.analysis-score { flex: 0 0 3.8rem; font-family: "PGN Notation", Georgia, serif; font-size: .95rem; font-weight: 400; font-variant-numeric: tabular-nums; line-height: 1.9; color: var(--accent-dark); white-space: nowrap; }
.analysis-pv { min-width: 0; font-family: "PGN Notation", Georgia, serif; font-size: 1.05rem; line-height: 1.9; white-space: normal; overflow-wrap: anywhere; flex: 1; font-variant-numeric: tabular-nums; text-align: left; }

.moves {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: .45rem .8rem;
  padding: .3rem .15rem;
  scrollbar-width: thin;
  scrollbar-color: #d5c7a8 transparent;
}
.move-row { display: inline-flex; align-items: baseline; gap: .1rem; margin: 0; }
.move-row > span {
  font-family: "PGN Notation", Georgia, serif;
  font-size: .95rem;
  color: var(--ink);
  margin-right: .25rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.moves .move-row button {
  position: relative;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: .25rem .35rem;
  min-height: 40px;
  font-size: 1.15rem;
  font-weight: 450;
  line-height: 1.5;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: background-color .15s, color .15s;
}
.moves .move-row button:hover { background: #c9762f0d; color: var(--accent-dark); }
.moves .move-row button[aria-current=true] {
  background: #c9762f18;
  color: var(--accent-dark);
  font-weight: 450;
  box-shadow: inset 0 -2px 0 #c9762f80;
}

@font-face { font-family: "PGN Notation"; src: url("fonts/FreeSerif.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
.notation-token { display: inline-flex; align-items: center; white-space: nowrap; vertical-align: baseline; font-family: "PGN Notation", Georgia, serif; font-size: 1em; line-height: 1; font-weight: 400; }
.notation-san { line-height: 1; }
.notation-piece { font-family: "PGN Notation", Georgia, serif; font-weight: 400; font-size: 1.15em; line-height: 1; display: inline-block; margin-right: .04em;  }
.notation-space { white-space: pre-wrap; }


button.analysis-line { width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--panel-border); border-radius: 0; color: var(--ink); }
button.analysis-line:hover:not(:disabled) { background: #e8ddba50; }
button.analysis-line:disabled { opacity: 1; }

#promotion { padding: 3.25rem 1.25rem 1.25rem; width: min(340px, 85vw); box-sizing: border-box; }
.promotion-close { position: absolute; top: .5rem; right: .5rem; display: grid; place-items: center; width: 40px; height: 40px; min-height: 40px; border: 0; background: transparent; border-radius: 50%; }
.promotion-choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.promotion-choices button { display: grid; place-items: center; padding: .3rem; height: 76px; }
.promotion-choices button:hover { background: #d4eacc; }
.promotion-choices span { display: block; width: 100%; height: 60px; background: center / contain no-repeat; }
#promotion [data-promotion="q"] span { background-image: var(--active-queen); }
#promotion [data-promotion="r"] span { background-image: var(--active-rook); }
#promotion [data-promotion="b"] span { background-image: var(--active-bishop); }
#promotion [data-promotion="n"] span { background-image: var(--active-knight); }
#promotion[data-color="b"] [data-promotion="q"] span { background-image: var(--black-queen); }
#promotion[data-color="b"] [data-promotion="r"] span { background-image: var(--black-rook); }
#promotion[data-color="b"] [data-promotion="b"] span { background-image: var(--black-bishop); }
#promotion[data-color="b"] [data-promotion="n"] span { background-image: var(--black-knight); }

body.pgn-player { padding-right: 6rem; }
.pgn-tools .piece-glyph { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: 2rem; line-height: 1; color: #fffaf0; }
.pgn-tools #pieceset-btn .piece-glyph { background: var(--active-king) center / contain no-repeat; filter: var(--piece-filter); }
.pgn-tools #theme-btn { padding: .7rem; }
@media (max-width: 760px) {
  body.pgn-player { padding-right: .75rem; }
  .pgn-tools { position: static; right: auto; top: auto; transform: none; flex-direction: row; justify-content: center; flex-wrap: wrap; width: 100%; margin: 0 0 1rem; }
}

.control-icon { display: grid; place-items: center; }
.control-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; }
.info-panel .player-header { padding-right: 0; margin-bottom: 1rem; }
.info-panel .player-header h1 { font-size: 1.2rem; }


.playback-controls { gap: .5rem; }
.playback-controls button { display: grid; place-items: center; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 10px; transition: background-color .15s, border-color .15s; }
.playback-controls button:not(#play):not(:disabled):hover { background: #f7e8d3; border-color: var(--accent-dark); }
.playback-controls svg { width: 22px; height: 22px; fill: none; stroke: currentColor; }

/* Let the board use the viewport, placing notation below on narrower screens. */
@media (max-width: 1100px) {
  .pgn-layout { grid-template-columns: minmax(0, 1fr); }
  .pgn-shell { max-width: min(1000px, 100dvh - 110px); }
}

.info-panel .player-header { padding-bottom: 1rem; border-bottom: 1px solid var(--panel-border); }
.info-panel #game-title { display: flex; align-items: center; gap: .85rem; margin: 0; }
.game-number { display: grid; place-items: center; flex: 0 0 auto; min-width: 48px; height: 48px; box-sizing: border-box; padding: 0 .65rem; border-radius: 14px; background: linear-gradient(145deg, #fffaf0, #f4dfb8); border: 1px solid #d5b987; box-shadow: inset 0 1px 0 #fff, 0 2px 5px #4a3f2b0a; color: var(--accent-dark); font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.game-players { display: flex; flex-direction: column; gap: .45rem; min-width: 0; }
.game-player { display: flex; align-items: baseline; gap: .55rem; font-size: 1rem; line-height: 1.4; font-weight: 600; overflow-wrap: anywhere; }
.game-player::before { content: ''; flex: 0 0 .65rem; width: .65rem; height: .65rem; border: 1px solid #8a7f5e; border-radius: 50%; background: #fffaf0; }
.game-player.black::before { background: #4a3f2b; border-color: #4a3f2b; }

@media print {
  .notation-token, .move-row > span { color: #000; }
  .moves .move-row button[aria-current=true] { background: transparent; color: #000; box-shadow: none; }
}

.analysis-pv .notation-number { font-size: .82em; color: var(--muted); }
.analysis-pv .notation-space { word-spacing: .08em; }
.analysis-line:last-child { border-bottom: 0; }
@media print {
  .analysis-score, .analysis-pv .notation-number { color: #000; }
}

#board-stage:fullscreen {
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100dvh;
  padding: 12px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--body-bg, #f6f4ef);
}
#board-stage:fullscreen g-chess-board { width: min(calc(100vw - 24px), calc(100dvh - 24px)); }
#board-stage::backdrop { background: var(--body-bg, #f6f4ef); }
