/* Copyright Quad4 2026
 * SPDX-License-Identifier: 0BSD
 */

html,
body,
#input,
#line-numbers,
#preview-wrap,
.tab-scroll {
  scrollbar-width: thin;
  scrollbar-color: #3a465b #0b0f14;
}

body.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
}

.app-header {
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.app-header .brand {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.app-header .brand a {
  color: var(--text);
  text-decoration: none;
}

.app-header .brand a:hover {
  color: var(--accent);
}

.header-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.header-links a,
.header-links .header-action {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  background: none;
  border: none;
  padding: 0.35rem 0.45rem;
  min-height: 2rem;
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
}

.header-links a:hover,
.header-links .header-action:hover {
  color: var(--text);
  background: var(--accent-dim);
  text-decoration: none;
}

.header-links .header-action.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.show-narrow {
  display: none !important;
}

.tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: #0e1218;
  flex-shrink: 0;
  min-height: 2.5rem;
}

.tab-scroll {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 1.5rem), transparent);
}

.tab-scroll.at-end {
  mask-image: none;
}

.tab-list {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-height: 2.5rem;
  width: max-content;
}

.tab-item {
  display: inline-flex;
  align-items: stretch;
  position: relative;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  max-width: 14rem;
  flex-shrink: 0;
}

.tab-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.tab-item.active {
  background: var(--bg-elevated);
}

.tab-item.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  z-index: 1;
}

.tab-btn,
.tab-close {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
}

.tab-btn {
  padding: 0.55rem 0.35rem 0.55rem 0.75rem;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  min-height: 2.5rem;
}

.tab-item.active .tab-btn {
  color: var(--text);
  font-weight: 500;
}

.tab-btn:focus-visible,
.tab-close:focus-visible,
.tab-add-btn:focus-visible,
.view-btn:focus-visible,
.tool-btn:focus-visible,
.header-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  min-width: 2rem;
  padding: 0;
  line-height: 1;
  border-radius: var(--radius);
  margin: 0.35rem 0.3rem 0.35rem 0;
  opacity: 0.55;
}

.tab-item:hover .tab-close,
.tab-item.active .tab-close,
.tab-close:focus-visible {
  opacity: 1;
}

.tab-close:hover {
  color: var(--danger);
  background: rgba(248, 81, 73, 0.14);
}

.tab-add-btn {
  flex: 0 0 auto;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  width: 2.5rem;
  min-width: 2.5rem;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}

.tab-add-btn:hover {
  color: var(--accent);
  background: var(--accent-dim);
}

.mobile-viewbar {
  display: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  padding: 0.35rem 0.5rem;
  gap: 0.35rem;
}

.view-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.45rem 0.5rem;
  min-height: 2.4rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.view-btn.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.editor-toolbar .tool-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.75rem;
  font-family: inherit;
  padding: 0.35rem 0.55rem;
  min-height: 2rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.editor-toolbar .tool-btn:hover {
  border-color: var(--accent);
}

.editor-toolbar .tool-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.editor-toolbar .tool-sep {
  width: 1px;
  height: 1.1rem;
  background: var(--border);
  margin: 0 0.15rem;
}

.editor-toolbar .tool-meta {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.layout {
  --left-size: 50%;
  flex: 1;
  display: flex;
  min-height: 0;
  width: 100%;
}

body.preview-only .layout #source-pane,
body.preview-only .layout #splitter {
  display: none !important;
}

body.preview-only .layout #preview-pane {
  flex: 1 1 100%;
  max-width: 100%;
  border: none;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#source-pane {
  flex: 0 0 var(--left-size);
  min-width: 180px;
  border-right: 1px solid var(--border);
}

#preview-pane {
  flex: 1 1 auto;
  min-width: 180px;
}

.splitter {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--border);
  user-select: none;
  touch-action: none;
}

.splitter:hover,
.splitter:focus-visible {
  background: var(--accent);
}

.pane-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  font-family: var(--mono);
  flex-shrink: 0;
}

.pane-title .pane-stat {
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.editor-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--panel);
  overflow: hidden;
}

