/**
 * Overlay Editor Styles
 * Two-layer architecture: transparent input + syntax-highlighted background
 */

:root {
  --editor-padding-top: 8px;
  --editor-padding-left: 16px;
  --editor-padding-bottom: 8px;
  --editor-padding-right: 16px;
}

.overlay-editor-container {
  position: relative;
  min-height: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
}

/* Background layer - syntax highlighted, read-only */
.highlight-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
  padding: var(--editor-padding-top) var(--editor-padding-right) var(--editor-padding-bottom)
    var(--editor-padding-left);
  white-space: pre;
  word-wrap: break-word;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  color: var(--color-text, var(--text, #d4d4d4));
  font-kerning: none;
  font-variant-ligatures: none;
  font-feature-settings:
    "liga" 0,
    "calt" 0,
    "tnum" 1;
  letter-spacing: 0;
  text-rendering: optimizeSpeed;
}

.highlight-layer *,
.selection-layer,
.selection-layer * {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
}

/* Syntax colors must not change glyph metrics; selection/caret geometry is measured per font. */
.highlight-layer [class*="token-"] {
  font-style: inherit !important;
  font-weight: inherit !important;
}

.highlight-layer .token-markdown-code {
  padding: 0;
  border-radius: 0;
  background: transparent;
}

/* Foreground layer - transparent text, visible caret */
.input-layer {
  position: absolute;
  inset: 0;
  overflow: auto;
  z-index: 3;
  padding: var(--editor-padding-top) var(--editor-padding-right) var(--editor-padding-bottom)
    var(--editor-padding-left);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: transparent;
  caret-color: var(--text, #d4d4d4);
  white-space: pre;
  word-wrap: break-word;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  tab-size: inherit;
  font-kerning: none;
  font-variant-ligatures: none;
  font-feature-settings:
    "liga" 0,
    "calt" 0,
    "tnum" 1;
  letter-spacing: 0;
  text-rendering: optimizeSpeed;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;

  scroll-behavior: auto;
  scrollbar-gutter: stable;
}

@supports not selector(::-webkit-scrollbar) {
  .input-layer {
    scrollbar-color: var(--app-scrollbar-thumb, rgba(128, 128, 128, 0.42)) transparent;
    scrollbar-width: thin;
  }
}

/* Keep passive layers visually clean */
.highlight-layer::-webkit-scrollbar {
  display: none;
}

.highlight-layer {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.input-layer::-webkit-scrollbar {
  -webkit-appearance: none !important;
  width: var(--app-scrollbar-size, 11px) !important;
  height: var(--app-scrollbar-size, 11px) !important;
  background-color: transparent !important;
  cursor: default;
}

.input-layer::-webkit-scrollbar-track {
  -webkit-appearance: none !important;
  background-color: transparent !important;
  cursor: default;
}

.input-layer::-webkit-scrollbar-thumb {
  -webkit-appearance: none !important;
  background-color: rgba(128, 128, 128, 0.42) !important;
  background-color: var(--app-scrollbar-thumb, rgba(128, 128, 128, 0.42)) !important;
  border: var(--app-scrollbar-thumb-border, 3px solid transparent) !important;
  border-radius: var(--app-scrollbar-radius, 999px) !important;
  background-clip: content-box !important;
  transition: background-color 0.18s ease;
  cursor: default;
}

.input-layer:hover::-webkit-scrollbar-thumb,
.input-layer:focus::-webkit-scrollbar-thumb,
.input-layer:focus-within::-webkit-scrollbar-thumb {
  background-color: rgba(128, 128, 128, 0.58) !important;
  background-color: var(--app-scrollbar-thumb-hover, rgba(128, 128, 128, 0.58)) !important;
  border: 2px solid transparent !important;
  background-clip: content-box !important;
}

.input-layer::-webkit-scrollbar-thumb:hover {
  background-color: rgba(160, 160, 160, 0.7) !important;
  background-color: var(--app-scrollbar-thumb-hover, rgba(160, 160, 160, 0.7)) !important;
  border: 2px solid transparent !important;
  background-clip: content-box !important;
}

.input-layer::-webkit-scrollbar-corner {
  background-color: transparent !important;
  cursor: default;
}

/* Native selection styling for wrapped mode */
.input-layer.native-selection::selection {
  background: rgba(106, 155, 204, 0.42);
  background: color-mix(in srgb, var(--accent, #6a9bcc) 44%, transparent);
  color: transparent;
}

.input-layer.native-selection::-moz-selection {
  background: rgba(106, 155, 204, 0.42);
  background: color-mix(in srgb, var(--accent, #6a9bcc) 44%, transparent);
  color: transparent;
}

.input-layer.selection-transparent::selection,
textarea.input-layer.selection-transparent::selection {
  background: transparent !important;
  color: transparent !important;
}

.input-layer.selection-transparent::-moz-selection,
textarea.input-layer.selection-transparent::-moz-selection {
  background: transparent !important;
  color: transparent !important;
}

.editor-bracket-match {
  position: absolute;
  box-sizing: border-box;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--accent, #6a9bcc) 72%, transparent);
  border-radius: 0;
  background: transparent;
}

.editor-bracket-match-unmatched {
  border-bottom-color: color-mix(in srgb, var(--color-error, #ef4444) 72%, transparent);
  background: transparent;
}

.editor-word-highlight,
.editor-word-highlight-current {
  position: absolute;
  box-sizing: border-box;
  border-radius: 3px;
  background: color-mix(in srgb, var(--color-text, #d4d4d4) 10%, transparent);
}

.editor-word-highlight-current {
  border: 1px solid color-mix(in srgb, var(--color-text, #d4d4d4) 18%, transparent);
}

.editor-current-line {
  position: absolute;
  right: 0;
  left: 0;
  box-sizing: border-box;
  border: 0;
  background: color-mix(in srgb, var(--color-text, #d4d4d4) 5%, transparent);
}

.editor-indent-guide {
  position: absolute;
  width: 1px;
  background: color-mix(in srgb, var(--color-border, #8a8f98) 42%, transparent);
}

.editor-indent-guide-active {
  background: color-mix(in srgb, var(--accent, #6a9bcc) 52%, transparent);
}

.editor-visible-whitespace {
  position: relative;
}

.editor-visible-whitespace::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  color: color-mix(in srgb, var(--color-text-lighter, #8a8f98) 56%, transparent);
  pointer-events: none;
}

.editor-visible-whitespace-space::after {
  justify-content: center;
  content: "·";
}

.editor-visible-whitespace-tab::after {
  justify-content: flex-start;
  content: "→";
}

/* Line structure in highlight layer */
.highlight-layer-line {
  display: block;
  min-height: 1em;
  line-height: inherit;
  box-sizing: border-box;
}

.inlay-hint {
  display: inline-flex;
  align-items: center;
  margin: 0 2px;
  padding: 0 3px;
  max-height: 1.45em;
  border: 1px solid color-mix(in srgb, var(--color-border, #8a8f98) 42%, transparent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--color-primary-bg, #ffffff) 94%, transparent);
  color: var(--color-text-lighter, #8a8f98);
  font-size: 0.85em;
  line-height: 1.25;
  vertical-align: 0.08em;
  box-shadow: 0 1px 3px color-mix(in srgb, #000 12%, transparent);
}

.diagnostic-decoration {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-thickness: 1.4px;
  text-underline-offset: 3px;
}

.diagnostic-error {
  text-decoration-color: var(--error, #f85149);
}

.diagnostic-warning {
  text-decoration-color: var(--warning, #d29922);
}

.diagnostic-info {
  text-decoration-color: var(--info, #58a6ff);
}

.editor-selection-box {
  background-color: rgba(106, 155, 204, 0.42);
  background-color: color-mix(in srgb, var(--accent, #6a9bcc) 44%, transparent);
  border-radius: 4px;
}

@supports not (background-color: color-mix(in srgb, #6a9bcc 44%, transparent)) {
  .editor-selection-box {
    background-color: rgba(106, 155, 204, 0.42);
  }
}

/* Multi-cursor layer */
.multi-cursor-layer {
  padding: var(--editor-padding-top) var(--editor-padding-right) var(--editor-padding-bottom)
    var(--editor-padding-left);
}

/* Git blame layer */
.git-blame-layer {
  padding: var(--editor-padding-top) var(--editor-padding-right) var(--editor-padding-bottom)
    var(--editor-padding-left);
}

/* Cursor blink animation */
@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.animate-blink {
  animation: blink 1s step-end infinite;
}
