/* ── API Key Masking (avoids Chrome password save prompt) ── */
.api-key-mask {
  -webkit-text-security: disc;
}

/* ── Coach Page Layout ───────────────────────────── */
.coach-main {
  padding: 5rem 2rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Setup Panel ────────────────────────────────── */
.coach-setup {
  max-width: 600px;
  margin: 0 auto 2rem;
}

.coach-options {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.coach-start-actions {
  margin-top: 0.2rem;
}

.coach-start-actions .llm-config:not(.collapsed) .llm-config-body {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.coach-color-pick {
  display: flex;
  gap: 0.5rem;
}

.color-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  font-family: var(--font);
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.color-btn.active {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-faint);
}

.color-btn:hover:not(.active) {
  border-color: var(--border-hover);
  color: var(--text);
}

/* ── Game Layout ────────────────────────────────── */
.coach-layout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
  align-items: start;
}

.coach-board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.coach-board-wrap {
  display: flex;
  gap: 0;
}

.coach-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(480px, calc(100vw - 4rem));
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 30px var(--red-faint);
}

.coach-board .sq {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.coach-board .sq.light { background: var(--sq-light); }
.coach-board .sq.dark { background: var(--sq-dark); }
.coach-board .sq.highlight {
  background: var(--sq-highlight) !important;
  box-shadow: inset 0 0 8px var(--sq-highlight);
}
.coach-board .sq.selected {
  background: rgba(255, 200, 0, 0.25) !important;
  box-shadow: inset 0 0 10px rgba(255, 200, 0, 0.2);
}
.coach-board .sq.legal-target::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
}
.coach-board .sq.legal-capture::after {
  content: '';
  position: absolute;
  width: 85%;
  height: 85%;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  background: transparent;
}

.coach-board .sq .piece-img {
  width: 85%;
  height: 85%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

.coach-board .sq .piece-img.black-piece {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.4));
}

/* Eval bar */
.coach-eval-bar {
  width: 20px;
  align-self: stretch;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 3px 0 0 3px;
  overflow: hidden;
  position: relative;
}

.coach-eval-bar .eval-bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: #d4d0c8;
  transition: height 0.4s ease;
}

/* Status and controls */
.coach-status {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.coach-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  touch-action: manipulation;
}

.coach-controls .btn {
  font-size: 0.7rem;
  padding: 0.4rem 0.8rem;
}

/* ── Coach Panel ────────────────────────────────── */
.coach-panel-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.coach-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
  max-height: 50vh;
}

.coach-card-header {
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.coach-thinking {
  color: var(--red);
  font-weight: 400;
  font-style: italic;
  margin-left: 0;
  font-size: 0.7rem;
  letter-spacing: 0;
  text-transform: none;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.coach-messages {
  padding: 0.8rem 1rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.coach-msg {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-dim);
  padding: 0.5rem 0.7rem;
  border-left: 2px solid var(--border);
  border-radius: 0 4px 4px 0;
}

.coach-msg.coach-msg-coach {
  border-left-color: var(--red);
}

.coach-msg-loading {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  font-style: italic;
}

.coach-msg .coach-msg-move {
  font-weight: 600;
  color: var(--red);
  margin-right: 0.3rem;
}

.coach-msg .coach-msg-eval {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 0.3rem;
}

.coach-msg.coach-msg-system {
  font-size: 0.75rem;
  color: var(--text-muted);
  border-left-color: var(--border);
  font-style: italic;
}

.coach-msg.coach-msg-user {
  font-size: 0.8rem;
  color: var(--text);
  border-left-color: var(--red);
  background: rgba(255, 10, 43, 0.05);
  font-style: italic;
}

/* Coach Q&A input */
.coach-qa-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
}

.coach-qa-input {
  flex: 1;
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
}

.coach-qa-send {
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Move list */
.coach-moves-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  max-height: 30vh;
}

.coach-move-list {
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  color: var(--text);
  overflow-y: auto;
  max-height: 25vh;
  line-height: 1.8;
}

.coach-move-list:empty::before {
  content: 'Moves will appear here as you play.';
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 0.5rem 0;
}

.coach-move-list .move-num {
  color: var(--text-muted);
  margin-right: 0.2rem;
}

.coach-move-list .move {
  cursor: default;
  padding: 0.1rem 0.2rem;
  border-radius: 2px;
}

.coach-move-list .move.move-bad { color: var(--red); }
.coach-move-list .move.move-bad .nag { color: var(--red); }
.coach-move-list .move.move-blunder { color: var(--red); text-shadow: 0 0 8px var(--red-glow); }
.coach-move-list .move.move-blunder .nag { color: var(--red); text-shadow: 0 0 8px var(--red-glow); }
.coach-move-list .move.move-good { color: #4caf50; }
.coach-move-list .move.move-good .nag { color: #4caf50; }
.coach-move-list .move .nag {
  font-size: 0.7rem;
  vertical-align: super;
}

/* Latest coach comment strip (mobile only — below board controls) */
.coach-latest-comment {
  display: none;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 1100px) {
  .coach-layout {
    grid-template-columns: 1fr;
  }

  .coach-board {
    width: min(360px, calc(100vw - 4rem));
  }

  .coach-card {
    max-height: none;
  }

  .coach-card .coach-messages {
    display: none;
  }

  .coach-qa-input {
    pointer-events: none;
  }

  .coach-qa-row {
    cursor: pointer;
  }


  .coach-latest-comment {
    display: block;
    margin-top: 0.6rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 2px solid var(--red);
    border-radius: 0 4px 4px 0;
    font-size: 0.8rem;
    color: var(--text-dim);
    line-height: 1.5;
    max-height: 10rem;
    overflow-y: auto;
    width: 100%;
  }

  .coach-latest-comment .comment-strip-move {
    font-weight: 600;
    color: var(--red);
    margin-right: 0.4rem;
  }
}

@media (max-width: 600px) {
  .coach-main {
    padding: 4rem 0.75rem 1rem;
  }

  .coach-board {
    width: min(calc(100vw - 3rem), 360px);
  }

  .coach-controls {
    flex-wrap: wrap;
  }

  .coach-controls .btn {
    min-height: 44px;
  }
}

.coach-setup .input-error {
  margin-top: 0.8rem;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--red);
  background: var(--red-faint);
  border: 1px solid rgba(255, 10, 43, 0.3);
  border-radius: 4px;
}
