* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  -webkit-tap-highlight-color: transparent;
}

header {
  background: #1a1a2e;
  color: #eee;
  padding: 14px 20px;
  border-bottom: 3px solid #4a90d9;
}
header h1 { font-size: 1.1rem; font-weight: 600; }

.player-tag {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  padding: 12px 16px; min-height: 44px;
  background: rgba(232, 124, 30, 0.18); color: #e87c1e;
  border: 1px solid rgba(232, 124, 30, 0.6); border-radius: 8px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.player-tag .separator { color: #888; margin: 0 4px; }
.player-tag .player-stats { color: #888; font-weight: 500; font-size: 0.85rem; }

dialog#profile-sheet {
  max-width: 440px; width: 90vw; max-height: 90vh;
  border: none; border-radius: 10px; padding: 18px 20px;
  background: #fff; color: #1a1a2e;
}
dialog#profile-sheet::backdrop { background: rgba(20, 20, 40, 0.55); }
dialog#profile-sheet h2 { font-size: 1.05rem; margin-bottom: 12px; }
dialog#profile-sheet label { display: block; font-size: 0.78rem; color: #666; margin-bottom: 4px; }
dialog#profile-sheet input[type="text"] {
  width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px;
  font-size: 0.95rem; margin-bottom: 14px;
  -webkit-appearance: none; appearance: none;
}
dialog#profile-sheet fieldset {
  display: grid; grid-template-columns: repeat(6, 44px);
  gap: 6px; margin-bottom: 14px; border: none; padding: 0;
}
dialog#profile-sheet fieldset legend {
  font-size: 0.78rem; color: #666; margin-bottom: 4px; padding: 0;
  grid-column: 1 / -1;
}
dialog#profile-sheet .tile {
  width: 44px; height: 44px; border: 2px solid transparent; border-radius: 6px;
  cursor: pointer; background: #f4f4f8; font-size: 1.4rem;
  display: flex; align-items: center; justify-content: center;
  -webkit-appearance: none; appearance: none;
}
dialog#profile-sheet .tile[aria-pressed="true"] { border-color: #1a1a2e; }
.profile-share {
  background: #f4f4f8; border-radius: 6px; padding: 10px 12px;
  margin-bottom: 14px; border: 1px solid #e0e0e8;
}
.profile-share .share-toggle {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  margin: 0; font-size: 0.85rem; color: #1a1a2e;
}
.profile-share input[type="checkbox"] {
  margin: 2px 0 0 0; width: 18px; height: 18px; flex-shrink: 0;
}
.profile-share .share-text strong { font-weight: 600; }
.profile-share .share-text small { color: #555; font-size: 0.8rem; line-height: 1.3; }

.profile-actions { display: flex; gap: 8px; justify-content: flex-end; }
.profile-actions button {
  padding: 10px 16px; border: 1px solid #bbb; border-radius: 6px;
  background: #fafafa; cursor: pointer; font-size: 0.9rem; font-weight: 500;
}
.profile-actions button.primary { background: #1a1a2e; color: #fff; border-color: #1a1a2e; }
.profile-actions button:disabled { opacity: 0.4; cursor: not-allowed; }

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
}

#scoreboard {
  display: flex;
  gap: 18px;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
  width: 100%;
  justify-content: center;
}
#scoreboard .label { font-size: 0.75rem; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
#scoreboard .value { font-size: 1.7rem; font-weight: 800; color: #1a1a2e; line-height: 1; }
#scoreboard .ref-tier { font-size: 0.78rem; color: #c0392b; font-weight: 600; }

#progress-wrap {
  width: 100%;
  height: 8px;
  background: #ddd;
  border-radius: 4px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #4a90d9 0%, #c0392b 100%);
  width: 0%;
  transition: width 0.25s ease-out;
}

#board-wrap {
  background: #fff;
  border: 1px solid #dde;
  border-radius: 10px;
  padding: 8px;
  overflow: auto;
  max-width: 100%;
}
#board-svg { display: block; touch-action: manipulation; user-select: none; }

#controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
#controls button {
  padding: 8px 14px;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fafafa;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  -webkit-appearance: none;
  appearance: none;
}
#controls button.primary {
  background: #1a1a2e;
  color: #fff;
  border-color: #1a1a2e;
}
#controls button:disabled { opacity: 0.4; cursor: not-allowed; }
#controls button:active:not(:disabled) { transform: translateY(1px); }

#status-line {
  font-size: 0.82rem;
  color: #555;
  min-height: 1.4em;
  text-align: center;
  line-height: 1.4;
  width: 100%;
}
#status-line.ok { color: #2e7d32; }
#status-line.err { color: #c62828; }

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 0.95; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-card {
  background: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h2 { font-size: 1rem; margin-bottom: 10px; }
.modal-card p { font-size: 0.85rem; color: #555; margin-bottom: 12px; line-height: 1.45; }
.modal-card label { display: block; font-size: 0.78rem; color: #666; margin-bottom: 4px; }
.modal-card input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 0.9rem;
  margin-bottom: 14px;
  -webkit-appearance: none;
  appearance: none;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button {
  padding: 8px 14px;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fafafa;
  cursor: pointer;
  font-size: 0.85rem;
}
.modal-actions button.primary {
  background: #1a1a2e;
  color: #fff;
  border-color: #1a1a2e;
}

/* Candidate-line picker (when a tap matches multiple legal moves). */
.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.candidate-list button {
  text-align: left;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
  font-size: 0.84rem;
  font-family: ui-monospace, monospace;
}
.candidate-list button:hover { background: #f4f4f8; }

/* Board SVG visuals */
.dot-orig { fill: #4a90d9; stroke: #2266aa; stroke-width: 1; }
.dot-new  { fill: var(--dot-new-color, #e87c1e); stroke: #a04000; stroke-width: 1; }
.dot-target { fill: rgba(192,57,43,0.75); stroke: #c0392b; stroke-width: 1.5; }
.tap-cell { fill: transparent; stroke: none; cursor: pointer; }
.tap-cell:hover { fill: rgba(74,144,217,0.10); }
.line-stroke { stroke: #c0392b; stroke-width: 2.5; opacity: 0.4; fill: none; }
.line-flash { stroke: #c0392b; stroke-width: 5; opacity: 0.95; fill: none; }
/* History lines: per-axis colour + visible-by-default opacity. The previous
   value (0.18) was too faint — players couldn't see the lines they had just
   drawn. The colour is set inline by `lineForMove` per-axis (see ui.js). */
.line-history { stroke-width: 2.4; opacity: 0.55; fill: none; stroke-linecap: round; }
.line-history-last { stroke-width: 3.4; opacity: 0.95; fill: none; stroke-linecap: round; }
.line-pending { stroke: #c0392b; stroke-width: 3; opacity: 0.7; fill: none; stroke-dasharray: 4,3; }

/* Graphical candidate-line picker (when a tapped dot completes >1 line). */
.candidate-overlay { pointer-events: all; }
.candidate-line {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.78;
}
.candidate-line:hover { opacity: 1; stroke-width: 8; }
/* Invisible thicker hit-area for forgiving fingertip taps. */
.candidate-hit {
  fill: none;
  stroke: rgba(0,0,0,0.001);
  stroke-width: 26;
  stroke-linecap: round;
}
.candidate-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 3;
  stroke-linejoin: round;
}

@media (max-width: 480px) {
  header { padding: 10px 14px; }
  header h1 { font-size: 1rem; }
  #scoreboard .value { font-size: 1.4rem; }
}
