.inline-external-link {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-style: dashed;
  text-decoration-color: currentColor;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  cursor: pointer;
}

.inline-external-link::before {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-right: 4px;
  vertical-align: -0.02em;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 3h8v8M21 3 10 14M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.inline-external-link:hover {
  color: var(--brand);
}

.inline-link-window {
  width: 440px;
  max-width: 100%;
}

.inline-link-window .media-window-body {
  min-height: 0;
  padding: 16px;
}

.inline-link-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.inline-link-label {
  color: var(--secondary);
  font-size: 12px;
}

.inline-link-form input,
.html-local-dialog-panel input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--background);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  box-sizing: border-box;
  transition: border-color 160ms ease;
}

.inline-link-form input:focus,
.html-local-dialog-panel input:focus {
  border-color: var(--brand);
}

.inline-link-error {
  color: #FF0060;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.inline-link-error:empty {
  display: none;
}

.inline-link-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.inline-link-footer > button {
  min-width: 80px;
  height: 36px;
}

#dialog-description {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#sidebar {
  position: relative;
}

.sidebar-auth-footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 12px;
  background: var(--sidebar);
  box-sizing: border-box;
}

.sidebar-auth-button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 40px;
  min-width: 0;
  padding: 0 12px;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  outline: none;
  background: var(--hover);
  color: var(--secondary);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  box-sizing: border-box;
  transition: background 160ms ease, color 160ms ease;
}

.sidebar-auth-button svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.sidebar-auth-button:hover {
  background: var(--surface);
  color: var(--text);
}

#sidebar #tree {
  padding-bottom: 72px;
}

.html-block {
  display: block;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
}

.html-block .html-block-preview {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  aspect-ratio: 16 / 9;
  margin: 0;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 8px;
  outline: none;
  overflow: hidden;
  background: #FFFFFF;
  box-sizing: border-box;
  cursor: auto;
}

.html-preview-frame {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: #FFFFFF;
  box-sizing: border-box;
}

.html-block-preview > .html-preview-frame {
  position: absolute;
  inset: 0;
}

.html-window {
  overflow: hidden;
}

.html-window .media-window-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.html-layout {
  position: relative;
  display: flex;
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.html-stage {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 16px 16px 80px;
  overflow: hidden;
  background: var(--background);
  box-sizing: border-box;
}

.html-stage-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  flex: 1;
  min-width: 0;
  min-height: 0;
  gap: 12px;
  overflow: hidden;
}

.html-stage-content[data-mode="preview"] > .html-code-editor,
.html-stage-content[data-mode="edit"] > .html-editor-preview {
  display: none;
}

.html-stage-content[data-mode="split"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.html-editor-preview {
  display: block;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: #FFFFFF;
  box-sizing: border-box;
}

.html-editor-preview > .html-preview-frame {
  position: absolute;
  inset: 0;
}

.html-toolbar {
  pointer-events: none;
}

.html-toolbar .html-view-toolbar {
  pointer-events: auto;
}

.html-code-editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--sidebar);
  overflow: hidden;
  box-sizing: border-box;
}

.html-code-header {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  gap: 12px;
  border-bottom: 2px solid var(--border);
  box-sizing: border-box;
}

.html-code-filename {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 12px;
}

.html-code-language {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 10px;
}

