/* Chess Coach — mobile-first dark UI */
:root {
  --bg: #0f1620;
  --bg2: #16202c;
  --panel: #1b2733;
  --line: #2a3947;
  --ink: #e8eef5;
  --ink-dim: #93a4b5;
  --accent: #4c9ef2;
  --accent2: #37c98b;
  --warn: #f2b34c;
  --danger: #f2685c;
  --lt-sq: #e9d8b8;
  --dk-sq: #9b6b45;
  --sel: #f2d24c;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
/* The [hidden] attribute must always win over display rules below. */
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
.app {
  max-width: 520px; margin: 0 auto; min-height: 100vh;
  padding: calc(var(--safe-t) + 8px) 14px calc(var(--safe-b) + 20px);
  display: flex; flex-direction: column;
}

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: .2px; display: flex; align-items: center; gap: 6px; }
.brand .logo { color: var(--accent2); font-size: 24px; }
.ghost {
  background: var(--bg2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; font-size: 15px; cursor: pointer;
}
.ghost:active { transform: translateY(1px); }
#helpBtn { width: 38px; height: 38px; border-radius: 50%; padding: 0; font-weight: 700; }

/* step rail */
.steps {
  display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 14px;
  counter-reset: s;
}
.steps li {
  flex: 1; text-align: center; font-size: 12px; color: var(--ink-dim);
  padding: 8px 2px 9px; border-radius: 10px; background: var(--bg2);
  border: 1px solid var(--line); position: relative; white-space: nowrap;
}
.steps li::before {
  counter-increment: s; content: counter(s);
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; margin-right: 5px;
  background: var(--line); color: var(--ink); font-weight: 700; font-size: 11px;
  vertical-align: middle;
}
.steps li.on { color: var(--ink); border-color: var(--accent); background: #16283a; }
.steps li.on::before { background: var(--accent); }
.steps li.done::before { background: var(--accent2); content: "✓"; }

/* stage / panels */
.stage { flex: 1; }
.panel { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.lead { font-size: 15px; color: var(--ink); margin: 2px 0 12px; }
.hint { color: var(--ink-dim); font-size: 13px; margin-top: 10px; }

/* capture */
.capbox {
  width: 100%; aspect-ratio: 3/4; max-height: 62vh;
  background: #0a0f15; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.capbox video, .capbox img { width: 100%; height: 100%; object-fit: cover; }
.placeholder { text-align: center; color: var(--ink-dim); padding: 24px; }
.ph-emoji { font-size: 46px; margin-bottom: 8px; }

/* controls */
.controls { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.primary {
  flex: 1; min-width: 130px; background: linear-gradient(180deg, #4c9ef2, #2f7fd6);
  color: #fff; border: 0; border-radius: 12px; padding: 14px 16px;
  font-size: 16px; font-weight: 700; cursor: pointer; box-shadow: 0 2px 0 #245ea3;
}
.primary:active { transform: translateY(1px); box-shadow: 0 1px 0 #245ea3; }
.primary:disabled { opacity: .5; box-shadow: none; }
.filebtn { display: inline-flex; align-items: center; }
.filebtn input { display: none; }

/* corner picker */
.corner-area {
  width: 100%; height: 56vh; background: #0a0f15; border: 1px solid var(--line);
  border-radius: var(--radius); position: relative; overflow: hidden;
}
.corner-host { touch-action: none; }
.corner-canvas { position: absolute; touch-action: none; }
.corner-handle {
  position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; border: 3px solid #fff;
  background: rgba(76,158,242,.5); box-shadow: 0 0 0 2px rgba(0,0,0,.4);
  touch-action: none; cursor: grab;
}
.corner-handle::after {
  content: ""; position: absolute; inset: 10px; border-radius: 50%; background: #fff;
}

.orient-row, .sidestm {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 14px; font-size: 14px; color: var(--ink-dim); flex-wrap: wrap;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
  background: var(--bg2); color: var(--ink-dim); border: 0; padding: 9px 14px;
  font-size: 14px; cursor: pointer;
}
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }

/* board */
.board-root { position: relative; width: 100%; max-width: 460px; margin: 0 auto; }
.board { position: relative; width: 100%; max-width: 460px; margin: 0 auto; }
.board-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1;
  border: 2px solid #05243a; border-radius: 8px; overflow: hidden;
  touch-action: manipulation;
}
.sq {
  border: 0; padding: 0; margin: 0; aspect-ratio: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(20px, 8vw, 38px); line-height: 1; user-select: none;
  position: relative;
}
.sq.light { background: var(--lt-sq); }
.sq.dark { background: var(--dk-sq); }
.sq.white-piece { color: #fbfbfb; text-shadow: 0 1px 1px rgba(0,0,0,.55), 0 0 2px rgba(0,0,0,.4); }
.sq.black-piece { color: #16202c; text-shadow: 0 1px 0 rgba(255,255,255,.25); }
.locked .sq { cursor: default; }

/* coordinates */
.coord { position: absolute; font-size: 10px; color: rgba(0,0,0,.5); pointer-events: none; font-weight: 700; }
.coord.file { bottom: 1px; transform: translateX(-50%); }
.coord.rank { left: 2px; transform: translateY(-50%); }

/* overlay */
.board-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ov-arrow { stroke-linecap: round; }
.ov-arrow-primary { color: #f2685c; stroke: #f2685c; stroke-width: .16; opacity: .92; }
.ov-arrow-second  { color: #4c9ef2; stroke: #4c9ef2; stroke-width: .12; opacity: .78; }
.ov-arrow-third   { color: #37c98b; stroke: #37c98b; stroke-width: .10; opacity: .66; }
.ov-from { fill: rgba(242,104,92,.28); stroke: rgba(242,104,92,.7); stroke-width: .03; }
.ov-to   { fill: rgba(242,104,92,.20); stroke: rgba(242,104,92,.7); stroke-width: .03; }

/* confirm layout */
.confirm-wrap { display: flex; gap: 12px; align-items: flex-start; }
.confirm-wrap .board { flex: 1; }
.warp-thumb {
  width: 84px; height: 84px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); flex: 0 0 auto;
}

/* palette */
.palette {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 14px 0 4px;
}
.pal {
  aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg2); font-size: 26px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.pal.wpiece { color: #fff; text-shadow: 0 1px 2px #000; }
.pal.bpiece { color: #cbd6e2; }
.pal.erase { color: var(--ink-dim); font-size: 20px; }
.pal.sel { border-color: var(--sel); box-shadow: inset 0 0 0 2px var(--sel); background: #22303e; }

.minorbtns { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ghost.sm { padding: 8px 12px; font-size: 13px; flex: 1; text-align: center; }

.warn {
  margin-top: 12px; color: #23303c; background: var(--warn); padding: 10px 12px;
  border-radius: 10px; font-size: 13.5px; font-weight: 600;
}

/* result */
.board-and-eval { display: flex; gap: 10px; align-items: stretch; }
.board-and-eval .board { flex: 1; }
.evalbar {
  width: 16px; flex: 0 0 16px; border-radius: 8px; overflow: hidden;
  background: #16202c; border: 1px solid var(--line);
  display: flex; align-items: flex-end; align-self: stretch;
  background-image: linear-gradient(#2a3947, #2a3947);
}
.evalfill { width: 100%; height: 50%; background: linear-gradient(180deg, #eef3f8, #cdd8e4); transition: height .4s ease; }

.movecards { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.movecard {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; width: 100%; color: var(--ink);
}
.movecard.best { border-color: #f2685c; background: #26232a; }
.movecard.active { outline: 2px solid var(--accent); }
.mc-rank {
  flex: 0 0 auto; font-size: 12px; font-weight: 800; color: var(--ink-dim);
  min-width: 34px;
}
.movecard.best .mc-rank { color: #f2685c; }
.mc-main { flex: 1; }
.mc-san { font-size: 20px; font-weight: 800; letter-spacing: .3px; }
.mc-desc { font-size: 13px; color: var(--ink-dim); }
.mc-reply { font-size: 12px; color: #6f8296; margin-top: 2px; }
.mc-eval { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.mc-eval.good { color: var(--accent2); }
.mc-eval.bad { color: var(--danger); }
.movecard.big { display: block; text-align: center; }
.mc-head { font-size: 20px; font-weight: 800; }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--ink-dim); padding: 16px; }
.spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.engine-note { margin-top: 12px; color: var(--ink-dim); font-size: 12px; text-align: center; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 18px); transform: translateX(-50%);
  background: #05121e; color: var(--ink); border: 1px solid var(--line);
  padding: 11px 16px; border-radius: 12px; font-size: 14px; max-width: 88%;
  box-shadow: 0 8px 26px rgba(0,0,0,.5); z-index: 40; text-align: center;
}

/* help sheet */
.sheet {
  position: fixed; inset: 0; background: rgba(5,10,16,.6); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 22px 20px calc(var(--safe-b) + 22px); width: 100%; max-width: 520px;
  animation: up .2s ease;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-card h2 { margin: 0 0 12px; font-size: 20px; }
.sheet-card ol { margin: 0 0 14px; padding-left: 20px; }
.sheet-card li { margin-bottom: 8px; font-size: 14.5px; }
.fine { font-size: 12.5px; color: var(--ink-dim); margin: 0 0 18px; }

@media (min-width: 620px) {
  .capbox { max-height: 56vh; }
}
