:root {
  --bg: #0b0d10;
  --panel: #141821;
  --panel-2: #1b2130;
  --text: #e6edf3;
  --muted: #93a1b2;
  --accent: #7aa2f7;
  --accent-2: #9ece6a;
  --danger: #f7768e;
  --warning: #e0af68;
  --grid: rgba(255,255,255,0.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 800px at 10% 0%, #0f1320, #0b0d10);
}

.app-header {
  padding: 16px 20px 8px;
}

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

.title-section {
  flex: 1;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.4px;
}

.subtitle {
  margin: 6px 0 0 0;
  color: var(--muted);
  font-size: 13px;
}

.map-name-display {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.map-name-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: all 0.2s ease;
  display: block;
  text-align: center;
}

.map-name-link:hover {
  color: var(--accent-2);
  text-shadow: 0 0 8px rgba(158, 206, 106, 0.3);
  transform: scale(1.02);
}

.language-toggle {
  background: var(--panel-2);
  border: 1px solid #253048;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.2s ease;
}

.language-toggle:hover {
  border-color: var(--accent);
}

.controls {
  display: grid;
  grid-template-columns: auto 2fr 2fr 2fr auto;
  gap: 12px;
  padding: 0 20px 12px;
}
.control-group {
  background: var(--panel);
  border: 1px solid #22283a;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.orientation-group { gap: 10px; }
.actions-group { justify-content: space-between; }
.waypoints-group { align-items: start; flex-wrap: wrap; }
input#mapNameInput { width: 160px; }
select#mapSelect { background: var(--panel-2); border: 1px solid #253048; color: var(--text); border-radius: 8px; padding: 6px 8px; }
.waypoints-list { display: flex; gap: 6px; flex-wrap: wrap; max-height: 90px; overflow: auto; }
.waypoints-list .chip { background: #22314a; border: 1px solid #2b3a57; border-radius: 999px; padding: 4px 8px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.waypoints-list .chip button { padding: 2px 6px; font-size: 11px; }

label { color: var(--muted); font-size: 12px; }
input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.file-group {
  justify-content: center;
}

.file-label {
  background: var(--panel-2);
  border: 1px solid #253048;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 16px;
  display: inline-block;
  transition: border-color 0.2s ease;
}

.file-label:hover {
  border-color: var(--accent);
}
input[type="range"] { width: 45%; }
input[type="number"] {
  width: 100px;
  background: var(--panel-2);
  border: 1px solid #253048;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
}

button {
  background: var(--panel-2);
  border: 1px solid #253048;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

.course-display {
  font-size: 18px;
  color: var(--accent-2);
  background: var(--panel-2);
  border: 1px solid #253048;
  border-radius: 6px;
  padding: 6px 10px;
  width: 80px;
  text-align: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.course-display.editable-course {
  cursor: pointer;
  user-select: none;
}

.course-display.editable-course:hover {
  border-color: var(--accent);
  background: var(--panel);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(122, 162, 247, 0.2);
}

.course-display.editing {
  color: var(--text);
  background: var(--panel);
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(158, 206, 106, 0.3);
}

.course-display.editing:focus {
  outline: none;
}

.course-display.editable-course:focus:not(.editing) {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(158, 206, 106, 0.4);
}

.course-control {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.course-arrows {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.course-arrow-btn {
  background: var(--panel-2);
  border: 1px solid #253048;
  color: var(--muted);
  border-radius: 3px;
  padding: 0;
  cursor: pointer;
  width: 20px;
  height: 16px;
  font-size: 10px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  user-select: none;
}

.course-arrow-btn:hover {
  border-color: var(--accent);
  color: var(--accent-2);
  background: var(--panel);
}

.course-arrow-btn:active {
  transform: scale(0.95);
  background: var(--panel);
}

.course-arrow-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.course-arrow-btn:disabled:hover {
  border-color: #253048;
  color: var(--muted);
  background: var(--panel-2);
  transform: none;
}

/* Two-column layout */
.main-content {
  display: flex;
  gap: 20px;
  padding: 0 20px 20px;
  min-height: 60vh;
}

.courses-sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid #22283a;
  border-radius: 12px;
  padding: 16px;
  max-height: 70vh;
  overflow-y: auto;
}

.courses-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid #22283a;
  padding-bottom: 8px;
}

.courses-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.courses-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.global-color-picker {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: none;
}

.courses-sidebar h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text);
}

.toggle-all-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  transition: background-color 0.2s ease;
}

.toggle-all-btn:hover {
  background: var(--panel-2);
}

.canvas-wrapper {
  flex: 1;
  min-width: 0; /* Allow flex item to shrink below content size */
}

.canvas-container {
  position: relative;
  background: var(--panel);
  border: 1px solid #22283a;
  border-radius: 12px;
  min-height: 60vh;
  overflow: hidden;
}

#mapCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hint {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid #384154;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
}

.app-footer {
  padding: 10px 20px 20px;
  color: var(--muted);
}
.app-footer ul {
  margin: 8px 0 0 0;
}
.app-footer li { margin: 4px 0; }

/* Course item styling */
.course-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid #253048;
  border-radius: 8px;
  transition: border-color 0.2s ease, transform 0.2s ease;
  cursor: move;
}

