/* Chess Champs — original maple & walnut UI. System fonts only. */
:root {
  --bg: #ebd7b8;
  --bg-deep: #2a1b10;
  --ink: #2a1b10;
  --ink-soft: #5a4330;
  --cream: #fbf4e6;
  --paper: #f7edd8;
  --line: rgba(90, 53, 28, 0.22);
  --wood-frame: #5a351c;
  --wood-frame-dark: #3d2210;
  --wood-light: #e3c690;
  --wood-light-2: #d4b074;
  --wood-dark: #8a5630;
  --wood-dark-2: #6e4122;
  --gold: #c4a04a;
  --gold-deep: #8a6a22;
  --check: #c04532;
  --shadow: 0 10px 28px rgba(42, 27, 16, 0.22);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, #f6e6c8 0%, transparent 60%),
    repeating-linear-gradient(90deg, rgba(90,53,28,0.035) 0 1px, transparent 1px 5px),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

#app {
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(12px + var(--safe-top)) 14px calc(16px + var(--safe-bottom));
}

.view { }

.brand {
  text-align: center;
  margin: 8px 0 18px;
}
.brand h1 {
  font-size: clamp(2rem, 7vw, 3.1rem);
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--wood-frame);
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
}
.brand p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

.stat-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0 0 22px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: 0 2px 0 rgba(90,53,28,0.08);
  min-height: 44px;
}
.chip .label { color: var(--ink-soft); font-size: 0.92rem; }
.chip .value { font-weight: 700; font-size: 1.05rem; }
.chip svg { width: 22px; height: 22px; display: block; flex: 0 0 auto; }