.editor-stack {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.editor-mirror {
  display: none;
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0.75rem;
  border: none;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  background: var(--panel);
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--editor-font-size, 0.875rem);
  line-height: 1.45;
  white-space: pre;
  overflow-wrap: normal;
  tab-size: 2;
  -webkit-text-size-adjust: 100%;
}

.editor-mirror.wrap-on {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.editor-stack.colors-on .editor-mirror {
  display: block;
}

.editor-stack.colors-on #input {
  color: transparent;
  caret-color: var(--text);
  background: transparent;
}

.mu-color-slot {
  color: transparent;
}

.color-decos {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}

.color-decos.color-decos-off {
  display: none;
}

.color-swatch {
  position: absolute;
  width: 0.95rem;
  height: 0.95rem;
  padding: 0;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.65);
  appearance: none;
  -webkit-appearance: none;
  vertical-align: middle;
}

.color-swatch::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-swatch::-webkit-color-swatch {
  border: none;
  border-radius: 1px;
}

.color-swatch::-moz-color-swatch {
  border: none;
  border-radius: 1px;
}

.color-swatch.color-swatch-invalid {
  background-image:
    linear-gradient(45deg, #444 25%, transparent 25%),
    linear-gradient(-45deg, #444 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #444 75%),
    linear-gradient(-45deg, transparent 75%, #444 75%);
  background-size: 6px 6px;
  background-position: 0 0, 0 3px, 3px -3px, -3px 0;
  background-color: #222;
}

.color-swatch.color-swatch-invalid::-webkit-color-swatch {
  opacity: 0.35;
}

.color-swatch:hover,
.color-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 3;
}

#line-numbers,
.line-numbers {
  flex: 0 0 auto;
  min-width: 2.75rem;
  margin: 0;
  padding: 0.75rem 0.2rem 0.75rem 0.35rem;
  border: none;
  border-right: 1px solid var(--border);
  background: #0a0c10;
  color: #5c6775;
  font-family: var(--mono);
  font-size: var(--editor-font-size, 0.875rem);
  line-height: 1.45;
  text-align: right;
  overflow: hidden;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.line-numbers .ln {
  appearance: none;
  display: block;
  width: 100%;
  height: calc(var(--editor-font-size, 0.875rem) * 1.45);
  margin: 0;
  padding: 0 0.35rem 0 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: right;
  cursor: pointer;
  flex: 0 0 auto;
}

.line-numbers .ln:hover,
.line-numbers .ln:focus-visible {
  color: var(--accent);
  outline: none;
  background: rgba(88, 166, 255, 0.08);
}

.line-numbers .ln.active {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.14);
}

#input {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0;
  padding: 0.75rem;
  border: none;
  resize: none;
  background: var(--panel);
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--editor-font-size, 0.875rem);
  line-height: 1.45;
  outline: none;
  overflow: auto;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  -webkit-text-size-adjust: 100%;
  position: relative;
  z-index: 1;
}

#input.wrap-on {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#preview-wrap {
  flex: 1;
  overflow: auto;
  padding: 0.75rem;
  background: var(--panel);
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

#preview {
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  flex: 1 1 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  width: 100%;
}

#preview > .Mu-root,
#preview > div[dir="auto"] {
  flex: 1 1 auto;
  min-height: 100%;
  width: 100%;
  box-sizing: border-box;
}

.mu-line-flash {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
  transition: outline-color 0.2s ease;
}

.diag-panel {
  flex-shrink: 0;
  max-height: 28%;
  overflow: auto;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 0.4rem 0.75rem 0.6rem;
  font-size: 0.75rem;
}

.diag-panel.diag-collapsed {
  max-height: none;
  overflow: hidden;
  padding-bottom: 0.35rem;
}

.diag-panel.diag-collapsed #diag-body {
  display: none;
}

.diag-panel.diag-hidden {
  display: none;
}

.diag-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.diag-toggle {
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.diag-toggle:hover,
.diag-toggle:focus-visible {
  color: var(--accent);
  outline: none;
}

.diag-close {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
}

.diag-close:hover,
.diag-close:focus-visible {
  color: var(--accent);
  outline: none;
}

.diag-title #diag-count {
  font-weight: 500;
  opacity: 0.8;
}

