/* Chess.com-inspired modern theme for Xiangqi
   - Deep green felt board
   - Calm, darker grid lines (not to clash with move highlights)
   - Gold accents & subtle move dots
   - Woodgrain ambient background
   - Crisp piece tokens, gentle shadows, and clear feedback states
*/

:root{
  /* Backgrounds */
  --bg-wood-1:#1a1e19;
  --bg-wood-2:#0f1310;

  /* Board */
  --board-green-1:#0f3d2e;   /* felt top */
  --board-green-2:#0b2a20;   /* felt bottom */
  --board-edge:#0a241b;

  /* Lines (muted so they don’t compete with highlights) */
  --line-color:#0b2018;      /* darker & calmer than highlights */
  --river-tint: rgba(255,255,255,.02);

  /* Accents */
  --accent:#f4c75c;          /* warm gold for selection */
  --accent-2:#ffb85a;        /* amber for legal-move dots */

  /* Shadows */
  --shadow: rgba(0,0,0,.45);

  /* Text */
  --text-1:#f8f9fa;
  --text-2:#d2d9de;
}

*{ box-sizing:border-box }

html, body{ height:100% }

body {
  margin: 0;
  color: var(--text-1);
  font-family: 'Noto Sans TC', 'Helvetica Neue', Arial, sans-serif;

  /* Ambient wood/room feel */
  background:
    radial-gradient(1200px 600px at 10% -20%, rgba(255,255,255,.04), transparent 60%),
    radial-gradient(1000px 500px at 110% 120%, rgba(255,255,255,.03), transparent 60%),
    repeating-linear-gradient(12deg, rgba(255,255,255,.02) 0 2px, transparent 2px 6px),
    linear-gradient(180deg, var(--bg-wood-1), var(--bg-wood-2));
  background-attachment: fixed;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: .02em;
  margin: .25rem 0 1rem;
}

#root{ padding: 0 16px 24px }

/* ---------------- Board ---------------- */
.board {
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;

  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 9 / 10;
  margin: 36px auto;
  padding: 32px;
  border-radius: 16px;

  /* Felt + vignette */
  background:
    radial-gradient(120% 120% at 22% 18%, var(--board-green-1), var(--board-green-2));
  box-shadow:
    0 18px 45px -10px var(--shadow),
    inset 0 2px 0 rgba(255,255,255,.06),
    inset 0 0 0 2px var(--board-edge);
  border: 1px solid rgba(255,255,255,.06);

  /* keep edge pieces visible */
  overflow: visible;
}

/* Subtle texture & vignette, chess.com-esque depth */
.board::before{
  content:"";
  position:absolute; inset:0;
  border-radius:16px;
  background:
    radial-gradient(120% 120% at 50% 40%, transparent 60%, rgba(0,0,0,.18)),
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 2px, transparent 2px 6px);
  pointer-events:none;
  mix-blend-mode: overlay;
}

/* Let the felt extend beyond the board edges */
.board { 
  z-index: 0; /* create a stacking context so ::after can sit behind */
}

/* Felt bleed halo */
.board::after{
  content: "";
  position: absolute;
  inset: -35px;                /* how far the green extends past the edge */
  border-radius: 10px;         /* match the inset so corners stay soft */
  background: radial-gradient(120% 120% at 22% 18%, var(--board-green-1), var(--board-green-2));
  z-index: -1;                 /* sit behind the board surface */
  pointer-events: none;
  /* (optional) subtle rim so it blends nicer into the page */
  box-shadow: 
    0 18px 45px -10px var(--shadow),
    inset 0 2px 0 rgba(255,255,255,.06),
    inset 0 0 0 2px var(--board-edge);
}

/* Canvas layer: grid & palace diagonals */
.board-lines {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  /* Slight inner rim like chess.com */
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.25);
}

.board-lines canvas {
  width: 100%;
  height: 100%;
  display: block;
  /* Calm line tint applied in JS by reading --line-color; ensure fallback here */
  filter: saturate(.9);
}

/* ---------------- Squares & states ---------------- */
.square {
  position: absolute;
  width: var(--sq, 44px);
  height: var(--sq, 44px);
  transform: translate(-50%, -50%);
  cursor: pointer;
  z-index: 1;
}

