* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #161512;
  --panel: #262421;
  --panel-2: #302e2b;
  --text: #e8e6e3;
  --muted: #9d9a96;
  --accent: #629924;
  --accent-2: #7bb332;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px 6px;
}
header h1 { font-size: 1.15rem; font-weight: 700; }
.opp-label { font-size: .8rem; color: var(--muted); }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 0 16px;
}

/* Board */
#board-frame {
  position: relative;
  /* full width, but never taller than what leaves room for the controls */
  width: min(100%, calc(100dvh - 300px));
  margin: 0 auto;
}
#board.cg-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
}
/* chessground's default file-coord offset (+24px) overflows narrow windows */
#board coords.files { left: 0; }
#board coords.files coord { text-align: center; padding-left: 8px; }

/* thinking dots */
.thinking {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,.55);
  border-radius: 12px;
  padding: 6px 10px;
  display: flex; gap: 4px;
  z-index: 5;
}
.thinking span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-2);
  animation: blink 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: .2s; }
.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% {opacity:.25} 40% {opacity:1} }

.status {
  text-align: center;
  font-size: .95rem;
  min-height: 1.3em;
  color: var(--muted);
}
.status.alert { color: #e8a33d; }

/* Difficulty slider */
.difficulty { padding: 2px 16px; }
.diff-row { display: flex; justify-content: space-between; align-items: baseline; }
.diff-name { font-weight: 600; font-size: .95rem; }
.diff-elo { color: var(--muted); font-size: .85rem; }
.diff-scale {
  display: flex; justify-content: space-between;
  font-size: .65rem; color: var(--muted);
  margin-top: 2px;
}
input[type=range] {
  width: 100%;
  margin: 8px 0 2px;
  appearance: none; -webkit-appearance: none;
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, #4a90d9, #629924, #d9a04a, #d94a4a);
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--panel-2);
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
  cursor: pointer;
}

/* Buttons */
.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0 14px;
}
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 12px 6px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.subtle { background: transparent; color: var(--muted); margin-top: 10px; }

/* Move list */
.movelist {
  padding: 4px 14px 10px;
  font-size: .85rem;
  line-height: 1.7;
  color: var(--muted);
  overflow-y: auto;
  max-height: 20vh;
}
.movelist b { color: var(--text); font-weight: 600; }
.movelist .num { color: #6e6b67; margin-right: .15em; }
.movelist span.mv { margin-right: .5em; }

/* Overlays / dialogs */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.overlay.hidden, .hidden { display: none; }
.dialog {
  background: var(--panel);
  border-radius: 16px;
  padding: 22px 26px;
  text-align: center;
  min-width: 260px;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.dialog h2 { margin-bottom: 8px; }
.dialog p { color: var(--muted); margin-bottom: 14px; }

.color-picker, .promo-picker { display: flex; gap: 10px; justify-content: center; margin-bottom: 6px; }
.color-btn, .promo-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid transparent;
  border-radius: 12px;
  font-size: 1.6rem;
  line-height: 1.2;
  padding: 10px 14px;
  cursor: pointer;
}
.color-btn { font-size: 1.3rem; min-width: 72px; }
.color-btn:active, .promo-btn:active { border-color: var(--accent); }
.promo-btn { font-size: 2rem; }

/* chessground last-move + selected tint tweaks for dark bg */
#over-title.win { color: var(--accent-2); }
#over-title.loss { color: #d95f5f; }

/* Wide/landscape windows (iPad landscape, full-size Mac window):
   board on the left sized to the window height, controls beside it.
   Narrow windows (iPad portrait, half-screen Mac window, phones)
   keep the vertical column layout above. */
@media (orientation: landscape) and (min-width: 700px) and (min-height: 420px) {
  main {
    display: grid;
    grid-template-columns: auto minmax(280px, 440px);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    justify-content: center;
    align-content: start;
    align-items: start;
    column-gap: 24px;
    row-gap: 12px;
    max-width: none;
    padding: 0 16px 16px;
    min-height: 0;
  }
  #board-frame {
    grid-column: 1;
    grid-row: 1 / span 4;
    width: min(calc(100dvh - 84px), calc(100vw - 380px), 760px);
  }
  .status { grid-column: 2; margin-top: 4px; }
  .difficulty { grid-column: 2; width: 100%; }
  .controls { grid-column: 2; width: 100%; padding: 0; }
  .movelist {
    grid-column: 2;
    width: 100%;
    max-height: none;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 2px 10px;
  }
}
