:root {
  --bg: #0e1518;
  --bg-2: #10191c;
  --panel: rgba(22, 34, 37, 0.62);
  --panel-solid: #16242700;
  --ink: #e7ddc7;
  --muted: #8ba09a;
  --brass: #d9a441;
  --brass-soft: #ecc873;
  --danger: #c05548;
  --line: rgba(217, 164, 65, 0.16);

  --sq-light: #ccb994;
  --sq-dark: #46605a;
  --sq-light-last: #d9b970;
  --sq-dark-last: #6d7a58;

  --board: min(94vw, 68vh);
  --gap: 22px;
  --radius: 14px;

  --serif: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 90% at 50% -10%, #16262a 0%, var(--bg) 55%, #0a1013 100%);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---------- ambient sea fog ---------- */
.fog {
  position: fixed;
  inset: -20% -20% -20% -20%;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(40% 30% at 20% 30%, rgba(120, 150, 150, 0.10), transparent 70%),
    radial-gradient(45% 35% at 80% 65%, rgba(150, 170, 160, 0.08), transparent 70%),
    radial-gradient(35% 25% at 55% 15%, rgba(90, 120, 120, 0.08), transparent 70%);
  filter: blur(14px);
  animation: drift 34s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1.02); }
  to   { transform: translate3d(2%, 2%, 0) scale(1.06); }
}

