/* ── PUZZLE TAB ── */
#tab-puzzles {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 36px;
  padding: 24px;
}

#board-wrap {
  position: relative;
  flex-shrink: 0;
}

#turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.turn-dot {
  width: 10px; height: 10px;
  border-radius: 50%; flex-shrink: 0;
}
.turn-dot.white { background: #f0ead6; box-shadow: 0 0 6px rgba(240,234,214,.5); }
.turn-dot.black { background: #2a2a2a; border: 1px solid #666; }
.turn-dot.player-turn { box-shadow: 0 0 10px var(--accent); }

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(78vmin, 620px);
  height: min(78vmin, 620px);
  border: 2px solid var(--border);
  box-shadow: 0 0 60px rgba(0,0,0,.7);
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}
.sq.light { background: var(--light-sq); }
.sq.dark  { background: var(--dark-sq); }
.sq.selected   { outline: 3px inset rgba(168,208,128,.7); background: rgba(168,208,128,.4) !important; }
.sq.last-move  { background: rgba(168,208,128,.2) !important; }
.sq.hint-sq    { background: rgba(232,200,74,.5) !important; }
.sq.wrong-sq   { background: rgba(224,80,80,.45) !important; }

.sq.valid-move::after {
  content: ''; position: absolute;
  width: 30%; height: 30%;
  background: rgba(0,0,0,.22);
  border-radius: 50%; pointer-events: none; z-index: 3;
}
.sq.valid-capture::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 50%;
  border: 5px solid rgba(0,0,0,.22);
  pointer-events: none; z-index: 3;
}

.coord-file {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 9px; font-weight: 500; opacity: .5;
  pointer-events: none;
}
.coord-rank {
  position: absolute; top: 2px; left: 4px;
  font-size: 9px; font-weight: 500; opacity: .5;
  pointer-events: none;
}

.piece {
  width: 88%; height: 88%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: grab;
  z-index: 2;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,.5));
  pointer-events: none;
}
.piece.dragging { opacity: 0 !important; }

#drag-ghost {
  position: fixed;
  width: 78px; height: 78px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%,-50%);
  filter: drop-shadow(0 4px 14px rgba(0,0,0,.75));
  display: none;
}

#board-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  justify-content: center;
}
.nav-btn {
  padding: 6px 18px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 15px;
  letter-spacing: .1em;
  cursor: pointer;
  transition: all .15s;
}
.nav-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.nav-btn:disabled { opacity: .25; cursor: default; }
.nav-pos { font-size: 10px; color: var(--muted); letter-spacing: .15em; min-width: 55px; text-align: center; }

/* Side panel */
#side-panel {
  width: 210px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ── #6 Mastery loop panel ── */
.train-focus { box-sizing: border-box; }
.tf-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(255,255,255,.02);
  overflow: hidden;
}
.tf-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; cursor: pointer;
  background: rgba(232,200,74,.06);
  user-select: none;
}
.tf-head-left { display: flex; align-items: baseline; min-width: 0; }
.tf-head-title { font-size: 10px; letter-spacing: .16em; color: var(--accent2); font-weight: 600; white-space: nowrap; }
.tf-head-chev  { font-size: 11px; color: var(--accent2); transition: transform .2s ease; flex: none; }
.train-focus.tf-collapsed .tf-head-chev { transform: rotate(-90deg); }
.train-focus.tf-collapsed .tf-body { display: none; }
.tf-body { padding: 11px 12px 13px; border-top: 1px solid var(--border); }