#diag-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.diag-item {
  cursor: pointer;
  padding: 0.2rem 0;
  border-bottom: 1px solid transparent;
  color: var(--text);
}

.diag-item:hover,
.diag-item:focus {
  color: var(--accent);
  outline: none;
}

.diag-item.diag-warning {
  color: #d4a017;
}

.diag-item.diag-error {
  color: #e35d6a;
}

.Mu-nl {
  cursor: pointer;
  text-decoration: underline;
  color: var(--accent);
}

.Mu-mnt {
  display: inline-block;
  width: 0.6em;
  text-align: center;
  white-space: pre;
  text-decoration: inherit;
  font-variant-numeric: tabular-nums;
}

.Mu-mws {
  text-decoration: inherit;
  display: inline-block;
  white-space: pre-wrap;
}

.Mu-mnt-group {
  display: inline;
  white-space: pre-wrap;
  text-decoration: inherit;
  vertical-align: baseline;
}

.Mu-partial {
  display: block;
  min-height: 1.2em;
}

.Mu-partial.pending {
  opacity: 0.85;
}

.Mu-partial.error {
  color: var(--danger);
}

#preview input.Mu-armed {
  outline: 1px dashed var(--warn);
  outline-offset: 1px;
}

#preview textarea {
  font: inherit;
  color: inherit;
  background: inherit;
}

#preview textarea.Mu-multiline {
  outline: 1px solid #34d399;
  outline-offset: 1px;
  resize: vertical;
}

#multiline-hint {
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom, 0));
  right: calc(12px + env(safe-area-inset-right, 0));
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  background: var(--warn);
  color: #111;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.15s;
}

#multiline-hint.visible {
  opacity: 1;
}

#context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 11rem;
  max-width: min(18rem, calc(100vw - 1rem));
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: none;
}

#context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.85rem;
  min-height: 2.4rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

#context-menu button:hover {
  background: var(--accent-dim);
}

#context-menu .ctx-hint {
  padding: 0.35rem 0.85rem 0.15rem;
  font-size: 0.7rem;
  color: var(--muted);
  pointer-events: none;
}

.bench-page {
  padding: 1.25rem;
  max-width: 48rem;
}

.bench-page h1 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.bench-page .lede {
  margin: 0 0 1.1rem;
  color: var(--muted);
}

.bench-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.bench-status {
  font-size: 0.86rem;
  color: var(--muted);
  font-family: var(--mono);
}

.bench-status.running {
  color: var(--accent);
}

.bench-status.ok {
  color: var(--ok);
}

.bench-status.err {
  color: var(--danger);
}

.bench-out {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .mobile-viewbar {
    display: flex;
  }

  .hide-narrow {
    display: none !important;
  }

  .show-narrow {
    display: inline-flex !important;
  }

  .layout {
    flex-direction: column;
  }

  .splitter {
    display: none !important;
  }

  #source-pane,
  #preview-pane {
    min-width: 0;
    border-right: none;
    flex: 1 1 auto;
  }

  #source-pane {
    border-bottom: 1px solid var(--border);
  }

  body.mview-source .layout #preview-pane {
    display: none !important;
  }

  body.mview-source .layout #source-pane {
    border-bottom: none;
    flex: 1 1 100%;
  }

  body.mview-preview .layout #source-pane {
    display: none !important;
  }

  body.mview-preview .layout #preview-pane {
    flex: 1 1 100%;
  }

  body.mview-split .layout #source-pane,
  body.mview-split .layout #preview-pane {
    flex: 1 1 50%;
    min-height: 0;
  }

  body.preview-only.mview-source .layout #source-pane {
    display: flex !important;
  }

  body.preview-only.mview-source .layout #preview-pane {
    display: none !important;
  }

  #line-numbers {
    display: none;
  }

  .tab-btn {
    max-width: 8.5rem;
    padding-left: 0.6rem;
  }

  .tab-close {
    opacity: 1;
  }
}

@media (max-width: 520px) {
  .hide-xs {
    display: none !important;
  }

  .app-header {
    padding: 0.45rem 0.65rem;
  }

  .editor-toolbar .tool-meta {
    width: 100%;
    margin-left: 0;
    order: 10;
  }

  .tab-item {
    max-width: 10rem;
  }
}