/* ---------- layout ---------- */
.app {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 22px 18px 40px;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  display: block;
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--brass);
  opacity: 0.85;
  margin-bottom: 2px;
}
.title {
  font-family: var(--serif);
  font-weight: 600;
  font-style: italic;
  font-size: clamp(30px, 7vw, 46px);
  line-height: 0.95;
  margin: 0;
  letter-spacing: 0.01em;
  color: #f1e8d2;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

.icon-btn {
  flex: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
}
.icon-btn:hover { border-color: var(--brass); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.off { opacity: 0.55; }

.table {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  align-items: center;
}

/* ---------- board ---------- */
.board-side {
  width: var(--board);
  max-width: 100%;
}

.rank-of {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 4px 2px;
}
.side-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.side-label .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #33403d;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06) inset;
}
.side-label.on .dot { background: var(--brass); box-shadow: 0 0 8px var(--brass); }
.side-label.turn { color: var(--ink); }

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  font-size: 18px;
  line-height: 1;
  min-height: 20px;
  opacity: 0.9;
}
.tray .cap-w { color: #efe7d3; -webkit-text-stroke: 0.6px #2b2118; }
.tray .cap-b { color: #1c2624; -webkit-text-stroke: 0.6px #cbbd9c; }

.board-frame {
  position: relative;
  width: var(--board);
  height: var(--board);
  border-radius: var(--radius);
  padding: 12px;
  background:
    linear-gradient(145deg, #3a2c20, #241a12);
  box-shadow:
    0 26px 60px -24px rgba(0, 0, 0, 0.85),
    0 0 0 1px rgba(217, 164, 65, 0.22),
    inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.board {
  position: relative;
  width: 100%; height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 5px;
  overflow: hidden;
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.55);
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }
.sq.light.last { background: var(--sq-light-last); }
.sq.dark.last  { background: var(--sq-dark-last); }
.sq.playable { cursor: pointer; }

.coord {
  position: absolute;
  font-size: calc(var(--board) / 8 * 0.16);
  font-weight: 600;
  font-family: var(--sans);
  opacity: 0.55;
  pointer-events: none;
}
.coord.file { right: 4px; bottom: 2px; }
.coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: #5f5138; }
.sq.dark .coord { color: #cbb894; }

.piece {
  font-size: calc(var(--board) / 8 * 0.76);
  line-height: 1;
  cursor: inherit;
  transition: transform 0.08s ease;
  will-change: transform;
}
.piece.white {
  color: #f4ecd6;
  -webkit-text-stroke: 1.4px #2a2017;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.45);
}
.piece.black {
  color: #16201e;
  -webkit-text-stroke: 1.3px #d6c7a4;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.42);
}
.sq.sel .piece { transform: translateY(-2px) scale(1.04); }

/* selection + move hints */
.sq.sel::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px var(--brass-soft);
  background: radial-gradient(closest-side, rgba(236, 200, 115, 0.28), transparent 78%);
}
.sq .hint-dot {
  position: absolute;
  width: 30%; height: 30%;
  border-radius: 50%;
  background: rgba(30, 22, 12, 0.32);
  box-shadow: 0 0 0 2px rgba(236, 200, 115, 0.55);
  pointer-events: none;
}
.sq.light .hint-dot { background: rgba(60, 48, 26, 0.34); }
.sq .hint-ring {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px rgba(236, 200, 115, 0.72);
  pointer-events: none;
}
.sq.check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(closest-side, rgba(192, 85, 72, 0.85), rgba(192, 85, 72, 0) 72%);
  pointer-events: none;
}

/* checkmate / draw banner over the board */
.board-overlay {
  position: absolute;
  inset: 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(9, 14, 16, 0.72);
  backdrop-filter: blur(2px);
  z-index: 3;
}
.board-overlay .big {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(26px, 6vw, 44px);
  color: #f1e8d2;
  padding: 0 18px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}

/* ---------- panel ---------- */
.panel {
  width: var(--board);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  backdrop-filter: blur(3px);
}
.card-h {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brass);
  opacity: 0.85;
  margin-bottom: 8px;
}
.hint {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

.status-card { text-align: left; }
.you {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.you b { color: var(--ink); }
.turn {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  color: #f1e8d2;
}
.turn-pip {
  width: 14px; height: 14px; border-radius: 50%;
  background: #efe7d3;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35), 0 0 10px rgba(236, 200, 115, 0.5);
}
.turn-pip.black { background: #1a2422; box-shadow: 0 0 0 1px rgba(214,199,164,0.5); }
.alert {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(192, 85, 72, 0.4);
  background: rgba(192, 85, 72, 0.14);
  color: #f0c4bd;
}
.alert.good {
  border-color: rgba(217, 164, 65, 0.45);
  background: rgba(217, 164, 65, 0.14);
  color: var(--brass-soft);
}

.share-row { display: flex; gap: 8px; }
.share-input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  padding: 8px 10px;
}
.share-input:focus { outline: none; border-color: var(--brass); }

.btn {
  border: 1px solid var(--brass);
  background: linear-gradient(180deg, rgba(217,164,65,0.22), rgba(217,164,65,0.10));
  color: var(--brass-soft);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s, transform 0.08s, border-color 0.18s;
}
.btn:hover { background: linear-gradient(180deg, rgba(217,164,65,0.34), rgba(217,164,65,0.16)); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--ink);
}
.btn.ghost:hover { border-color: var(--brass); color: var(--brass-soft); }
.btn.danger-ghost {
  border-color: rgba(192, 85, 72, 0.4);
  background: rgba(192, 85, 72, 0.08);
  color: #e2a89f;
}
.btn.danger-ghost:hover { border-color: var(--danger); color: #f0c4bd; }

.moves-card { padding-bottom: 8px; }
.moves {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 168px;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
  scrollbar-width: thin;
  scrollbar-color: rgba(217,164,65,0.35) transparent;
}
.moves li {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 6px;
  padding: 3px 4px;
  font-size: 13.5px;
  border-radius: 5px;
}
.moves li:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }
.moves .num { color: var(--muted); }
.moves .san { color: var(--ink); font-family: var(--serif); font-size: 15px; }
.moves .san.empty { color: transparent; }

.actions {
  display: flex;
  gap: 10px;
}
.actions .btn { flex: 1; }

/* ---------- promotion ---------- */
.promo-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 12, 0.72);
  backdrop-filter: blur(3px);
}
.promo {
  background: linear-gradient(180deg, #1a2a2d, #121d20);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px 20px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.8);
  text-align: center;
}
.promo-h {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 12px;
}
.promo-row { display: flex; gap: 8px; }
.promo-pick {
  width: 64px; height: 64px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--sq-light);
  font-size: 40px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.18s;
}
.promo-pick:hover { border-color: var(--brass); transform: translateY(-2px); }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  :root { --board: min(66vh, 520px); }
  .table {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
  }
  .board-side { width: var(--board); }
  .panel { width: 330px; }
}

@media (prefers-reduced-motion: reduce) {
  .fog { animation: none; }
  .piece { transition: none; }
}
[hidden]{display:none!important}
.piece, .tray span { font-variant-emoji: text; }
