/* ---- theme ---- */
:root {
  --bg:        #11151c;
  --bg2:       #182030;
  --card:      #1c2533;
  --card2:     #222d3d;
  --ink:       #e8eef7;
  --ink-dim:   #93a1b5;
  --line:      #2c3850;
  --accent:    #4ea1ff;
  --blue:      #3d7dff;
  --blue-soft: #21304f;
  --red:       #ff5a4d;
  --red-soft:  #4a2622;
  --land:      #6f8f5a;
  --land2:     #618050;
  --river:     #2f6f9e;
  --trap:      #b9912f;
  --den:       #8a6d3b;
  --sq: clamp(34px, 8.6vmin, 60px);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #1b2942 0%, var(--bg) 55%) fixed;
  color: var(--ink);
  font: 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.18);
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar .sub { font-size: 12px; color: var(--ink-dim); font-weight: 400; margin-left: 8px; }
.engine-state { margin-left: auto; font-size: 12px; color: var(--ink-dim); }
.engine-state.ready { color: #7fd18a; }
.engine-state.busy  { color: var(--accent); }

/* ---- layout ---- */
.layout {
  display: grid; grid-template-columns: auto minmax(300px, 380px);
  gap: 26px; padding: 22px; align-items: start; justify-content: center;
}
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

/* ---- board ---- */
.board-col { display: flex; flex-direction: column; gap: 12px; }
.status-bar { display: flex; justify-content: space-between; align-items: center; min-height: 26px; }
.status-bar .turn { font-weight: 600; }
.status-bar .result { font-weight: 700; color: var(--accent); }

.board-wrap {
  display: grid;
  grid-template-columns: 20px auto;
  grid-template-rows: auto 20px;
  grid-template-areas: "ranks board" ".  files";
  user-select: none; width: max-content;
}
.ranks { grid-area: ranks; display: grid; grid-auto-rows: var(--sq); }
.ranks span, .files span {
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--ink-dim);
}
.files { grid-area: files; display: grid; grid-template-columns: repeat(7, var(--sq)); }

.board {
  grid-area: board;
  display: grid;
  grid-template-columns: repeat(7, var(--sq));
  grid-auto-rows: var(--sq);
  border: 2px solid var(--line);
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}

.square {
  position: relative;
  background: var(--land);
  display: flex; align-items: center; justify-content: center;
  cursor: default;
}
.square:nth-child(odd) { background: var(--land2); }
.square.river  { background: var(--river); }
.square.river::after { content: "〜"; position: absolute; color: #ffffff22; font-size: 20px; }
.square.trap   { background: var(--trap); }
.square.trap::before {
  content: "✕"; position: absolute; color: #00000044; font-size: calc(var(--sq) * .5); font-weight: 700;
}
.square.den    { background: var(--den); }
.square.den::before {
  content: "★"; position: absolute; color: #00000055; font-size: calc(var(--sq) * .55);
}
.square.den.den-red::before  { color: #ff8a8055; }
.square.den.den-blue::before { color: #8ab4ff66; }

.square.clickable { cursor: pointer; }
.square.sel { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 2; }
.square.lastmove::after {
  content: ""; position: absolute; inset: 0; background: #ffe06622; pointer-events: none;
}
.square.target::after {
  content: ""; position: absolute; width: 34%; height: 34%; border-radius: 50%;
  background: #ffffffcc; box-shadow: 0 0 0 3px #00000033; pointer-events: none;
}
.square.target.capture::after {
  width: 86%; height: 86%; background: transparent;
  border: 4px solid #ffffffcc; border-radius: 50%;
}
.square.threat { box-shadow: inset 0 0 0 3px var(--red); }

/* pieces */
.piece {
  position: relative; z-index: 1;
  width: 84%; height: 84%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--sq) * .5);
  background: var(--blue-soft);
  border: 2px solid var(--blue);
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.piece.red { background: var(--red-soft); border-color: var(--red); }
.piece .rank {
  position: absolute; right: -2px; bottom: -3px;
  font-size: 10px; line-height: 1; font-weight: 700;
  background: var(--blue); color: #fff; border-radius: 8px; padding: 1px 4px;
  border: 1px solid #00000044;
}
.piece.red .rank { background: var(--red); }
.piece.movable { cursor: pointer; }
.piece.movable:hover { filter: brightness(1.15); }

/* ---- buttons / controls ---- */
.board-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: var(--card2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 12px; font-size: 13px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #2a3650; border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.tiny  { padding: 4px 8px; font-size: 11px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 650; }
.btn.primary:hover { background: #6fb2ff; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---- cards / panel ---- */
.panel { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.card-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--ink-dim); margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between;
}
.title-actions { text-transform: none; letter-spacing: 0; }

.player-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.player-row .pname { flex: 0 0 auto; min-width: 64px; }
.player-row .pname small { color: var(--ink-dim); font-size: 11px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.dot.blue { background: var(--blue); }
.dot.red  { background: var(--red); }
.ai-set { display: flex; align-items: center; gap: 6px; }
.ai-set.hidden { display: none; }

.sel, .num, .text {
  background: var(--bg2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
.sel.small { padding: 4px 6px; font-size: 12px; }
.num { width: 72px; }
.unit { color: var(--ink-dim); font-size: 12px; }

.think-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; align-items: baseline; }
.think-grid > span:nth-child(odd) { color: var(--ink-dim); }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; }
.pv { word-break: break-word; }

.movelist {
  display: grid; grid-template-columns: 28px 1fr 1fr; gap: 2px 6px;
  max-height: 200px; overflow-y: auto; font-size: 13px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.movelist .mvn { color: var(--ink-dim); text-align: right; }
.movelist .mv { cursor: pointer; padding: 1px 4px; border-radius: 4px; }
.movelist .mv:hover { background: var(--card2); }
.movelist .mv.cur { background: #2a3650; color: var(--accent); }
.movelist .mv.blue::before { content: ""; }

.fen-row { display: flex; gap: 6px; margin-top: 10px; }
.fen { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px;
       background: var(--bg2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

.field-label { display: block; font-size: 12px; color: var(--ink-dim); margin: 12px 0 4px; }
.row { display: flex; gap: 6px; }
.row .text { flex: 1; }
.text.area { width: 100%; height: 56px; resize: vertical; margin-top: 6px;
             font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.msg { font-size: 12px; margin-top: 8px; min-height: 16px; }
.msg.err { color: var(--red); }
.msg.ok  { color: #7fd18a; }

.hint { font-size: 11px; color: var(--ink-dim); margin-top: 8px; }

/* ---- editor ---- */
.editor .palette { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; margin-bottom: 10px; }
.pal {
  aspect-ratio: 1; border-radius: 8px; border: 2px solid var(--line);
  background: var(--bg2); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 18px; position: relative;
}
.pal.blue { border-color: var(--blue); }
.pal.red  { border-color: var(--red); }
.pal.sel  { outline: 2px solid var(--accent); outline-offset: 1px; }
.pal .r { position: absolute; right: 1px; bottom: 0; font-size: 9px; color: var(--ink-dim); }
.editor-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.editor-row label { display: flex; align-items: center; gap: 4px; font-size: 13px; }

.hidden { display: none !important; }
