/* ===== Premium chess trainer — dark wood + green accent ===== */
:root {
  --bg-0: #0e1114;
  --bg-1: #161b22;
  --bg-2: #1c232c;
  --bg-3: #242d38;
  --border: rgba(255, 255, 255, 0.07);
  --text: #e8edf2;
  --text-muted: #8b97a5;
  --accent: #3d9a6a;
  --accent-soft: rgba(61, 154, 106, 0.18);
  --accent-strong: #4fc48a;
  --danger: #e06c75;
  --warn: #e5c07b;
  --light-sq: #e8d5b5;
  --dark-sq: #b58863;
  --light-sq-hover: #f0e0c4;
  --dark-sq-hover: #c4966e;
  --highlight: rgba(61, 154, 106, 0.55);
  --last-move: rgba(246, 193, 72, 0.42);
  --check: rgba(224, 108, 117, 0.65);
  --legal-dot: rgba(20, 28, 24, 0.28);
  --legal-capture: rgba(224, 108, 117, 0.55);
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  /* Доска занимает почти всю высоту окна минус шапка/кнопки */
  --board-max: min(calc(100dvh - 9.5rem), calc(100svh - 9.5rem), 92vw);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 154, 106, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(181, 136, 99, 0.1), transparent 50%),
    var(--bg-0);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  line-height: 1.45;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.app {
  width: min(1480px, 100% - 1rem);
  margin: 0 auto;
  padding: calc(0.45rem + var(--safe-top)) max(var(--safe-right), 0.35rem) calc(0.45rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
}

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-logout {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
}

.btn-logout:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.14);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--bg-3), var(--bg-1));
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  font-size: 1.35rem;
  color: var(--accent-strong);
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.1rem 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
  font-weight: 600;
  font-size: 0.85rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.status-pill.is-check .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(224, 108, 117, 0.25);
}

.status-pill.is-end .status-dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(229, 192, 123, 0.25);
}

.status-pill.is-mate {
  background: linear-gradient(135deg, rgba(224, 108, 117, 0.35), rgba(246, 193, 72, 0.22));
  border-color: rgba(224, 108, 117, 0.55);
  color: #fff;
  font-size: 1.05rem;
  padding: 0.65rem 1.55rem;
  box-shadow:
    0 0 0 1px rgba(224, 108, 117, 0.35),
    0 12px 32px rgba(224, 108, 117, 0.28);
  animation: mate-pill-pulse 1.6s ease-in-out infinite;
}

.status-pill.is-mate .status-dot {
  background: #ff6b76;
  box-shadow: 0 0 0 4px rgba(255, 107, 118, 0.35);
}

@keyframes mate-pill-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* ---- Layout ---- */
.main {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.75fr);
  gap: 0.75rem;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.board-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.board-shell {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 0.55rem 0.55rem 0.65rem;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: center;
}

