:root {
  color-scheme: dark;
  --app: #262421;
  --rail: #312e2b;
  --panel: #3b3936;
  --panel-2: #44413d;
  --panel-3: #262421;
  --ink: #f1f1ef;
  --muted: #b7b3ac;
  --line: #5a5650;
  --green: #81b64c;
  --green-dark: #5b8e35;
  --blue: #5ca6d7;
  --red: #d85d54;
  --gold: #f0b94c;
  --orange: #d99b43;
  --light-square: #eeeed2;
  --dark-square: #769656;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--app);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

.shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px;
  background: var(--rail);
  border-right: 1px solid #1e1c1a;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: #17200f;
  font-size: 28px;
  font-weight: 900;
}

.brand h1,
.panel-head h2,
.section-heading h2,
.detail-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 23px;
  line-height: 1;
}

.brand p,
.panel-head p,
.section-heading span,
.metric-strip span,
.player-strip span,
.meta {
  margin: 0;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: #dedbd5;
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid #5a5650;
  border-radius: 5px;
  background: #262421;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input,
select {
  height: 42px;
}

textarea {
  min-height: 96px;
  padding: 10px 12px;
  line-height: 1.4;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(129, 182, 76, 0.2);
}

input[type="range"] {
  height: 28px;
  padding: 0;
  accent-color: var(--green);
}

output {
  justify-self: end;
  color: var(--muted);
  font-size: 12px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 5px;
  background: var(--green);
  color: #102006;
  cursor: pointer;
  font-weight: 900;
}

button:hover:not(:disabled) {
  background: #91c85a;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 12px 0;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--green);
}

.status-dot.busy {
  background: var(--gold);
}

.status-dot.error {
  background: var(--red);
}

.workspace {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 16px;
  background: #211f1d;
}

.analysis-shell {
  display: grid;
  grid-template-columns: minmax(320px, 500px) minmax(350px, 1fr);
  gap: 14px;
  align-items: start;
}

.board-area,
.review-panel,
.panel,
.recommendation,
.metric-strip article,
.detail-card,
.position-item,
.game-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.board-area {
  display: grid;
  gap: 10px;
  padding: 12px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 18px;
}

.player-strip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
}

.player-strip div {
  display: grid;
  gap: 2px;
}

.player-strip strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.player-strip span {
  font-size: 12px;
}

#top-clock,
#bottom-clock {
  min-width: 72px;
  border-radius: 5px;
  background: #211f1d;
  color: #d8d3cc;
  padding: 7px 10px;
  text-align: center;
  font-weight: 900;
}

.board-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

.eval-bar {
  position: relative;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  border-radius: 5px;
  background: #171615;
  border: 1px solid #1b1a18;
}

.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #f4f1e9;
  transition: height 160ms ease;
}

#eval-label {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  z-index: 2;
  min-width: 28px;
  border-radius: 4px;
  background: rgba(38, 36, 33, 0.82);
  color: #fff;
  padding: 3px 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
}

.board-frame {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 1;
  justify-self: center;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
}

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

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

.square.highlight::after {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 999px;
  background: rgba(245, 199, 84, 0.38);
  box-shadow: inset 0 0 0 2px rgba(92, 74, 17, 0.18);
}

.piece {
  position: relative;
  z-index: 2;
  width: 92%;
  height: 92%;
  object-fit: contain;
  transform: translateY(3%);
  user-select: none;
  pointer-events: none;
}

.white-piece {
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.38));
}

.black-piece {
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.32));
}

.coord {
  position: absolute;
  z-index: 3;
  color: rgba(42, 47, 36, 0.7);
  font-size: 11px;
  font-weight: 900;
  pointer-events: none;
}

.coord.rank {
  top: 3px;
  left: 4px;
}

.coord.file {
  right: 5px;
  bottom: 2px;
}

.arrow-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.arrow-layer line {
  stroke-width: 4.5;
  stroke-linecap: round;
  opacity: 0.62;
  vector-effect: non-scaling-stroke;
}

.arrow-layer polygon {
  opacity: 0.62;
}

.arrow-layer line.played {
  stroke: var(--orange);
}

.arrow-layer line.best {
  stroke: var(--green);
}

.arrow-layer line.played-best {
  stroke: var(--green);
}

.arrow-layer polygon.played {
  fill: var(--orange);
}

.arrow-layer polygon.best {
  fill: var(--green);
}

.arrow-layer polygon.played-best {
  fill: var(--green);
}

.board-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  color: #d8d3cc;
  font-size: 12px;
  font-weight: 900;
  padding: 0 4px;
}

.board-legend span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.board-legend b {
  font: inherit;
}

.board-legend .is-muted {
  opacity: 0.42;
}

.legend-line {
  display: inline-block;
  width: 24px;
  height: 4px;
  border-radius: 999px;
}

.legend-line.played {
  background: var(--orange);
}

.legend-line.best {
  background: var(--green);
}

.board-controls {
  display: grid;
  grid-template-columns: 42px 42px minmax(120px, 1fr) 42px 42px 72px;
  gap: 8px;
  align-items: center;
}

.board-controls button,
.detail-actions button,
.game-actions button,
.position-item button {
  min-height: 36px;
  background: #57534d;
  color: var(--ink);
}

.board-controls button:hover:not(:disabled),
.detail-actions button:hover,
.game-actions button:hover,
.position-item button:hover {
  background: #68635b;
}

#move-state {
  min-width: 0;
  border-radius: 5px;
  background: #262421;
  padding: 8px 10px;
  color: #ddd8d0;
  text-align: center;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  min-width: 0;
  overflow: visible;
}

