:root {
  --bg: #ebe9e4;
  --panel: #ffffff;
  --panel-soft: #f0f3ec;
  --ink: #1e2524;
  --muted: #6a7470;
  --line: #d9dfd7;
  --accent: #6a9c23;
  --accent-strong: #4f7b16;
  --blue: #2f668b;
  --coral: #bc5648;
  --gold: #c69232;
  --light-square: #f2d9ad;
  --dark-square: #b88762;
  --last-move: rgba(192, 210, 61, 0.72);
  --arrow: rgba(28, 43, 61, 0.32);
  --shadow: 0 14px 32px rgba(31, 42, 36, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1560px;
  margin: 0 auto 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.1;
}

.topbar-meta {
  min-width: 84px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 290px) minmax(360px, 1fr) minmax(300px, 390px);
  gap: 16px;
  max-width: 1560px;
  margin: 0 auto;
  align-items: start;
}

.library-panel,
.board-panel,
.review-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.library-panel,
.review-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.library-panel {
  padding: 14px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  outline: none;
}

select,
input {
  height: 38px;
  padding: 0 10px;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 111, 99, 0.14);
}

.search-box {
  display: block;
  margin-bottom: 14px;
}

.game-list {
  display: grid;
  gap: 8px;
}

.game-card {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: inherit;
  text-align: left;
}

.game-card:hover,
.game-card.active {
  border-color: var(--accent);
  background: #eef5ef;
}

.game-card.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.game-card strong {
  font-size: 14px;
}

.game-card span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 16px 8px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.board-panel {
  padding: 16px;
}

.game-strip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.game-kicker {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.game-strip h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.25;
}

.ghost-button,
.icon-button,
.text-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
}

.ghost-button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  font-size: 21px;
  font-weight: 900;
}

.board-stage {
  display: grid;
  place-items: center;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(100%, 72vh, 680px);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: var(--dark-square);
  box-shadow: 0 3px 12px rgba(35, 31, 27, 0.32);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  line-height: 1;
  user-select: none;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background: var(--dark-square);
}

.square.last::after {
  position: absolute;
  inset: 0;
  content: "";
  background: var(--last-move);
  pointer-events: none;
}

.square .piece {
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding-bottom: 4%;
  font-family: "Chess Merida", "Chess Alpha", "Apple Symbols", "Arial Unicode MS", "DejaVu Sans", "Noto Sans Symbols2", serif;
  font-size: clamp(45px, 8.8vmin, 88px);
  font-weight: 400;
  line-height: 1;
  transform: translateY(2%);
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.25));
}

.square .piece-white {
  color: #fff;
  -webkit-text-stroke: 1.25px #000;
  text-shadow:
    0 1px 0 #000,
    0 2px 0 rgba(0, 0, 0, 0.45),
    1px 0 0 #000,
    -1px 0 0 #000;
}

.square .piece-black {
  color: #000;
  -webkit-text-stroke: 0.4px #000;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.52),
    0 -1px 0 rgba(255, 255, 255, 0.18);
}

.square .coord {
  position: absolute;
  z-index: 2;
  color: var(--dark-square);
  font-size: clamp(11px, 1.7vw, 18px);
  font-weight: 800;
  line-height: 1;
}

.square .coord-file {
  left: 6px;
  bottom: 4px;
}

.square .coord-rank {
  top: 6px;
  right: 6px;
}

.square.dark .coord {
  color: var(--light-square);
}

.square.has-note::before {
  position: absolute;
  z-index: 3;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border: 2px solid rgba(255, 255, 255, 0.78);
  border-radius: 50%;
  background: var(--coral);
  content: "";
}

.move-arrow {
  position: absolute;
  z-index: 4;
  height: 18px;
  margin-top: -9px;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent 0 8%, var(--arrow) 8% 78%, transparent 78%);
  pointer-events: none;
  transform-origin: left center;
}

.move-arrow::after {
  position: absolute;
  top: 50%;
  right: 2%;
  width: 0;
  height: 0;
  border-top: 28px solid transparent;
  border-bottom: 28px solid transparent;
  border-left: 38px solid var(--arrow);
  content: "";
  transform: translateY(-50%);
}

.board-note {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
}

.board-note strong {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-size: 13px;
}

.board-note span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(5, 42px) minmax(70px, 1fr);
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.icon-button {
  width: 42px;
  height: 38px;
  font-size: 18px;
  font-weight: 900;
}

.icon-button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.38;
}

