:root {
  --bg: #faf9f5;
  --panel: #f4f2eb;
  --line: #ece8df;
  --fg: #2c271e;
  --dim: #9a9285;
  --accent: #bf982f;
  --accent-ink: #2c271e;
  --sel: #ecddb0;
  --hover: color-mix(in srgb, var(--sel) 40%, transparent);
  --ok: #589a64;
  --warn: #c0822f;
  --err: #c2605a;
  --tok-keyword: #9d0006;
  --tok-type: #b57614;
  --tok-string: #79740e;
  --tok-number: #8f3f71;
  --tok-comment: #a89984;
  --tok-func: #af3a03;
  --tok-attr: #427b58;
}

:root[data-theme="dark"] {
  --bg: #1b1813;
  --panel: #232019;
  --line: #2c2820;
  --fg: #e9e4d8;
  --dim: #968e7d;
  --accent: #ddb454;
  --accent-ink: #1b1813;
  --sel: #463c22;
  --ok: #80bd88;
  --warn: #d6a559;
  --err: #dd8b85;
  --tok-keyword: #fb4934;
  --tok-type: #fabd2f;
  --tok-string: #b8bb26;
  --tok-number: #d3869b;
  --tok-comment: #928374;
  --tok-func: #fe8019;
  --tok-attr: #8ec07c;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

body {
  display: flex;
  flex-direction: column;
}

::selection {
  background: var(--sel);
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 18px;
  color: var(--accent);
}

.version {
  margin-left: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.3px;
  color: var(--dim);
}

.version:not(:empty)::before {
  content: "v";
}

.opts {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--dim);
}

.opts label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.opts select,
.opts input[type="number"] {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 12px;
  padding: 2px 6px;
}

.opts input[type="number"] {
  width: 3.5em;
  padding: 2px 4px;
}

.opts input[type="checkbox"] {
  accent-color: var(--accent);
}

.theme {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 11px;
  cursor: pointer;
}

.theme:hover {
  color: var(--fg);
  border-color: var(--accent);
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
}

.pane:last-child {
  border-right: none;
}

.pane:first-child .pane-head,
.pane:first-child .view {
  padding-left: 16px;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  min-height: 34px;
  padding: 4px 12px;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 11px;
}

.view {
  flex: 1;
  width: 100%;
  outline: none;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.55;
  padding: 12px;
  overflow: auto;
  white-space: pre;
  tab-size: 2;
}

.editor {
  caret-color: var(--fg);
}

#out {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

::highlight(yuku-src) {
  background-color: color-mix(in srgb, var(--sel) 80%, transparent);
}

::highlight(yuku-decl) {
  background-color: color-mix(in srgb, var(--accent) 32%, transparent);
  text-decoration: underline 1.5px var(--accent);
}

::highlight(yuku-ref) {
  background-color: color-mix(in srgb, var(--accent) 18%, transparent);
  text-decoration: underline 1px dashed color-mix(in srgb, var(--accent) 65%, transparent);
}

.sem-sym {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 4px;
  cursor: pointer;
  border-radius: 3px;
}

.sem-sym:hover {
  background: var(--hover);
}

.sem-site {
  padding-left: 1.1em;
}

.sem-name {
  color: var(--fg);
}

.sem-flag,
.problem-count {
  font-size: 10px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
}

.tok-text {
  padding: 0 5px;
  border-radius: 3px;
  white-space: pre;
  background: color-mix(in srgb, var(--line) 45%, transparent);
}

.tok-count {
  padding: 1px 4px;
}

.sem-err {
  color: var(--dim);
  padding: 12px;
}

.tree {
  white-space: normal;
  line-height: 1.75;
}

.tree details {
  width: max-content;
  min-width: 100%;
}

.tree summary {
  list-style: none;
  cursor: pointer;
  white-space: pre;
  border-radius: 4px;
  padding-block: 1px;
}

.tree summary::-webkit-details-marker {
  display: none;
}

.tree summary::before {
  content: "\25B8";
  display: inline-block;
  width: 1.1em;
  color: var(--dim);
  transition: transform 0.15s ease;
}

.tree details[open] > summary::before {
  transform: rotate(90deg);
}

.tree summary:hover {
  background: var(--panel);
}

.tree details.ast-hit {
  background: color-mix(in srgb, var(--sel) 32%, transparent);
  border-radius: 4px;
}

.tree details.ast-hit > summary {
  background: var(--sel);
}

.tree .sem-current {
  background: var(--sel);
}

.tree .ast-body {
  margin-left: 0.65em;
  padding-left: 0.95em;
  border-left: 1px solid var(--line);
}

.tree .ast-row {
  white-space: pre;
  padding-left: 1.1em;
  padding-block: 1px;
}

.ast-type {
  color: var(--accent);
}

.ast-key {
  color: var(--tok-attr);
}

.ast-str {
  color: var(--tok-string);
}

.ast-num {
  color: var(--tok-number);
}

.ast-bool,
.ast-null {
  color: var(--tok-keyword);
}

.ast-span,
.ast-meta {
  color: var(--dim);
}