.menu {
  display: grid;
  gap: 12px;
  max-width: 380px;
  margin: 0 auto;
}
.btn {
  appearance: none;
  border: 1px solid var(--wood-frame-dark);
  background: linear-gradient(#6a3f22, #4a2a14);
  color: var(--cream);
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 48px;
  box-shadow: 0 2px 0 #2a160a, inset 0 1px 0 rgba(255,255,255,0.14);
  letter-spacing: 0.01em;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(#8a5a2c, #5a351c); font-size: 1.12rem; }
.btn.ghost {
  background: var(--cream);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: 0 1px 0 rgba(90,53,28,0.12);
}
.btn.danger { background: linear-gradient(#8a3228, #5a1c16); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; transform: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1 1 0; }

.privacy, .footnote {
  max-width: 420px;
  margin: 22px auto 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 44px;
}
.topbar h2 { flex: 1; margin: 0; font-size: 1.25rem; text-align: center; }
.topbar .btn { min-width: 72px; padding: 8px 12px; min-height: 42px; }

/* Setup */
.opp-list { display: grid; gap: 10px; max-width: 520px; margin: 0 auto; }
.opp {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  text-align: left;
  background: var(--cream);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-height: 72px;
}
.opp:hover { border-color: var(--gold-deep); }
.opp.picked { border-color: var(--wood-frame); box-shadow: 0 0 0 3px rgba(196,160,74,0.35); }
.opp .name { font-weight: 700; font-size: 1.15rem; }
.opp .blurb { grid-column: 1 / -1; color: var(--ink-soft); font-size: 0.95rem; }
.opp .rating { color: var(--gold-deep); font-weight: 700; }

.color-pick { display: flex; gap: 10px; justify-content: center; margin: 16px 0; }
.color-pick .btn { min-width: 140px; }
.color-pick .btn.picked { outline: 3px solid var(--gold); outline-offset: 1px; }

/* Game layout */
.game-layout {
  display: grid;
  gap: 14px;
}
.game-status {
  text-align: center;
  font-size: 1.05rem;
  min-height: 1.4em;
  font-weight: 700;
}
.game-status.check { color: var(--check); }
.caps {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--ink-soft);
  min-height: 1.3em;
}
.caps .group { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.mini-piece { width: 20px; height: 26px; display: inline-block; }

.board-wrap { width: min(100%, 92vw, 72vh, 560px); margin: 0 auto; }
.board-frame {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.08) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #6b4022, #4a2a14 40%, #3d2210);
  border-radius: 10px;
  padding: 4.6%;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.15);
  border: 1px solid #2a160a;
}
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  touch-action: manipulation;
  user-select: none;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(42,27,16,0.35);
}
.board-squares {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}
.sq {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  appearance: none;
  display: block;
  width: 100%;
  height: 100%;
  background: none;
}
.sq.light {
  background:
    repeating-linear-gradient(90deg, rgba(90,50,20,0.05) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, #edd4a4, #d7b57a);
}
.sq.dark {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.07) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, #9a6236, #73431f);
}
.sq.coord-file::after {
  content: attr(data-file-label);
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 10px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  opacity: 0.72;
  pointer-events: none;
  line-height: 1;
}
.sq.coord-rank::before {
  content: attr(data-rank-label);
  position: absolute;
  left: 3px;
  top: 2px;
  font-size: 10px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  opacity: 0.72;
  pointer-events: none;
  line-height: 1;
}
.sq.light.coord-file::after, .sq.light.coord-rank::before { color: #6e4122; }
.sq.dark.coord-file::after, .sq.dark.coord-rank::before { color: #f0ddb8; }

.sq.last-from, .sq.last-to {
  box-shadow: inset 0 0 0 999px rgba(214, 176, 72, 0.38);
}
.sq.selected { box-shadow: inset 0 0 0 999px rgba(90, 160, 80, 0.38); }
.sq.check { box-shadow: inset 0 0 0 999px rgba(192, 69, 50, 0.46); }
.sq.hint-from, .sq.hint-to {
  box-shadow: inset 0 0 0 3px #d4a017, inset 0 0 0 999px rgba(212, 160, 23, 0.2);
}
.sq.legal::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 32%;
  height: 32%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(42, 27, 16, 0.45);
  pointer-events: none;
  z-index: 2;
}
.sq.legal.capture::after {
  width: 78%;
  height: 78%;
  background: transparent;
  box-shadow: inset 0 0 0 5px rgba(42, 27, 16, 0.5);
}

.piece-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}
.piece {
  position: absolute;
  left: 0;
  top: 0;
  width: 12.5%;
  height: 12.5%;
  display: grid;
  place-items: center;
  transition: transform 160ms ease;
  will-change: transform;
  filter: drop-shadow(0 2px 1px rgba(40,22,8,0.28));
}
.piece.dragging { z-index: 5; transition: none; filter: drop-shadow(0 8px 6px rgba(40,22,8,0.4)); }
.piece-svg { width: 92%; height: 92%; display: block; overflow: visible; }

.side-panel {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 2px 0 rgba(90,53,28,0.08);
}
.move-list {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.92rem;
  max-height: 160px;
  overflow: auto;
  line-height: 1.55;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  columns: 1;
}
.move-list li { display: grid; grid-template-columns: 2.2em 1fr 1fr; gap: 6px; }
.move-list .n { color: var(--ink-soft); }

/* Lesson */
.coach-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: center;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.coach-art { width: 72px; height: 90px; }
.coach-card h3 { margin: 0 0 4px; }
.coach-card p { margin: 0; color: var(--ink-soft); }
.speech {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 0 0 12px;
  line-height: 1.45;
}

/* Settings / credits */
.panel {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  max-width: 640px;
  margin: 0 auto 14px;
  line-height: 1.5;
}
.panel h3 { margin: 0 0 8px; }
.panel pre, .notice {
  white-space: pre-wrap;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
  background: var(--paper);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
}

/* Modal + promotion */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 27, 16, 0.46);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 16px;
}
.modal {
  background: var(--cream);
  color: var(--ink);
  border-radius: 16px;
  padding: 20px 18px;
  width: min(100%, 400px);
  box-shadow: var(--shadow);
  text-align: center;
}
.modal h3 { margin: 0 0 8px; font-size: 1.4rem; }
.modal p { margin: 0 0 16px; }
.elo-change { font-size: 1.15rem; font-weight: 700; margin: 0 0 8px; }
.elo-change.up { color: #2d6a32; }
.elo-change.down { color: #8a3228; }

.promo-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 27, 16, 0.46);
  display: grid;
  place-items: center;
  z-index: 21;
  padding: 16px;
}
.promo {
  background: var(--cream);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  gap: 8px;
  box-shadow: var(--shadow);
}
.promo button {
  width: 68px;
  height: 88px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 4px;
}
.promo button svg { width: 100%; height: 100%; }

@media (min-width: 860px) {
  .game-layout {
    grid-template-columns: minmax(0, 560px) 280px;
    align-items: start;
    justify-content: center;
  }
  .move-list { max-height: 320px; }
  .board-wrap { margin: 0; width: 100%; }
}

@media (max-width: 400px) {
  #app { padding-left: 8px; padding-right: 8px; }
  .btn { padding: 10px 12px; }
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 700;
}
.toggle input {
  width: 20px;
  height: 20px;
  accent-color: #5a351c;
}