.tf-intro { font-size: 11px; color: var(--muted); margin-bottom: 11px; }
.tf-focus { margin-bottom: 12px; }
.tf-focus:last-child { margin-bottom: 0; }
.tf-focus-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.tf-focus-label { font-size: 12.5px; color: var(--text); }
.tf-focus-val   { font-size: 11px; color: var(--muted); flex: none; }
.tf-meter { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.tf-meter-fill { height: 100%; border-radius: 3px; background: var(--accent2); transition: width .5s ease; }
.tf-arrow { font-weight: bold; }
.tf-trend-up   .tf-arrow { color: var(--accent); }
.tf-trend-down .tf-arrow { color: var(--red); }

.progress-label { font-size: 10px; letter-spacing: .25em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.progress-bar { height: 2px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .4s ease; }
.progress-text { font-size: 10px; color: var(--muted); margin-top: 4px; }

.rating-badge { font-family: 'Bebas Neue', sans-serif; font-size: 38px; color: var(--accent2); letter-spacing: .05em; line-height: 1; }
.rating-sub   { font-size: 9px; color: var(--muted); letter-spacing: .2em; text-transform: uppercase; margin-top: 2px; }

.meta-row { display: flex; justify-content: space-between; align-items: flex-start; font-size: 10px; gap: 8px; }
.meta-key { color: var(--muted); letter-spacing: .15em; text-transform: uppercase; flex-shrink: 0; }
.meta-val { color: var(--text); text-align: right; line-height: 1.5; }

.score-wrap { display: flex; gap: 20px; }
.score-item { display: flex; flex-direction: column; gap: 2px; }
.score-num { font-family: 'Bebas Neue', sans-serif; font-size: 38px; line-height: 1; }
.score-num.green { color: var(--accent); }
.score-num.red   { color: var(--red); }
.score-lbl { font-size: 9px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }

#feedback { min-height: 44px; }
.feedback-msg {
  font-size: 11px; letter-spacing: .08em;
  padding: 8px 12px; border-left: 2px solid;
  animation: slideIn .18s ease; line-height: 1.5;
}
.feedback-msg.good  { border-color: var(--accent);  color: var(--accent);  background: rgba(168,208,128,.07); }
.feedback-msg.bad   { border-color: var(--red);     color: var(--red);     background: rgba(224,80,80,.07); }
.feedback-msg.hint  { border-color: var(--accent2); color: var(--accent2); background: rgba(232,200,74,.07); }
.feedback-msg.info  { border-color: var(--muted);   color: var(--muted); }

/* Puzzle complete overlay */
#complete-overlay {
  display: none;
  position: absolute; inset: 0;
  background: rgba(13,15,14,.88);
  align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  backdrop-filter: blur(5px);
  z-index: 10; animation: fadeIn .25s ease;
}
#complete-overlay.show { display: flex; }
.complete-icon { font-size: 52px; animation: pop .3s cubic-bezier(0.34,1.56,0.64,1); }
.complete-text { font-family: 'Bebas Neue', sans-serif; font-size: 30px; letter-spacing: .1em; }
.next-btn {
  margin-top: 6px; padding: 10px 36px;
  background: transparent; border: 1px solid var(--accent);
  color: var(--accent); font-family: 'Bebas Neue', sans-serif;
  font-size: 18px; letter-spacing: .15em; cursor: pointer; transition: all .2s;
}
.next-btn:hover { background: var(--accent); color: var(--bg); }

/* Session done */
.done-title { font-family: 'Bebas Neue', sans-serif; font-size: 72px; color: var(--accent); letter-spacing: .1em; }
.done-stats { display: flex; gap: 48px; }
.done-stat { text-align: center; }
.done-stat-num { font-family: 'Bebas Neue', sans-serif; font-size: 56px; line-height: 1; }
.done-stat-lbl { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.done-btn {
  padding: 12px 44px; background: transparent;
  border: 1px solid var(--accent); color: var(--accent);
  font-family: 'Bebas Neue', sans-serif; font-size: 20px;
  letter-spacing: .15em; cursor: pointer; transition: all .2s;
}
.done-btn:hover { background: var(--accent); color: var(--bg); }

/* Retry failed toggle */
.done-retry-toggle {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px; cursor: pointer; gap: 12px;
  transition: border-color .15s; width: 100%; max-width: 320px;
}
.done-retry-toggle:hover { border-color: var(--muted); }
.done-retry-main { font-size: 10px; letter-spacing: .08em; color: var(--muted); transition: color .15s; }
.done-retry-sub  { font-size: 10px; color: var(--muted); opacity: .45; margin-top: 3px; letter-spacing: .04em; }
.done-retry-pill {
  width: 30px; height: 17px; background: var(--border);
  border-radius: 9px; position: relative; flex-shrink: 0; transition: background .2s;
}
.done-retry-thumb {
  width: 11px; height: 11px; background: var(--muted);
  border-radius: 50%; position: absolute; top: 3px; left: 3px;
  transition: left .2s, background .2s;
}
#done-retry-section.retry-active .done-retry-toggle { border-color: var(--accent); }
#done-retry-section.retry-active .done-retry-main   { color: var(--accent); }
#done-retry-section.retry-active .done-retry-pill   { background: rgba(168,208,128,.15); }
#done-retry-section.retry-active .done-retry-thumb  { left: 16px; background: var(--accent); }

/* ── REPORT TAB ── */
#tab-report {
  flex-direction: column;
  padding: 36px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}

.report-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 32px; color: var(--accent); letter-spacing: .1em;
  margin-bottom: 24px;
}