.hljs-keyword,
.hljs-literal {
  color: var(--tok-keyword);
}

.hljs-built_in,
.hljs-title.class_,
.hljs-type {
  color: var(--tok-type);
}

.hljs-string,
.hljs-regexp,
.hljs-template-tag {
  color: var(--tok-string);
}

.hljs-number {
  color: var(--tok-number);
}

.hljs-comment {
  color: var(--tok-comment);
}

.hljs-title,
.hljs-title.function_ {
  color: var(--tok-func);
}

.hljs-attr,
.hljs-property {
  color: var(--tok-attr);
}

.hljs-subst {
  color: var(--fg);
}

.pane-head .opts {
  font-size: 11px;
  gap: 8px;
  text-transform: none;
  letter-spacing: normal;
}

.pane-head .opts select,
.pane-head .opts input[type="number"] {
  font-size: 11px;
}

#status {
  padding: 7px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--dim);
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  user-select: none;
}

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

#status.warn {
  color: var(--warn);
}

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

::highlight(yuku-diag-error),
::highlight(yuku-diag-warning),
::highlight(yuku-diag-info) {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-skip-ink: none;
}

::highlight(yuku-diag-error) {
  text-decoration-color: var(--err);
  text-decoration-thickness: 1.5px;
}

::highlight(yuku-diag-warning) {
  text-decoration-color: var(--warn);
  text-decoration-thickness: 1.5px;
}

::highlight(yuku-diag-info) {
  text-decoration-color: var(--dim);
  text-decoration-thickness: 1px;
}

::highlight(yuku-label-error),
::highlight(yuku-label-warning),
::highlight(yuku-label-info) {
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1.5px;
  text-decoration-skip-ink: none;
}

::highlight(yuku-label-error) {
  text-decoration-color: var(--err);
}

::highlight(yuku-label-warning) {
  text-decoration-color: var(--warn);
}

::highlight(yuku-label-info) {
  text-decoration-color: var(--dim);
}

#problems {
  display: flex;
  flex-direction: column;
  max-height: 34vh;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

#problems[hidden] {
  display: none;
}

.problems-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  padding: 5px 12px 5px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 10px;
}

.problems-counts {
  display: flex;
  gap: 12px;
  letter-spacing: normal;
  font-size: 11px;
}

.problems-counts .count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.problems-close {
  margin-left: auto;
  padding: 0 3px;
  background: transparent;
  border: none;
  color: var(--dim);
  font-family: inherit;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.problems-close:hover {
  color: var(--fg);
}

#problemsList {
  overflow: auto;
  padding-block: 2px 4px;
}

.problem-group.problem-active {
  background: var(--sel);
}

.problem {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 16px 3px 6px;
  cursor: pointer;
  white-space: pre;
}

.problem:hover {
  background: var(--hover);
}

.problem-chev {
  flex: none;
  display: inline-block;
  width: 1em;
  color: var(--dim);
  transition: transform 0.15s ease;
}

.problem-chev.open {
  transform: rotate(90deg);
}

.problem-chev:hover {
  color: var(--fg);
}

.problem-count {
  flex: none;
}

.problem-detail {
  padding: 0 16px 4px 2.5em;
}

.problem-rel,
.problem-help,
.tip-rel,
.tip-help {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.problem-rel,
.problem-help {
  padding: 2px 6px;
  border-radius: 4px;
}

.problem-rel {
  cursor: pointer;
}

.problem-rel:hover {
  background: var(--hover);
}

.rel-arrow {
  flex: none;
  color: var(--dim);
}

.rel-msg {
  color: var(--dim);
}

.problem-rel:hover .rel-msg,
.tip-rel:hover .rel-msg,
.tip-rel-focus .rel-msg {
  color: var(--fg);
}

.help-icon {
  flex: none;
  color: var(--accent);
  font-size: 10px;
}

.help-msg {
  color: var(--dim);
}

.problem-icon {
  flex: none;
  width: 1em;
}

.sev-error .problem-icon {
  color: var(--err);
}

.sev-warning .problem-icon {
  color: var(--warn);
}

.sev-info .problem-icon {
  color: var(--dim);
}

.problem-msg {
  overflow: hidden;
  text-overflow: ellipsis;
}

.problem-pos {
  flex: none;
  margin-left: auto;
  padding-left: 16px;
  color: var(--dim);
}

#diagTip {
  position: fixed;
  z-index: 20;
  min-width: 200px;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.15);
  font-size: 12px;
  line-height: 1.55;
  overflow: hidden;
}

.tip-item {
  padding: 9px 12px;
}

.tip-item + .tip-item {
  border-top: 1px solid var(--line);
}

.tip-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.tip-level {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 10px;
  color: var(--dim);
}

.tip-head .problem-pos {
  padding-left: 12px;
}

.tip-msg {
  color: var(--fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tip-rels,
.tip-help {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.tip-rel {
  margin-inline: -6px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.tip-rel:hover {
  background: var(--hover);
}

.tip-rel-focus {
  background: var(--sel);
}

@media (prefers-reduced-motion: reduce) {
  .problem-chev {
    transition: none;
  }
}
