:root {
  --bg-main: #0d1117;
  --bg-panel: #131a23;
  --bg-panel-soft: #0f151e;
  --text-main: #e7edf5;
  --text-muted: #94a4b8;
  --accent: #7db1ff;
  --accent-strong: #5f99f0;
  --border: #243244;
  --danger: #ff8080;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 20% 10%, #1a2230 0%, transparent 38%),
    radial-gradient(circle at 80% 90%, #1a2235 0%, transparent 35%),
    var(--bg-main);
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(720px, 100%);
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel-soft));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

.card-header {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(1.3rem, 2.4vw, 2rem);
}

.subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 20px 0;
}

.mode-btn {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  justify-content: stretch;
  gap: 8px;
  border: 1px solid #2f4564;
  background: #101a29;
  color: var(--text-main);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: 0.18s ease;
  box-shadow: none;
}

.mode-btn-side {
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  min-width: 0;
}

.mode-btn-arrow {
  color: #8db8ff;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mode-btn-arrow svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mode-btn:hover {
  border-color: #5a7aa8;
  background: #142134;
}

.mode-btn.active {
  background: #1a2b45;
  border-color: #80acff;
  box-shadow: none;
}

.mode-btn.active .mode-btn-arrow {
  color: #c9dcff;
}

.usage-note {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid #2a3a51;
  border-radius: 10px;
  background: #101825;
}

.usage-title {
  margin: 0;
  font-weight: 700;
  color: #c3d9ff;
}

.usage-text {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

input {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0d141f;
  color: var(--text-main);
  padding: 12px;
  font-size: 1rem;
  outline: none;
}

input:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(125, 177, 255, 0.22);
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-position 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.btn.primary {
  background: #7db1ff;
  border-color: #7aa8ee;
  color: #0b1628;
}

.btn.primary:hover {
  background: #6a9df0;
  border-color: #6f9fe9;
}

.btn.ghost {
  background: #111823;
  color: var(--text-main);
  border-color: var(--border);
}

.btn.ghost:hover {
  border-color: #3b4f68;
}

.locations-panel {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: rgba(12, 18, 27, 0.85);
  overflow: visible;
}

.locations-title {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #c7dbff;
}

.location-input-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: 14px;
  row-gap: 14px;
}

.location-input-grid label {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  min-width: 0;
}

.location-input-grid input {
  padding: 10px;
  width: 100%;
}

.location-input-grid .field-name {
  grid-column: 1 / -1;
}

.location-input-grid .field-x {
  grid-column: span 4;
}

.location-input-grid .field-y {
  grid-column: span 4;
}

.location-input-grid .field-z {
  grid-column: span 4;
}

.location-input-grid .field-color {
  grid-column: 1 / -1;
  position: relative;
  z-index: 2;
}

.color-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-preview-btn {
  border: 1px solid #2f4564;
  border-radius: 10px;
  background: #0d141f;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.color-preview-btn:hover {
  border-color: #4e6f99;
}

.color-custom-row input {
  flex: 1;
  min-width: 0;
}

.color-preview {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.28);
  background: #7db1ff;
}

#locationColorHex {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: uppercase;
}

#locationColorHex.invalid {
  border-color: #995161;
}

.custom-color-picker {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(340px, 100%);
  border: 1px solid #2c415d;
  border-radius: 10px;
  padding: 10px;
  background: #0f1826;
  display: grid;
  gap: 10px;
  z-index: 25;
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.42);
}

.color-spectrum {
  position: relative;
  width: 100%;
  height: 150px;
  border-radius: 8px;
  overflow: hidden;
  background: hsl(214 100% 50%);
  cursor: crosshair;
}

.color-spectrum::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
}

.color-spectrum::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, #000, rgba(0, 0, 0, 0));
}

.spectrum-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.custom-color-picker input[type="range"] {
  width: 100%;
  padding: 0;
  accent-color: #7db1ff;
}

.hue-slider {
  appearance: none;
  -webkit-appearance: none;
  height: 12px;
  border-radius: 999px;
  border: 1px solid #3a4d65;
  background: linear-gradient(to right,
    #ff0000 0%,
    #ffff00 16%,
    #00ff00 33%,
    #00ffff 50%,
    #0000ff 66%,
    #ff00ff 83%,
    #ff0000 100%);
  cursor: pointer;
}

.hue-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: #7db1ff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.hue-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: #7db1ff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.color-presets {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.color-chip {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid #3a4d65;
  background: var(--chip, #7db1ff);
  cursor: pointer;
  padding: 0;
}

.color-chip:hover {
  border-color: #7ea5dc;
}

.locations-form-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-start;
}

.btn.save-location {
  background: #1b2a3f;
  color: #d9e6fa;
  border-color: #35507a;
}

.btn.save-location:hover {
  background: #223755;
  border-color: #4f73aa;
}

.locations-note {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.locations-empty {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.locations-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.location-item {
  border: 1px solid #2b3d53;
  border-left: 4px solid var(--location-color, #7db1ff);
  border-radius: 10px;
  background: #0f1723;
  padding: 11px;
}

.location-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.location-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--location-color, #7db1ff);
  flex-shrink: 0;
}

.location-name {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  color: #e8eff9;
}

.location-coords {
  margin: 7px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.location-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn.location-calc {
  background: #19304f;
  color: #d9e7fc;
  border-color: #355d93;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn.location-calc:hover {
  background: #214270;
}

.btn.location-edit {
  background: #2a2d47;
  color: #e7e8ff;
  border-color: #505486;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn.location-edit:hover {
  background: #393f63;
}

.btn.location-delete {
  background: #2d1a20;
  color: #ffd7de;
  border-color: #67323d;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn.location-delete:hover {
  background: #3f2129;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 17, 0.7);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 1000;
}

.modal-card {
  width: min(620px, 100%);
  background: linear-gradient(180deg, #121a28, #0f1722);
  border: 1px solid #2c3f5a;
  border-radius: 14px;
  padding: 16px;
}

.modal-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.edit-color-field {
  grid-column: 1 / -1;
  position: relative;
  z-index: 2;
}

.modal-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
}

.result-card {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: rgba(16, 22, 31, 0.75);
}

.result-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.result-main {
  margin: 10px 0 0;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1.1rem, 2.2vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.result-hint {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.result-hint.error {
  color: var(--danger);
}

.result-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-start;
}

.btn.copy {
  background: #162132;
  color: #d5e2f5;
  border-color: #2d3e55;
  padding: 9px 13px;
}

.btn.copy:hover:enabled {
  border-color: #5778a8;
}

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

@media (max-width: 640px) {
  .card {
    padding: 18px;
  }

  .location-input-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .location-input-grid .field-name,
  .location-input-grid .field-color {
    grid-column: span 2;
  }

  .location-input-grid .field-x,
  .location-input-grid .field-y,
  .location-input-grid .field-z {
    grid-column: span 1;
  }

  .input-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }
}

@media (max-width: 420px) {
  .location-input-grid {
    grid-template-columns: 1fr;
  }

  .location-input-grid .field-name,
  .location-input-grid .field-color,
  .location-input-grid .field-x,
  .location-input-grid .field-y,
  .location-input-grid .field-z {
    grid-column: span 1;
  }

  .edit-grid {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    flex-direction: column;
  }
}