.course-item:hover {
  border-color: var(--accent);
}

.course-item.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.course-item.drag-over {
  border-color: var(--accent-2);
  background: var(--panel);
}

.visibility-toggle {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  transition: background-color 0.2s ease;
}

.visibility-toggle:hover {
  background: var(--panel);
}

.course-item input[type="color"] {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: none;
}

.manual-course-color {
  width: 32px;
  height: 32px;
  border: 1px solid var(--panel-2);
  border-radius: 6px;
  cursor: pointer;
  background: none;
  margin-left: 6px;
}

.manual-course-color:hover {
  border-color: var(--accent);
}

.color-reset-btn {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  color: var(--text);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  font-size: 10px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.color-reset-btn:hover {
  background: var(--panel-2);
  border-color: var(--accent);
}

.course-item span {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  word-wrap: break-word;
  line-height: 1.3;
}

.course-name {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background-color 0.2s ease;
  user-select: none;
}

.course-name:hover {
  background: var(--panel);
}

.course-name.editing {
  background: var(--panel);
  border: 1px solid var(--accent-2);
  outline: none;
  user-select: text;
  cursor: text;
}

.course-name.editing:focus {
  box-shadow: 0 0 0 2px rgba(158, 206, 106, 0.3);
}

.course-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.course-bearing {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

/* Bearing text in canvas should appear draggable */
canvas {
  cursor: default;
}

canvas:hover {
  cursor: default;
}

.course-left-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.course-actions-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.actions-row {
  display: flex;
  gap: 4px;
}

.course-item-buttons {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.course-item button {
  padding: 0;
  font-size: 12px;
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.course-item button:last-child {
  color: var(--danger);
}

.default-star {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
  color: var(--muted);
}

.default-star:hover {
  background: var(--panel-2);
  color: var(--warning);
}

.default-star.active {
  color: var(--warning);
}

/* Help button and modal styles */
.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-toggle {
  background: var(--panel-2);
  border: 1px solid #253048;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.2s ease;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-toggle:hover {
  border-color: var(--accent);
}

.help-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.help-modal[hidden] {
  display: none !important;
}

.help-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1;
}

.help-modal-content {
  position: relative;
  background: var(--panel);
  border: 1px solid #22283a;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  z-index: 2;
}

.help-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid #22283a;
}

.help-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.help-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.help-close-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}

.help-modal-body {
  padding: 16px 24px 24px;
  overflow-y: auto;
  max-height: calc(80vh - 80px);
}

.help-modal-body ul {
  margin: 0;
  padding-left: 20px;
  list-style-type: disc;
}

.help-modal-body li {
  margin: 12px 0;
  line-height: 1.5;
  color: var(--text);
}

.help-modal-body li:first-child {
  margin-top: 0;
}

.help-modal-body li:last-child {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .controls {
    grid-template-columns: 1fr;
  }
  input[type="range"] { width: 100%; }

  .main-content {
    flex-direction: column;
  }

  .courses-sidebar {
    width: 100%;
    max-height: 40vh;
    order: 2;
  }

  .canvas-wrapper {
    order: 1;
  }

  .help-modal {
    padding: 10px;
  }

  .help-modal-content {
    max-height: 90vh;
    max-width: none;
  }

  .help-modal-header {
    padding: 16px 20px 12px;
  }

  .help-modal-body {
    padding: 12px 20px 20px;
    max-height: calc(90vh - 60px);
  }
}


