/* ChessSnap — warm dark theme */
:root {
  --bg: #17130f;
  --surface: #241e18;
  --surface2: #2e2620;
  --line: #3d332a;
  --text: #f0e8dc;
  --muted: #a4937f;
  --accent: #e8a33d;        /* action amber */
  --good: #6fbf59;          /* best-move green (semantic: good for you) */
  --good2: #4a9  ;
  --bad: #e06c5a;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand .knight { color: var(--accent); font-size: 22px; }
.pill {
  font-size: 12px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
  transition: opacity .4s;
}
.pill.ok { color: var(--good); }
.pill.err { color: var(--bad); }

main { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 18px 16px 30px; }
footer {
  color: var(--muted); font-size: 11.5px; text-align: center;
  padding: 10px 16px 14px; border-top: 1px solid var(--line);
}

h1 { font-size: 30px; line-height: 1.2; margin: 26px 0 12px; }
h2 { font-size: 22px; margin: 4px 0 6px; }
.sub { color: var(--muted); max-width: 34em; margin-bottom: 26px; }
.hint { color: var(--muted); font-size: 14px; margin-bottom: 14px; max-width: 40em; }

/* ----- buttons ----- */
.btn {
  font: inherit; color: var(--text); cursor: pointer;
  background: var(--surface2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 16px;
  transition: filter .15s, transform .05s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.985); }
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #221a0d; font-weight: 700; }
.btn.primary:disabled { background: var(--surface2); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
.btn.big { font-size: 19px; padding: 16px 26px; width: 100%; max-width: 430px; display: block; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 6px 8px; }
.btn.link:hover { color: var(--text); }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 4px; align-items: center; }
.btnrow.small { margin-top: 6px; }
#screen-home .btnrow { margin-top: 14px; }

.fenbox { margin-top: 26px; color: var(--muted); font-size: 14px; max-width: 560px; }
.fenbox summary { cursor: pointer; }
.fenrow { display: flex; gap: 8px; margin-top: 10px; }
.fenrow input {
  flex: 1; font: 13px/1.4 ui-monospace, Consolas, monospace; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.errline { color: var(--bad); font-size: 13px; margin-top: 8px; min-height: 1.2em; }

/* ----- corners screen ----- */
#cornerWrap { position: relative; display: inline-block; user-select: none; touch-action: none; }
#cornerCanvas { display: block; border-radius: 10px; }
#cornerGrid {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
}
#cornerGrid line { stroke: rgba(120, 255, 140, .85); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
#cornerGrid line.outer { stroke: rgba(120, 255, 140, 1); stroke-width: 2.6; }
.pin {
  position: absolute; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  cursor: grab; z-index: 3;
}
.pin::after {
  content: ""; position: absolute; inset: 12px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.6);
}
.pin:active { cursor: grabbing; }
#nearTag {
  position: absolute; transform: translate(-50%, 6px); z-index: 2;
  font-size: 11.5px; color: #dff5d8; background: rgba(20, 60, 25, .75);
  border: 1px solid rgba(120,255,140,.5); border-radius: 999px; padding: 2px 9px;
  pointer-events: none; white-space: nowrap;
}
#loupe {
  position: absolute; width: 132px; height: 132px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 4px 18px rgba(0,0,0,.7);
  pointer-events: none; z-index: 4; background-repeat: no-repeat;
  background-color: #000;
}
#loupe::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px;
  margin: -7px 0 0 -7px; border: 2px solid var(--accent); border-radius: 50%;
}

/* ----- board ----- */
.boardwrap { position: relative; width: 100%; max-width: 560px; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr);
  width: 100%; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  box-shadow: 0 4px 22px rgba(0,0,0,.45);
}
.cell { position: relative; background: var(--board-light); }
.cell.dark { background: var(--board-dark); }
.cell.photo { background-repeat: no-repeat; }
.cell img.piece {
  position: absolute; inset: 4%; width: 92%; height: 92%;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.55));
  pointer-events: none;
}
.cell .ghostpiece {
  position: absolute; inset: 16%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: clamp(12px, 3.4vw, 22px);
  pointer-events: none;
}
.cell .ghostpiece.w { background: rgba(255,255,255,.88); color: #333; }
.cell .ghostpiece.b { background: rgba(20,20,20,.82); color: #eee; border: 1px solid rgba(255,255,255,.5); }
.cell.unknown { outline: 3px dashed var(--accent); outline-offset: -3px; z-index: 1; }
.cell.selsq { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 1; }
.cell.legal::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 26%; height: 26%;
  margin: -13% 0 0 -13%; border-radius: 50%; background: rgba(111,191,89,.65);
}
.cell.legalcap::before {
  width: 88%; height: 88%; margin: -44% 0 0 -44%;
  background: none; border: 4px solid rgba(111,191,89,.65); border-radius: 50%;
}
.cell .sqlabel {
  position: absolute; right: 3px; bottom: 1px; font-size: 9px;
  color: rgba(0,0,0,.45); pointer-events: none;
}
.cell.dark .sqlabel { color: rgba(255,255,255,.45); }
.board.tappable .cell { cursor: pointer; }

/* ----- palette ----- */
#palette {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 6px; max-width: 560px; margin-top: 12px;
}
#palette button {
  position: relative; aspect-ratio: 1; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 2px solid var(--line); padding: 8%;
}
#palette button img { width: 100%; height: 100%; }
#palette button.on { border-color: var(--accent); background: var(--surface2); box-shadow: 0 0 0 2px rgba(232,163,61,.35); }
#palette button.erase { color: var(--muted); font-size: 20px; }
#paletteHint { color: var(--muted); font-size: 13px; margin-top: 8px; min-height: 1.2em; max-width: 560px; }
#paletteHint.flash { color: var(--accent); }

