/* ------------------------------------------------------------------------
   Self-hosted games — shared UI (chess board, panels, buttons, sudoku grid).

   Every colour and font is a --gm-* custom property with a fallback, so a
   homepage version themes the games by defining those properties on :root
   (v6 does this at the top of css/style.scss). Nothing here depends on the
   homepage stylesheet apart from those tokens.
   ------------------------------------------------------------------------ */

.gm-page {
  padding: clamp(40px, 6vw, 80px) 0 clamp(64px, 8vw, 112px);
  background: var(--gm-bg, #0f1520);
  color: var(--gm-text, #f2eee6);
}

.gm-page .wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.gm-crumbs {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  font-size: 0.8rem;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
}

.gm-crumbs a {
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  text-decoration: none;
}

.gm-crumbs a:hover {
  color: var(--gm-accent-bright, #e0584a);
}

.gm-crumbs i {
  font-size: 0.7em;
  opacity: 0.6;
}

.gm-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 32px;
  margin-bottom: clamp(24px, 3vw, 40px);
}

.gm-head h1 {
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
  font-size: clamp(2.2rem, 4.2vw, 3.4rem);
  margin: 0 0 8px;
}

.gm-head p {
  margin: 0;
  max-width: 60ch;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
}

.gm-head .gm-kind {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gm-accent-bright, #e0584a);
}

.gm-head .gm-kind::before {
  content: "";
  width: 28px;
  height: 2px;
  background: var(--gm-accent, #c0392b);
}

/* ---------------------------------------------------------------- layout */

.gm-layout {
  display: grid;
  grid-template-columns: minmax(0, 640px) minmax(280px, 1fr);
  gap: clamp(24px, 3vw, 48px);
  align-items: start;
}

.gm-stage {
  min-width: 0;
}

.gm-panel {
  background: var(--gm-surface, #1b2740);
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: var(--gm-radius, 12px);
  padding: 22px;
}

.gm-panel + .gm-panel {
  margin-top: 16px;
}

.gm-panel h2 {
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-weight: 500;
  font-size: 1.25rem;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.gm-panel p {
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  margin: 0 0 0.8em;
}

.gm-panel p:last-child {
  margin-bottom: 0;
}

.gm-label {
  display: block;
  margin: 0 0 8px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
}

.gm-field {
  margin-bottom: 18px;
}

.gm-field:last-child {
  margin-bottom: 0;
}

/* ---------------------------------------------------------------- status */

.gm-status {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin: 16px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: var(--gm-radius, 12px);
  background: var(--gm-surface, #1b2740);
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-size: 1.1rem;
}

.gm-status .gm-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gm-accent, #c0392b);
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.35);
}

.gm-status.is-thinking .gm-dot {
  animation: gm-pulse 1.1s ease-out infinite;
}

.gm-status.is-good {
  border-color: rgba(88, 190, 130, 0.5);
}

.gm-status.is-good .gm-dot {
  background: #58be82;
}

.gm-status.is-bad .gm-dot {
  background: #e0584a;
}

.gm-status.is-end {
  border-color: var(--gm-accent-line, rgba(192, 57, 43, 0.42));
}

@keyframes gm-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.35); }
  100% { box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
}

/* ---------------------------------------------------------------- controls */

.gm-btn,
.gm-seg button {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.gm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--gm-text, #f2eee6);
  background: transparent;
  border: 1px solid var(--gm-line-2, rgba(255, 255, 255, 0.16));
}

.gm-btn:hover {
  border-color: var(--gm-accent-bright, #e0584a);
  color: var(--gm-accent-bright, #e0584a);
}

.gm-btn:disabled {
  opacity: 0.45;
  cursor: default;
  border-color: var(--gm-line, rgba(255, 255, 255, 0.09));
  color: var(--gm-text, #f2eee6);
}

.gm-btn.gm-primary {
  background: var(--gm-accent, #c0392b);
  border-color: var(--gm-accent, #c0392b);
  color: #fff;
}

.gm-btn.gm-primary:hover {
  background: var(--gm-accent-bright, #e0584a);
  border-color: var(--gm-accent-bright, #e0584a);
  color: #fff;
  transform: translateY(-1px);
}

.gm-btn i {
  font-size: 0.85em;
}

.gm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.gm-seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: 999px;
  background: var(--gm-bg-2, #131c2b);
}

.gm-seg button {
  padding: 8px 16px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  background: transparent;
  border: 0;
}

.gm-seg button[aria-pressed="true"] {
  background: var(--gm-surface-2, #22304a);
  color: var(--gm-text, #f2eee6);
  box-shadow: inset 0 0 0 1px var(--gm-line-2, rgba(255, 255, 255, 0.16));
}

.gm-seg button:hover {
  color: var(--gm-text, #f2eee6);
}

/* ---------------------------------------------------------------- chess board */

.gm-board-wrap {
  position: relative;
  width: 100%;
  max-width: 640px;
  padding: 10px;
  background: var(--gm-surface, #1b2740);
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: var(--gm-radius, 12px);
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.7);
}

.gm-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--gm-board-edge, rgba(0, 0, 0, 0.45));
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.gm-sq {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.gm-sq:focus-visible {
  outline: 3px solid var(--gm-accent-bright, #e0584a);
  outline-offset: -3px;
  z-index: 2;
}

.gm-light { background: var(--gm-sq-light, #e9e0cc); }
.gm-dark { background: var(--gm-sq-dark, #6b3a44); }

.gm-sq[data-rank]::before,
.gm-sq[data-file]::after {
  position: absolute;
  font: 600 0.62rem/1 var(--gm-body, "DM Sans", system-ui, sans-serif);
  pointer-events: none;
  opacity: 0.75;
}

.gm-sq[data-rank]::before {
  content: attr(data-rank);
  top: 4px;
  left: 5px;
}

.gm-sq[data-file]::after {
  content: attr(data-file);
  right: 5px;
  bottom: 3px;
}

.gm-light::before, .gm-light::after { color: var(--gm-sq-dark, #6b3a44); }
.gm-dark::before, .gm-dark::after { color: var(--gm-sq-light, #e9e0cc); }

.gm-piece {
  position: absolute;
  inset: 4%;
  width: 92%;
  height: 92%;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.gm-piece.w { fill: var(--gm-piece-w, #f7f3ea); stroke: #2a2623; }
.gm-piece.b { fill: var(--gm-piece-b, #14161c); stroke: #c9c3b8; }
.gm-piece { stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.gm-piece .gm-cut, .gm-piece .gm-cross { fill: none; stroke-width: 2.2; }
.gm-piece.w .gm-cut, .gm-piece.w .gm-cross { stroke: #2a2623; }
.gm-piece.b .gm-cut, .gm-piece.b .gm-cross { stroke: #c9c3b8; }
.gm-piece.w .gm-eye { fill: #2a2623; stroke: none; }
.gm-piece.b .gm-eye { fill: #c9c3b8; stroke: none; }

.gm-sq.is-last { box-shadow: inset 0 0 0 100vmax var(--gm-last, rgba(240, 192, 74, 0.42)); }
.gm-sq.is-selected { box-shadow: inset 0 0 0 100vmax var(--gm-select, rgba(240, 192, 74, 0.6)); }
.gm-sq.is-hint { box-shadow: inset 0 0 0 4px var(--gm-accent-bright, #e0584a); }
.gm-sq.is-check { background: radial-gradient(circle, rgba(224, 88, 74, 0.95) 0%, rgba(224, 88, 74, 0.6) 45%, transparent 72%); }

.gm-sq.is-legal::after,
.gm-sq.is-legal::before {
  content: "";
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  opacity: 1;
}

.gm-sq.is-capture::after,
.gm-sq.is-capture::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 6px solid rgba(0, 0, 0, 0.28);
  background: none;
}

.gm-sq.is-legal[data-file]::after, .gm-sq.is-legal[data-rank]::before,
.gm-sq.is-capture[data-file]::after, .gm-sq.is-capture[data-rank]::before {
  content: "";
  font-size: 0;
}

.gm-sq.is-shake .gm-piece {
  animation: gm-shake 0.35s ease;
}

@keyframes gm-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6%); }
  75% { transform: translateX(6%); }
}

/* ---------------------------------------------------------------- move list */

.gm-moves {
  display: grid;
  grid-template-columns: 2.6em 1fr 1fr;
  gap: 2px 8px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.gm-moves .gm-mv-n {
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
}

.gm-moves span {
  padding: 4px 6px;
  border-radius: 6px;
}

.gm-moves .is-current {
  background: var(--gm-surface-2, #22304a);
}

.gm-empty {
  grid-column: 1 / -1;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  font-style: italic;
}

/* ---------------------------------------------------------------- key/value */

.gm-kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 20px;
  margin: 0;
}

.gm-kv dt {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  align-self: center;
}

.gm-kv-row { display: contents; }
.gm-kv-row[hidden] { display: none; }

.gm-kv dd {
  margin: 0;
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-size: 1.05rem;
}

/* ---------------------------------------------------------------- sudoku */

.gm-sudoku {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1;
  border: 2px solid var(--gm-text, #f2eee6);
  border-radius: 6px;
  overflow: hidden;
  background: var(--gm-text, #f2eee6);
  gap: 1px;
  user-select: none;
  -webkit-user-select: none;
}

.gm-cell {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  aspect-ratio: 1;
  font: 500 clamp(1rem, 3.4vw, 1.7rem)/1 var(--gm-display, "Fraunces", Georgia, serif);
  color: var(--gm-text, #f2eee6);
  background: var(--gm-surface, #1b2740);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease;
}

.gm-cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--gm-text, #f2eee6); }
.gm-cell:nth-child(n+19):nth-child(-n+27),
.gm-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--gm-text, #f2eee6); }

.gm-cell.is-given { color: var(--gm-muted, rgba(242, 238, 230, 0.8)); font-weight: 600; }
.gm-cell.is-peer { background: var(--gm-surface-2, #22304a); }
.gm-cell.is-same { background: var(--gm-accent-soft, rgba(192, 57, 43, 0.3)); }
.gm-cell.is-selected { background: var(--gm-accent, #c0392b); color: #fff; }
.gm-cell.is-wrong { color: #ff7b6b; }
.gm-cell.is-wrong.is-selected { color: #fff; }
.gm-cell.is-selected.is-wrong::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid #ff7b6b;
}

.gm-cell:focus-visible {
  outline: 3px solid var(--gm-accent-bright, #e0584a);
  outline-offset: -3px;
  z-index: 1;
}

.gm-numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.gm-numpad button {
  appearance: none;
  -webkit-appearance: none;
  font: 500 1.25rem/1 var(--gm-display, "Fraunces", Georgia, serif);
  padding: 14px 0;
  color: var(--gm-text, #f2eee6);
  background: var(--gm-bg-2, #131c2b);
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.gm-numpad button:hover {
  border-color: var(--gm-accent-bright, #e0584a);
}

.gm-numpad button.is-done {
  opacity: 0.35;
}

.gm-numpad button.gm-erase {
  font-family: var(--gm-body, "DM Sans", system-ui, sans-serif);
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------- game hub cards (index) */

.gm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.gm-card {
  display: block;
  padding: 20px;
  background: var(--gm-surface, #1b2740);
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: var(--gm-radius, 12px);
  color: var(--gm-text, #f2eee6);
  text-decoration: none;
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.gm-card:hover {
  transform: translateY(-4px);
  border-color: var(--gm-accent-line, rgba(192, 57, 43, 0.42));
  color: var(--gm-text, #f2eee6);
}

.gm-card svg {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: 16px;
}

.gm-card h3 {
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-weight: 500;
  font-size: 1.4rem;
  margin: 0 0 6px;
}

.gm-card p {
  margin: 0;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------- built-in shell (v1–v5) */

.gm-standalone {
  margin: 0;
  background: var(--gm-bg, #0f1520);
  color: var(--gm-text, #f2eee6);
  font-family: var(--gm-body, "DM Sans", system-ui, sans-serif);
  font-size: 1rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.gm-standalone a {
  color: var(--gm-accent-bright, #e0584a);
  text-decoration: none;
}

.gm-standalone h1,
.gm-standalone h2,
.gm-standalone h3 {
  color: var(--gm-text, #f2eee6);
}

.gm-top {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--gm-bg, #0f1520);
  border-bottom: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
}

.gm-top .wrap,
.gm-foot .wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  flex-wrap: wrap;
}

.gm-top .wrap {
  min-height: 68px;
}

.gm-brand {
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--gm-text, #f2eee6) !important;
}

.gm-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}

.gm-nav a {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  transition: color 0.2s ease, background 0.2s ease;
}

.gm-nav a:hover,
.gm-nav a.is-active {
  color: var(--gm-text, #f2eee6);
  background: var(--gm-surface, #1b2740);
}

.gm-foot {
  padding: 28px 0 36px;
  border-top: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  background: var(--gm-bg-2, #131c2b);
  font-size: 0.9rem;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
}

.gm-foot p {
  margin: 0;
}

/* ---------------------------------------------------------------- legal pages (custom sites) */

.gm-legal {
  max-width: 800px;
}

.gm-legal h1 {
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-weight: 500;
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0 0 12px;
  color: var(--gm-text, #f2eee6);
}

.gm-legal .gm-legal-lead {
  font-size: 1.1rem;
  margin-bottom: 36px;
}

.gm-legal h2 {
  font-family: var(--gm-display, "Fraunces", Georgia, serif);
  font-weight: 500;
  font-size: 1.35rem;
  margin: 36px 0 10px;
  color: var(--gm-text, #f2eee6);
}

.gm-legal p,
.gm-legal li {
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  line-height: 1.7;
}

.gm-legal ul {
  padding-left: 20px;
  margin: 0 0 1em;
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 991px) {
  .gm-layout {
    grid-template-columns: 1fr;
  }

  .gm-board-wrap,
  .gm-sudoku {
    margin: 0 auto;
  }

  .gm-moves {
    max-height: 180px;
  }
}

@media (max-width: 480px) {
  .gm-page .wrap {
    padding: 0 14px;
  }

  .gm-board-wrap {
    padding: 6px;
  }

  .gm-panel {
    padding: 18px;
  }

  .gm-btn {
    padding: 10px 16px;
    font-size: 0.88rem;
  }

  .gm-sq[data-rank]::before,
  .gm-sq[data-file]::after {
    font-size: 0.5rem;
  }
}
