* { 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; }
header .subtitle { font-size: 0.78rem; color: #9aa; margin-top: 4px; line-height: 1.4; }

#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: #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; }
}
