/* ============ Cờ Vua 3D — UI Styles ============ */
:root {
  --bg: #0a0d16;
  --gold: #d4af37;
  --gold-soft: #e8c96a;
  --ink: #e9e4d8;
  --ink-dim: #9aa0b4;
  --glass: rgba(13, 17, 30, 0.72);
  --glass-border: rgba(212, 175, 55, 0.22);
  --danger: #ff6b6b;
  --ok: #7dd87d;
  --radius: 14px;
  --font-ui: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-title: "Cinzel", Georgia, serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#app { position: fixed; inset: 0; }

#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- Loading ---------- */
#loading {
  position: absolute; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 42%, #17203a 0%, #0a0d16 70%);
  transition: opacity .6s ease; 
}
#loading.done { opacity: 0; pointer-events: none; }
.loader-piece {
  font-size: 72px; color: var(--gold);
  animation: bob 1.6s ease-in-out infinite;
  filter: drop-shadow(0 6px 18px rgba(212,175,55,.35));
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-14px) rotate(4deg); } }
.loader-bar { width: 220px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.08); overflow: hidden; }
.loader-bar span { display: block; height: 100%; width: 40%; border-radius: 4px; background: linear-gradient(90deg, transparent, var(--gold), transparent); animation: sweep 1.2s linear infinite; }
@keyframes sweep { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
.loader-text { color: var(--ink-dim); font-size: 14px; letter-spacing: .06em; }

/* ---------- Top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 12px 18px; pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.brand-icon {
  font-size: 34px; color: var(--gold); line-height: 1;
  filter: drop-shadow(0 3px 10px rgba(212,175,55,.45));
}
.brand-text h1 {
  font-family: var(--font-title); font-size: 22px; font-weight: 700;
  letter-spacing: .12em; color: var(--ink); line-height: 1.1;
}
.brand-text h1 em { font-style: normal; color: var(--gold); }
.brand-sub { font-size: 11px; color: var(--ink-dim); letter-spacing: .18em; text-transform: uppercase; }

/* ---------- Panels ---------- */
.panel {
  position: absolute; z-index: 20;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
  padding: 14px;
}
#panel-left { top: 78px; left: 16px; width: 236px; display: flex; flex-direction: column; gap: 12px; }
#panel-right { top: 78px; right: 16px; width: 252px; max-height: calc(100% - 130px); display: flex; flex-direction: column; gap: 10px; }

.field label { display: block; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-dim); margin-bottom: 6px; }
.field select {
  width: 100%; padding: 9px 10px; border-radius: 9px;
  background: rgba(255,255,255,.06); color: var(--ink);
  border: 1px solid rgba(255,255,255,.12); font-family: var(--font-ui); font-size: 13px;
  outline: none; cursor: pointer; transition: border-color .2s;
}
.field select:hover, .field select:focus { border-color: var(--gold-soft); }
.field.checkbox label { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink); cursor: pointer; }
.field.checkbox input { accent-color: var(--gold); width: 16px; height: 16px; cursor: pointer; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  padding: 10px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06); color: var(--ink);
  font-family: var(--font-ui); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: transform .12s ease, background .2s, border-color .2s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.12); border-color: var(--gold-soft); }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, #b58e2c, #d4af37 55%, #e8c96a);
  border-color: transparent; color: #241a05;
  box-shadow: 0 4px 16px rgba(212,175,55,.35);
}
.btn.primary:hover { filter: brightness(1.08); }

/* ---------- Turn card ---------- */
#turn-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1);
}
#turn-icon { font-size: 30px; line-height: 1; color: #f5f0e1; text-shadow: 0 0 12px rgba(255,255,255,.35); transition: transform .3s; }
#turn-icon.black { color: #2a2a30; text-shadow: 0 1px 0 rgba(255,255,255,.25); }
.turn-info { flex: 1; min-width: 0; }
#turn-text { font-weight: 700; font-size: 14px; }
#status-line { font-size: 12px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status-line.alert { color: var(--danger); font-weight: 600; }
#status-line.good { color: var(--ok); font-weight: 600; }

#thinking { display: flex; gap: 4px; align-items: center; }
#thinking .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: blink 1s infinite; }
#thinking .dot:nth-child(2) { animation-delay: .18s; }
#thinking .dot:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,100% { opacity: .25; transform: scale(.8);} 50% { opacity: 1; transform: scale(1.15);} }
.hidden { display: none !important; }