/* Selection: thin gold ring + soft glow (chess.com vibe) */
.square.selected {
  outline: 2px solid var(--accent);
  box-shadow:
    0 0 0 4px rgba(244,199,92,.10) inset,
    0 0 10px rgba(244,199,92,.28);
  filter: saturate(1.02);
}

/* Legal moves: small amber pip + faint halo (clearer, calmer) */
.square.legal-move::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 10px; height: 10px;
  background-color: var(--accent-2);
  border-radius: 50%;
  opacity: .92;
  box-shadow: 0 0 0 6px rgba(255,184,90,.16);
  pointer-events: none;
}

/* Last move: soft gold inset band (non-intrusive) */
.square.last-move {
  outline: 2px solid rgba(244,199,92,.9);
  box-shadow: 0 0 0 4px rgba(244,199,92,.14) inset;
}

/* King in check: chess.com-like red alert ring */
.square.check-king {
  box-shadow:
    0 0 0 3px #ef4444 inset,
    0 0 0 8px rgba(239,68,68,.18) inset;
}

/* Captured “flash” on the destination */
.square.captured-glow {
  box-shadow:
    0 0 0 4px rgba(255,184,90,.22) inset,
    0 0 14px rgba(255,184,90,.32);
}

/* ---------------- Pieces ---------------- */
.piece {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  width: 100%;
  height: 100%;
  line-height: 1;
  font-size: 1.45rem;
  border-radius: 50%;
  user-select: none;
  text-align: center;
  letter-spacing: .02em;

  /* token gloss */
  background-image:
    radial-gradient(140% 140% at 30% 25%, rgba(255,255,255,.35), rgba(255,255,255,.05) 40%, transparent 60%),
    linear-gradient(180deg, rgba(0,0,0,.15), rgba(0,0,0,0));
  border: 2px solid transparent;
  box-shadow:
    0 6px 14px rgba(0,0,0,.35),
    inset 0 1px 0 rgba(255,255,255,.25);
  transition: transform .15s ease, filter .2s ease, box-shadow .2s ease;
}

.piece:hover {
  transform: translateY(-1px) scale(1.04);
  filter: saturate(1.05);
}

/* Red / Black tokens tuned for contrast on green felt */
.piece.red {
  background-color: #fdecea;  /* slightly brighter than before */
  color: #a01818;             /* deep red glyph */
  border-color: #c0392b;
  text-shadow: 0 1px 0 rgba(255,255,255,.65);
}

.piece.black {
  background-color: #e6ebef;
  color: #141c21;             /* near-black */
  border-color: #1f2c33;
  text-shadow: 0 1px 0 rgba(255,255,255,.6);
}

/* ---------------- MUI side panel polish ---------------- */
.MuiFormControl-root,
.MuiTypography-root {
  margin-bottom: 1.1em !important;
}

.MuiPaper-root, .MuiMenu-paper{
  background: #18221b !important;
  color: var(--text-1) !important;
  border: 1px solid rgba(255,255,255,.06);
  box-shadow:
    0 10px 24px rgba(0,0,0,.35),
    inset 0 1px 0 rgba(255,255,255,.05) !important;
  backdrop-filter: blur(2px) saturate(115%);
}