#report-content {
  font-size: 13px;
  line-height: 1.9;
  color: var(--text);
  white-space: pre-wrap;
  border: 1px solid var(--border);
  padding: 24px;
  background: var(--surface);
}

/* ── Assessment mode: compact banner so header + nav fit on one screen ── */
#menu-puzzle.assessment-active #tab-puzzles {
  padding: 12px 24px;
}

/* ── Mobile/narrow: stack board + side panel vertically (UX-9) ── */
@media (max-width: 768px) {
  #tab-puzzles {
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 12px 16px 24px;
  }

  #board-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
  }

  #board {
    width: min(calc(100vw - 24px), 540px);
    height: min(calc(100vw - 24px), 540px);
  }

  /* Drag ghost scales down with board cells */
  #drag-ghost { width: 56px; height: 56px; }

  /* Side panel below board, full width */
  #side-panel {
    width: min(calc(100vw - 24px), 540px);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px 20px;
    align-items: flex-start;
  }
  .train-focus { flex: 0 0 100%; } /* mastery panel: full width above the stacked chips */
  .sp-progress { flex: 0 0 100%; } /* progress bar: full width */
  .sp-rating   { flex: 0 0 auto; } /* rating badge */
  .score-wrap { flex: 0 0 auto; align-items: center; }
  #puzzle-meta { flex: 0 0 100%; flex-direction: row; flex-wrap: wrap; gap: 4px 8px; }
  #feedback { flex: 0 0 100%; }
  .rating-badge { font-size: 28px; }

  /* Board nav */
  #board-nav { margin-top: 8px; }

  /* Session done: shrink huge type */
  .done-title { font-size: 42px; }
  .done-stats { gap: 20px; }
  .done-stat-num { font-size: 40px; }
  .done-btn { padding: 10px 28px; font-size: 17px; }

  /* Report tab */
  #tab-report { padding: 20px 16px; }
}

/* ── ANIMATIONS ── */
@keyframes fadeIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pop     { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse   { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes shake   { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
@keyframes pulseGreen { 0% { box-shadow: 0 0 0 0 rgba(168,208,128,.7); } 70% { box-shadow: 0 0 0 16px rgba(168,208,128,0); } 100% { box-shadow: 0 0 0 0 rgba(168,208,128,0); } }

.shake { animation: shake .35s ease; }

/* ── TRAIN help "?" + hover tooltip (puzzle subbar) ───────────────────────── */
.train-help {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid var(--accent); color: var(--accent);
  font-size: 11px; line-height: 1; cursor: help; margin-left: 10px;
  flex: none; user-select: none;
}
.train-help-pop {
  display: none; position: absolute; top: 145%; left: 0; z-index: 60;
  width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px 18px; text-align: left; cursor: default;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.th-row { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.th-row:last-child { margin-bottom: 0; }
.th-ico { flex: none; width: 22px; height: 22px; display: block; }
.th-emoji { font-size: 18px; line-height: 22px; text-align: center; }
.th-txt { font-size: 12px; color: var(--muted); line-height: 1.5; }
.th-txt b { display: block; color: var(--text); font-weight: 600;
  letter-spacing: .04em; font-size: 11.5px; margin-bottom: 3px; }
.train-help:hover .train-help-pop,
.train-help:focus .train-help-pop { display: block; }
.train-help-title {
  display: block; font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent2); margin-bottom: 8px;
}
.train-help-item {
  display: block; font-size: 12px; color: var(--text); line-height: 1.5;
  position: relative; padding-left: 14px; margin-bottom: 5px;
}
.train-help-item:last-child { margin-bottom: 0; }
.train-help-item::before { content: "›"; position: absolute; left: 2px; color: var(--accent); }
