:root {
  --page: #eef1ec;
  --surface: #fbfcf8;
  --surface-2: #f4f6f1;
  --ink: #18201d;
  --muted: #69736e;
  --line: #d9dfd9;
  --charcoal: #171c1a;
  --green: #39775a;
  --green-soft: #dceade;
  --blue: #34668a;
  --blue-soft: #e2edf5;
  --amber: #bd7a25;
  --coral: #c95748;
  --light-square: #e8e5d3;
  --dark-square: #73905c;
  --shadow: 0 12px 34px rgba(24, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.drop-zone:focus-visible {
  outline: 3px solid rgba(52, 102, 138, 0.3);
  outline-offset: 2px;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 24px;
  background: var(--charcoal);
  color: #fff;
  border-bottom: 3px solid var(--green);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-lockup,
.engine-strip,
.panel-head,
.board-head,
.board-actions,
.ai-summary-head,
.piece-editor-head {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #f4f7f1;
  color: var(--charcoal);
  border-radius: 6px;
  font-size: 31px;
  line-height: 1;
}

.eyebrow,
.section-kicker {
  margin: 0;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.eyebrow {
  color: #8ec4a4;
}

.section-kicker {
  color: var(--green);
  margin-bottom: 4px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 21px;
}

h2 {
  font-size: 18px;
}

.engine-strip {
  gap: 8px;
}

.engine-chip,
.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.engine-chip {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #38413d;
  border-radius: 6px;
  color: #dbe1dd;
  direction: ltr;
}

.engine-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.stockfish-dot {
  background: #65b982;
}

.ai-dot {
  background: #6aa9d5;
}

.maia-dot {
  background: var(--amber);
}

#maiaChip.is-confirmed {
  border-color: #9a783d;
  color: #f4d38d;
}

.status-pill {
  min-width: 72px;
  min-height: 34px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 6px;
  background: #29312e;
  color: #9fd3b1;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.is-busy {
  color: #fff;
  background: var(--blue);
}

.status-pill.is-error {
  color: #fff;
  background: var(--coral);
}

.app-shell {
  width: min(1640px, 100%);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(292px, 340px) minmax(430px, 1fr) minmax(315px, 390px);
  gap: 16px;
  align-items: start;
}

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

.panel,
.board-panel {
  padding: 16px;
}

.panel-head,
.board-head {
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  margin-bottom: 14px;
}

.board-actions {
  gap: 7px;
}

.tabs,
.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  background: #e9ede8;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.segmented.three {
  grid-template-columns: repeat(3, 1fr);
}

.tab,
.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 5px;
  padding: 6px 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.tab.is-active,
.segmented button.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(24, 32, 29, 0.12);
}

.is-hidden {
  display: none !important;
}

.drop-zone {
  min-height: 218px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px dashed #b9c4bd;
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.drop-zone.is-over {
  border-color: var(--green);
  background: var(--green-soft);
}

.drop-zone img {
  width: 100%;
  height: 100%;
  max-height: 290px;
  object-fit: contain;
  display: block;
}

.drop-empty {
  display: grid;
  place-items: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.drop-empty strong {
  color: var(--ink);
  font-size: 17px;
}

.drop-icon {
  min-width: 52px;
  min-height: 38px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border: 1px solid #aeb9b2;
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #fff;
  color: var(--green);
  font-weight: 900;
  direction: ltr;
}

.button-row,
.compact-settings,
.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.button-row {
  margin-top: 9px;
}

.button,
.icon-button,
.close-editor {
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  user-select: none;
}

.button {
  min-height: 42px;
  padding: 8px 12px;
}

.icon-button,
.close-editor {
  width: 38px;
  height: 38px;
  padding: 0;
  background: #fff;
  color: var(--ink);
}

.fen-button {
  width: 48px;
  font-size: 11px;
  font-weight: 900;
  direction: ltr;
}

.button.primary {
  width: 100%;
  margin-top: 14px;
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

.button.primary:hover {
  background: #2e654b;
}

.button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.button.secondary {
  background: #fff;
  color: var(--ink);
  font-weight: 750;
}

textarea {
  width: 100%;
  min-height: 218px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.settings-grid {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field {
  min-width: 0;
}

.field input,
.field select {
  width: 100%;
  min-height: 39px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 7px 9px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.advanced {
  margin-top: 11px;
  color: var(--muted);
  font-size: 13px;
}

.advanced summary {
  cursor: pointer;
  font-weight: 800;
}

.advanced-grid {
  margin-top: 10px;
}

.board-wrap {
  display: grid;
  place-items: center;
  padding: 4px;
  background: #222925;
  border-radius: 5px;
}

.board {
  direction: ltr;
  position: relative;
  width: min(70vh, 100%);
  max-width: 720px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  overflow: hidden;
  background: var(--light-square);
}

.move-navigator {
  min-height: 52px;
  display: grid;
  grid-template-columns: 46px minmax(100px, 1fr) 46px;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.move-nav-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 25px;
  font-weight: 900;
  line-height: 1;
}

.move-nav-button:hover:not(:disabled) {
  border-color: var(--blue);
  color: var(--blue);
}

.move-nav-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.move-nav-position {
  display: grid;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.move-nav-count {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
}

.move-nav-count strong {
  color: var(--ink);
  font-size: 17px;
}

.move-nav-san {
  color: var(--blue);
  font-size: 12px;
}

.square {
  position: relative;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

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

.square:hover {
  box-shadow: inset 0 0 0 3px rgba(24, 32, 29, 0.28);
}

.square.is-from {
  box-shadow: inset 0 0 0 5px rgba(52, 102, 138, 0.78);
}

.square.is-to {
  box-shadow: inset 0 0 0 5px rgba(189, 122, 37, 0.9);
}

.square.is-low-confidence::after {
  content: "!";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  z-index: 6;
}

.piece-image {
  position: relative;
  z-index: 4;
  width: 86%;
  height: 86%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 1px rgba(17, 22, 20, 0.2));
}

.coord-file,
.coord-rank,
.confidence {
  position: absolute;
  z-index: 7;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

.coord-file {
  right: 4px;
  bottom: 4px;
}

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

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

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

.confidence {
  left: 4px;
  bottom: 4px;
  padding: 2px 3px;
  border-radius: 3px;
  background: rgba(251, 252, 248, 0.82);
  color: var(--coral);
  direction: ltr;
}

.move-arrow {
  position: absolute;
  z-index: 5;
  height: 12px;
  border-radius: 8px;
  background: rgba(52, 102, 138, 0.8);
  transform-origin: 6px 50%;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(24, 32, 29, 0.2);
}

.move-arrow::after {
  content: "";
  position: absolute;
  right: -12px;
  top: -7px;
  width: 0;
  height: 0;
  border-top: 13px solid transparent;
  border-bottom: 13px solid transparent;
  border-left: 19px solid rgba(52, 102, 138, 0.86);
}

.piece-editor {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.piece-editor-head {
  justify-content: space-between;
  margin-bottom: 8px;
}

.piece-palette {
  direction: ltr;
  display: grid;
  grid-template-columns: repeat(7, minmax(34px, 1fr));
  gap: 5px;
}

.palette-piece {
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

.palette-piece img {
  width: 82%;
  height: 82%;
}

.palette-piece.empty-piece-button {
  color: var(--coral);
  font-size: 22px;
  font-weight: 900;
}

.correction-button {
  width: 100%;
  margin-top: 9px;
  border-color: #9db5a6;
  background: var(--green-soft);
  color: #25563e;
  font-weight: 900;
}

.fen-box {
  direction: ltr;
  margin-top: 10px;
  padding: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #46504b;
}

.confidence-line {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.results-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.verified-badge {
  min-height: 29px;
  padding: 0 8px;
  border-radius: 5px;
  background: var(--green-soft);
  color: #285c42;
}

.ai-summary {
  margin-bottom: 12px;
  padding: 12px;
  border-right: 4px solid var(--blue);
  border-radius: 6px;
  background: var(--blue-soft);
}

.ai-summary-head {
  gap: 7px;
  color: #244f6b;
  font-size: 13px;
}

.ai-spark {
  font-size: 16px;
}

.ai-summary p {
  margin: 7px 0 0;
  color: #31464f;
  font-size: 13px;
  line-height: 1.65;
}

.ai-summary.is-loading {
  border-right-color: var(--amber);
  background: #f6efe2;
}

.ai-summary.is-loading .ai-summary-head,
.ai-summary.is-loading p {
  color: #6d512c;
}

.moves-list {
  display: grid;
  gap: 9px;
}

.move-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: inherit;
}

.move-item.is-active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(52, 102, 138, 0.2);
}

.move-primary {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px;
}

.move-rank {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--charcoal);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.move-item:first-child .move-rank {
  background: var(--green);
}

.move-name {
  min-width: 0;
}

.move-san {
  display: block;
  direction: ltr;
  text-align: right;
  color: var(--ink);
  font-size: 22px;
  font-weight: 950;
}

.move-route {
  display: block;
  direction: ltr;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.eval-block {
  direction: ltr;
  text-align: center;
}

.eval-label {
  display: block;
  color: var(--green);
  font-size: 16px;
  font-weight: 950;
  white-space: nowrap;
}

.eval-caption {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
}

.move-details {
  display: none;
  padding: 0 12px 12px;
}

.move-item.is-active .move-details {
  display: block;
}

.human-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.move-fact {
  margin: 0 0 9px;
  padding: 8px;
  border-right: 3px solid var(--green);
  border-radius: 4px;
  background: var(--green-soft);
  color: #28583f;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.55;
}

.meter-track {
  flex: 1;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: #e4e8e3;
}

.meter-fill {
  display: block;
  height: 100%;
  background: var(--amber);
}

.engine-line {
  margin: 0 0 9px;
  padding: 8px;
  border-radius: 5px;
  background: var(--surface-2);
  color: #46504b;
  font-size: 11px;
  line-height: 1.55;
  direction: ltr;
  text-align: left;
  overflow-wrap: anywhere;
}

.explanation-grid {
  display: grid;
  gap: 7px;
}

.explanation-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 7px;
  color: #46504b;
  font-size: 12px;
  line-height: 1.6;
}

.explanation-row strong {
  color: var(--ink);
}

.empty-state {
  min-height: 250px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  margin: 0;
}

.empty-piece {
  color: #adb6b1;
  font-size: 74px;
  line-height: 1;
}

.warnings {
  display: grid;
  gap: 7px;
  margin-top: 11px;
}

.warning-item {
  border-right: 4px solid var(--coral);
  border-radius: 6px;
  background: #fff0ec;
  color: #763a31;
  padding: 9px;
  font-size: 12px;
  line-height: 1.55;
}

.warning-item.info {
  border-right-color: var(--blue);
  background: var(--blue-soft);
  color: #2d5269;
}

@media (max-width: 1240px) {
  .app-shell {
    grid-template-columns: 320px minmax(430px, 1fr);
  }

  .moves-panel {
    grid-column: 1 / -1;
  }

  .moves-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .move-item.is-active .move-details {
    display: block;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: flex-start;
    padding: 12px 14px;
  }

  .engine-chip {
    display: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .board-panel {
    grid-row: 1;
  }

  .capture-panel {
    grid-row: 2;
  }

  .moves-panel {
    grid-row: 3;
    grid-column: 1;
  }

  .moves-list {
    grid-template-columns: 1fr;
  }

  .board {
    width: 100%;
  }
}

@media (max-width: 460px) {
  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 26px;
  }

  h1 {
    font-size: 18px;
  }

  .button-row,
  .compact-settings,
  .advanced-grid {
    grid-template-columns: 1fr;
  }

  .piece-palette {
    grid-template-columns: repeat(5, minmax(34px, 1fr));
  }
}
