:root {
  color-scheme: dark;
  --bg: #0b1116;
  --panel: rgba(23, 35, 43, 0.92);
  --text: #f7f4e8;
  --muted: #bac7c4;
  --line: rgba(247, 244, 232, 0.15);
  --yellow: #f4c430;
  --green: #7fd15b;
  --blue: #78c6ff;
  --pink: #ff8fbd;
  --orange: #ffae73;
  --mark: rgba(244, 196, 48, 0.18);
  --mark-strong: rgba(244, 196, 48, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.workspace {
  min-height: 100svh;
  width: 100%;
  overflow-x: hidden;
}

.bubble {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: auto;
  z-index: 20;
  width: calc(100vw - 20px);
  max-width: calc(100vw - 20px);
  margin: 0 auto;
  border: 1px solid rgba(247, 244, 232, 0.22);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
}

.counter {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

p {
  margin-top: 0;
}

.bubble p {
  max-height: 22svh;
  margin-bottom: 12px;
  overflow: auto;
  color: #e7efe8;
  font-size: 0.94rem;
  line-height: 1.42;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.nav-button {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(247, 244, 232, 0.08);
  color: var(--text);
  cursor: pointer;
}

.nav-button.primary {
  border-color: rgba(244, 196, 48, 0.55);
  background: #f4c430;
  color: #151200;
  font-weight: 800;
}

.nav-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.code-area {
  min-width: 0;
  width: 100%;
  overflow-x: hidden;
}

.source-stack {
  min-height: 100svh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  padding: calc(172px + env(safe-area-inset-top)) 0 44px;
  background: #0b1116;
  color: var(--text);
  font: 0.82rem/1.58 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.source-file {
  scroll-margin-top: 188px;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
  border-top: 1px solid rgba(247, 244, 232, 0.12);
}

.source-file h2 {
  position: sticky;
  top: calc(156px + env(safe-area-inset-top));
  z-index: 8;
  margin: 0;
  border-bottom: 1px solid rgba(247, 244, 232, 0.12);
  padding: 9px 12px;
  background: rgba(11, 17, 22, 0.88);
  color: var(--yellow);
  font: 800 0.86rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  backdrop-filter: blur(12px);
}

.source-file.active-file h2 {
  color: #ffe27c;
  background: rgba(45, 42, 22, 0.9);
}

.code-view {
  display: block;
  width: 100%;
  max-width: 100vw;
  margin: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 0 18px;
  tab-size: 2;
  -webkit-overflow-scrolling: touch;
}

.code-view code {
  display: block;
  width: max-content;
  min-width: 100%;
}

.code-line {
  display: grid;
  grid-template-columns: 44px max-content;
  width: max-content;
  min-width: 100%;
  padding-right: 16px;
  scroll-margin-top: 204px;
}

.line-no {
  position: sticky;
  left: 0;
  z-index: 1;
  padding-right: 8px;
  background: #0b1116;
  color: #66747c;
  text-align: right;
  user-select: none;
}

.line-code {
  padding-left: 10px;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

.line-code .hljs,
.line-code [class^="hljs-"],
.line-code [class*=" hljs-"] {
  white-space: pre;
}

.line-code .hljs {
  display: inline;
  padding: 0;
  background: transparent;
}

.code-line.focused {
  background: var(--mark);
}

.code-line.focused .line-no {
  background: #2d2a16;
  color: #ffe27c;
}

.code-line.primary-focus {
  background: var(--mark-strong);
}

.image-view {
  min-height: 78svh;
  display: grid;
  place-items: center;
  padding: 24px 12px 42px;
}

.image-view img {
  width: min(100%, 520px);
  max-height: 72svh;
  border: 1px solid rgba(247, 244, 232, 0.2);
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
}

.source-file.focused-image .image-view img {
  border-color: rgba(244, 196, 48, 0.78);
  box-shadow:
    0 0 0 5px rgba(244, 196, 48, 0.16),
    0 24px 70px rgba(0, 0, 0, 0.36);
}

.load-error {
  margin: 220px 12px 0;
  border: 1px solid rgba(255, 143, 189, 0.5);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 143, 189, 0.12);
  color: #ffe0eb;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

@media (min-width: 900px) {
  .bubble {
    left: 24px;
    right: auto;
    width: min(430px, calc(100vw - 48px));
  }

  .source-stack {
    padding-top: 24px;
    padding-left: 470px;
    font-size: 0.9rem;
  }

  .source-file {
    scroll-margin-top: 28px;
  }

  .source-file h2 {
    top: 0;
  }

  .code-line {
    scroll-margin-top: 40px;
  }
}