/* ---------- Captured ---------- */
.captured-block { display: flex; flex-direction: column; gap: 6px; }
.cap-row { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.cap-label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-dim); width: 66px; flex: none; white-space: nowrap; }
.cap-list { flex: 1; font-size: 19px; line-height: 1.1; letter-spacing: 1px; min-height: 22px; overflow: hidden; white-space: nowrap; }
.cap-list .w-piece { color: #f2ead8; text-shadow: 0 0 3px rgba(0,0,0,.9); }
.cap-list .b-piece { color: #43434e; text-shadow: 0 0 3px rgba(255,255,255,.35); }
.mat-diff { font-size: 12px; font-weight: 700; color: var(--ok); flex: none; }

/* ---------- Moves ---------- */
.moves-block { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.moves-title { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-dim); margin-bottom: 6px; }
.moves-list {
  list-style: none; overflow-y: auto; min-height: 60px; flex: 1;
  font-size: 13px; scrollbar-width: thin; scrollbar-color: rgba(212,175,55,.4) transparent;
  display: grid; grid-template-columns: auto 1fr 1fr; gap: 2px 6px; align-content: start;
  padding-right: 4px;
}
.moves-list::-webkit-scrollbar { width: 6px; }
.moves-list::-webkit-scrollbar-thumb { background: rgba(212,175,55,.35); border-radius: 3px; }
.moves-list .mv-num { color: var(--ink-dim); font-size: 12px; }
.moves-list .mv { padding: 1px 6px; border-radius: 6px; font-weight: 600; }
.moves-list .mv.last { background: rgba(212,175,55,.22); color: var(--gold-soft); }
.moves-empty { grid-column: 1 / -1; color: var(--ink-dim); font-size: 12px; font-style: italic; padding: 4px; }

/* ---------- Hint & toast ---------- */
#hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  font-size: 12px; color: var(--ink-dim);
  background: rgba(10,13,22,.55); border: 1px solid rgba(255,255,255,.08);
  padding: 7px 16px; border-radius: 999px; backdrop-filter: blur(8px);
  white-space: nowrap;
}
#toast {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: rgba(20,26,42,.92); color: var(--ink); border: 1px solid var(--glass-border);
  padding: 10px 20px; border-radius: 10px; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); transition: opacity .3s, transform .3s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modals ---------- */
.modal-wrap {
  position: absolute; inset: 0; z-index: 55;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,6,12,.6); backdrop-filter: blur(6px);
}
.modal {
  padding: 26px 30px; text-align: center; max-width: 340px; width: calc(100% - 40px);
  animation: pop .3s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2 { font-family: var(--font-title); font-size: 22px; margin-bottom: 6px; letter-spacing: .04em; }
.modal p { color: var(--ink-dim); font-size: 14px; margin-bottom: 16px; }
.over-emoji { font-size: 54px; margin-bottom: 8px; filter: drop-shadow(0 6px 16px rgba(212,175,55,.4)); }
.modal-btns { display: flex; gap: 10px; justify-content: center; }

.promo-row { display: flex; gap: 10px; justify-content: center; }
.promo-btn {
  width: 64px; height: 64px; font-size: 40px; line-height: 1;
  border-radius: 12px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.06); cursor: pointer;
  transition: transform .15s, border-color .2s, background .2s;
}
.promo-btn:hover { transform: translateY(-4px) scale(1.06); border-color: var(--gold); background: rgba(212,175,55,.15); }
.promo-btn.white { color: #f2ead8; text-shadow: 0 2px 6px rgba(0,0,0,.6); }
.promo-btn.black { color: #3a3a44; text-shadow: 0 0 4px rgba(255,255,255,.4); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #panel-left { top: auto; bottom: 10px; left: 10px; right: 10px; width: auto; flex-direction: row; flex-wrap: wrap; align-items: end; gap: 8px; padding: 10px; }
  #panel-left .field { flex: 1 1 140px; }
  #panel-left .field select { padding: 7px 8px; font-size: 12px; }
  .btn-grid { display: flex; flex-wrap: wrap; }
  .btn-grid .btn { padding: 8px 10px; font-size: 12px; }
  #autoflip-field { display: none; }
  #panel-right { top: 64px; right: 10px; width: 208px; padding: 10px; max-height: 46%; }
  #hint { display: none; }
  .brand-text h1 { font-size: 17px; }
  .brand-sub { display: none; }
}
