:root {
  --bg: #050505;
  --panel: #0d0d0d;
  --panel-alt: #121212;
  --panel-soft: #171717;
  --text: #f4f4f4;
  --muted: #a8a8a8;
  --border: #2b2b2b;
  --border-strong: #5a5a5a;
  --chip-bg: #dbd7cf;
  --chip-text: #111111;
  --accent: #d9d5cd;
  --surface-light: #dcd8d1;
  --surface-light-strong: #ebe7df;
  --surface-light-border: #b8b2a8;
  --ble-off: #d94a4a;
  --ble-on: #3e7cff;
  --hold-start: #2ed573;
  --hold-hold: #4f8cff;
  --hold-foot: #f59e0b;
  --hold-end: #ff5d73;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  --radius-xl: 12px;
  --radius-lg: 8px;
  --radius-md: 6px;
  --radius-sm: 4px;
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-ui: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  color: var(--text);
  font-family: var(--font-ui);
  overflow-x: hidden;
}

.app-shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 22px 18px 34px;
}

.page-stack,
.stack {
  display: grid;
  gap: 16px;
}

.hidden {
  display: none !important;
}

.surface {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.subcard {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.screen-header {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 22px 0;
  background: linear-gradient(180deg, rgba(13, 13, 13, 0.98), rgba(13, 13, 13, 0.86) 72%, rgba(13, 13, 13, 0));
}

.screen-panel {
  padding: 14px 22px 22px;
}

.screen-title,
h1,
h2,
h3,
h4,
.display-text,
.climb-name,
.preview-title {
  margin: 0;
  font-family: var(--font-display);
  color: var(--text);
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.screen-title {
  font-size: clamp(2.1rem, 4vw, 3.6rem);
  line-height: 0.92;
}

.screen-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.top-actions,
.nav-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-spacer {
  min-width: 42px;
  min-height: 42px;
}

.btn,
.icon-btn,
.toggle,
.legend-btn,
.custom-select-button,
.rating-buttons button {
  font: inherit;
}

.btn,
.icon-btn,
.toggle,
.legend-btn,
.rating-buttons button {
  border: 1px solid var(--border);
  background: #101010;
  color: var(--text);
  cursor: pointer;
}

.btn,
.legend-btn {
  min-height: 42px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--surface-light);
  color: #080808;
  border-color: var(--surface-light);
}

.btn-secondary {
  background: #101010;
}

.ble-off {
  color: var(--ble-off);
}

.ble-on {
  color: var(--ble-on);
}

.field-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.field-group {
  grid-column: span 4;
  display: grid;
  gap: 8px;
}

.field-group.wide {
  grid-column: span 12;
}

.field-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.toolbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--surface-light-border);
  border-radius: var(--radius-md);
  background: var(--surface-light-strong);
  color: #050505;
}

.search-bar i {
  color: #5a5a5a;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
}

.filters-panel {
  display: grid;
  gap: 12px;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.66);
}

.confirm-overlay.open {
  display: flex;
}

.confirm-modal {
  width: min(100%, 420px);
  display: grid;
  gap: 14px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.field-help,
.muted,
.status-text {
  color: var(--muted);
  font-size: 0.84rem;
}

.error-text {
  min-height: 1.1em;
  color: #d94a4a;
  font-size: 0.84rem;
}

.input,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--surface-light-border);
  border-radius: var(--radius-md);
  background: var(--surface-light-strong);
  color: #050505;
  font: inherit;
}

.input::placeholder,
textarea::placeholder {
  color: #595959;
}

.toggle-group,
.chip-row,
.legend-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.toggle {
  min-height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: left;
  white-space: nowrap;
}

.toggle.active,
.legend-btn.active {
  background: var(--surface-light);
  color: #050505;
  border-color: var(--surface-light);
}

.legend-btn.active.legend-start {
  background: var(--hold-start);
  color: #050505;
  border-color: var(--hold-start);
}