/* Одна ширина для доски и подписей a–h */
.board-frame {
  width: min(100%, calc(var(--board-max) + 1.55rem + 0.25rem));
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.board-wrap {
  display: grid;
  grid-template-columns: 1.55rem minmax(0, 1fr);
  gap: 0.25rem;
  align-items: stretch;
  width: 100%;
}

.coords {
  color: #c5d0dc;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--mono);
  user-select: none;
  line-height: 1;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.coords-ranks {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
  align-self: stretch;
  font-size: 1.05rem;
}

.coords-files {
  display: grid;
  grid-template-columns: 1.55rem minmax(0, 1fr);
  gap: 0.25rem;
  width: 100%;
  margin: 0;
}

.coords-files .files-inner {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  justify-items: center;
  align-items: center;
  width: 100%;
  font-size: 1.05rem;
  padding-top: 0.15rem;
}

.board {
  width: 100%;
  aspect-ratio: 1;
  max-width: none;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  container-type: inline-size;
  container-name: chessboard;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.35),
    0 10px 30px rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  transition: background-color 0.12s ease;
}

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

.square.last-move.light { background: color-mix(in srgb, var(--light-sq) 55%, #f6c148); }
.square.last-move.dark { background: color-mix(in srgb, var(--dark-sq) 50%, #f6c148); }

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

.square.in-check {
  background:
    radial-gradient(circle at center, rgba(224, 108, 117, 0.95) 0%, transparent 70%),
    var(--dark-sq);
  animation: check-pulse 0.9s ease-in-out infinite;
  z-index: 2;
}

.square.light.in-check {
  background:
    radial-gradient(circle at center, rgba(224, 108, 117, 0.95) 0%, transparent 70%),
    var(--light-sq);
}

.square.in-check .piece {
  filter: drop-shadow(0 0 8px rgba(255, 80, 90, 0.9));
}

.piece {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  /* Размер от ширины доски: ~75% клетки */
  font-size: 9.2cqi;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: transform 0.08s ease;
  -webkit-user-drag: none;
  user-select: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}

/* Fallback if container queries unsupported */
@supports not (font-size: 1cqi) {
  .piece {
    font-size: clamp(2rem, 8vmin, 4rem);
  }
}

.piece:active,
.piece.dragging {
  cursor: pointer;
  transform: scale(1.05);
  z-index: 5;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4));
}

.piece.white {
  color: #fff8ee;
  /* залитый глиф + тёмный ободок, чтобы не сливаться со светлыми клетками */
  text-shadow:
    0 0 1px #2a2118,
    1px 0 0 #2a2118,
    -1px 0 0 #2a2118,
    0 1px 0 #2a2118,
    0 -1px 0 #2a2118,
    1px 1px 0 #2a2118,
    -1px -1px 0 #2a2118,
    0 2px 3px rgba(0, 0, 0, 0.35);
}

.piece.black {
  color: #12151a;
  text-shadow:
    0 0 1px rgba(255, 248, 238, 0.55),
    1px 0 0 rgba(255, 248, 238, 0.35),
    -1px 0 0 rgba(255, 248, 238, 0.35),
    0 1px 0 rgba(255, 248, 238, 0.35),
    0 -1px 0 rgba(255, 248, 238, 0.35),
    0 2px 3px rgba(0, 0, 0, 0.4);
}


/* Ghost for drag */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  font-size: clamp(1.8rem, 8vw, 3.5rem);
  line-height: 1;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.45));
  opacity: 0.95;
}

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 0.8rem;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover {
  background: var(--bg-3);
  border-color: rgba(255, 255, 255, 0.12);
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-primary {
  background: linear-gradient(180deg, #48b07a, var(--accent));
  border-color: transparent;
  color: #06140d;
  box-shadow: 0 8px 20px rgba(61, 154, 106, 0.28);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #54c48a, #3d9a6a);
  border-color: transparent;
}

.btn-icon {
  opacity: 0.85;
  font-size: 0.95em;
}

.toast {
  margin: 0;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(61, 154, 106, 0.35);
  color: var(--accent-strong);
  font-size: 0.88rem;
  font-weight: 500;
}

.toast.is-error {
  background: rgba(224, 108, 117, 0.15);
  border-color: rgba(224, 108, 117, 0.35);
  color: #f0a0a6;
}

/* ---- Side panels ---- */
.side {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  align-self: stretch;
}

.panel {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.75rem;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.meta {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.meta > div {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.5rem;
}

.meta dt {
  margin: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta dd {
  margin: 0.25rem 0 0;
  font-weight: 700;
  font-size: 0.95rem;
}

.panel-moves {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.panel-moves-under {
  max-height: 8rem;
  overflow: hidden;
  padding: 0.55rem 0.7rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.moves-under-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex: 0 0 auto;
}

.moves-under-head h2 {
  margin: 0;
}

.panel-moves-under .moves-empty {
  margin: 0;
  font-size: 0.8rem;
}

.panel-moves-under .moves {
  flex: 1 1 auto;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: center;
  gap: 0.25rem 0.65rem;
  min-height: 0;
  max-height: 5.25rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 0.9rem;
  padding-right: 0.15rem;
}

.panel-moves-under .moves li {
  gap: 0.25rem 0.35rem;
  flex: 0 0 auto;
}

.moves {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-family: var(--mono);
  font-size: 0.86rem;
  flex: 1;
}

.moves li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.45rem;
}

.moves .n {
  color: var(--text-muted);
  min-width: 1.6rem;
  text-align: right;
}

.moves .san {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  min-width: 2.4ch;
}

.moves .san.latest {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.moves-empty {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ---- Coach chat ---- */
.panel-coach {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  padding-bottom: 0.55rem;
  /* не даём чату раздувать layout */
  max-height: 100%;
}

.coach-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.coach-header h2 {
  margin: 0;
}

.coach-autospeak {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.coach-autospeak input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  margin: 0;
}

.coach-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.55rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-0);
  scroll-behavior: smooth;
}

.coach-msg {
  display: flex;
  width: 100%;
}

.coach-msg-coach {
  justify-content: flex-start;
}

.coach-msg-user {
  justify-content: flex-end;
}

.coach-bubble {
  position: relative;
  max-width: min(92%, 280px);
  padding: 0.55rem 0.7rem 0.45rem;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.coach-msg-coach .coach-bubble {
  background: var(--accent-soft);
  border: 1px solid rgba(61, 154, 106, 0.35);
  color: var(--text);
  border-bottom-left-radius: 4px;
  padding-right: 1.85rem;
}

.coach-msg-user .coach-bubble {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.coach-bubble-text {
  white-space: pre-wrap;
}

.coach-bubble-meta {
  margin-top: 0.35rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
}

.coach-speak-icon {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0.75;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.coach-speak-icon:hover {
  opacity: 1;
  background: rgba(61, 154, 106, 0.25);
}

.coach-tts-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-sm {
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 10px;
}

.coach-compose {
  display: flex;
  gap: 0.45rem;
  align-items: stretch;
  position: sticky;
  bottom: 0;
  padding-top: 0.15rem;
  background: linear-gradient(180deg, transparent, var(--bg-1) 30%);
}

.coach-input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-0);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
}

.coach-input:focus {
  border-color: rgba(61, 154, 106, 0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.coach-input::placeholder {
  color: var(--text-muted);
}

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding-top: 0.1rem;
}

.footer-sep {
  opacity: 0.5;
}

/* ---- Responsive (mobile ~800px) ---- */
@media (max-width: 800px) {
  .app {
    width: 100%;
    max-width: 100%;
    padding:
      calc(0.4rem + var(--safe-top))
      max(0.5rem, var(--safe-right))
      calc(0.55rem + var(--safe-bottom))
      max(0.5rem, var(--safe-left));
    gap: 0.45rem;
  }

  .header {
    gap: 0.4rem;
  }

  .brand h1 {
    font-size: 0.98rem;
  }

  .tagline {
    display: none;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 1.55rem;
    border-radius: 10px;
  }

  .status-pill {
    font-size: 0.78rem;
    padding: 0.32rem 0.6rem;
  }

  .app {
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow: visible;
  }

  .main {
    grid-template-columns: 1fr;
    overflow: visible;
    gap: 0.5rem;
  }

  .side {
    max-height: none;
    overflow: visible;
  }

  .board-shell {
    padding: 0.4rem;
  }

  .board-stage,
  .board {
    max-width: min(100%, calc(100vw - 1.2rem - var(--safe-left) - var(--safe-right)));
  }

  .board-wrap {
    grid-template-columns: 1rem 1fr;
    gap: 0.2rem;
  }

  .coords-files {
    grid-template-columns: 1rem 1fr;
    margin-top: 0.2rem;
  }

  .toolbar {
    gap: 0.3rem;
  }

  .btn {
    flex: 1 1 calc(50% - 0.3rem);
    justify-content: center;
    font-size: 0.74rem;
    padding: 0.42rem 0.45rem;
  }

  .btn-primary {
    flex: 1 1 100%;
  }

  .btn-icon {
    display: none;
  }

  .hint {
    font-size: 0.75rem;
    margin-top: 0.15rem;
  }

  .panel {
    padding: 0.55rem 0.6rem;
  }

  .panel-moves-under {
    max-height: 6.5rem;
  }

  .side {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .panel-coach {
    min-height: 0;
    max-height: min(55vh, 420px);
    height: auto;
  }

  .coach-messages {
    min-height: 12rem;
    max-height: min(42vh, 320px);
  }

  .meta {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
  }

  .footer {
    font-size: 0.68rem;
  }
}

@media (max-width: 480px) {
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .btn-logout {
    margin-left: auto;
  }
}

@media (hover: hover) and (pointer: fine) {
  .square.light:hover { background: var(--light-sq-hover); }
  .square.dark:hover { background: var(--dark-sq-hover); }
  .square.last-move.light:hover,
  .square.last-move.dark:hover {
    filter: brightness(1.04);
  }
}

.hint {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.square {
  cursor: pointer;
}

/* ---- End-of-game overlay (mate / draw) ---- */
.board-stage {
  position: relative;
  width: 100%;
  max-width: none;
  margin: 0;
}

.board-stage .board {
  max-width: none;
  width: 100%;
  margin: 0;
}

.end-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  pointer-events: none;
  background:
    radial-gradient(circle at center, rgba(8, 10, 14, 0.15) 0%, rgba(8, 10, 14, 0.55) 100%);
  border-radius: 10px;
  animation: end-fade-in 0.35s ease-out;
}

.end-overlay[hidden] {
  display: none !important;
}

.end-card {
  pointer-events: none;
  text-align: center;
  padding: 1.25rem 1.75rem 1.35rem;
  min-width: min(78%, 280px);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(28, 35, 44, 0.96), rgba(14, 17, 20, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 0 0 1px rgba(224, 108, 117, 0.35),
    0 20px 50px rgba(0, 0, 0, 0.55),
    0 0 40px rgba(224, 108, 117, 0.25);
  backdrop-filter: blur(8px);
}

.end-overlay.is-mate .end-card {
  border-color: rgba(255, 107, 118, 0.55);
  box-shadow:
    0 0 0 2px rgba(255, 107, 118, 0.45),
    0 24px 60px rgba(0, 0, 0, 0.6),
    0 0 60px rgba(255, 80, 90, 0.35);
}

.end-badge {
  display: inline-block;
  font-size: clamp(2rem, 8vw, 3.1rem);
  font-weight: 800;
  letter-spacing: 0.18em;
  line-height: 1;
  margin-bottom: 0.55rem;
  color: #fff;
  text-shadow:
    0 0 18px rgba(255, 90, 100, 0.85),
    0 2px 0 rgba(0, 0, 0, 0.35);
  animation: mate-badge-pop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.end-overlay.is-mate .end-badge {
  background: linear-gradient(180deg, #ff8a93, #e06c75 55%, #c94a56);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 90, 100, 0.75));
}

.end-title {
  margin: 0;
  font-size: clamp(1.55rem, 3.8vw, 1.45rem);
  font-weight: 700;
  color: #fff;
}

.end-sub {
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

@keyframes end-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes mate-badge-pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}


/* ---- Auth boot: no flash of login form ---- */
body.auth-pending .login-gate,
body.auth-pending .app {
  visibility: hidden !important;
  pointer-events: none !important;
}

body.auth-pending::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: var(--bg-0);
}

/* ---- Login gate ---- */
.login-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding:
    calc(1rem + var(--safe-top))
    max(1rem, var(--safe-right))
    calc(1rem + var(--safe-bottom))
    max(1rem, var(--safe-left));
  background:
    radial-gradient(900px 500px at 20% -10%, rgba(61, 154, 106, 0.16), transparent 55%),
    radial-gradient(700px 400px at 100% 10%, rgba(181, 136, 99, 0.12), transparent 50%),
    rgba(8, 10, 12, 0.92);
  backdrop-filter: blur(10px);
}

.login-gate[hidden] {
  display: none !important;
}

.login-card {
  width: min(100%, 380px);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.35rem 1.25rem 1.25rem;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.login-sub {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.login-field input {
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-0);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
}

.login-field input:focus {
  border-color: rgba(61, 154, 106, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-error {
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: rgba(224, 108, 117, 0.15);
  border: 1px solid rgba(224, 108, 117, 0.35);
  color: #f0a0a6;
  font-size: 0.85rem;
  font-weight: 500;
}

.login-error[hidden] {
  display: none !important;
}

.login-submit {
  width: 100%;
  justify-content: center;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  margin-top: 0.15rem;
}

.btn-danger-soft {
  color: #f0a0a6;
  border: 1px solid rgba(224, 108, 117, 0.35);
  background: rgba(224, 108, 117, 0.1);
}
.btn-danger-soft:hover {
  background: rgba(224, 108, 117, 0.2);
}
.coach-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
