/* ==========================================================================
   Catur Analis - stylesheet
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  color-scheme: dark;

  --bg:            #0e1116;
  --bg-soft:       #151a21;
  --panel:         #171d26;
  --panel-2:       #1e2632;
  --line:          #2a3441;
  --line-soft:     #222b36;

  --text:          #e6edf3;
  --text-dim:      #9aa7b4;
  --text-faint:    #6b7887;

  --accent:        #6ea8fe;
  --accent-strong: #3d7dfa;
  --good:          #57c66b;
  --warn:          #e5b23c;
  --bad:           #e5533d;
  --brilliant:     #21c2b3;

  --light-sq:      #e9edcc;
  --dark-sq:       #7d9b5e;
  --sel:           rgba(255, 226, 106, .55);
  --last:          rgba(255, 226, 106, .32);
  --check:         radial-gradient(circle, rgba(229,83,61,.95) 0%, rgba(229,83,61,.72) 35%, rgba(229,83,61,0) 72%);

  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 8px 30px rgba(0,0,0,.35);
  --mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Board themes */
[data-board-theme="green"] { --light-sq: #e9edcc; --dark-sq: #7d9b5e; }
[data-board-theme="blue"]  { --light-sq: #dee3e6; --dark-sq: #6f8ca8; }
[data-board-theme="brown"] { --light-sq: #f0d9b5; --dark-sq: #b58863; }
[data-board-theme="gray"]  { --light-sq: #dcdcdc; --dark-sq: #8f8f8f; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 12% -10%, #1b2735 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #17222e 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

/* ------------------------------------------------------------------ header */

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px clamp(12px, 2vw, 24px);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(14, 17, 22, .72);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 40;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .2px; }
.brand .logo {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--accent-strong), #2b5fd0);
  box-shadow: 0 4px 14px rgba(61,125,250,.35);
  font-size: 19px; line-height: 1;
}
.brand b { font-size: 17px; }
.brand small { display: block; font-size: 11px; color: var(--text-dim); font-weight: 500; letter-spacing: .04em; }

.topbar-spacer { flex: 1 1 auto; }

.eng-badge {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--line);
  padding: 6px 11px; border-radius: 999px;
  white-space: nowrap;
}
.eng-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.eng-dot.loading { background: var(--warn); animation: pulse 1.1s infinite; }
.eng-dot.ready   { background: var(--good); }
.eng-dot.error   { background: var(--bad); }
.eng-dot.thinking{ background: var(--accent); animation: pulse .8s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

/* ------------------------------------------------------------------ layout */

.wrap {
  max-width: 1400px; margin: 0 auto;
  padding: clamp(12px, 2vw, 22px);
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(340px, 430px);
  gap: clamp(12px, 1.6vw, 22px);
  align-items: start;
}
@media (max-width: 1000px) {
  .wrap { grid-template-columns: 1fr; }
  /* Kolom dibubarkan supaya kartu bisa diurutkan ulang: panel saran harus
     berada tepat di bawah papan, bukan di dasar halaman. */
  .wrap > .col-board, .wrap > .col-side { display: contents; }
  .wrap .board-stage      { order: 1; }
  .wrap #editBar          { order: 2; }
  .wrap .status           { order: 3; }
  .wrap .col-board .toolbar { order: 4; }
  .wrap #editCard         { order: 5; }
  .wrap #suggCard         { order: 6; }
  .wrap #movesCard        { order: 7; }
  .wrap #manualNotice     { order: 8; }
  .wrap #settingsCard     { order: 9; }
}

.col-board { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.col-side  { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { margin: 0; font-size: 13px; letter-spacing: .07em; text-transform: uppercase; color: var(--text-dim); font-weight: 700; }
.card-head .sp { flex: 1 }
.card-body { padding: 12px 14px; }

/* -------------------------------------------------------------- board area */

.board-stage {
  display: flex; gap: 10px; align-items: stretch;
  width: 100%;
}

.board-holder {
  flex: 1 1 auto; min-width: 0;
  display: flex; justify-content: center;
}

/* evaluation bar */
.evalbar {
  flex: none; width: 26px;
  border-radius: 7px; overflow: hidden;
  background: #2a2f36;
  border: 1px solid var(--line);
  position: relative;
  align-self: stretch;
  min-height: 200px;
}
.evalbar-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, #ffffff, #dfe4ea);
  height: 50%;
  transition: height .28s cubic-bezier(.4,0,.2,1);
}
.evalbar-mid { position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(120,140,160,.55); }
.evalbar-txt {
  position: absolute; left: 0; right: 0; text-align: center;
  font-family: var(--mono); font-size: 9.5px; font-weight: 700;
  letter-spacing: -.4px;
  overflow: hidden; white-space: nowrap;
  transition: top .28s, bottom .28s;
}
.evalbar-txt.top    { top: 3px; color: #cfd8e3; }
.evalbar-txt.bottom { bottom: 3px; color: #1b1f24; }

/* ---------------------------------------------------------------- chessboard */

.cb {
  position: relative;
  width: 100%;
  max-width: min(72vh, 640px);
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 34px rgba(0,0,0,.45);
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cb-squares {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}

.cb-sq { position: relative; }
.cb-sq.light { background: var(--light-sq); }
.cb-sq.dark  { background: var(--dark-sq); }

.cb-sq.last::after,
.cb-sq.sel::after {
  content: ""; position: absolute; inset: 0;
}
.cb-sq.last::after { background: var(--last); }
.cb-sq.sel::after  { background: var(--sel); }

.cb-sq.check::before {
  content: ""; position: absolute; inset: 0;
  background: var(--check);
  z-index: 1;
}

/* legal move hints */
.cb-hint, .cb-hint-cap {
  position: absolute; pointer-events: none;
  z-index: 2;
}
.cb-hint {
  left: 50%; top: 50%;
  width: 28%; height: 28%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(20,30,20,.28);
}
.cb-hint-cap {
  inset: 0;
  border-radius: 50%;
  border: .42em solid rgba(20,30,20,.24);
}
.cb-sq.hover-target::after {
  content: ""; position: absolute; inset: 0;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.65);
  z-index: 3;
}

/* coordinates */
.cb-coord {
  position: absolute;
  font-size: clamp(8px, 1.6cqw, 11px);
  font-weight: 700;
  font-family: var(--mono);
  opacity: .62;
  pointer-events: none;
  z-index: 2;
}
.cb-coord.file { bottom: 1px; right: 3px; }
.cb-coord.rank { top: 1px; left: 3px; }
.cb-sq.light .cb-coord { color: #5d7040; }
.cb-sq.dark  .cb-coord { color: #eef1dc; }

/* pieces layer */
.cb-pieces { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.cb-piece {
  position: absolute; top: 0; left: 0;
  width: 12.5%; height: 12.5%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100%;
  will-change: transform;
  transition: transform 140ms cubic-bezier(.3,.9,.4,1);
  z-index: 5;
}
.cb-pieces.no-anim .cb-piece { transition: none; }
.cb-piece.dragging { transition: none; z-index: 20; cursor: grabbing; filter: drop-shadow(0 6px 10px rgba(0,0,0,.45)); }
.cb-piece.ghost { opacity: .32; }

.cb.interactive .cb-piece.movable { cursor: grab; pointer-events: auto; }

/* arrows overlay */
.cb-marks { position: absolute; inset: 0; z-index: 8; pointer-events: none; overflow: visible; }

/* promotion picker */
.cb-promo { position: absolute; inset: 0; z-index: 30; display: none; }
.cb-promo.open { display: block; }
.cb-promo-back { position: absolute; inset: 0; background: rgba(8,10,14,.62); }
.cb-promo-col {
  position: absolute; width: 12.5%;
  display: flex; flex-direction: column;
}
.cb-promo-btn {
  width: 100%; aspect-ratio: 1/1;
  border: none; padding: 0; cursor: pointer;
  background: #eef2f6 no-repeat center / 88%;
  border-bottom: 1px solid rgba(0,0,0,.12);
  transition: background-color .12s, transform .12s;
}
.cb-promo-btn:first-child { border-radius: 6px 6px 0 0; }
.cb-promo-btn:last-child  { border-radius: 0 0 6px 6px; border-bottom: none; }
.cb-promo-btn:hover, .cb-promo-btn:focus-visible { background-color: var(--accent); outline: none; transform: scale(1.04); z-index: 2; }

/* ----------------------------------------------------------- board toolbar */

.toolbar { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .14s, border-color .14s, transform .08s, color .14s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #26313f; border-color: #38455a; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: linear-gradient(180deg, var(--accent-strong), #2f6ae0); border-color: #3f78e8; color: #fff; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #4b88ff, #3671e6); }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 10px; font-size: 15px; }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn.on { background: rgba(110,168,254,.18); border-color: var(--accent); color: #cfe0ff; }

.nav-group { display: inline-flex; }
.nav-group .btn { border-radius: 0; margin-left: -1px; }
.nav-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.nav-group .btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ------------------------------------------------------- penyusun posisi */

.editbar {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 11px 13px;
  box-shadow: var(--shadow);
}
.editbar-hint { margin: 0 0 10px; font-size: 12.5px; color: var(--text-dim); }
.editbar-hint b { color: var(--text); }

.palette { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.palette-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; }

.pal-btn {
  width: 42px; height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2) no-repeat center / 82%;
  cursor: pointer; padding: 0;
  transition: border-color .12s, background-color .12s, transform .08s;
}
.pal-btn:hover { border-color: #46566e; background-color: #26313f; }
.pal-btn:active { transform: translateY(1px); }
.pal-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pal-btn.sel { border-color: var(--accent); background-color: rgba(110,168,254,.22); box-shadow: 0 0 0 1px var(--accent) inset; }
/* Latar dibedakan agar bidak putih maupun hitam sama-sama jelas terlihat. */
.pal-btn.white-piece { background-color: #333d4c; }
.pal-btn.black-piece { background-color: #b7c0cc; border-color: #8e99a8; }
.pal-btn.black-piece:hover { background-color: #c7cfd9; }
.pal-btn.black-piece.sel { background-color: #a8bcdd; }
.pal-btn.tool {
  width: auto; min-width: 42px; padding: 0 11px;
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text);
  background-image: none;
}
.pal-btn.tool.sel { color: #cfe0ff; }

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

.cb.editing .cb-piece { pointer-events: auto; cursor: grab; }
.cb.editing .cb-sq.sel::after,
.cb.editing .cb-sq.last::after { background: none; }
.cb.editing.erasing { cursor: crosshair; }

body.editing .toolbar .btn:disabled { opacity: .3; }

/* --------------------------------------------------------------- status row */

.status {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 13px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13.5px;
}
.turn-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 700;
}
.turn-dot { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid #6d7885; flex: none; }
.turn-dot.w { background: #f4f6f8; }
.turn-dot.b { background: #1c2026; }
.status .sep { color: var(--text-faint); }
.status .muted { color: var(--text-dim); font-size: 12.5px; }
.status .flag { font-weight: 700; }
.status .flag.check { color: var(--warn); }
.status .flag.over  { color: var(--bad); }

/* ------------------------------------------------------------- suggestions */

.sugg-head-num { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }

.sugg-list { display: flex; flex-direction: column; gap: 7px; }

.sugg {
  display: grid;
  grid-template-columns: 26px minmax(54px, auto) 62px minmax(0, 1fr);
  gap: 9px; align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  cursor: pointer;
  transition: border-color .14s, background .14s, transform .08s;
  text-align: left; width: 100%; font: inherit; color: inherit;
}
.sugg:hover, .sugg:focus-visible { border-color: var(--accent); background: #232e3d; outline: none; }
.sugg:active { transform: translateY(1px); }
.sugg.best { border-color: rgba(87,198,107,.55); background: rgba(87,198,107,.09); }
.sugg .rank {
  width: 26px; height: 26px; border-radius: 7px;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  background: #2b3543; color: var(--text-dim);
}
.sugg.best .rank { background: rgba(87,198,107,.22); color: #8ee39c; }
.sugg .san { font-family: var(--mono); font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.sugg .score { font-family: var(--mono); font-size: 13px; font-weight: 700; text-align: right; }
.sugg .score.plus  { color: #9fe6ac; }
.sugg .score.minus { color: #f0a08f; }
.sugg .score.mate  { color: #ffd166; }
.sugg .pv { display: block; min-width: 0; overflow: hidden; }
.sugg .line {
  display: block; min-width: 0;
  font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sugg .wr {
  display: block;
  font-size: 11px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sugg-empty { color: var(--text-dim); font-size: 13px; padding: 10px 2px; }

.engine-meta {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 11.5px; color: var(--text-faint);
  padding: 9px 14px 0;
}
.engine-meta b { color: var(--text-dim); font-weight: 700; }

.progress {
  height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 8px;
}
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* --------------------------------------------------------------- move list */

.moves {
  max-height: 268px; overflow-y: auto;
  font-family: var(--mono); font-size: 13px;
}
.moves-grid { display: grid; grid-template-columns: 42px 1fr 1fr; align-items: stretch; }
.mv-num { color: var(--text-faint); padding: 4px 6px; text-align: right; font-size: 12px; background: rgba(255,255,255,.015); }
.mv {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 7px; cursor: pointer; border-radius: 5px;
  background: none; border: none; color: inherit; font: inherit; text-align: left;
  transition: background .12s;
}
.mv:hover { background: #26313f; }
.mv.current { background: var(--accent-strong); color: #fff; font-weight: 700; }
.mv .q { font-size: 11px; flex: none; }
.q.best       { color: var(--good); }
.q.brilliant  { color: var(--brilliant); }
.q.good       { color: #86c98f; }
.q.inaccuracy { color: var(--warn); }
.q.mistake    { color: #f0894c; }
.q.blunder    { color: var(--bad); }
.moves-empty { color: var(--text-faint); font-size: 12.5px; padding: 6px 2px; }

/* ---------------------------------------------------------------- settings */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > label { font-size: 12px; color: var(--text-dim); font-weight: 600; letter-spacing: .03em; }
.field .row { display: flex; align-items: center; gap: 9px; }
.field .val { font-family: var(--mono); font-size: 12px; color: var(--text); min-width: 62px; }

input[type="range"] { flex: 1; accent-color: var(--accent); height: 22px; min-width: 0; }

select, input[type="text"], textarea {
  font: inherit; font-size: 13px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
}
select:focus, input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; min-height: 74px; }

.check-row { display: flex; align-items: center; gap: 9px; padding: 5px 0; cursor: pointer; font-size: 13px; }
.check-row input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }

.io-row { display: flex; gap: 7px; }
.io-row input { flex: 1; font-family: var(--mono); font-size: 11.5px; }

details.acc { border-top: 1px solid var(--line-soft); }
details.acc > summary {
  padding: 11px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--text-dim); list-style: none; display: flex; align-items: center; gap: 8px;
}
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::before { content: "▸"; font-size: 11px; transition: transform .15s; }
details.acc[open] > summary::before { transform: rotate(90deg); }
details.acc > summary:hover { color: var(--text); }
details.acc > .card-body { padding-top: 2px; }

/* ------------------------------------------------------------------- misc */

.notice {
  font-size: 12.5px; color: var(--text-dim);
  background: rgba(110,168,254,.08);
  border: 1px solid rgba(110,168,254,.22);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}
.notice.warn { background: rgba(229,178,60,.09); border-color: rgba(229,178,60,.3); color: #e8d3a0; }
.notice.err  { background: rgba(229,83,61,.1); border-color: rgba(229,83,61,.32); color: #f2b3a6; }

.toast-host {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: #202a36; border: 1px solid var(--line);
  color: var(--text); font-size: 13px;
  padding: 9px 15px; border-radius: 999px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast.err { border-color: rgba(229,83,61,.5); background: #33201d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

footer.site {
  max-width: 1400px; margin: 0 auto;
  padding: 6px clamp(12px, 2vw, 22px) 30px;
  color: var(--text-faint); font-size: 12px;
}
footer.site a { color: var(--text-dim); }

kbd {
  font-family: var(--mono); font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; color: var(--text-dim);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.hidden { display: none !important; }

@media (max-width: 600px) {
  body { font-size: 14px; }
  .brand small { display: none; }
  /* Toolbar dipadatkan agar panel saran tidak terdorong jauh ke bawah. */
  .toolbar { gap: 5px; }
  .toolbar .btn { padding: 6px 9px; font-size: 12.5px; }
  .toolbar .btn.icon { padding: 6px 8px; font-size: 14px; }
  .pal-btn { width: 38px; height: 38px; }
  .pal-btn.tool { min-width: 38px; padding: 0 9px; font-size: 12px; }
  .castle-grid { grid-template-columns: 1fr; }
  .card-body { padding: 10px 11px; }
  .evalbar { width: 20px; }
  .sugg { grid-template-columns: 24px minmax(50px, auto) 58px minmax(0, 1fr); }
  .sugg .line { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cb-piece { transition: none; }
  .evalbar-fill { transition: none; }
}
