/* The playground: a toolbar header (the site links, theme and credits
   in it or in its menu), the editor and the output side by side
   (stacked on phones). Tokens and components come
   from nabi.css (the web kit); this file only lays them out and adds
   what a code playground needs. */

.nb {
  --err: var(--cli-red);
  --warn: var(--cli-amber);
  --info: var(--cli-sky);
  --ed-font: 14px;
  --ed-line: 23px;
  --ed-pad: 14px;
  /* plain values per theme: no color-mix() for older engines */
  --btn-hover: #3b3539;
  --gutter-ink: rgb(105 107 117 / .7);
  --sel: rgb(0 106 165 / .22);
}
/* paper is light (nabi.css): the dark values are for screens */
@media not print {
  .nb.dk {
    --btn-hover: #f29bbd;
    --gutter-ink: rgb(126 128 136 / .7);
    --sel: rgb(122 213 248 / .22);
  }
}

html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; min-height: 100%; background: var(--bg); }
button, select, textarea { font: inherit; color: inherit; }


.hdr { flex: none; }
.hdr .in { height: 52px; padding: 0 14px; gap: 10px; }
.hdr .brand { min-height: 24px; font-size: 15px; margin-right: 8px; white-space: nowrap; }
.tools { display: flex; align-items: center; gap: 10px; min-width: 0; }
.run { height: 32px; padding: 0 14px; font-size: 13px; white-space: nowrap; justify-content: center; }
.run:hover { background: var(--btn-hover); }
.tools .btn-2 { height: 32px; padding: 0 12px; box-sizing: border-box; white-space: nowrap; justify-content: center; }
.tools .btn-2:hover { border-color: var(--ink-3); }
.tools .btn-2:disabled { color: var(--ink-3) !important; cursor: default; }
.tb {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  background: var(--panel);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.tb:hover { border-color: var(--ink-3); }
select.tb.mono { font-size: 12px; }
.pick { position: relative; display: flex; }
.pick select { padding-right: 28px; appearance: none; -webkit-appearance: none; max-width: 15rem; text-overflow: ellipsis; }
.pick::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 10px;
  height: 10px;
  transform: translateY(-50%);
  background: var(--ink-3);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 6l5 5 5-5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 6l5 5 5-5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  pointer-events: none;
}

/* The Nabi sites: in the header when there is room, else in the menu. */
.hdr .sites { margin-left: auto; flex-wrap: nowrap; }
.ver { white-space: nowrap; }
.ib.theme, .more > summary { width: 32px; height: 32px; flex: none; }
.ib.theme:hover, .more > summary:hover, .more[open] > summary { color: var(--ink); border-color: var(--ink-3); }

/* The menu: the sites (when the header has no room), the release,
   licence and credit, the social links and the System / Light / Dark
   switch the other Nabi sites keep in their footers. */
.more { position: relative; flex: none; }
.more > summary { list-style: none; }
.more > summary::-webkit-details-marker { display: none; }
.more .menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 10;
  width: max-content;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  box-shadow: 0 12px 32px -8px rgb(0 0 0 / .3);
  color: var(--ink-3);
}
/* It drops in on open and fades out on close (the close only where
   ::details-content is known; elsewhere it just goes). */
.more:not([open]) .menu { opacity: 0; translate: 0 -4px; pointer-events: none; }
@keyframes drop { from { opacity: 0; translate: 0 -4px; } }
@media (prefers-reduced-motion: no-preference) {
  .more[open] .menu { animation: drop var(--dur) var(--ease); }
  .more .menu { transition: opacity var(--dur-out) var(--ease), translate var(--dur-out) var(--ease); }
  .more::details-content { transition: content-visibility var(--dur-out) allow-discrete; }
}
.more .menu p { margin: 0; }
.more .menu p a { color: var(--ink-2); }
.more .menu .mono { font-size: 12px; }
.more .menu .sites { margin: 0 0 2px -10px; }
.more .menu .seg { margin: 0; }
.more .menu .social { margin-left: -6px; }