.MuiButton-root{
  text-transform: none !important;
  border-radius: 10px !important;
  padding: .5rem .9rem !important;
  box-shadow: 0 6px 14px rgba(0,0,0,.25);
}
.MuiButton-contained { background:#1f7a5a !important }
.MuiButton-contained:hover { filter: brightness(1.05) }
.MuiButton-outlined { border-color:#335b4c !important; color: var(--text-2) !important }
.MuiButton-outlined:hover { background: rgba(255,255,255,.04) !important }

/* Captured trays */
.MuiList-root {
  max-height: 300px;
  overflow-y: auto;
}
.MuiSnackbarContent-root {
  background-color: #2e7d32;
  color: #fff;
  font-weight: bold;
  text-align: center;
}


/* --- Sidebar panel (matches the screenshot) --- */
.side-panel{
  background: radial-gradient(180% 140% at 0% -20%, rgba(255,255,255,.04), transparent 60%),
              linear-gradient(180deg, #0f1b15, #0b1511);
  border: 1px solid rgba(255,255,255,.06);
  box-shadow:
    0 18px 45px -10px rgba(0,0,0,.45),
    inset 0 1px 0 rgba(255,255,255,.05);
  border-radius: 16px;
  padding: 18px;
  color: var(--text-1);
}
/* Make the sidebar a vertical flex container */
.side-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* keep sections at the top */
}

/* Push the Reset button to the bottom */
.panel-reset {
  margin-top: auto !important;
}

.side-panel .panel-title{
  letter-spacing: .06em;
  text-shadow: 0 1px 0 rgba(0,0,0,.5);
  margin-bottom: .25rem;
}

.panel-section{
  width: 100%;
  padding: 10px 0 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.panel-section:first-of-type{ border-top: 0; }

.section-label{
  color: var(--text-2);
  font-weight: 600 !important;
  margin-bottom: 6px !important;
}

/* recessed “well” used for captured lists */
.panel-well{
  width: 100%;
  box-sizing: border-box; /* ensures padding doesn't reduce usable width */
  background: linear-gradient(180deg, rgba(0,0,0,.20), rgba(0,0,0,.14));
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px;
  padding: 8px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04), inset 0 -1px 0 rgba(0,0,0,.35);
}

/* stat badges like small chips */
.stat-badges{
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip{
  display:inline-block; padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  font-size: 12px; color: var(--text-1);
}
.chip-red{ background: rgba(220,38,38,.14); border-color: rgba(220,38,38,.28); }
.chip-blue{ background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.26); }

/* CTA buttons styled like the screenshot */
.panel-cta{
  width: 100%;
  border-radius: 12px !important;
  padding: .7rem 1rem !important;
  font-weight: 700 !important;
}
.panel-reset{
  width: 100%;
  border-radius: 12px !important;
  padding: .7rem 1rem !important;
}

/* tighten MUI surface to match panel */
.side-panel .MuiPaper-root, 
.side-panel .MuiMenu-paper{
  background:#0f1b15 !important;
  border: 1px solid rgba(255,255,255,.06);
}

/* selects and inputs */
.side-panel .MuiInputBase-root{
  background: rgba(255,255,255,.03);
  border-radius: 10px;
}

.move-log {
  background: linear-gradient(180deg, rgba(0,0,0,.20), rgba(0,0,0,.14));
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04), inset 0 -1px 0 rgba(0,0,0,.35);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-1);
  height: 500px;       /* ✅ fixed height */
  overflow-y: auto;
}

.move-log table {
  width: 100%;
  border-collapse: collapse;
}

.move-log th,
.move-log td {
  text-align: center;
  padding: 2px 4px;
}

.move-log thead {
  color: var(--text-2);
  font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.move-log tbody tr:nth-child(odd) {
  background: rgba(255,255,255,.02);
}


/* Match difficulty & AI style selector text to sidebar font color */
.MuiInputLabel-root,
.MuiSelect-select,
.MuiMenuItem-root {
  color: #e9ecef !important; /* same as sidebar text */
}

.MuiInputLabel-root.Mui-focused {
  color: #f8f9fa !important; /* match heading color when active */
}

.MuiOutlinedInput-notchedOutline {
  border-color: rgba(255,255,255,.2) !important;
}


/* ---------------- AI overlay ---------------- */
.ai-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.28);
  backdrop-filter: saturate(120%) blur(4px);
  -webkit-backdrop-filter: saturate(120%) blur(4px);
  animation: fadeInOverlay 200ms ease-out;
  border-radius: 16px;
}

@keyframes fadeInOverlay {
  from { opacity: 0; } to { opacity: 1; }
}

.ai-message {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.28);
  background: linear-gradient(180deg, rgba(23,32,37,0.95), rgba(23,32,37,0.9));
  color: var(--text-1);
  box-shadow: 0 8px 28px rgba(0,0,0,0.35);
  max-width: 90%;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  position: relative;
}

@keyframes spin { to { transform: rotate(360deg); } }

