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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0d1117;
  color: #e0e0e0;
}

.app {
  display: flex;
  height: 100vh;
}

/* Maze takes most of the screen */
.maze-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-width: 0;
  overflow: hidden;
  height: 100vh;
  cursor: grab;
}

.maze-container:active {
  cursor: grabbing;
}

.maze-zoom-wrapper {
  transform-origin: center center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.maze-zoom-wrapper svg {
  max-width: 100%;
  max-height: 100%;
}

/* Sidebar */
.sidebar {
  width: 320px;
  background: #161b22;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  border-left: 1px solid #30363d;
  flex-shrink: 0;
}

.title {
  font-size: 18px;
  color: #f0f0f0;
  border-bottom: 1px solid #30363d;
  padding-bottom: 12px;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #30363d;
  padding-bottom: 12px;
}

.sidebar-header .title-inline {
  flex: 1;
  border-bottom: none;
  padding-bottom: 0;
  margin: 0;
}

.btn-logout {
  flex-shrink: 0;
  margin-top: 2px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #8b949e;
  background: transparent;
  border: 1px solid #30363d;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-logout:hover {
  color: #e0e0e0;
  border-color: #484f58;
}

/* Login screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse 80% 60% at 50% 20%, #1c2333 0%, #0d1117 55%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.login-title {
  font-size: 22px;
  color: #f0f0f0;
  font-weight: 700;
  text-align: center;
}

.login-subtitle {
  font-size: 14px;
  color: #8b949e;
  text-align: center;
  margin-top: -8px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #8b949e;
}

.login-error {
  color: #f85149;
  font-size: 13px;
  font-weight: 600;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
  padding: 10px 16px;
}

/* Control panel */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hint { color: #8b949e; font-size: 14px; }
.path-info { color: #8b949e; font-size: 13px; }

.button-row {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: #4fc3f7; color: #0d1117; }
.btn-secondary { background: #30363d; color: #e0e0e0; }
.btn-danger { background: #f85149; color: white; }
.btn-small { font-size: 12px; padding: 6px 12px; margin-top: 12px; }

/* Name input */
.name-input {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #4fc3f7;
  background: #0d1117;
  color: #e0e0e0;
  font-size: 16px;
  width: 100%;
  outline: none;
}
.name-input:focus { border-color: #80d8ff; box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.2); }

/* Feedback text */
.feedback-success { color: #66bb6a; font-weight: 600; }
.feedback-fail { color: #f85149; font-weight: 600; }

.restore-banner {
  background: #1c2333;
  border: 1px solid #f0883e;
  border-radius: 6px;
  padding: 12px;
  margin: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.restore-banner p {
  color: #f0883e;
  font-size: 13px;
  line-height: 1.4;
}

/* Discovered list */
.discovered-section { margin-top: auto; }
.discovered-section h3 {
  font-size: 14px;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.empty-text { color: #484f58; font-size: 13px; font-style: italic; }

.discovered-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.discovered-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #0d1117;
  border-radius: 6px;
  font-size: 14px;
}
.discovered-number { color: #484f58; font-size: 12px; min-width: 20px; }
.discovered-name { flex: 1; }
.btn-forget {
  background: none;
  border: none;
  color: #484f58;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}
.btn-forget:hover { color: #f85149; }

.discovered-show-all {
  margin-bottom: 8px;
  display: flex;
  gap: 6px;
}
.btn-active { background: #238636; color: #fff; }
.btn-show-path {
  background: none;
  border: 1px solid #30363d;
  color: #484f58;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  border-radius: 4px;
  line-height: 1.2;
  flex-shrink: 0;
}
.btn-show-path:hover { border-color: #8b949e; color: #8b949e; }
.btn-show-path-active { border-color: #4fc3f7; color: #4fc3f7; }
.discovered-item-shown { background: #161b22; border: 1px solid #30363d; }

/* SVG interaction */
.maze-node { cursor: pointer; }
.maze-node:hover { filter: brightness(1.4); }

/* Maze wall styling */
.maze-wall {
  stroke: #4a5568;
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

.maze-boundary {
  stroke: #5a6a7a;
  stroke-width: 3;
  fill: none;
}

/* Traced path on maze */
.traced-path {
  stroke: #4fc3f7;
  stroke-width: 4;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px rgba(79, 195, 247, 0.6));
}

/* Traced path glow effect */
.path-edge {
  filter: drop-shadow(0 0 3px rgba(79, 195, 247, 0.6));
}

/* Destination icons (all zones) */
.destination-icon { cursor: pointer; }
.destination-icon:hover { filter: brightness(1.3); }

/* Icon name labels */
.icon-label {
  font-size: 10px;
  fill: #c0c0c0;
  pointer-events: none;
  user-select: none;
  font-weight: 600;
}

/* Connector lines from outer/inner icons to maze boundary nodes */
.icon-connector {
  stroke: #2a3a5a;
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.5;
  pointer-events: none;
}

/* Dev mode node labels */
.dev-label {
  font-size: 7px;
  fill: #666;
  pointer-events: none;
  user-select: none;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: #8b949e;
  font-size: 18px;
}

/* Responsive: stack on small screens */
/* ================================
   Dev Toolbar (Pattern Matching)
   ================================ */

.dev-toolbar {
  background: #1c2333;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dev-tool-toggle {
  display: flex;
  gap: 2px;
  background: #0d1117;
  border-radius: 6px;
  padding: 2px;
}

.dev-tool-toggle button {
  flex: 1;
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #8b949e;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}

.dev-tool-toggle button:hover {
  color: #e0e0e0;
}

.dev-tool-toggle button.active {
  background: rgba(224, 64, 251, 0.2);
  color: #e040fb;
}

.pattern-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pattern-info {
  color: #8b949e;
  font-size: 13px;
}

.reflection-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #8b949e;
  font-size: 13px;
  cursor: pointer;
}

.reflection-toggle input[type="checkbox"] {
  accent-color: #e040fb;
}

.match-results {
  border-top: 1px solid #30363d;
  padding-top: 8px;
  margin-top: 4px;
}

.match-count {
  color: #66bb6a;
  font-weight: 600;
  font-size: 13px;
}

.match-count.no-matches {
  color: #8b949e;
  font-weight: 400;
}

.match-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}

.match-nav button {
  padding: 4px 10px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: #0d1117;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}

.match-nav button:hover:not(:disabled) {
  border-color: #e040fb;
  color: #e040fb;
}

.match-nav button.active {
  background: rgba(224, 64, 251, 0.2);
  border-color: #e040fb;
  color: #e040fb;
}

.match-nav button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.match-counter {
  color: #8b949e;
  font-size: 12px;
  min-width: 50px;
  text-align: center;
}

.icon-node-toggles {
  border-top: 1px solid #30363d;
  padding-top: 8px;
  margin-top: 4px;
}

.icon-toggle-list {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
  max-height: 120px;
  overflow-y: auto;
}

.icon-toggle-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-family: monospace;
  color: #8b949e;
  cursor: pointer;
}

.icon-toggle-item input {
  margin: 0;
}

/* Icon Tool */
.icon-brush-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
}

.icon-brush-label {
  color: #8b949e;
  font-size: 11px;
  font-weight: 600;
}

.icon-brush-name {
  color: #e040fb;
  font-size: 12px;
  font-weight: 600;
}

.icon-search-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #0d1117;
  color: #e0e0e0;
  font-size: 13px;
  outline: none;
}

.icon-search-input:focus {
  border-color: #e040fb;
  box-shadow: 0 0 0 2px rgba(224, 64, 251, 0.15);
}

.icon-search-results {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.icon-result-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: #8b949e;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  text-align: left;
  transition: all 0.1s;
}

.icon-result-btn:hover {
  background: #1c2333;
  color: #e0e0e0;
}

.icon-result-btn.active {
  background: rgba(224, 64, 251, 0.15);
  border-color: #e040fb;
  color: #e040fb;
}

.icon-result-btn.used {
  color: #66bb6a;
}

.icon-result-btn span:nth-child(2) {
  flex: 1;
}

.icon-assigned-section {
  border-top: 1px solid #30363d;
  padding-top: 8px;
}

.icon-assigned-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 150px;
  overflow-y: auto;
}

.icon-palette-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 14px;
  height: 14px;
  margin-left: auto;
  padding: 0 3px;
  border-radius: 7px;
  background: #2e5a30;
  color: #66bb6a;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

.icon-result-btn.active .icon-palette-count {
  background: rgba(224, 64, 251, 0.3);
  color: #e040fb;
}

.dev-paths-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 250px;
  overflow-y: auto;
}

.dev-path-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  background: #0d1117;
  border-radius: 6px;
  position: relative;
}

.dev-path-name {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e0;
}

.dev-path-meta {
  font-size: 10px;
  color: #8b949e;
  font-family: monospace;
}

.dev-path-actions {
  position: absolute;
  right: 6px;
  top: 6px;
  display: flex;
  gap: 2px;
}

.dev-path-result {
  border-top: 1px solid #30363d;
  padding-top: 12px;
}

.dev-path-result h3 {
  font-size: 14px;
  margin-bottom: 6px;
  color: #e0e0e0;
}

.dev-path-result p {
  font-size: 12px;
  color: #8b949e;
  margin-bottom: 4px;
}

.dev-path-list {
  font-size: 11px;
  color: #8b949e;
  padding-left: 20px;
  max-height: 200px;
  overflow-y: auto;
}

.dev-path-list li {
  padding: 1px 0;
  font-family: monospace;
}

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid #30363d;
  }
}

.pattern-finder-section {
  padding: 12px 20px;
  border-top: 1px solid #30363d;
  margin-top: 4px;
}

.pattern-finder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
