/* Gambitle components: "Tournament Hall" direction (v0.2). See DESIGN.md
   for the identity evolution away from the warm-cream v0.1 look. System
   font stacks only, no vendored font file, no CDN. Design tokens and
   element resets live in theme.css. */

.gb-app {
  max-width: 620px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) var(--space-4) env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- header ---------- */

.gb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
}

.gb-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* The brand mark is a single board square: ink plaque, gold knight. */
.gb-brand-mark {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--gold);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.gb-brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.45rem;
  letter-spacing: 0.02em;
}

.gb-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.gb-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.gb-icon-btn:active {
  transform: translateY(1px);
  background: var(--bg-sunken);
}

.gb-streak-badge {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.gb-streak-badge:active {
  transform: translateY(1px);
}

.gb-streak-flame {
  font-size: 1.05rem;
  line-height: 1;
  opacity: 0.4;
}

.gb-streak-badge.gb-streak-lit {
  color: var(--gold-text);
  border-color: var(--gold);
  background: var(--gold-wash);
}

.gb-streak-badge.gb-streak-lit .gb-streak-flame {
  opacity: 1;
  color: var(--gold);
}

@media (hover: hover) {
  .gb-icon-btn:hover,
  .gb-streak-badge:hover {
    border-color: var(--border-strong);
  }
}

/* Checkerboard ribbon: the board motif as a horizontal rule. */
.gb-rule {
  height: 8px;
  background-image: repeating-conic-gradient(var(--border) 0% 25%, transparent 0% 50%);
  background-size: 16px 16px;
}

/* ---------- main / states ---------- */

.gb-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.gb-state-panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-5);
  text-align: center;
  margin-top: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.gb-state-panel .gb-btn {
  flex: 0 1 auto;
  min-width: 160px;
}

.gb-state-detail {
  font-size: 0.85rem;
  color: var(--text-soft);
  margin-bottom: var(--space-4);
}

.gb-game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  max-width: 500px;
  margin: var(--space-3) auto 0;
}

.gb-top-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.gb-meta-bar {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-soft);
  margin: 0;
}

.gb-mode-chip {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  background: var(--bg-sunken);
}

.gb-status-line {
  font-weight: 600;
  font-size: 1.02rem;
  margin: 0;
  min-height: 1.4em;
  align-self: flex-start;
}

.gb-status-line.gb-status-win {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--gold-text);
}

/* ---------- miss row: six fixed slots, filled as misses land ---------- */

.gb-miss-row {
  display: flex;
  gap: var(--space-2);
  align-self: flex-start;
  align-items: center;
}

.gb-miss-slot {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1;
  color: transparent;
}

.gb-miss-slot.gb-miss-used {
  background: var(--wrong);
  border-color: var(--wrong);
  color: var(--wrong-bg);
}

/* On a win, unspent miss slots turn gold: the budget you never needed. */
.gb-miss-slot.gb-miss-saved {
  background: var(--gold-wash);
  border-color: var(--gold);
}

.gb-miss-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  margin-right: var(--space-1);
}

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

.gb-board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.gb-board-wrap.gb-shake {
  animation: gbShake 0.28s ease;
}

@keyframes gbShake {
  20% { transform: translateX(-5px); }
  45% { transform: translateX(4px); }
  70% { transform: translateX(-3px); }
  90% { transform: translateX(2px); }
}

.gb-board {
  position: relative;
  width: min(100%, 500px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 3px solid var(--ink);
  transition: box-shadow 0.2s ease;
}

.gb-board.gb-flash-correct {
  box-shadow: 0 0 0 3px var(--correct), var(--shadow-md);
}

.gb-board.gb-flash-wrong {
  box-shadow: 0 0 0 3px var(--wrong), var(--shadow-md);
}

.gb-board.gb-board-won {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold), var(--shadow-md);
}

.gb-square {
  position: relative;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(10vw, 46px);
  cursor: pointer;
}

.gb-square:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.gb-square.gb-wave {
  animation: gbWave 0.6s ease;
}

@keyframes gbWave {
  45% { box-shadow: inset 0 0 0 100px var(--last-move-wash); filter: brightness(1.25); }
}

.gb-square[data-coord-file]::before {
  content: attr(data-coord-file);
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  pointer-events: none;
}