/* The share link, to copy by hand when the clipboard says no; it
   slides open in a .reveal (nabi.css). */
#sharebar { flex: none; }
.sharebar { display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2); color: var(--ink-2); }
.sharebar label { white-space: nowrap; }
.sharebar .lk { margin-left: auto; }
.sharebar input { flex: 1; min-width: 0; height: 28px; padding: 0 8px; border: 1px solid var(--field-line); border-radius: 6px; background: var(--panel); color: var(--ink); font-size: 12px; }

/* Editor beside output; stacked under 860px. */

.ws {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, var(--split, 60%)) 1px minmax(280px, 1fr);
}
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ph {
  flex: none;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  line-height: 18px;
}
.ph .file { font-size: 12px; color: var(--ink-2); align-self: stretch; display: flex; align-items: center; }
.ed-pane:focus-within .file { color: var(--ink); box-shadow: inset 0 -2px 0 var(--acc); }
.ph .file + .lk { margin-left: auto; }

.divider { position: relative; background: var(--line); cursor: col-resize; touch-action: none; }
.divider::after { content: ""; position: absolute; inset: 0 -4px; z-index: 2; }
.divider:hover, .divider:focus-visible { background: var(--acc); }
.nb .divider:focus-visible { outline: none; }
.ws.dragging { cursor: col-resize; -webkit-user-select: none; user-select: none; }

/* The editor: CodeMirror (static/editor/), its own base styles put in
   this sheet ahead of these (editor/style.ts), so these win. Colours
   are the site's tokens, so both themes follow. */
.ed { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--code); }
.ed .cm-editor { flex: 1; min-height: 0; height: 100%; background: var(--code); color: var(--ink); font-size: var(--ed-font); }
.ed .cm-editor.cm-focused { outline: none; }
.ed .cm-scroller { font-family: var(--mono); line-height: var(--ed-line); overflow: auto; }
.ed .cm-content { padding: var(--ed-pad) 0; caret-color: var(--ink); tab-size: 4; }
.ed .cm-line { padding: 0 16px 0 4px; }
.ed .cm-cursor, .ed .cm-dropCursor { border-left: 2px solid var(--ink); }
.ed .cm-selectionBackground, .ed .cm-editor.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground { background: var(--sel); }
.ed .cm-content ::selection { background: var(--sel); }
.ed .cm-activeLine { background: transparent; }
.ed .cm-editor.cm-focused .cm-activeLine { background: rgb(128 128 128 / .06); }
.ed .cm-gutters { background: var(--code); color: var(--gutter-ink); border: 0; -webkit-user-select: none; user-select: none; }
.ed .cm-lineNumbers .cm-gutterElement { min-width: 2.4em; padding: 0 6px 0 10px; }
.ed .cm-activeLineGutter { background: transparent; color: var(--ink-2); }
.ed .cm-gutterElement.bad { color: var(--err); }
.ed .cm-gutterElement.warn { color: var(--warn); }
.ed .cm-foldGutter .cm-gutterElement { width: 14px; padding-right: 4px; color: var(--ink-3); cursor: pointer; }
.ed .cm-foldGutter .fold { opacity: 0; }
.ed .cm-gutters:hover .fold, .ed .fold:not(.open) { opacity: 1; }
.ed .cm-foldPlaceholder { margin: 0 2px; padding: 0 4px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--bg-2); color: var(--ink-2); }
.ed .cm-matchingBracket, .ed .cm-editor.cm-focused .cm-matchingBracket { background: var(--sel); outline: 1px solid var(--ink-3); outline-offset: -1px; border-radius: 2px; color: inherit; }
.ed .cm-nonmatchingBracket, .ed .cm-editor.cm-focused .cm-nonmatchingBracket { background: none; color: var(--err); }
.ed .cm-selectionMatch { background: rgb(128 128 128 / .16); }
.ed .cm-searchMatch { background: rgb(229 167 0 / .25); outline: 1px solid rgb(229 167 0 / .6); }
.ed .cm-searchMatch-selected { background: rgb(229 167 0 / .5); }
/* nabic's diagnostics: a wavy underline, as the old editor drew it */
.ed .cm-lintRange-error, .ed .cm-lintRange-warning { background: none; text-decoration: underline wavy var(--err); text-decoration-thickness: 1.5px; text-underline-offset: 4px; text-decoration-skip-ink: none; }
.ed .cm-lintRange-warning { text-decoration-color: var(--warn); }
.ed .cm-lintPoint::after { border-bottom-color: var(--err); }
.ed .cm-lintPoint-warning::after { border-bottom-color: var(--warn); }

