.r-platform {
  --r-code-font: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --r-syntax-keyword: #702a86;
  --r-syntax-string: #206144;
  --r-syntax-number: #8b4217;
  --r-syntax-comment: #526674;
  --r-syntax-operator: #405e75;
  --r-syntax-boolean: #6b3987;
  --r-syntax-function: #215a86;
  --r-syntax-builtin: #225c68;
  --r-syntax-constant: #8a3c46;
  --r-syntax-punctuation: #4d6271;
  --r-selection: #bcd8e9;
}

html[data-theme="dark"] .r-platform {
  --r-syntax-keyword: #d9b2ef;
  --r-syntax-string: #91dcb5;
  --r-syntax-number: #f3be8a;
  --r-syntax-comment: #a4b6c3;
  --r-syntax-operator: #acd0e3;
  --r-syntax-boolean: #dcb6ef;
  --r-syntax-function: #9bcdf1;
  --r-syntax-builtin: #92d2d7;
  --r-syntax-constant: #f0b2bd;
  --r-syntax-punctuation: #b4c7d2;
  --r-selection: #395d79;
}

body.r-platform-page #main.r-platform {
  max-width: 1440px;
}

.r-platform .r-platform__intro {
  margin-bottom: clamp(1.5rem, 4vw, 2.5rem);
}

.r-platform .r-platform__back {
  display: inline-block;
  margin-bottom: .85rem;
  font-weight: 650;
  text-underline-offset: 3px;
}

.r-platform .r-platform__intro h1 {
  font-size: clamp(2rem, 5vw, 2.75rem);
  line-height: 1.15;
  margin: 0 0 .55rem;
}

.r-platform .r-platform__intro p {
  color: var(--xi-muted);
  margin: 0;
  max-width: 43rem;
}

.r-platform .r-platform__workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
  gap: 1rem;
}

.r-platform .r-platform__results {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  min-width: 0;
}

.r-platform .r-platform__panel {
  background: var(--xi-surface-raised);
  border: 1px solid var(--xi-border);
  border-radius: var(--xi-radius);
  box-shadow: var(--xi-shadow-soft);
  min-width: 0;
  padding: clamp(1rem, 3vw, 1.35rem);
  margin: 0;
}

.r-platform .r-platform__editor {
  display: flex;
  flex-direction: column;
}

.r-platform .r-platform__heading {
  color: var(--xi-ink);
  font-size: 1.12rem;
  line-height: 1.3;
  margin: 0 0 .75rem;
}

.r-platform .r-platform__heading label {
  color: inherit;
  font: inherit;
  font-weight: inherit;
  margin: 0;
}

.r-platform .r-platform__editor-heading {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .75rem;
  justify-content: space-between;
  margin-bottom: .75rem;
}

.r-platform .r-platform__editor-heading .r-platform__heading {
  margin: 0;
}

.r-platform #r-line-count {
  color: var(--xi-muted);
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}

.r-platform .r-platform__code-frame {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-width: 0;
}

.r-platform .r-platform__code-area {
  display: flex;
  flex: 0 0 auto;
  isolation: isolate;
  min-width: 0;
  position: relative;
}

.r-platform #r-code,
.r-platform #r-code-highlight,
.r-platform #r-code-lines,
.r-platform #r-output,
.r-platform #r-package-details {
  border: 1px solid var(--xi-border);
  border-radius: .65rem;
  box-shadow: none;
  font-family: var(--r-code-font);
  font-size: .875rem;
  line-height: 1.65;
  margin: 0;
  overflow: auto;
  padding: .8rem;
  tab-size: 2;
}

.r-platform #r-code {
  background: var(--xi-bg);
  color: var(--xi-ink);
  flex: 1 1 auto;
  min-height: 17rem;
  min-width: 0;
  position: relative;
  resize: vertical;
  width: 100%;
  z-index: 1;
}

.r-platform #r-code,
.r-platform #r-code-highlight,
.r-platform #r-code-lines {
  box-sizing: border-box;
  font-variant-ligatures: none;
  font-weight: 400;
  font-style: normal;
  letter-spacing: normal;
  overflow-wrap: normal;
  text-indent: 0;
  white-space: pre;
  word-break: normal;
  word-spacing: normal;
}

.r-platform #r-code,
.r-platform #r-code-highlight {
  border-start-start-radius: 0;
  border-end-start-radius: 0;
}

.r-platform #r-code-lines {
  background: var(--xi-surface-soft);
  border-inline-end: 0;
  border-start-end-radius: 0;
  border-end-end-radius: 0;
  color: var(--xi-muted);
  contain: size;
  inline-size: calc(var(--r-line-number-chars, 2) * 1ch + 1.15rem);
  min-block-size: 0;
  overflow: hidden;
  /* Reserve scroll space when the textarea's horizontal scrollbar is visible. */
  padding-block-end: 2.8rem;
  padding-inline: .55rem;
  pointer-events: none;
  text-align: end;
  user-select: none;
}

.r-platform #r-code-highlight {
  background: var(--xi-bg);
  border-color: transparent;
  color: var(--xi-ink);
  display: none;
  inset: 0;
  pointer-events: none;
  position: absolute;
  /* Keep the same scrollbar dimensions as the textarea for synchronized scrolling. */
  scrollbar-color: transparent transparent;
  z-index: 0;
}

