:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --border: #e3e5ec;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --success: #16a34a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  max-width: 42rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nav-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.nav-link:hover {
  text-decoration: underline;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.prompt {
  font-size: 1.05rem;
  margin: 0 0 1rem;
}

.prompt strong {
  color: var(--primary);
}

#par-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.actions-row {
  margin-top: 0.5rem;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 1rem 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.divider span {
  padding: 0 0.75rem;
}

.text-input {
  flex: 1;
  min-width: 8rem;
  font: inherit;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.text-input:disabled {
  background: var(--bg);
  color: var(--text-muted);
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn-chip {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
}

.btn-chip:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--primary);
}

.btn-chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

#graph-controls {
  margin: 0.5rem 0 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.controls-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.controls-row input[type="range"] {
  flex: 1;
  min-width: 6rem;
  accent-color: var(--primary);
}

.controls-row input[type="number"] {
  width: 4.5rem;
  font: inherit;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.difficulty-group {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

#chain-graph {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 1rem;
}

#score {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 1rem 0 0.25rem;
}

#status {
  font-weight: 600;
  color: var(--text-muted);
  margin: 0;
}

#setup-status {
  color: var(--danger);
  margin: 0.5rem 0 0;
  white-space: pre-line;
}

.node rect {
  fill: #4a90d9;
  stroke: #2c5f8a;
  stroke-width: 1.5;
  cursor: grab;
}

.node rect.node-pinned {
  fill: #2b2f3a;
  stroke: #14161c;
  cursor: default;
}

.node rect.node-digression {
  fill: #e08a2b;
  stroke: #a05e10;
}

.node rect.node-suggested {
  fill: #9ca3af;
  stroke: #6b7280;
  stroke-dasharray: 3, 2;
}

/* Layers on top of whichever fill rule above applies (pinned/digression/
   default) - only overrides the border, so a hint's digression status
   (fill color) stays visible alongside the "this was a hint" marker. */
.node rect.node-hint {
  stroke: #8b5cf6;
  stroke-width: 3;
  stroke-dasharray: 4, 2;
}

.node text {
  font-size: 14px;
  fill: #fff;
  pointer-events: none;
  user-select: none;
}

.edge {
  stroke: #a3a8b8;
}

.edge.edge-winning {
  stroke: var(--success);
}

.edge.edge-suggested {
  stroke: #f59e0b;
  stroke-dasharray: 6, 4;
}

.edge-label {
  font-size: 13px;
  font-weight: bold;
  fill: #146c37;
  pointer-events: none;
  user-select: none;
}

#graph-tooltip {
  position: fixed;
  background: #1a1d29;
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  z-index: 10;
}

.table-wrap {
  overflow-x: auto;
}

#scores-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

#scores-table th,
#scores-table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#scores-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#scores-table tbody tr:hover {
  background: var(--bg);
}

#empty-message {
  color: var(--text-muted);
  margin: 1rem 0;
}

#clear-scores-btn {
  margin-top: 1rem;
}

.version-info {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.6;
  margin: 2rem 0 0;
}

#filter-empty-message {
  color: var(--text-muted);
  margin: 1rem 0;
}

.table-instructions {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.controls-row-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  align-self: center;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 20;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 46rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header .card-title {
  margin: 0;
}

#solution-graph {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-top: 0.75rem;
}

#solution-error {
  color: var(--danger);
  margin: 0.75rem 0 0;
}

#solution-threshold {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0;
}