/* The search and lint panels: the site's fields and buttons. */
.ed .cm-panels { background: var(--bg-2); color: var(--ink); border-color: var(--line); font-family: var(--sans, inherit); font-size: 13px; }
.ed .cm-panels-top { border-bottom: 1px solid var(--line); }
.ed .cm-panels-bottom { border-top: 1px solid var(--line); }
.ed .cm-panel.cm-search { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 8px 36px 8px 12px; }
.ed .cm-panel.cm-search br { display: none; }
.ed .cm-panel.cm-search label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-size: 12px; color: var(--ink-2); }
.ed .cm-textfield { height: 28px; margin: 0; padding: 0 8px; box-sizing: border-box; border: 1px solid var(--field-line); border-radius: 6px; background: var(--panel); color: var(--ink); font: inherit; font-family: var(--mono); font-size: 12px; }
.ed .cm-textfield:focus { outline: 2px solid var(--acc); outline-offset: -1px; }
.ed .cm-button { height: 28px; margin: 0; padding: 0 10px; border: 1px solid var(--field-line); border-radius: 6px; background: var(--panel); background-image: none; color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; }
.ed .cm-button:hover { border-color: var(--ink-3); }
.ed .cm-panel button[name="close"] { top: 8px; right: 10px; color: var(--ink-3); font-size: 18px; }
.ed .cm-panel.cm-panel-lint ul { max-height: 30vh; }
.ed .cm-panel.cm-panel-lint ul [aria-selected] { background: var(--acc-bg); }
.ed .cm-panel.cm-panel-lint ul:focus [aria-selected] { background: var(--acc-bg); color: var(--ink); }
.ed .cm-panel.cm-panel-lint .tip { padding: 2px 0; }