.gb-square[data-coord-rank]::after {
  content: attr(data-coord-rank);
  position: absolute;
  left: 3px;
  top: 2px;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  pointer-events: none;
}

.gb-light[data-coord-file]::before,
.gb-light[data-coord-rank]::after {
  color: var(--coord-on-light);
}

.gb-dark[data-coord-file]::before,
.gb-dark[data-coord-rank]::after {
  color: var(--coord-on-dark);
}

.gb-light {
  background: var(--sq-light);
}

.gb-dark {
  background: var(--sq-dark);
}

.gb-square.gb-selected {
  box-shadow: inset 0 0 0 3px var(--select-ring);
}

.gb-square.gb-last-from,
.gb-square.gb-last-to {
  background-image: linear-gradient(0deg, var(--last-move-wash), var(--last-move-wash));
}

.gb-square.gb-check {
  background-image: linear-gradient(0deg, var(--check-wash), var(--check-wash));
}

.gb-square.gb-target::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--target-dot);
  pointer-events: none;
}

.gb-square.gb-target.gb-target-capture::after {
  width: 82%;
  height: 82%;
  background: transparent;
  border: 4px solid var(--target-dot);
  border-radius: 50%;
}

/* Both sides use the filled Unicode glyph; the fill color plus a real
   outline is what keeps every piece readable on every square in both
   themes. The glide transition is what animates a moved piece: board.js
   sets a starting translate inline, then clears it a frame later. */
.gb-piece {
  position: relative;
  z-index: 1;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1;
  transition: transform 0.16s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.gb-piece.gb-white {
  color: var(--piece-white-fill);
  -webkit-text-stroke: 1px var(--piece-white-line);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.gb-piece.gb-black {
  color: var(--piece-black-fill);
  -webkit-text-stroke: 1px var(--piece-black-line);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* ---------- promotion picker ---------- */

.gb-promo-picker {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-3) var(--space-4);
}

.gb-promo-title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
}

.gb-promo-row {
  display: flex;
  gap: var(--space-2);
}

.gb-promo-choice {
  width: 52px;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.gb-promo-choice:active {
  background: var(--border);
}

.gb-promo-cancel {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  text-decoration: underline;
}

@media (hover: hover) {
  .gb-promo-choice:hover {
    border-color: var(--gold);
  }
  .gb-promo-cancel:hover {
    color: var(--text);
  }
}

/* ---------- actions / buttons ---------- */

.gb-action-row {
  display: flex;
  gap: var(--space-3);
  width: 100%;
}

.gb-btn {
  flex: 1;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 12px 18px;
  min-height: 44px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.gb-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.gb-btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  box-shadow: var(--shadow-sm);
}

.gb-btn-primary:not(:disabled):active {
  background: var(--btn-primary-bg-active);
}

.gb-btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-soft);
}

.gb-btn-ghost:active {
  background: var(--bg-sunken);
}

@media (hover: hover) {
  .gb-btn-primary:not(:disabled):hover {
    background: var(--btn-primary-bg-hover);
  }
  .gb-btn-ghost:not(:disabled):hover {
    background: var(--bg-sunken);
    color: var(--text);
    border-color: var(--border-strong);
  }
}

/* ---------- moves / reveal ---------- */

.gb-moves-panel {
  width: 100%;
}

.gb-panel-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  margin-bottom: var(--space-2);
}

.gb-move-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0;
  margin: 0;
  list-style: none;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  min-height: 28px;
}

.gb-move-list li {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
}

.gb-move-list li.gb-move-none {
  background: transparent;
  border: none;
  padding-left: 0;
  color: var(--text-soft);
  font-family: var(--font-body);
  font-size: 0.85rem;
}

.gb-reveal-panel {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.gb-reveal-solution {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.gb-reveal-themes {
  font-size: 0.9rem;
  color: var(--text-soft);
}

.gb-reveal-link {
  display: inline-block;
  margin-bottom: var(--space-2);
  font-weight: 600;
}

@media (hover: hover) {
  .gb-reveal-link:hover {
    text-decoration-thickness: 2px;
  }
}

.gb-reveal-comeback {
  color: var(--text-soft);
  font-size: 0.9rem;
}

.gb-reveal-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.gb-reveal-actions .gb-btn {
  font-size: 0.85rem;
  padding: 10px 12px;
}