.html-code-body {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.html-code-gutter {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  min-height: 0;
  overflow: hidden;
  background: var(--background);
  color: var(--muted);
  border-right: 2px solid var(--border);
  box-sizing: border-box;
  user-select: none;
}

.html-code-numbers {
  padding: 12px 8px;
  text-align: right;
  white-space: pre;
  font-family: Consolas, monospace;
  font-size: 14px;
  line-height: 24px;
  box-sizing: border-box;
}

.html-code-surface {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.html-code-highlight,
.html-code-input {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 12px 16px;
  border: 0;
  outline: none;
  border-radius: 0;
  background: transparent;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  font-weight: 400;
  font-style: normal;
  font-variant-ligatures: none;
  line-height: 24px;
  letter-spacing: 0;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  overflow: auto;
  scrollbar-width: none;
  box-sizing: border-box;
}

.html-code-highlight::-webkit-scrollbar,
.html-code-input::-webkit-scrollbar {
  display: none;
}

.html-code-highlight {
  z-index: 0;
  color: #D4D4D4;
  pointer-events: none;
  user-select: none;
}

.html-code-highlight > code.hljs {
  display: block;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #D4D4D4;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  font-style: normal;
  line-height: inherit;
  letter-spacing: inherit;
  tab-size: inherit;
  white-space: inherit;
  overflow: visible;
  box-sizing: border-box;
}

.html-code-input {
  z-index: 1;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--text);
  resize: none;
}

.html-code-input::placeholder {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
}

.html-code-input::selection {
  background: var(--brand-soft);
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.html-code-highlight .hljs span {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  font-style: normal;
  line-height: inherit;
  letter-spacing: inherit;
  background: transparent;
}

.html-code-highlight .hljs-keyword,
.html-code-highlight .hljs-selector-tag,
.html-code-highlight .hljs-literal {
  color: #C586C0;
}

.html-code-highlight .hljs-string,
.html-code-highlight .hljs-regexp,
.html-code-highlight .hljs-template-tag {
  color: #CE9178;
}

.html-code-highlight .hljs-number {
  color: #B5CEA8;
}

.html-code-highlight .hljs-comment,
.html-code-highlight .hljs-quote {
  color: #6A9955;
}

.html-code-highlight .hljs-built_in,
.html-code-highlight .hljs-type,
.html-code-highlight .hljs-title.class_,
.html-code-highlight .hljs-title.class_.inherited__ {
  color: #4EC9B0;
}

.html-code-highlight .hljs-title,
.html-code-highlight .hljs-title.function_,
.html-code-highlight .hljs-function > .hljs-title {
  color: #DCDCAA;
}

.html-code-highlight .hljs-variable,
.html-code-highlight .hljs-property,
.html-code-highlight .hljs-params,
.html-code-highlight .hljs-subst {
  color: #9CDCFE;
}

.html-code-highlight .hljs-variable.constant_,
.html-code-highlight .hljs-variable.language_ {
  color: #4FC1FF;
}

.html-code-highlight .hljs-tag {
  color: #808080;
}

.html-code-highlight .hljs-name {
  color: #569CD6;
}

.html-code-highlight .hljs-attr,
.html-code-highlight .hljs-attribute {
  color: #9CDCFE;
}

.html-code-highlight .hljs-selector-class,
.html-code-highlight .hljs-selector-id,
.html-code-highlight .hljs-selector-attr,
.html-code-highlight .hljs-selector-pseudo {
  color: #D7BA7D;
}

.html-code-highlight .hljs-meta {
  color: #808080;
}

.html-code-highlight .hljs-meta .hljs-keyword {
  color: #569CD6;
}

.html-code-highlight .hljs-symbol,
.html-code-highlight .hljs-bullet,
.html-code-highlight .hljs-template-variable {
  color: #D7BA7D;
}

.html-code-highlight .hljs-operator,
.html-code-highlight .hljs-punctuation {
  color: #D4D4D4;
}

.html-code-highlight .hljs-section {
  color: #569CD6;
}

.html-code-highlight .hljs-link {
  color: #CE9178;
}

.html-code-highlight .hljs-addition {
  color: #B5CEA8;
}

.html-code-highlight .hljs-deletion {
  color: #F44747;
}

.html-code-highlight .language-javascript .hljs-keyword {
  color: #569CD6;
}

.html-code-highlight .language-javascript .hljs-keyword.hljs-control {
  color: #C586C0;
}

.html-code-highlight .language-css .hljs-keyword {
  color: #C586C0;
}

.html-code-highlight .language-css .hljs-attribute {
  color: #9CDCFE;
}

.html-code-highlight .language-css .hljs-number {
  color: #B5CEA8;
}

.html-code-highlight .language-css .hljs-built_in {
  color: #DCDCAA;
}

.html-code-highlight .language-xml .hljs-name {
  color: #569CD6;
}

.html-code-highlight .language-xml .hljs-attr {
  color: #9CDCFE;
}

.html-code-highlight .language-xml .hljs-string {
  color: #CE9178;
}

.html-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 12px;
  overflow: hidden;
  box-sizing: border-box;
}

.html-file-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-width: 0;
  gap: 8px;
}

.html-file-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 12px;
}

.html-file-title svg {
  width: 16px;
  height: 16px;
  color: var(--secondary);
}

.html-file-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: 16px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
}