.legend-btn.active.legend-hold {
  background: var(--hold-hold);
  color: #ffffff;
  border-color: var(--hold-hold);
}

.legend-btn.active.legend-foot {
  background: var(--hold-foot);
  color: #050505;
  border-color: var(--hold-foot);
}

.legend-btn.active.legend-end {
  background: var(--hold-end);
  color: #050505;
  border-color: var(--hold-end);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid #d7d7d7;
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 0.78rem;
}

.chip-icon-img,
.toggle-icon-img {
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
}

.chip-icon-img {
  width: 16px;
  height: 16px;
}

.toggle-icon-img {
  width: 20px;
  height: 20px;
}

.split-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
  align-items: start;
}

.split-layout > * {
  min-width: 0;
}

.browse-layout {
  grid-template-columns: minmax(380px, 460px) minmax(0, 1fr);
}

.sidebar-stack,
.filter-grid,
.preview-shell {
  display: grid;
  gap: 14px;
}

.range-section {
  display: grid;
  gap: 10px;
}

.range-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
}

.range-value {
  font-family: var(--font-ui);
  font-size: 1rem;
  color: var(--text);
}

.range-wrap {
  position: relative;
  height: 34px;
  width: 100%;
  max-width: 100%;
}

.range-wrap .track,
.range-wrap .fill {
  position: absolute;
  left: 0;
  right: 0;
  top: 14px;
  height: 4px;
  border-radius: 999px;
}

.range-wrap .track {
  background: #303030;
}

.range-wrap .fill {
  background: var(--surface-light);
}

.range-wrap input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  background: transparent;
  pointer-events: none;
  appearance: none;
}

.range-wrap input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-light);
  border: 2px solid #ffffff;
  pointer-events: auto;
}

.range-wrap input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-light);
  border: 2px solid #ffffff;
  pointer-events: auto;
}

.angle-section {
  border: 1px solid var(--border-strong);
  background: #111111;
}

.list-grid {
  display: grid;
  gap: 12px;
}

