/* ChessPuzzle — shared styles v3 */
* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  margin: 0;
  min-height: 100vh;
  padding: 16px;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: #cbd5e1; }
a { color: #60a5fa; }
.container { max-width: 680px; margin: 0 auto; }
.card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.card.subtle { background: #15203a; border-color: #1e3a5f; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  background: #3b82f6; color: white;
  border: none; border-radius: 8px;
  padding: 10px 18px; font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  min-height: 44px;
}
.btn:hover { background: #2563eb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: #475569; }
.btn-secondary:hover { background: #334155; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 13px; min-height: 32px; }

/* Info dot: small "i" in the top-right corner of admin cards.
   Click opens a modal with a short usage guide for that section. */
.card { position: relative; }
.info-dot {
  position: absolute; top: 10px; right: 10px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(96,165,250,0.15);
  color: #93c5fd;
  border: 1px solid rgba(96,165,250,0.4);
  font-family: 'Georgia', serif;
  font-style: italic;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  user-select: none;
  z-index: 5;
  transition: background 0.15s, transform 0.1s;
}
.info-dot:hover { background: rgba(96,165,250,0.3); transform: scale(1.08); }
.info-dot:focus { outline: 2px solid #60a5fa; outline-offset: 1px; }
.info-modal-content {
  font-size: 14px;
  line-height: 1.55;
  color: #e2e8f0;
}
.info-modal-content h3 {
  margin-top: 0;
  font-size: 16px;
  color: #93c5fd;
}

/* Collapsible cards (v4.7.10): the header has a chevron that rotates to
   show open/closed state. Body has display:none/block toggled via JS. */
.collapsible-card .collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding-right: 30px;   /* space for info-dot */
}
.collapsible-card .collapsible-header:hover { color: #93c5fd; }
.collapsible-arrow {
  display: inline-block;
  font-size: 12px;
  color: #94a3b8;
  transition: transform 0.2s;
  width: 12px;
  text-align: center;
}
.collapsible-arrow.open { transform: rotate(90deg); }

/* Mini-board preview for browsing other-admin puzzles */
.mini-board-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mini-board-card .mini-board {
  width: 120px; height: 120px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
}
.mini-board-card .mini-board svg { width: 100%; height: 100%; display: block; }
.mini-board-card .mini-info {
  flex: 1; min-width: 0;
}
.mini-board-card .mini-info .t { font-weight: 500; }
.mini-board-card .mini-info .s {
  font-size: 12px; color: #94a3b8; margin-top: 4px;
}
.mini-board-card .mini-actions { display: flex; flex-direction: column; gap: 6px; }

/* Admin search autocomplete results */
#adminSearchResults .admin-item {
  padding: 8px 12px;
  border-bottom: 1px solid #334155;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
#adminSearchResults .admin-item:hover { background: #1e293b; }
#adminSearchResults .admin-item:last-child { border-bottom: none; }
#adminSearchResults .admin-item .type-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #334155;
  color: #cbd5e1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Password show/hide toggle.
 * The wrapper goes inline-block so its 100% width matches what the bare
 * <input> had (most layouts expect inputs to be block-level in .field).
 * The toggle button sits absolute-positioned over the input's right edge.
 */
.pw-wrap {
  position: relative;
  display: block;
  width: 100%;
}
.pw-wrap input[type="password"],
.pw-wrap input[type="text"] {
  width: 100%;
  padding-right: 42px;        /* leave room for the eye button */
  box-sizing: border-box;
}
.pw-toggle-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 6px;
  line-height: 1;
  user-select: none;
  opacity: 0.75;
}
.pw-toggle-btn:hover { opacity: 1; }
.pw-toggle-btn:focus { outline: 2px solid #3b82f6; outline-offset: 1px; }

/* Piece palette in admin editor: clickable piece "tools" */
.paint-btn {
  background: #334155;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  color: #f1f5f9;
}
.paint-btn:hover { background: #475569; }
.paint-btn.active {
  border-color: #fbbf24;
  background: #1e293b;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.35);
}
.paint-btn .piece-w { color: #ffffff; text-shadow: 0 0 1px #000, 0 0 1px #000, 0 0 1px #000; }
.paint-btn .piece-b { color: #000000; text-shadow: 0 0 1px #fff, 0 0 1px #fff, 0 0 1px #fff; }
.btn-link { background: none; color: #60a5fa; padding: 4px 6px; font-size: 13px; min-height: auto; }
.btn-link:hover { background: rgba(96,165,250,0.1); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

input, textarea, select {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 60px; }
label { display: block; margin-bottom: 4px; font-size: 13px; color: #94a3b8; font-weight: 500; }
.field { margin-bottom: 12px; }
.field-row { display: flex; gap: 10px; align-items: stretch; }
.field-row input { flex: 1; }
.field-row .btn { flex-shrink: 0; }

/* Chessboard */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  /* Each square sets aspect-ratio: 1/1 individually (see .sq below).
     We do NOT constrain grid-template-rows to repeat(8, 1fr) because that
     interacts badly with aspect-ratio at fractional pixel heights and can
     cause the last row to be clipped. */
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border: 2px solid #475569;
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* v4.7.17 — Puzzle page board sizing per user spec:
     PC (desktop, ≥880px viewport):  ~40% of viewport width
     Mobile (<880px viewport):       ~90% of viewport width
   #boardCard is the wrapping card on /s/<shareId>. The flex container inside
   makes the board flex:1, so we control size by capping the card itself. */
#boardCard #board.board {
  max-width: min(40vw, 480px);
}
@media (max-width: 880px) {
  #boardCard #board.board {
    max-width: 90vw;
  }
}
.board.small { max-width: 320px; }
.sq {
  position: relative;
  aspect-ratio: 1 / 1;          /* keep cells square — no clipping of last row */
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: clamp(24px, 7vw, 44px);
  line-height: 1;
}
.sq.light { background: #f0d9b5; }    /* v4.7.22: uniforme con landing */
.sq.dark  { background: #b58863; }    /* v4.7.22: uniforme con landing */
.sq.sel { box-shadow: inset 0 0 0 4px #fbbf24; }
.sq.hint { box-shadow: inset 0 0 0 4px #60a5fa; }
.sq.lastmove { background-color: #f7e26b !important; }
.sq.lastmove.dark { background-color: #c5b358 !important; }
.sq .dot {
  position: absolute;
  width: 28%; height: 28%;
  background: rgba(0,0,0,0.3);
  border-radius: 50%;
  pointer-events: none;
}
.sq .target {
  position: absolute; inset: 0;
  border: 3px solid rgba(0,0,0,0.35);
  border-radius: 4px;
  pointer-events: none;
}
.sq .coord {
  position: absolute; left: 2px; top: 2px;
  font-size: 10px; font-weight: 600; color: rgba(0,0,0,0.4);
  pointer-events: none;
}
.sq.dark .coord { color: rgba(255,255,255,0.5); }

/* v4.7.25: SVG Cburnett pieces — riempiono il quadrato della casa.
   pointer-events: none così il click event passa al .sq (per il move). */
.piece-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.piece-w {
  color: #ffffff;
  text-shadow:
    -1.5px -1.5px 0 #000, 1.5px -1.5px 0 #000,
    -1.5px  1.5px 0 #000, 1.5px  1.5px 0 #000,
     0    -1.5px 0 #000,  0     1.5px 0 #000,
    -1.5px  0    0 #000,  1.5px  0    0 #000;
}
.piece-b {
  color: #000000;
  text-shadow:
    -1.5px -1.5px 0 #fff, 1.5px -1.5px 0 #fff,
    -1.5px  1.5px 0 #fff, 1.5px  1.5px 0 #fff,
     0    -1.5px 0 #fff,  0     1.5px 0 #fff,
    -1.5px  0    0 #fff,  1.5px  0    0 #fff;
}

/* Badges / status */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge-ok { background: #14532d; color: #86efac; }
.badge-ko { background: #7f1d1d; color: #fca5a5; }
.badge-mute { background: #1e293b; color: #94a3b8; }
.badge-info { background: #1e3a5f; color: #93c5fd; }

.alert { padding: 12px 14px; border-radius: 8px; margin: 12px 0; font-size: 14px; }
.alert-ok { background: #14532d; color: #86efac; border: 1px solid #166534; }
.alert-ko { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }
.alert-info { background: #1e3a8a; color: #bfdbfe; border: 1px solid #1e40af; }
.alert-warn { background: #78350f; color: #fcd34d; border: 1px solid #92400e; }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 18px;
  background: #0f172a; border: 1px solid #334155;
  padding: 6px 10px; border-radius: 8px;
}
.timer.warn { color: #fca5a5; border-color: #991b1b; }

table.lb { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lb th, table.lb td { padding: 6px 8px; text-align: left; border-bottom: 1px solid #334155; }
table.lb th { color: #94a3b8; font-weight: 500; font-size: 12px; text-transform: uppercase; }
table.lb tr.me { background: #1e3a5f; }
table.lb td.plus { color: #86efac; }
table.lb td.minus { color: #fca5a5; }
.board.medium { max-width: 380px; }
.mono { font-family: ui-monospace, "SF Mono", Monaco, monospace; font-size: 13px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

hr { border: none; border-top: 1px solid #334155; margin: 18px 0; }
small.muted, .muted { color: #94a3b8; }
.tag { display: inline-block; background: #1e3a5f; color: #93c5fd; padding: 2px 8px; border-radius: 10px; font-size: 11px; margin: 2px 4px 2px 0; }

.puzzle-list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: #0f172a; border: 1px solid #334155; border-radius: 8px;
  margin-bottom: 8px; gap: 8px;
}
.puzzle-list-item .info { flex: 1; min-width: 0; }
.puzzle-list-item .info .t { font-weight: 600; font-size: 14px; }
.puzzle-list-item .info .s { font-size: 11px; color: #94a3b8; word-break: break-all; }
.puzzle-list-item .actions { display: flex; gap: 6px; flex-shrink: 0; }

/* v4.7.28: su cellulare le actions hanno troppi bottoni e schiacciano la
   colonna del nome → testo verticale di 1 carattere per riga. Soluzione:
   stack verticale sotto 700px, actions a fondo cella, info full-width. */
@media (max-width: 700px) {
  .puzzle-list-item {
    flex-direction: column;
    align-items: stretch;
  }
  .puzzle-list-item .info { width: 100%; }
  .puzzle-list-item .info .t { font-size: 15px; word-break: break-word; }
  .puzzle-list-item .actions {
    margin-top: 6px;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .puzzle-list-item .actions .btn { font-size: 13px; }
}

/* Comments */
.comments { margin-top: 8px; }
.comment {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.comment-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
  margin-bottom: 4px;
}
.comment-author { font-weight: 600; color: #93c5fd; }
.comment-time { color: #64748b; font-size: 11px; }
.comment-body { font-size: 14px; line-height: 1.4; word-break: break-word; white-space: pre-wrap; }
.comment-actions { margin-top: 4px; display: flex; gap: 4px; align-items: center; }
.comment-replies { margin-top: 8px; margin-left: 16px; padding-left: 12px; border-left: 2px solid #334155; }
.reply-form { margin-top: 8px; }
.comment-form { display: flex; flex-direction: column; gap: 8px; }
.comment-form textarea { min-height: 60px; }
.comment.own { border-color: #1e40af; background: #15203a; }

/* Stockfish lines */
.sf-info { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; padding: 6px 0; font-size: 13px; color: #94a3b8; }
.sf-info .depth { background: #1e3a5f; color: #93c5fd; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.sf-line {
  background: #0f172a; border: 1px solid #334155; border-radius: 8px;
  padding: 6px 10px; margin-bottom: 5px;
  display: flex; gap: 8px; align-items: baseline;
  /* v4.7.29: una linea per riga, niente wrap su mobile */
  flex-wrap: nowrap;
  overflow: hidden;
}
.sf-line.best { border-color: #14532d; background: #0c1d12; }
.sf-line .rank {
  flex-shrink: 0;
  background: #334155; color: #cbd5e1;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; font-weight: 700; font-size: 11px;
}
.sf-line.best .rank { background: #14532d; color: #86efac; }
.sf-line .ev { font-weight: 700; min-width: 48px; font-variant-numeric: tabular-nums; font-size: 13px; flex-shrink: 0; }
.sf-line .ev.plus { color: #86efac; }
.sf-line .ev.minus { color: #fca5a5; }
.sf-line .pv {
  flex: 1; min-width: 0;
  /* v4.7.29: troncamento ellipsis su mobile, una linea per riga */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}
.sf-line .pv .move { display: inline-block; padding: 0 3px; }
.sf-line .pv .num { color: #64748b; }

/* v4.7.29: header analisi con versione + bottone pausa */
.sf-engine-header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 8px 0 6px;
  font-size: 12px; color: #94a3b8;
}
.sf-engine-header .version { font-family: monospace; }
.sf-engine-header .sf-toggle-btn {
  background: rgba(212,165,116,0.15);
  color: #d4a574;
  border: 1px solid rgba(212,165,116,0.4);
  padding: 4px 12px; border-radius: 6px;
  font-family: inherit; font-size: 12px;
  cursor: pointer;
}
.sf-engine-header .sf-toggle-btn:hover { background: rgba(212,165,116,0.25); }
.sf-engine-header .sf-toggle-btn.paused { background: rgba(34,197,94,0.15); color: #4ade80; border-color: rgba(34,197,94,0.4); }

/* Solution / Stockfish panels (admin) */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; align-items: baseline; font-size: 14px; }
.kv dt { color: #94a3b8; font-size: 12px; text-transform: uppercase; }
.kv dd { margin: 0; font-weight: 600; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  overflow-y: auto;       /* allow background scroll if modal is taller than viewport */
}
.modal-bg.open { display: flex; }
.modal {
  background: #1e293b; border: 1px solid #334155;
  border-radius: 12px; padding: 20px;
  max-width: 360px; width: 100%;
  max-height: calc(100vh - 40px);   /* never exceed viewport */
  overflow-y: auto;                  /* scroll contents inside modal */
  -webkit-overflow-scrolling: touch; /* smooth scroll on iOS */
}

/* Top nav */
.topnav {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 13px;
}
.topnav a {
  padding: 6px 12px;
  background: #1e293b; border: 1px solid #334155;
  border-radius: 6px;
  color: #cbd5e1; text-decoration: none;
}
.topnav a:hover { background: #334155; }
.topnav a.current { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }

/* Move list */
.movelist {
  font-family: ui-monospace, monospace; font-size: 13px;
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  margin-top: 8px;
}
.movelist .num { color: #64748b; }
.movelist .move-correct { color: #86efac; }
.movelist .move-wrong { color: #fca5a5; }
.movelist .move-current { background: #1e3a5f; color: #93c5fd; padding: 0 4px; border-radius: 4px; }

.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs .tab {
  padding: 8px 14px; border-radius: 6px;
  background: #1e293b; border: 1px solid #334155;
  cursor: pointer; font-size: 13px; font-weight: 600;
  color: #cbd5e1;
}
.tabs .tab.active { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }

/* Player chips & avatars */
.cp-player-chip {
  display: inline-flex; align-items: center; gap: 6px;
  vertical-align: middle;
  border-radius: 6px;
  padding: 1px 4px;
}
.cp-player-chip:hover { background: rgba(96,165,250,0.1); }
.cp-player-chip:focus { outline: 2px solid #60a5fa; outline-offset: 1px; }
.cp-player-chip .cp-player-name { font-weight: 600; }

table.lb td .cp-player-chip { padding: 0; }
table.lb td .cp-player-chip:hover { background: transparent; text-decoration: underline; }

/* Online pill: small green badge appended next to a player's name when they
   are online. Clickable: opens the message-compose modal. */
.cp-online-pill {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 500;
  color: #86efac; background: rgba(34,197,94,0.12);
  padding: 1px 8px; border-radius: 999px;
  margin-left: 6px;
  border: 1px solid rgba(34,197,94,0.3);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, transform 0.1s;
}
.cp-online-pill:hover {
  background: rgba(34,197,94,0.25);
  transform: scale(1.04);
}
table.lb td .cp-online-pill:hover { background: rgba(34,197,94,0.25); text-decoration: none; }

.cp-avatar { flex-shrink: 0; }

/* Country picker (datalist input) */
.country-picker { display: flex; gap: 8px; align-items: center; }
.country-picker .flag { font-size: 22px; min-width: 28px; text-align: center; }

/* Profile complete prompt button */
.profile-complete-btn {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
}

/* Avatar preview in profile dialog */
.avatar-preview {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: #0f172a; border: 2px dashed #334155;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

/* Admin players list */
.admin-player-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: #0f172a; border: 1px solid #334155; border-radius: 8px;
  margin-bottom: 8px;
}
.admin-player-row.banned { opacity: 0.55; border-color: #7f1d1d; }
.admin-player-row .info { flex: 1; min-width: 0; }
.admin-player-row .info .top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.admin-player-row .actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Curriculum gallery — edit mode (in profile modal) */
.cp-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 6px;
}
.cp-gallery-item {
  background: #0f172a; border: 1px solid #334155; border-radius: 8px;
  padding: 6px;
  display: flex; flex-direction: column; gap: 4px;
}
.cp-gallery-item img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 4px; background: #000; }
.cp-gallery-item .cp-gallery-caption { font-size: 12px; padding: 4px 6px; }
.cp-gallery-item .cp-gallery-actions { display: flex; gap: 4px; }
.cp-gallery-item .cp-gallery-actions .btn { flex: 1; min-height: 28px; padding: 4px 6px; font-size: 12px; }

/* Curriculum gallery — view mode (in profile popup) */
.cp-gallery-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin-top: 6px;
}
.cp-gallery-thumb {
  margin: 0;
  background: #0f172a; border: 1px solid #334155; border-radius: 8px;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.cp-gallery-thumb img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: #000; transition: transform 0.15s; }
.cp-gallery-thumb:hover img { transform: scale(1.04); }
.cp-gallery-thumb figcaption {
  font-size: 11px; color: #cbd5e1;
  padding: 4px 6px; line-height: 1.3;
  border-top: 1px solid #334155;
  background: #0a1525;
}