.r-platform #r-code-highlight::-webkit-scrollbar,
.r-platform #r-code-highlight::-webkit-scrollbar-track,
.r-platform #r-code-highlight::-webkit-scrollbar-thumb,
.r-platform #r-code-highlight::-webkit-scrollbar-corner {
  background: transparent;
}

.r-platform #r-code-highlight code {
  background: none;
  border: 0;
  color: inherit;
  display: block;
  font: inherit;
  margin: 0;
  padding: 0;
  tab-size: inherit;
  white-space: inherit;
  width: max-content;
  min-width: 100%;
}

.r-platform .has-highlight #r-code-highlight {
  display: block;
}

.r-platform .has-highlight #r-code {
  background: transparent;
  caret-color: var(--xi-ink);
  color: transparent;
}

.r-platform .has-highlight #r-code::selection {
  background: var(--r-selection);
  color: var(--xi-ink);
}

.r-platform #r-code-highlight .token.keyword { color: var(--r-syntax-keyword); }
.r-platform #r-code-highlight .token.string { color: var(--r-syntax-string); }
.r-platform #r-code-highlight .token.number { color: var(--r-syntax-number); }
.r-platform #r-code-highlight .token.comment { color: var(--r-syntax-comment); }
.r-platform #r-code-highlight .token.operator { color: var(--r-syntax-operator); }
.r-platform #r-code-highlight .token.boolean { color: var(--r-syntax-boolean); }
.r-platform #r-code-highlight .token.function { color: var(--r-syntax-function); }
.r-platform #r-code-highlight .token.builtin { color: var(--r-syntax-builtin); }
.r-platform #r-code-highlight .token.constant { color: var(--r-syntax-constant); }
.r-platform #r-code-highlight .token.punctuation { color: var(--r-syntax-punctuation); }

.r-platform #r-output {
  background: var(--xi-surface-soft);
  color: var(--xi-ink);
  min-height: 8.5rem;
  max-height: 16rem;
  white-space: pre;
}

.r-platform #r-plots {
  min-height: 11.5rem;
}

.r-platform .r-platform__empty {
  border: 1px dashed var(--xi-border);
  border-radius: .65rem;
  color: var(--xi-muted);
  display: grid;
  place-items: center;
  min-height: 11.5rem;
  margin: 0;
  padding: .75rem;
  text-align: center;
}

.r-platform #r-plots figure {
  margin: 0 0 .7rem;
}

.r-platform #r-plots img,
.r-platform #r-plots canvas,
.r-platform #r-plots svg {
  max-width: 100%;
  height: auto;
  border-radius: .45rem;
}

.r-platform .r-platform__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem;
  margin-top: .95rem;
}

.r-platform button:disabled {
  cursor: default;
  opacity: .55;
  transform: none;
  box-shadow: none;
}

.r-platform .r-platform__status {
  color: var(--xi-muted);
  font-size: .88rem;
  margin: .65rem 0 0;
}

.r-platform .r-platform__package-dialog {
  background: var(--xi-surface-raised);
  border: 1px solid var(--xi-border);
  border-radius: var(--xi-radius);
  box-shadow: var(--xi-shadow);
  box-sizing: border-box;
  color: var(--xi-ink);
  width: min(32rem, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(1rem, 4vw, 1.5rem);
}

.r-platform .r-platform__package-dialog::backdrop {
  background: rgba(18, 35, 48, .55);
}

.r-platform .r-platform__package-dialog .r-platform__actions {
  justify-content: flex-end;
}

.r-platform #r-package-form {
  margin: 0;
}

.r-platform #r-package-name {
  background: var(--xi-bg);
  border: 1px solid var(--xi-border);
  border-radius: .65rem;
  box-sizing: border-box;
  color: var(--xi-ink);
  font: inherit;
  margin: .35rem 0 0;
  padding: .6rem .75rem;
  width: 100%;
}

.r-platform #r-package-hint {
  color: var(--xi-muted);
  font-size: .88rem;
  margin: .35rem 0 0;
}

.r-platform #r-package-status:empty {
  margin: 0;
}

.r-platform #r-package-details {
  background: var(--xi-surface-soft);
  color: var(--xi-ink);
  margin-top: .65rem;
  max-height: 12rem;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.r-platform textarea:focus,
.r-platform #r-package-name:focus,
.r-platform pre:focus-visible {
  border-color: var(--xi-primary);
  outline: 2px solid var(--xi-primary);
  outline-offset: 1px;
}

@media (max-width: 720px) {
  .r-platform .r-platform__workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .r-platform #r-code {
    min-height: 15rem;
  }
}

@media (forced-colors: active) {
  .r-platform .has-highlight #r-code-highlight {
    display: none;
  }

  .r-platform .has-highlight #r-code {
    background: Canvas;
    caret-color: CanvasText;
    color: CanvasText;
  }

  .r-platform .has-highlight #r-code::selection {
    background: Highlight;
    color: HighlightText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .r-platform .button {
    transition: none;
  }

  .r-platform .button:hover {
    transform: none;
  }
}