.ai-lines { display: flex; flex-direction: column; line-height: 1.2; }
.ai-title { font-weight: 700; font-size: 14px; }
.ai-sub { font-size: 12px; color: #d1d5db; display: flex; align-items: center; }

.dots span {
  display: inline-block; width: 4px; height: 4px; margin-left: 3px; border-radius: 50%;
  background: var(--accent); opacity: .35; animation: bounce 1.3s infinite;
}
.dots span:nth-child(2) { animation-delay: .15s; }
.dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-3px); opacity: 1; } }

.spinner::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(244,199,92,0.32);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(244,199,92,0.26); } 70% { box-shadow: 0 0 0 10px rgba(244,199,92,0); } 100% { box-shadow: 0 0 0 0 rgba(244,199,92,0); } }




/* ---------------- Game End overlay ---------------- */
.result-overlay{
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px) saturate(120%);
  -webkit-backdrop-filter: blur(4px) saturate(120%);
  border-radius: 16px;
  animation: fadeInOverlay 220ms ease-out;
}

.result-card{
  width: min(520px, 92vw);
  border-radius: 16px;
  padding: 18px 18px 14px;
  background: linear-gradient(180deg, #15231c, #101a14);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 22px 50px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.05);
  color: var(--text-1);
  text-align: left;
  position: relative;
}

.result-ribbon{
  position: absolute;
  top: -12px; left: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .06em;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.06);
  text-transform: uppercase;
}
.result-ribbon.red{ background: rgba(220,38,38,.16); border-color: rgba(220,38,38,.36); }
.result-ribbon.black{ background: rgba(59,130,246,.16); border-color: rgba(59,130,246,.36); }
.result-ribbon.draw{ background: rgba(234,179,8,.16); border-color: rgba(234,179,8,.36); }

.result-grid{
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.result-item .k{
  color: var(--text-2);
  font-size: 12px;
  margin-bottom: 2px;
}
.result-item .v{
  font-weight: 700;
  font-size: 16px;
}
.result-item .sub{
  font-weight: 600;
  opacity: .8;
  font-size: 12px;
  margin-left: 6px;
}

.result-actions{
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}



/* ---------------- Responsive ---------------- */
@media (min-width: 1025px) {
  .side-panel {
    height: 70vh;       /* full viewport height */
    display: flex;
    overflow: auto;
    flex-direction: column;
    justify-content: space-between; /* optional, to push reset button to bottom */
  }
}
@media (max-width: 768px) {
  .piece { font-size: 1.05rem; }
  .square { width: 40px; height: 40px; }
  .square.legal-move::after { width: 8px; height: 8px; box-shadow: 0 0 0 5px rgba(255,184,90,.14); }
}

@media (max-width: 480px) {
  .board {margin-top: 16px;}
  .piece { font-size: 0.92rem; }
  .square { width: 36px; height: 36px; }
  .square.legal-move::after { width: 7px; height: 7px; box-shadow: 0 0 0 5px rgba(255,184,90,.12); }
}


/* ===================== Evaluation Bar (chess.com-like) ===================== */
.eval-wrap {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  width: 5px;
  border-radius: 2px;
  /* Always black on top, red on bottom */
  background: transparent;
  overflow: hidden;
  position: absolute;      /* overlay inside .board */
  left: -31px;
  top: 0;
  height: 100% !important;
  z-index: 1;              /* above board lines, below overlays */
  pointer-events: none;    /* never block clicks */
}

.eval-fill {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 50%;
  background: rgba(0,0,0,0.15); /* transparent overlay for effect */
  transition: height .25s ease;
}

/* .eval-top removed in unified black/red design */

.eval-score{
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 6px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  pointer-events: none;
}

@media (max-width: 768px){
  .eval-score{ font-size: 10px; bottom: 4px; }
}

/* === Eval bar track (dynamic split) === */
.eval-track{
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}
.eval-chunk{ width: 100%; }
.eval-black{
  background: linear-gradient(180deg, rgba(28,28,28,0.95) 0%, rgba(48,48,48,0.75) 100%);
}
.eval-red{
  background: linear-gradient(180deg, rgba(176,40,40,0.92) 0%, rgba(176,40,40,0.62) 100%);
}

/* === Smooth animation for evaluation bar changes === */
.eval-chunk{
  transition: height .45s cubic-bezier(.22,.61,.36,1);
  will-change: height;
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce){
  .eval-chunk{ transition: none; }
}
