:root {
  /* Octile Universe dark theme tokens */
  --color-bg: var(--bg);                       /* #0F1115 dark */
  --color-text: var(--text);                   /* #E8ECF2 light */
  --color-accent: var(--accent);               /* #6AA0FF blue */
  --color-conflict: var(--error);              /* #FF6B6B red */
  --color-preview: var(--warning);             /* #F7C948 yellow */
  --color-selected: var(--accent);             /* #6AA0FF */
  --color-neighbor: var(--muted);              /* #AAB3C2 */
  --color-given-stroke: rgba(255,255,255,0.25); /* Visible on dark + mobile */
  --color-btn-bg: var(--surface);              /* #151A22 */
  --color-btn-hover: var(--surface-2);         /* #1B2230 - more visible than --hover */
  --color-primary: var(--surface-2);           /* #1B2230 */
  --svg-width: clamp(320px, 90vw, 800px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--color-bg);
  min-height: 100vh;
  color: var(--color-text);
}

/* Menu Bar */
#menu-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  max-width: 820px;
  padding: 8px 12px;
  background: var(--color-primary);
  color: white;
}

.menu-item {
  position: relative;
}

.menu-btn {
  background: none;
  border: none;
  color: white;
  font-size: 0.95rem;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 4px;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.arrow {
  font-size: 0.7em;
  margin-left: 2px;
}

/* Dropdown */
.dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  color: var(--color-text);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  min-width: 280px;
  z-index: 100;
  overflow: hidden;
}

.dropdown.open {
  display: block;
}

.dropdown-section {
  padding: 8px 0;
}

.dropdown-label {
  padding: 4px 16px;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.dropdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.preset-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  border: none;
  background: none;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--color-text);
}

.preset-btn:hover {
  background: var(--hover);
}

#info-bar {
  margin-left: auto;
  display: flex;
  gap: 20px;
  font-size: 0.85rem;
  color: var(--muted);
}

#info-bar > span {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.info-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.info-value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Main content */
main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  gap: 12px;
  width: 100%;
  max-width: 820px;
}

/* SVG Map */
#map-svg {
  width: var(--svg-width);
  height: auto;
  cursor: pointer;
}

.region-fill {
  stroke: rgba(255,255,255,0.18);
  stroke-width: 0.5;
  transition: fill var(--t-fast) var(--ease-out);
}

.region-fill.given {
  opacity: 0.92;
  stroke: var(--color-given-stroke);
  stroke-width: 1;
  stroke-dasharray: 3 2;
}

.region-border {
  stroke: transparent;
  stroke-width: 0;
  pointer-events: none;
}

/* Highlight states — applied to both fill and border paths */
.region-border.selected {
  stroke: var(--color-selected);
  stroke-width: 3;
}

.region-border.neighbor {
  stroke: var(--color-neighbor);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.region-border.preview-conflict {
  stroke: var(--color-preview);
  stroke-width: 2.5;
}

.region-border.conflict {
  stroke: var(--error);
  stroke-width: 0;  /* Hidden by default */
  stroke-opacity: 0.75;
}

.region-border.conflict.selected,
.region-border.conflict:hover {
  stroke-width: 2.5;  /* Show on interaction */
  animation: pulse-conflict 1.2s ease-in-out 3;  /* Pulse 3 times then stop */
}

.region-fill.conflict {
  filter: brightness(0.9) saturate(1.1);  /* Subtle adjustment */
}

@keyframes pulse-conflict {
  from { stroke-opacity: 0.6; }
  to { stroke-opacity: 0.85; }  /* Lower peak opacity */
}

/* Color Palette */
#palette {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.palette-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--t-med) var(--ease-out);
  outline: 2px solid var(--border);
  outline-offset: -2px;
}

.palette-btn:hover {
  outline-color: var(--muted);
  transform: scale(1.05);
}

.palette-btn.active {
  border-color: var(--accent);
  outline-color: var(--accent);
  outline-width: 3px;
  outline-offset: 0px;
  box-shadow: 0 0 0 4px var(--accent-soft), 0 2px 8px rgba(0,0,0,0.3);
  transform: scale(1.08);
}

/* Mobile: make selection more obvious */
@media (hover: none) {
  .palette-btn.active {
    outline-width: 4px;
    box-shadow: 0 0 0 6px var(--accent-soft), 0 2px 12px rgba(0,0,0,0.4);
  }
}

/* Controls */
#controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

#controls button {
  padding: 8px 16px;
  font-size: 0.9rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
  border: 1px solid var(--border);
}

#controls button:active {
  transform: scale(0.97);
}

/* Primary action - one strong button */
#controls button[data-priority="primary"] {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 500;
}

#controls button[data-priority="primary"]:hover {
  background: var(--accent);
  filter: brightness(1.1);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* Secondary actions - calm instruments */
#controls button[data-priority="secondary"] {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