.climb-card {
  display: grid;
  justify-items: start;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.climb-card-head {
  display: grid;
  gap: 2px;
  justify-items: start;
}

.climb-name {
  font-size: 1.7rem;
  line-height: 0.94;
}

.climb-meta {
  color: var(--muted);
  font-size: 0.84rem;
  text-align: left;
}

.preview-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.preview-title {
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  line-height: 0.9;
}

.board-shell {
  width: 100%;
  overflow: hidden;
  padding-bottom: 2px;
}

.editor-board-shell {
  padding-bottom: 0;
}

.editor-board-viewport {
  overflow: hidden;
  border-radius: var(--radius-lg);
  touch-action: none;
  background: #0b0b0b;
  width: 100%;
}

.editor-board-stage {
  width: fit-content;
  transform-origin: 0 0;
  will-change: transform;
}

.editor-board-shell .board {
  margin: 0;
}

.board {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: #0b0b0b;
}

.board-bg {
  position: absolute;
  inset: 14px;
  width: calc(100% - 28px);
  height: calc(100% - 28px);
  object-fit: fill;
  object-position: center;
  opacity: 0.38;
  pointer-events: none;
  z-index: 0;
  background: #0b0b0b;
}

.grid {
  --cell-size: 22px;
  --cell-gap: 3px;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(16, var(--cell-size));
  grid-template-rows: repeat(18, var(--cell-size));
  gap: var(--cell-gap);
  min-width: max-content;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid rgba(180, 180, 180, 0.34);
  background: rgba(16, 16, 16, 0.22);
}

.grid.editable .cell {
  cursor: pointer;
}

.star-row {
  position: relative;
  display: inline-flex;
  gap: 2px;
  font-size: 24px;
  line-height: 1;
}

.star-empty {
  color: #4d4d4d;
}

.star-fill-wrap {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  white-space: nowrap;
  pointer-events: none;
}

.star-fill {
  color: var(--surface-light);
}

.rating-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.rating-buttons button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.rating-buttons button.active {
  background: var(--surface-light);
  color: #080808;
  border-color: var(--surface-light);
}

.nav-strip {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 0 8px;
  background: linear-gradient(180deg, rgba(13, 13, 13, 0.98), rgba(13, 13, 13, 0.82) 72%, rgba(13, 13, 13, 0));
}

.nav-strip.compact {
  justify-content: flex-end;
}

.wizard-bar {
  position: sticky;
  top: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 0 8px;
  background: linear-gradient(180deg, rgba(13, 13, 13, 0.98), rgba(13, 13, 13, 0.82) 72%, rgba(13, 13, 13, 0));
}

.wizard-center {
  min-width: 0;
  text-align: center;
}

.wizard-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.nav-copy {
  flex: 1;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.bottom-save {
  margin-top: 0;
}

.bottom-save .btn {
  width: 100%;
}

.empty-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
}

.custom-select {
  position: relative;
}

.custom-select-button {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--surface-light-border);
  border-radius: var(--radius-md);
  background: var(--surface-light-strong);
  color: #050505;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}

.custom-select.dark .custom-select-button {
  background: #111111;
  color: #f4f4f4;
  border-color: var(--border-strong);
}

.custom-select-button .placeholder {
  color: #5a5a5a;
}

.custom-select.dark .custom-select-button .placeholder {
  color: #9c9c9c;
}

.custom-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface-light-strong);
  color: #050505;
  border: 1px solid var(--surface-light-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: none;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

.custom-select.dark .custom-select-menu {
  background: #0f0f0f;
  color: #f5f5f5;
  border-color: var(--border-strong);
}

.custom-select.open .custom-select-menu {
  display: block;
}

.custom-select-option {
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.custom-select-option:hover,
.custom-select-option.active {
  background: rgba(0, 0, 0, 0.08);
}

.custom-select.dark .custom-select-option:hover,
.custom-select.dark .custom-select-option.active {
  background: rgba(255, 255, 255, 0.08);
}

@media (max-width: 1280px) {
  .split-layout,
  .browse-layout {
    grid-template-columns: 1fr;
  }

  .field-group {
    grid-column: span 6;
  }
}

@media (max-width: 900px) {
  .grid {
    --cell-size: 18px;
    --cell-gap: 2px;
  }

  .board {
    padding: 10px;
  }

  .board-bg {
    inset: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px 8px 18px;
  }

  .screen-header,
  .screen-panel {
    padding-left: 10px;
    padding-right: 10px;
  }

  .screen-header {
    gap: 10px;
    padding-top: 12px;
  }

  .card,
  .subcard {
    padding: 10px;
  }

  .page-stack,
  .stack,
  .sidebar-stack,
  .filter-grid,
  .preview-shell {
    gap: 12px;
  }

  .preview-top {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions,
  .nav-actions {
    justify-content: flex-end;
  }

  .screen-header {
    flex-direction: row;
    align-items: center;
  }

  .nav-strip {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .nav-copy {
    min-width: 0;
    font-size: 0.74rem;
  }

  .range-head {
    align-items: start;
    flex-direction: column;
    gap: 6px;
  }

  .range-wrap {
    height: 38px;
    width: 100%;
  }

  .wizard-bar {
    gap: 8px;
    padding-top: 8px;
  }

  .editor-board-viewport {
    min-height: 360px;
    max-height: 68vh;
  }

  .board {
    padding: 8px;
  }

  .board-bg {
    inset: 8px;
    width: calc(100% - 16px);
    height: calc(100% - 16px);
  }

  .grid {
    --cell-size: max(12px, min(16px, calc((100vw - 138px) / 16)));
    --cell-gap: 2px;
  }

  .legend-row,
  .toggle-group,
  .chip-row {
    gap: 6px;
  }

  .legend-btn,
  .toggle {
    min-height: 40px;
  }

  .field-group,
  .field-group.wide {
    grid-column: span 12;
  }

  .toolbar-row {
    grid-template-columns: minmax(0, 1fr) 42px;
  }
}