/* ----- toggles ----- */
.toggles { display: flex; flex-wrap: wrap; gap: 18px; margin: 4px 0 14px; }
.toggle { display: flex; align-items: center; gap: 9px; }
.tlabel { color: var(--muted); font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
  font: inherit; font-size: 14px; padding: 7px 14px; cursor: pointer;
  background: var(--surface); color: var(--muted); border: none;
}
.seg button.on { background: var(--accent); color: #221a0d; font-weight: 700; }

/* ----- sanity ----- */
#sanity { max-width: 560px; margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.sanechip {
  font-size: 13.5px; border-radius: 10px; padding: 8px 12px;
  background: rgba(224,108,90,.12); border: 1px solid rgba(224,108,90,.5); color: #f2b3a8;
}
.sanechip.warn { background: rgba(232,163,61,.1); border-color: rgba(232,163,61,.5); color: #edc98d; }
.sanechip.okline { background: rgba(111,191,89,.08); border-color: rgba(111,191,89,.4); color: #b9dfae; }

#castlingBox {
  margin-top: 12px; max-width: 560px; font-size: 13.5px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
#castlingBox .tlabel { display: block; margin-bottom: 8px; }
.tsub { color: var(--muted); font-weight: 400; font-size: 12px; }
#castlingRow { display: flex; flex-wrap: wrap; gap: 12px; }
#castlingRow label { display: flex; align-items: center; gap: 5px; color: var(--text); cursor: pointer; }
#castlingRow input { accent-color: var(--accent); }

.mutednote {
  color: var(--muted); font-size: 12.5px; margin-top: 10px; max-width: 560px;
  border-left: 3px solid var(--line); padding-left: 10px;
}

/* ----- analyze ----- */
#evalWrap { display: flex; align-items: center; gap: 12px; max-width: 560px; margin: 8px 0 14px; }
#evalBar {
  flex: 1; height: 14px; border-radius: 999px; overflow: hidden;
  background: #45392e; border: 1px solid var(--line);
}
#evalFill { height: 100%; width: 50%; background: linear-gradient(90deg, #5da84a, #7ecf68); transition: width .5s; }
#evalText { font-weight: 700; font-size: 15px; white-space: nowrap; }
#evalText.neg { color: #f2b3a8; }
#evalText.pos { color: #b9dfae; }

.analyzeCols { display: flex; flex-direction: column; gap: 18px; }
.acol.side { max-width: 560px; }
#arrowSvg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#arrowSvg .arrow { opacity: .92; }
#arrowSvg .arrow.alt { opacity: .38; }

#moveCards { display: flex; flex-direction: column; gap: 8px; }
.mcard {
  display: flex; align-items: baseline; gap: 12px; cursor: pointer; text-align: left;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; font: inherit; color: var(--text);
}
.mcard.on { border-color: var(--good); background: var(--surface2); }
.mcard .rankdot { width: 12px; height: 12px; border-radius: 50%; flex: none; align-self: center; }
.mcard .san { font-size: 21px; font-weight: 800; min-width: 2.6em; }
.mcard .ev { font-weight: 700; color: var(--muted); min-width: 3.2em; }
.mcard .ev.pos { color: #b9dfae; } .mcard .ev.neg { color: #f2b3a8; }
.mcard .pv { color: var(--muted); font-size: 12.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcard .mate { color: var(--good); font-weight: 800; }

#photoPanel { margin-top: 14px; }
.panelLabel { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
#photoArrowCanvas { width: 100%; border-radius: 10px; display: block; }

#replyBanner {
  margin-top: 10px; max-width: 560px;
  background: rgba(232,163,61,.1); border: 1px solid rgba(232,163,61,.55);
  color: #edc98d; border-radius: 10px; padding: 10px 14px; font-size: 14.5px;
}
#promoAsk {
  margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  max-width: 560px; font-size: 14px;
}
#promoAsk[hidden] { display: none; }
#engineLine { color: var(--muted); font-size: 12.5px; margin-top: 14px; min-height: 1.2em; }

.screen h2 + .hint { margin-top: 2px; }

.confirmCols { display: flex; flex-direction: column; gap: 18px; }
.ccol.side { max-width: 560px; }

@media (min-width: 920px) {
  .analyzeCols, .confirmCols { flex-direction: row; align-items: flex-start; }
  .acol, .ccol { flex: 1; min-width: 0; }
  h1 { font-size: 40px; }
}