.html-file-list::-webkit-scrollbar {
  display: none;
}

.html-file-group {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-width: 0;
  gap: 4px;
}

.html-file-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  height: 24px;
  padding: 0 4px;
  gap: 8px;
  box-sizing: border-box;
}

.html-file-group-name {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.html-file-group-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  box-sizing: border-box;
  transition: background 160ms ease, color 160ms ease;
}

.html-file-group-add svg {
  width: 14px;
  height: 14px;
}

.html-file-group-add:hover {
  background: var(--hover);
  color: var(--text);
}

.html-file-group-items {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 4px;
}

.html-file-empty {
  display: flex;
  align-items: center;
  min-height: 28px;
  padding-left: 24px;
  color: var(--muted);
  font-size: 12px;
  box-sizing: border-box;
}

.html-file-row {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
  min-height: 36px;
  gap: 2px;
  border-radius: 4px;
  color: var(--secondary);
  box-sizing: border-box;
  transition: background 160ms ease, color 160ms ease;
}

.html-file-row:hover {
  background: var(--hover);
}

.html-file-row.active {
  background: var(--hover);
  color: var(--text);
}

.html-file-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  height: 28px;
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: grab;
  opacity: 0;
  pointer-events: none;
  box-sizing: border-box;
  transition: opacity 160ms ease, color 160ms ease;
}

.html-file-handle svg {
  width: 14px;
  height: 14px;
}

.html-file-row:hover > .html-file-handle,
.html-file-row:focus-within > .html-file-handle,
.html-file-row.dragging > .html-file-handle {
  opacity: 1;
  pointer-events: auto;
}

.html-file-handle:hover {
  color: var(--text);
}

.html-file-handle:active {
  cursor: grabbing;
}

.html-file-select {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 0 8px 0 0;
  gap: 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
}

.html-file-select > .icon {
  flex-shrink: 0;
}

.html-file-select svg {
  width: 16px;
  height: 16px;
}

.html-file-row.active .html-file-select > .icon {
  color: var(--brand);
}

.html-file-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.html-file-entry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--brand);
}

.html-file-entry svg {
  width: 12px;
  height: 12px;
}

.html-file-row.dragging {
  opacity: 0.4;
}

.html-file-row.drop-before::before,
.html-file-row.drop-after::after {
  content: "";
  position: absolute;
  right: 0;
  left: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--brand);
  pointer-events: none;
}

.html-file-row.drop-before::before {
  top: -2px;
}

.html-file-row.drop-after::after {
  bottom: -2px;
}

.html-file-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 4px;
  padding-top: 12px;
  border-top: 2px solid var(--border);
}

.html-file-actions > button {
  flex: 1;
  min-width: 0;
}

.html-file-actions > button:disabled {
  opacity: 0.3;
  cursor: default;
}

.html-local-dialog-panel {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

body.media-overlay-open #menu-layer {
  z-index: 120;
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
  }

  .sidebar-auth-footer {
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  #sidebar #tree {
    padding-bottom: 64px;
  }

  .inline-link-window {
    width: 100%;
  }

  .inline-link-window .media-window-body {
    padding: 12px;
  }

  .html-stage {
    padding: 8px 8px 64px;
  }

  .html-stage-content {
    gap: 8px;
  }

  .html-code-header {
    height: 36px;
    padding: 0 8px;
  }

  .html-code-gutter {
    width: 36px;
  }

  .html-code-numbers {
    padding: 8px 6px;
    font-size: 12px;
    line-height: 20px;
  }

  .html-code-highlight,
  .html-code-input {
    padding: 8px 12px;
    font-size: 12px;
    line-height: 20px;
  }

  .html-file-list {
    gap: 12px;
  }

  .html-file-handle {
    display: none;
  }

  .html-file-select {
    padding: 0 8px;
  }

  .html-file-empty {
    padding-left: 8px;
  }

  .html-layout.inspector-open .html-preview-frame {
    pointer-events: none;
  }

  .html-editor-block {
    padding-left: 28px;
  }

  .html-editor-block > .block-controls {
    position: absolute;
    top: 0;
    right: auto;
    bottom: auto;
    left: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 28px;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
  }

  .html-editor-block > .block-controls > .block-control:not(.block-more) {
    display: none;
  }

  .html-editor-block > .block-controls > .block-more {
    pointer-events: auto;
  }
}