:root {
  --bg-primary: #1e1e2e;
  --bg-secondary: #181825;
  --bg-surface: #313244;
  --bg-hover: #45475a;
  --text-primary: #cdd6f4;
  --text-secondary: #a6adc8;
  --text-muted: #6c7086;
  --accent: #89b4fa;
  --accent-hover: #74c7ec;
  --highlight: #f9e2af;
  --highlight-bg: rgba(249, 226, 175, 0.15);
  --modified-color: #f38ba8;
  --modified-bg: rgba(243, 139, 168, 0.15);
  --selection-bg: rgba(137, 180, 250, 0.3);
  --border: #45475a;
  --gutter-bg: #11111b;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --row-height: 22px;
  --sr-accent: #a6e3a1;
  --sr-accent-dim: rgba(166, 227, 161, 0.15);
  --sr-panel-width: 360px;
}

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

body {
  font-family: var(--font-mono);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
}

header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toolbar button {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: background 0.15s;
}

.toolbar button:hover:not(:disabled) {
  background: var(--bg-hover);
}

.toolbar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar label {
  font-size: 12px;
  color: var(--text-secondary);
}

.toolbar input[type="text"] {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  width: 160px;
}

.toolbar input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.toolbar select {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#welcomeScreen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-content {
  text-align: center;
}

.welcome-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.welcome-content h2 {
  font-size: 24px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-content p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 14px;
}

#welcomeOpenBtn {
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#welcomeOpenBtn:hover {
  background: var(--accent-hover);
}

.hidden {
  display: none !important;
}

#editorContainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.info-bar {
  display: flex;
  gap: 16px;
  padding: 4px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

#modifiedIndicator {
  color: var(--modified-color);
  font-weight: 600;
}

.editor-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.editor-layout {
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.offset-gutter {
  background: var(--gutter-bg);
  color: var(--text-muted);
  padding: 4px 12px;
  font-size: 13px;
  line-height: var(--row-height);
  user-select: none;
  border-right: 1px solid var(--border);
  white-space: pre;
  overflow: hidden;
}

.hex-view {
  flex: 1;
  padding: 4px 8px;
  font-size: 13px;
  line-height: var(--row-height);
  white-space: pre;
  overflow: hidden;
  cursor: text;
  outline: none;
  position: relative;
}

.ascii-view {
  padding: 4px 12px;
  font-size: 13px;
  line-height: var(--row-height);
  white-space: pre;
  overflow: hidden;
  border-left: 1px solid var(--border);
  color: var(--text-secondary);
  user-select: none;
  min-width: 160px;
}

.hex-byte {
  display: inline-block;
  width: 26px;
  text-align: center;
  border-radius: 2px;
  cursor: pointer;
}

.hex-byte:hover {
  background: var(--bg-hover);
}

.hex-byte.selected {
  background: var(--selection-bg);
  color: var(--accent);
}

.hex-byte.cursor {
  background: var(--accent);
  color: var(--bg-primary);
}

.hex-byte.modified {
  color: var(--modified-color);
  background: var(--modified-bg);
}

.hex-byte.search-match {
  background: var(--highlight-bg);
  color: var(--highlight);
}

.hex-byte.search-current {
  background: var(--highlight);
  color: var(--bg-primary);
}

.hex-group-space {
  display: inline-block;
  width: 8px;
}

.ascii-char {
  display: inline-block;
  width: 9px;
  text-align: center;
}

.ascii-char.selected {
  background: var(--selection-bg);
}

.ascii-char.non-printable {
  color: var(--text-muted);
}

.scrollbar-container {
  padding: 2px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.scrollbar-container input[type="range"] {
  width: 100%;
  height: 16px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.scrollbar-container input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--bg-surface);
  border-radius: 3px;
}

.scrollbar-container input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 14px;
  width: 40px;
  background: var(--text-muted);
  border-radius: 3px;
  margin-top: -4px;
}

.scrollbar-container input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--text-secondary);
}

.status-bar {
  display: flex;
  gap: 24px;
  padding: 4px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

/* Dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  min-width: 300px;
}

.dialog h3 {
  margin-bottom: 12px;
  color: var(--accent);
  font-size: 16px;
}

.dialog label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.dialog input[type="text"] {
  width: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 14px;
  margin-bottom: 16px;
}

.dialog input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-buttons button {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
}

.dialog-buttons button:last-child {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 600;
}

.dialog-buttons button:hover {
  opacity: 0.85;
}

/* Shadowrun toolbar button */
#srToggleBtn {
  background: var(--sr-accent-dim);
  color: var(--sr-accent);
  border-color: var(--sr-accent);
}