/* Tooltips: a diagnostic, a hover's docs, the completions. */
.ed .cm-tooltip { background: var(--panel); color: var(--ink); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 12px 32px -8px rgb(0 0 0 / .3); overflow: hidden; }
.ed .cm-tooltip-hover, .ed .cm-tooltip-lint { max-width: min(480px, calc(100vw - 24px)); }
.ed .cm-tooltip .cm-diagnostic { padding: 10px 12px; border-left: 0; margin: 0; }
.ed .cm-tooltip .cm-diagnostic + .cm-diagnostic { border-top: 1px solid var(--line); }
.ed .cm-diagnosticSource { display: none; }
.ed .cm-tooltip-autocomplete > ul { font-family: var(--mono); font-size: 13px; max-height: 16em; }
.ed .cm-tooltip-autocomplete > ul > li { padding: 2px 10px 2px 6px; line-height: 20px; }
.ed .cm-tooltip-autocomplete > ul > li[aria-selected] { background: var(--acc-bg); color: var(--ink); }
.ed .cm-completionDetail { margin-left: 10px; font-style: normal; color: var(--ink-3); }
.ed .cm-completionMatchedText { text-decoration: none; color: var(--acc); }
.ed .cm-completionIcon { width: 1.1em; padding-right: 4px; opacity: .7; }
.ed .cm-tooltip.cm-completionInfo { max-width: min(420px, 60vw); padding: 0; }
.cm-lsp-doc { padding: 10px 12px; font-size: 13px; line-height: 19px; }
.cm-lsp-doc pre { margin: 0; font-family: var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.cm-lsp-doc p { margin: 8px 0 0; color: var(--ink-2); }
.cm-lsp-doc pre + p, .cm-lsp-doc p:first-child { margin-top: 0; }
.cm-lsp-doc pre + p { margin-top: 8px; }
.cm-lsp-doc code { font-family: var(--mono); font-size: 12px; color: var(--ink); }

/* A diagnostic: the kind and headline, then a line a note. */
.tip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 19px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tip .h b { color: var(--err); font-weight: 600; }
.tip .h.w b { color: var(--warn); }
.tip .n { color: var(--ink-2); }
.tip .n b { color: var(--link); font-weight: 500; }

.sb { flex: none; display: flex; align-items: center; gap: 16px; padding: 6px 14px; border-top: 1px solid var(--line); background: var(--bg); }
.dg { padding: 0; border: 0; background: none; color: var(--err); font-size: inherit; line-height: inherit; cursor: pointer; }
.dg.w { color: var(--warn); }
.dg:hover { text-decoration: underline; text-underline-offset: 3px; }

/* The output follows the theme: white on light, near black on dark. */
.out-pane { background: var(--term); }
.ph .lbl { color: var(--ink-2); font-weight: 500; }
.ph .meta { margin-left: auto; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ph .meta[data-kind="bad"] { color: var(--err); }
.lk { min-height: 24px; padding: 2px 0; border: 0; background: none; color: var(--ink-2); font-size: 13px; cursor: pointer; }
.lk:hover:not(:disabled) { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.lk:disabled { color: var(--ink-3); cursor: default; opacity: .7; }
.meta:empty + .lk { margin-left: auto; }
.out {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  color: var(--ink);
  font-size: 14px;
  line-height: 23px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.out .dim { color: var(--ink-3); }
.out .rich { display: block; max-width: 100%; height: auto; margin: 8px 0; border-radius: 6px; background: #fff; }
.out .v { color: var(--info); font-weight: 600; }
.out .g { color: var(--info); }
.out .err { color: var(--err); }
.out .e { color: var(--err); font-weight: 600; }
.out .warn { color: var(--warn); }
.out .w { color: var(--warn); font-weight: 600; }
.out .loc { padding: 0; border: 0; background: none; font: inherit; color: var(--link); cursor: pointer; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; }
.out .loc:hover { text-decoration-color: currentColor; }
.note { flex: none; margin: 0; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12px; line-height: 17px; color: var(--ink-3); text-wrap: pretty; }

/* 404: the header, then the body every Nabi site shares (nabi.css). */
.nf .hdr .sites { margin-left: auto; }
.nf-main { flex: 1; width: 100%; max-width: 1160px; margin: 0 auto; padding: 32px 24px; box-sizing: border-box; }

/* The sites go into the menu, then the release. */
@media (max-width: 1320px) {
  .hdr .in > .sites { display: none; }
  .ver { margin-left: auto; }
}
@media (min-width: 1321px) {
  .menu .sites { display: none; }
}
@media (max-width: 1080px) {
  .ver { display: none; }
  .ib.theme { margin-left: auto; }
  /* the language menu sits right before the theme switch */
  .hdr .lang-menu { margin-left: auto; }
  .hdr .lang-menu + .ib.theme { margin-left: 0; }
}
@media (max-width: 860px) {
  body { height: auto; }
  .hdr .in { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .hdr .brand { margin-right: 0; }
  /* Row one: brand, Format, Share, theme, menu; row two: Run and the
     two pickers. */
  .tools { display: contents; }
  #fmt { order: 1; margin-left: auto; }
  #share { order: 1; }
  .ib.theme { order: 2; margin-left: 0; }
  .hdr .lang-menu { order: 2; margin-left: 0; }
  .more { order: 2; }
  .hdr .in::after { content: ""; order: 3; flex-basis: 100%; }
  .run { order: 4; }
  .pick { order: 5; }
  .pick:has(#example) { flex: 1; min-width: 0; }
  .pick #example { width: 100%; max-width: none; }
  .ws { display: flex; flex-direction: column; }
  .divider { display: none; }
  .ed-pane { height: 58vh; min-height: min(320px, 70vh); border-bottom: 1px solid var(--line); }
  /* About a screen under the toolbar, scrolling inside, so Run can
     bring all of it into view and long output stays in its pane. */
  .out-pane { height: max(320px, 78vh); height: max(320px, 78svh); }
  .nf .hdr .in > .sites { display: flex; order: 3; flex-basis: 100%; margin: 0 0 0 -10px; }
  .nf .ib.theme { margin-left: auto; }
  .nf-main { padding: 24px 16px; }
}
/* Phones: the theme switch is in the menu, so row one fits. Buttons
   are not fields, so they can stay under 16px. */
@media (max-width: 480px) {
  .hdr .in { column-gap: 6px; }
  .hdr .in > .ib.theme { display: none; }
  .nb .tools .btn-2 { font-size: 14px; padding: 0 10px; }
  .nf .hdr .in > .ib.theme { display: flex; }
}
/* Portrait phones: the toolbar stays reachable while the output scrolls. */
@media (max-width: 860px) and (min-height: 560px) {
  .hdr { position: sticky; top: 0; z-index: 5; }
}
/* nabi.css makes fields 16px here (iOS zooms into smaller ones); the
   editor and the toolbar follow. */
@media (max-width: 767px) {
  .nb { --ed-font: 16px; --ed-line: 25px; }
  .tb, select.tb.mono, .run, .tools .btn-2 { font-size: 16px; height: 36px; }
  .ib.theme, .more > summary { width: 36px; height: 36px; }
  .sharebar { flex-wrap: wrap; padding: 8px 12px; }
  .sharebar input { flex-basis: 100%; order: 3; height: 36px; font-size: 16px; }
  .ed .cm-textfield { height: 36px; font-size: 16px; }
  .ed .cm-button { height: 36px; font-size: 14px; }
  .ed .cm-foldGutter { display: none; }
}
/* Print: the code and its output; no toolbar, share bar or tips. */
@media print {
  .hdr, #sharebar, .cm-tooltip, .cm-panels { display: none !important; }
}

/* Standard input: a box between the output's bar and the output, open
   while the Input button says so; shut, a dot on the button says it
   holds text. */
#stdin-box { flex: none; }
.stdin {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  resize: vertical;
  min-height: 4.5em;
  max-height: 40vh;
  background: var(--code);
  color: var(--ink);
  font-size: 13px;
  line-height: 20px;
}
.stdin::placeholder { color: var(--ink-3); }
.nb .stdin:focus-visible { outline: none; box-shadow: inset 0 -2px 0 var(--acc); }
#stdin-btn[aria-expanded="true"] { color: var(--ink); }
#stdin-btn.has::after { content: ""; display: inline-block; width: 5px; height: 5px; margin-left: 5px; vertical-align: 2px; border-radius: 50%; background: var(--acc); }
@media (max-width: 767px) { .stdin { font-size: 16px; line-height: 24px; } }

/* The menu's English / Korean switch. */
.langs { display: flex; gap: 12px; }
.menu .legal { display: flex; flex-wrap: wrap; gap: 12px; }
/* the header's language menu; on a phone the header has no room, and
   the More menu's switch is the way */
@media (min-width: 521px) { .menu .langs { display: none; } }
@media (max-width: 520px) { .hdr .lang-menu { display: none; } }
.langs a { color: var(--ink-2); }
.langs [aria-current] { color: var(--ink); font-weight: 500; }
