* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f5f5f5;
}

.app {
  max-width: 100vw;
  min-height: 100vh;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.hidden {
  display: none !important;
}

.play-mode-header {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.board-name-display {
  font-size: 1.25rem;
  font-weight: 600;
}

.create-mode-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.toolbar-label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.toolbar-label select,
.toolbar-label input[type="text"] {
  padding: 0.25rem 0.4rem;
  font-size: 1rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #fff;
}

.toolbar-label #board-name-input {
  min-width: 8em;
  max-width: 14em;
}

.mode-label {
  font-weight: 600;
}

.btn {
  padding: 0.4rem 0.8rem;
  border: 1px solid #333;
  background: #fff;
  cursor: pointer;
  border-radius: 4px;
}

.btn:hover {
  background: #eee;
}

.btn.active {
  background: #333;
  color: #fff;
}

.hint {
  color: #666;
  font-size: 0.9rem;
}

.board-wrap {
  position: relative;
  background: #1a1a1a;
  border: 1px solid #444;
  border-radius: 8px;
  overflow: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.board-wrap.predefined-bg {
  background-color: #fff;
}

.board-wrap.predefined-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: var(--predefined-bg-url);
  background-size: cover;
  background-position: center;
  opacity: 0.6;
  border-radius: inherit;
  pointer-events: none;
}

.board-wrap.predefined-bg .board,
.board-wrap.predefined-bg .win-message,
.board-wrap.predefined-bg .connection-feedback,
.board-wrap.predefined-bg .number-form {
  position: relative;
  z-index: 1;
}

.board-wrap.predefined-bg .board .cell-number {
  fill: black;
  text-shadow: 0.15em 0 white, 0 0.15em white, -0.15em 0 white, 0 -0.15em white, -0.15em -0.15em white, -0.15em 0.15em white, 0.15em -0.15em white, 0.15em 0.15em white;

}

.board-wrap.won {
  background: #1a4d1a;
  border-color: #2d7a2d;
  box-shadow: 0 2px 12px rgba(0, 80, 0, 0.4);
}

.board-wrap .win-message {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.board-wrap.won .win-message {
  display: flex;
}

.connection-feedback {
  position: absolute;
  bottom: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.35rem 0.75rem;
  background: rgba(180, 60, 60, 0.95);
  color: #fff;
  font-size: 0.85rem;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 5;
}

.connection-feedback.visible {
  opacity: 1;
}

.board {
  display: block;
  overflow: visible;
  width: min(90vmin, 520px);
  height: min(90vmin, 520px);
}

.board.can-reroute {
  cursor: grab;
}

.board.can-reroute:active {
  cursor: grabbing;
}

/* Grid cells - medium grey */
.board .cell-rect {
  fill: none;
  stroke: #666;
  stroke-width: 1;
}

/* Lines drawn by user - pale blue, slightly wider; click to select */
.board .line-path {
  fill: none;
  stroke: #7eb8da;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: stroke;
  cursor: pointer;
}

.board .line-path.selected {
  stroke: #c45c5c;
  stroke-width: 3.5;
}

.board .line-terminal {
  fill: #7eb8da;
  stroke: #7eb8da;
  stroke-width: 1;
  cursor: pointer;
}

/* Continuation hints: possible next directions when drawing/editing a line */
.board .continuation-hint {
  fill: none;
  stroke: #9ec9e3;
  stroke-width: 1.5;
  pointer-events: all;
  cursor: pointer;
}

/* Single-cell path (just started): show a dot so user sees feedback and knows to drag */
.board .line-path-start-dot {
  fill: #9ec9e3;
  stroke: #7eb8da;
  stroke-width: 1;
  pointer-events: none;
}

/* Start hints: click to start a new line from a square that already has one terminal */
.board .start-hint {
  stroke: #b8daf0;
  stroke-width: 2;
}

/* "Start new line here" indicator: square has one terminal, room for one more */
.board .start-new-hint {
  fill: rgba(184, 218, 240, 0.85);
  stroke: #7eb8da;
  stroke-width: 1.5;
  cursor: pointer;
  pointer-events: all;
}
.board .start-new-hint:hover {
  fill: rgba(184, 218, 240, 1);
  stroke-width: 2;
}

/* Invisible hit area for line selection */
.board .line-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 12;
  stroke-linecap: round;
  stroke-linejoin: round;
  cursor: pointer;
}

/* Number labels in cells (sized to fit inside 1-unit squares) */
.board .cell-number {
  font: 11px system-ui, sans-serif;
  fill: #e0e0e0;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

/* Number form overlay */
.number-form {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: #fff;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 1rem;
  min-width: 220px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.number-form.hidden {
  display: none;
}

.number-form label {
  display: block;
  margin: 0.5rem 0;
}

.number-form input {
  margin-left: 0.5rem;
  width: 4rem;
}

.form-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.form-actions button {
  padding: 0.35rem 0.6rem;
  border: 1px solid #333;
  background: #fff;
  cursor: pointer;
  border-radius: 4px;
}

.form-actions button:hover {
  background: #eee;
}