#srToggleBtn:hover {
  background: var(--sr-accent);
  color: var(--bg-primary);
}

#srToggleBtn.sr-btn-active {
  background: var(--sr-accent);
  color: var(--bg-primary);
  font-weight: 600;
}

/* =============================================
   Shadowrun Overlay
   ============================================= */

/* Backdrop */
.sr-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
}

/* Overlay panel — centered modal */
.sr-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 720px;
  max-width: 92vw;
  height: 540px;
  max-height: 85vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  z-index: 210;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.sr-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
}

.sr-overlay-title-area {
  display: flex;
  flex-direction: column;
}

.sr-overlay-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--sr-accent);
}

.sr-overlay-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.sr-overlay-header-btns {
  display: flex;
  gap: 4px;
}

.sr-header-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: all 0.15s;
}

.sr-header-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.sr-header-btn.sr-close-btn:hover {
  color: var(--modified-color);
}

/* Body: nav + content */
.sr-overlay-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Category navigation sidebar */
.sr-nav {
  width: 120px;
  min-width: 120px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 4px 0;
}

.sr-nav::-webkit-scrollbar {
  width: 4px;
}

.sr-nav::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 2px;
}

.sr-nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: left;
  transition: all 0.1s;
  width: 100%;
}

.sr-nav-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.sr-nav-btn.sr-nav-active {
  background: var(--bg-surface);
  color: var(--sr-accent);
  border-left-color: var(--sr-accent);
  font-weight: 600;
}

.sr-nav-icon {
  font-size: 13px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sr-nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Content area */
.sr-content-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
}

.sr-content-area::-webkit-scrollbar {
  width: 6px;
}

.sr-content-area::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.sr-content-area::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

/* Category panels */
.sr-cat-panel {
  /* shown/hidden via JS */
}

/* RE Context box */
.sr-context-box {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.sr-context-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sr-context-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--sr-accent);
}

.sr-context-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 8px;
  transition: all 0.15s;
}

.sr-context-toggle:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.sr-context-desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.sr-context-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sr-context-detail-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.sr-context-detail-text {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  font-style: italic;
}

/* Editor fields */
.sr-cat-fields {
  /* container for generated fields */
}

.sr-subhead {
  font-size: 11px;
  font-weight: 600;
  color: var(--sr-accent);
  margin-top: 10px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sr-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.sr-field label {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.sr-input {
  width: 64px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 3px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
}

.sr-input:focus {
  outline: none;
  border-color: var(--sr-accent);
}

.sr-input-wide {
  width: 96px;
}

.sr-input::-webkit-inner-spin-button,
.sr-input::-webkit-outer-spin-button {
  opacity: 1;
  height: 18px;
}

.sr-addr {
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  min-width: 70px;
  text-align: right;
}

.sr-addr:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Select dropdown */
.sr-select {
  width: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  margin-bottom: 8px;
}

.sr-select:focus {
  outline: none;
  border-color: var(--sr-accent);
}

/* Hack toggle switches */
.sr-hack-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.sr-hack-label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-width: 0;
}

.sr-hack-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-hack-detail {
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
  font-family: var(--font-mono);
}

.sr-toggle {
  position: relative;
  display: inline-block;
  width: 32px;
  min-width: 32px;
  height: 18px;
}

.sr-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.sr-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-surface);
  border-radius: 9px;
  transition: background 0.2s;
}

.sr-toggle-slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.sr-toggle input:checked + .sr-toggle-slider {
  background: var(--sr-accent-dim);
}

.sr-toggle input:checked + .sr-toggle-slider::before {
  transform: translateX(14px);
  background: var(--sr-accent);
}

/* Checksum section */
.sr-checksum-val {
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
  min-width: 60px;
}

.sr-checksum-status {
  font-size: 11px;
  padding: 4px 0;
  font-weight: 600;
}

.sr-checksum-status.sr-valid {
  color: var(--sr-accent);
}

.sr-checksum-status.sr-invalid {
  color: var(--modified-color);
}

.sr-btn-row {
  padding-top: 6px;
}

.sr-btn {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  transition: background 0.15s;
}

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

/* Responsive */
@media (max-width: 768px) {
  .ascii-view {
    display: none;
  }
  .toolbar {
    gap: 4px;
  }
  .toolbar input[type="text"] {
    width: 100px;
  }
  .sr-overlay {
    width: 96vw;
    height: 90vh;
    max-width: 96vw;
    max-height: 90vh;
  }
  .sr-nav {
    width: 40px;
    min-width: 40px;
  }
  .sr-nav-label {
    display: none;
  }
  .sr-nav-icon {
    font-size: 16px;
  }
}