.panel-head {
  display: grid;
  gap: 5px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.kicker {
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-head h2 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.metric-strip article {
  display: grid;
  gap: 5px;
  min-height: 76px;
  padding: 12px;
  background: var(--panel-2);
}

.metric-strip.compact strong {
  font-size: clamp(20px, 2.3vw, 28px);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.review-panel .metric-strip {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.recommendations {
  display: grid;
  gap: 10px;
}

.recommendation {
  border-left: 5px solid var(--blue);
  padding: 12px 14px;
  background: #2d3b42;
  color: #e2edf2;
  line-height: 1.45;
}

.detail-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #302e2b;
}

.detail-card.blunder,
.position-item.blunder {
  border-color: rgba(216, 93, 84, 0.72);
}

.detail-card.mistake,
.position-item.mistake {
  border-color: rgba(240, 185, 76, 0.72);
}

.detail-card.inaccuracy,
.position-item.inaccuracy {
  border-color: rgba(92, 166, 215, 0.72);
}

.detail-top,
.position-top,
.game-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.detail-top h3 {
  margin-top: 3px;
  font-size: 26px;
}

.verdict {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #504b45;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.verdict.blunder,
.badge.blunder {
  background: rgba(216, 93, 84, 0.22);
  color: #ffaaa3;
}

.verdict.mistake,
.badge.mistake {
  background: rgba(240, 185, 76, 0.2);
  color: #ffd17a;
}

.verdict.inaccuracy,
.badge.inaccuracy,
.badge.imprecise {
  background: rgba(92, 166, 215, 0.19);
  color: #a9d9f7;
}

.verdict.good,
.badge.good {
  background: rgba(129, 182, 76, 0.18);
  color: #b9e585;
}

.verdict.quiet {
  color: #d0ccc4;
}

.explain-grid,
.move-line {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.explain-grid div,
.move-line div {
  display: grid;
  gap: 4px;
  min-width: 0;
  border-radius: 6px;
  background: #262421;
  padding: 10px;
}

.plain-move.played {
  box-shadow: inset 4px 0 0 var(--orange);
}

.plain-move.best {
  box-shadow: inset 4px 0 0 var(--green);
}

.explain-grid span,
.move-line span,
.meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.explain-grid strong,
.move-line strong,
.game-top strong {
  overflow-wrap: anywhere;
}

.explain-grid small,
.move-line small {
  min-height: 15px;
  color: var(--muted);
  line-height: 1.35;
}

.plain-grid strong {
  font-size: 15px;
  line-height: 1.25;
}

.notation-help {
  display: grid;
  gap: 5px;
  border: 1px solid #5a5650;
  border-radius: 6px;
  background: #262421;
  padding: 10px;
  color: #e4ded5;
  line-height: 1.4;
}

.notation-help strong {
  color: var(--green);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.notation-help span {
  color: #d4cec5;
  font-size: 13px;
}

.advice {
  margin: 0;
  color: #e5e1da;
  line-height: 1.5;
}

.pv {
  display: grid;
  gap: 4px;
  min-height: 24px;
  border-radius: 6px;
  background: #262421;
  color: #cbc6be;
  padding: 8px 10px;
}

.pv span {
  color: var(--muted);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 12px;
}

.pv strong {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.detail-actions,
.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.section-heading.tight {
  margin-top: 2px;
}

.section-heading h2 {
  font-size: 19px;
}

.move-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  max-height: 310px;
  overflow: auto;
  padding-right: 3px;
}

.move-chip {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
  min-height: 48px;
  border-radius: 4px;
  background: #2c2a27;
  color: #ded9d0;
  padding: 5px 8px;
  text-align: left;
  font-weight: 700;
}

.move-chip:hover,
.move-chip.active {
  background: #54504a;
}

.move-chip span {
  color: #a8a39a;
  font-size: 12px;
}

.move-chip strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-chip-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.move-chip small {
  min-width: 0;
  color: #bfb8ae;
  font-size: 11px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-chip.blunder {
  box-shadow: inset 4px 0 0 var(--red);
}

.move-chip.mistake {
  box-shadow: inset 4px 0 0 var(--gold);
}

.move-chip.inaccuracy,
.move-chip.imprecise {
  box-shadow: inset 4px 0 0 var(--blue);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.78fr);
  gap: 18px;
}

.panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
  padding: 14px;
}

.positions,
.games {
  display: grid;
  gap: 12px;
}

.empty-state {
  padding: 16px;
  border: 1px dashed #69645c;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(38, 36, 33, 0.62);
}

.position-item,
.game-item {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #302e2b;
}

.game-item.active {
  border-color: var(--green);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #504b45;
  color: #ddd7ce;
  font-size: 12px;
  font-weight: 900;
}

a {
  color: #aad7f4;
  font-weight: 900;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

@media (max-width: 1180px) {
  .analysis-shell,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .review-panel {
    max-height: none;
  }

  .board-area {
    position: static;
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #1e1c1a;
  }
}

@media (max-width: 640px) {
  .sidebar,
  .workspace {
    padding: 16px;
  }

  .field-grid,
  .metric-strip,
  .explain-grid,
  .move-line,
  .move-list {
    grid-template-columns: 1fr;
  }

  .board-row {
    grid-template-columns: 24px minmax(0, 1fr);
  }

  .eval-bar {
    min-height: 280px;
  }

  .board-controls {
    grid-template-columns: repeat(5, 1fr);
  }

  #move-state {
    grid-column: 1 / -1;
    order: -1;
  }

  #flip-btn {
    grid-column: auto;
  }

  .detail-top,
  .position-top,
  .game-top {
    display: grid;
  }
}