.ply-counter {
  justify-self: end;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.engine-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.engine-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.engine-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.engine-button:disabled {
  cursor: default;
  opacity: 0.62;
}

.engine-actions span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.engine-caveat {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.engine-progress {
  height: 6px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: #e6e2d9;
}

.engine-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.engine-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.engine-stat {
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  background: #f0f3ec;
}

.engine-stat span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.engine-stat strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eval-chart {
  height: 84px;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(#f8faf5 0 50%, #ece8e2 50% 100%);
}

.eval-chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

.eval-zero {
  stroke: rgba(30, 37, 36, 0.25);
  stroke-width: 1;
}

.eval-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.review-panel {
  display: grid;
  gap: 0;
  overflow: hidden;
}

.summary-block,
.moves-block,
.note-block,
.analysis-block,
.pgn-block {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.pgn-block {
  border-bottom: 0;
}

.player-row {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 9px;
  align-items: center;
  min-height: 42px;
}

.side-dot {
  width: 14px;
  height: 14px;
  border: 1px solid #222;
  border-radius: 50%;
}

.white-side .side-dot {
  background: #fff;
}

.black-side .side-dot {
  background: #222;
}

.player-row strong {
  display: block;
  font-size: 15px;
}

.player-row span:not(.side-dot) {
  color: var(--muted);
  font-size: 12px;
}

.meta-list {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 12px 0 0;
}

.meta-list div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.meta-list dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.meta-list dd {
  margin: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h3 {
  margin-bottom: 0;
  font-size: 14px;
  text-transform: uppercase;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.move-list {
  display: grid;
  gap: 5px;
  max-height: 320px;
  overflow: auto;
  padding-right: 2px;
}

.move-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) minmax(0, 1fr);
  gap: 5px;
  align-items: center;
}

.move-number {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.move-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  min-height: 32px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f3f5ef;
  color: var(--ink);
  text-align: left;
}

.move-pill:hover,
.move-pill.active {
  border-color: var(--accent);
  background: #e6f0e9;
}

.move-san {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-clock {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.note-mark {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--coral);
}

.move-quality {
  flex: 0 0 auto;
  min-width: 30px;
  padding: 2px 5px;
  border-radius: 6px;
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  text-align: center;
}

.move-quality.best,
.analysis-badge.best,
.analysis-item.best {
  background: #5f9f2f;
}

.move-quality.good,
.analysis-badge.good,
.analysis-item.good {
  background: #6f8fbd;
}

.move-quality.inaccuracy,
.analysis-badge.inaccuracy,
.analysis-item.inaccuracy {
  background: #d59a21;
}

.move-quality.mistake,
.analysis-badge.mistake,
.analysis-item.mistake {
  background: #c25b42;
}

.move-quality.blunder,
.analysis-badge.blunder,
.analysis-item.blunder {
  background: #9b2f36;
}

.note-block p {
  min-height: 72px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.analysis-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.analysis-empty {
  grid-column: 1 / -1;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.analysis-badge {
  grid-column: 1 / -1;
  width: fit-content;
  padding: 5px 9px;
  border-radius: 8px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.analysis-metric {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.analysis-metric span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.analysis-metric strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pv-line {
  grid-column: 1 / -1;
  margin-bottom: 0;
  padding: 8px;
  border-radius: 8px;
  background: #f0f3ec;
  color: #38423f;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
}

.analysis-list {
  display: grid;
  gap: 7px;
  max-height: 260px;
  margin-top: 12px;
  overflow: auto;
}

.analysis-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 9px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  text-align: left;
}

.analysis-item strong {
  font-size: 13px;
}

.analysis-item span {
  color: rgba(255, 255, 255, 0.86);
  font-size: 12px;
}

.text-button {
  height: 30px;
  padding: 0 10px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.text-button:hover,
.ghost-button:hover,
.icon-button:hover:not(:disabled) {
  border-color: var(--accent);
}

textarea {
  min-height: 210px;
  resize: vertical;
  padding: 10px;
  color: #26302d;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 260px minmax(360px, 1fr);
  }

  .review-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
    overflow: visible;
  }

  .review-panel {
    grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  }

  .summary-block,
  .note-block {
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace,
  .review-panel {
    grid-template-columns: 1fr;
  }

  .library-panel,
  .review-panel {
    position: static;
    max-height: none;
  }

  .board-panel {
    padding: 12px;
  }

  .game-strip h2 {
    font-size: 19px;
  }

  .timeline {
    grid-template-columns: repeat(5, 40px);
    justify-content: center;
  }

  .ply-counter {
    grid-column: 1 / -1;
    justify-self: center;
  }

  .summary-block,
  .note-block {
    border-right: 0;
  }

  .engine-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analysis-detail {
    grid-template-columns: 1fr;
  }
}
