:root {
  --bg: #1b1b20;
  --panel: #26262e;
  --panel2: #2e2e38;
  --text: #e8e6e3;
  --muted: #9d9a94;
  --accent: #7cb342;
  --accent2: #629924;
  --danger: #e57373;
  --border: #3a3a46;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header { text-align: center; padding: 18px 16px 4px; }
header h1 { margin: 0; font-size: 30px; letter-spacing: 1px; }
header h1 span { color: var(--accent); }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 18px 16px 40px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px; border-top: 1px solid var(--border); }
footer a { color: var(--muted); }

h2 { margin: 6px 0 4px; font-size: 20px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0; }
.status { color: var(--accent); font-size: 14px; }
.spacer { flex: 1; }

/* ---------- buttons & controls ---------- */
.btn {
  display: inline-block;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.btn:hover { background: #383844; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.active { outline: 2px solid var(--accent); }

select, input[type=text] {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
  width: 100%;
}
fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 0 12px;
  padding: 8px 12px 10px;
  font-size: 14px;
}
fieldset legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
fieldset label { margin-right: 12px; display: inline-block; padding: 2px 0; }
fieldset select { margin-top: 6px; }

.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- step 1: scan ---------- */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  margin-top: 14px;
}
#drop-zone.drag-over { border-color: var(--accent); }
.dz-inner svg { opacity: .6; }
.dz-inner p { font-size: 15px; line-height: 1.6; }

#image-stage { margin-top: 14px; }
#stage-box {
  position: relative;
  display: inline-block;
  max-width: 100%;
  user-select: none;
}
#src-image {
  display: block;
  max-width: 100%;
  max-height: 65vh;
  border-radius: 6px;
}
#crop-rect {
  position: absolute;
  border: 2.5px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
  cursor: move;
  touch-action: none;
}
#crop-rect .handle {
  position: absolute;
  width: 16px; height: 16px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
}
.handle.nw { left: -9px; top: -9px; cursor: nwse-resize; }
.handle.ne { right: -9px; top: -9px; cursor: nesw-resize; }
.handle.sw { left: -9px; bottom: -9px; cursor: nesw-resize; }
.handle.se { right: -9px; bottom: -9px; cursor: nwse-resize; }

.scan-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ---------- boards ---------- */
.board {
  width: min(540px, 92vw);
  aspect-ratio: 1 / 1;
}

/* ---------- step 2: review ---------- */
.review-layout {
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.review-panel { flex: 1; min-width: 300px; max-width: 430px; }

.palette { margin-bottom: 12px; }
.palette-row { display: flex; gap: 4px; margin-bottom: 4px; }
.pal-btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px;
  cursor: pointer;
}
.pal-btn.active { outline: 2px solid var(--accent); }
.pal-piece { width: 34px; height: 34px; display: block; position: static; }
.pal-piece piece {
  position: static !important;
  display: block;
  width: 100% !important;
  height: 100% !important;
  background-size: cover;
}

/* ---------- step 3: play ---------- */
.play-layout {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 12px;
}
#eval-bar {
  width: 26px;
  height: min(540px, 92vw);
  background: #3d3d3d;
  border-radius: 5px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
#eval-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 50%;
  background: #efefef;
  transition: height .4s;
}
#eval-mini {
  position: absolute;
  bottom: 4px; left: 0; right: 0;
  text-align: center;
  font-size: 9px;
  color: #444;
  font-weight: 700;
  mix-blend-mode: multiply;
}
.play-under { margin-top: 8px; min-height: 22px; }

.side-panel { flex: 1; min-width: 290px; max-width: 430px; }
.side-panel select { margin-bottom: 6px; }

.eval-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.eval-head { display: flex; justify-content: space-between; align-items: baseline; }
#eval-score { font-size: 22px; font-weight: 700; }
#eval-depth { color: var(--muted); font-size: 12px; }
.pv { color: var(--muted); font-size: 13px; margin-top: 6px; line-height: 1.5; min-height: 20px; word-wrap: break-word; }

#move-list {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.7;
  min-height: 60px;
  max-height: 180px;
  overflow-y: auto;
}