#controls button[data-priority="secondary"]:hover {
  background: var(--surface-2);
  border-color: var(--muted);
}

/* Tertiary/destructive - very subtle */
#controls button[data-priority="tertiary"] {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

#controls button[data-priority="tertiary"]:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.modal.visible {
  display: flex;
}

.modal-content {
  background: var(--surface);
  padding: 32px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  max-width: 520px;
  width: 90%;
}

.modal-content h2 {
  margin-bottom: 12px;
  font-size: 1.25rem;
  line-height: 1.3;
  color: var(--text);
}

.modal-content h3 {
  margin-top: 20px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
}

.modal-content p {
  margin-bottom: 12px;
  line-height: 1.6;
}

.modal-content ul {
  margin: 8px 0 16px 20px;
  line-height: 1.6;
}

.modal-content li {
  margin-bottom: 6px;
}

.modal-content label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.modal-content input,
.modal-content select {
  display: block;
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 0.95rem;
  background: var(--surface-2);
  color: var(--text);
}

.modal-content kbd {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

.btn-primary {
  padding: 10px 20px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.btn-primary:hover {
  opacity: 0.85;
}

.btn-cancel {
  padding: 10px 20px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 1rem;
}

.btn-cancel:hover {
  background: var(--hover);
}

/* Octile cross-promotion */
.octile-prompt {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  white-space: pre-line;
  line-height: 1.5;
}

/* Help modal styling */
.help-content h2 {
  margin-bottom: 12px;
}

.help-content h3 {
  margin-top: 20px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.help-content .help-objective {
  margin-bottom: 20px;
  line-height: 1.6;
  white-space: pre-line;
}

.help-content ul {
  margin-bottom: 16px;
}

.help-content .help-note {
  line-height: 1.6;
  color: var(--muted);
  font-style: italic;
  white-space: pre-line;
  margin-bottom: 20px;
}

.help-octile {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.help-octile p {
  white-space: pre-line;
  margin: 0;
}

/* Toast */
#toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  padding: 12px 24px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  font-size: 0.95rem;
  max-width: 300px;
  text-align: center;
  animation: slideIn var(--t-slow) var(--ease-out), slideOut var(--t-slow) var(--ease-in) 2.7s;
  animation-fill-mode: forwards;
  pointer-events: all;
  color: var(--text);
}

.toast.info { border-left: 4px solid var(--info); }
.toast.success { border-left: 4px solid var(--success); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.error { border-left: 4px solid var(--error); }

@keyframes slideIn {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-100%); opacity: 0; }
}

/* Drag-and-drop */
.drag-ghost {
  position: fixed;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0.8;
  z-index: 9999;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.dragging {
  cursor: grabbing !important;
}

body.dragging * {
  cursor: grabbing !important;
}

/* Responsive */
@media (max-width: 600px) {
  #menu-bar {
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 8px;
  }

  .menu-btn {
    font-size: 0.85rem;
    padding: 4px 8px;
  }

  #info-bar {
    font-size: 0.75rem;
    gap: 10px;
  }

  main {
    padding: 8px;
    gap: 8px;
  }

  .palette-btn {
    width: 38px;
    height: 38px;
  }

  #controls button {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .modal-content {
    padding: 20px;
  }
}

/* OTA Update Banner */
#update-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #0f3460, #1a5276);
  border-bottom: 2px solid #f1c40f;
  padding: 12px 16px;
  text-align: center;
  z-index: 9999;
  color: white;
}

#update-banner.show {
  display: block;
}

#update-banner.force {
  background: linear-gradient(135deg, #b85c00, #c0392b);
  z-index: 9999;
  pointer-events: all;
}

#update-banner.force::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9998;
  pointer-events: all;
}

#update-text {
  margin: 0 0 8px 0;
  font-size: 14px;
}

.update-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.btn-update,
.btn-dismiss {
  padding: 6px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.2s;
}

.btn-update {
  background: #f1c40f;
  color: #2c3e50;
}

.btn-update:hover {
  opacity: 0.9;
}

.btn-dismiss {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.btn-dismiss:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Help Modal Links */
.help-links {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.9em;
  color: #aaa;
}

.help-links a {
  color: #7986b8;
  text-decoration: none;
}

.help-links a:hover {
  text-decoration: underline;
}

.help-contact {
  margin-top: 8px;
  font-size: 0.85em;
}

.help-contact-alt {
  margin-top: 4px;
  font-size: 0.75em;
  color: #888;
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 20px;
  text-align: center;
  background: rgba(15, 25, 35, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.8em;
  color: #888;
  z-index: 100;
}

.footer-text {
  margin: 0 0 4px 0;
}

.footer-links {
  margin: 0;
}

.footer-links a {
  color: #7986b8;
  text-decoration: none;
  margin: 0 4px;
}

.footer-links a:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  .footer {
    font-size: 0.7em;
    padding: 8px 12px;
  }
}
