/* ── reset ── */

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

/* ── scrollbars ── */

html {
  scrollbar-color: #30363d #0d1117;
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: #0d1117;
}

*::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 10px;
  border: 2px solid #0d1117;
}

*::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

*::-webkit-scrollbar-corner {
  background: #0d1117;
}

/* ── page ── */

body {
  font-family: "Montserrat", sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  padding: 24px;
  height: 100svh;
  overflow: hidden;
}

.page-shell {
  display: table;
  width: 100%;
  height: 100%;
  table-layout: fixed;
}

.page-row {
  display: table-row;
}

.page-row-editor {
  height: 100%;
}

/* ── loading overlay ── */

.loading-overlay {
  position: fixed;
  inset: 0;
  border: none;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  background: #0d1117;
  display: table;
  transition: opacity 0.3s;
}

.loading-overlay::backdrop {
  background: transparent;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-overlay-body {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #30363d;
  border-top-color: #58a6ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

.loading-label {
  padding-top: 16px;
  font-size: 0.82rem;
  color: #8b949e;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── header ── */

.header {
  padding-bottom: 20px;
}

.header-main {
  display: table;
  width: 100%;
}

.header-labels {
  display: table-cell;
  vertical-align: middle;
  white-space: nowrap;
}

.header-labels > h1 {
  display: inline;
  font-size: 1.3rem;
  font-weight: 600;
  color: #e6edf3;
}

h1 .subtitle {
  font-weight: 400;
  color: #8b949e;
}

.github-link {
  font-size: 0.95rem;
  color: #8b949e;
  padding-left: 14px;
  text-decoration: none;
}

.github-link:hover {
  color: #e6edf3;
}

.github-link svg {
  vertical-align: -4px;
  margin-right: 5px;
  width: 22px;
  height: 22px;
}

.header-version {
  display: table-cell;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  padding-left: 14px;
}

/* ── badges ── */

.badge-link {
  display: inline-block;
  line-height: 0;
}

.badge-link img {
  display: block;
  height: 22px;
}

.badge-strip {
  margin-top: 10px;
  display: table;
}

.badge-strip > .badge-link,
.badge-strip > .fps-link {
  display: table-cell;
  vertical-align: middle;
  padding-right: 8px;
}

/* ── fps.coffee link ── */

.fps-link {
  font-size: 0.78rem;
  font-weight: 600;
  color: #c9a87c;
  text-decoration: none;
  border: 1px solid #c9a87c40;
  border-radius: 12px;
  padding: 2px 12px;
  letter-spacing: 0.02em;
  transition:
    color 0.15s,
    border-color 0.15s,
    background 0.15s;
}

.fps-link:hover {
  color: #e6d5b8;
  border-color: #c9a87c80;
  background: #c9a87c12;
}

/* ── controls ── */

.controls {
  display: table;
  padding-bottom: 20px;
}

.controls > label,
.controls > .btn-cell,
.controls > .sample-picker-cell {
  display: table-cell;
  vertical-align: bottom;
  padding-right: 14px;
  white-space: nowrap;
}

.controls > .btn-cell {
  padding-right: 0;
}

.controls > label {
  font-size: 0.75rem;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.control-label {
  display: block;
  font-size: 0.75rem;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.controls > label > select {
  display: block;
  margin-top: 4px;
}

.controls > label.checkbox-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.78rem;
  color: #c9d1d9;
  cursor: pointer;
  vertical-align: bottom;
  padding-bottom: 8px;
}

.controls > label.checkbox-label > input[type="checkbox"] {
  margin-right: 6px;
  vertical-align: -2px;
  accent-color: #58a6ff;
  cursor: pointer;
}

.sample-picker-cell {
  position: relative;
  min-width: 280px;
}

button.sample-picker-btn {
  display: table;
  table-layout: fixed;
  width: 280px;
  margin-top: 4px;
  padding: 6px 34px 6px 12px;
  background: #161b22;
  color: #c9d1d9;
  border: 1px solid #30363d;
  font-weight: 500;
  position: relative;
  text-align: left;
}

button.sample-picker-btn:hover:not(:disabled) {
  background: #1b222c;
  border-color: #58a6ff66;
}

button.sample-picker-btn[aria-expanded="true"] {
  border-color: #58a6ff;
  box-shadow: 0 0 0 1px #58a6ff33;
}

button.sample-picker-btn:disabled {
  background: #161b22;
  color: #8b949e;
  border-color: #30363d;
}

.sample-picker-caret {
  position: absolute;
  top: 50%;
  right: 12px;
  margin-top: -0.45em;
  color: #8b949e;
  font-size: 0.78rem;
}

.sample-picker-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: min(460px, 68vw);
  background: #11161d;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  z-index: 20;
  white-space: normal;
}

.sample-picker-head input {
  width: 100%;
  font-family: inherit;
  font-size: 0.84rem;
  background: #0d1117;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 8px 10px;
}

.sample-picker-head input:focus {
  outline: none;
  border-color: #58a6ff;
}

.sample-picker-list {
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: 10px;
  padding-right: 14px;
  scrollbar-gutter: stable;
}

.sample-picker-section + .sample-picker-section {
  margin-top: 12px;
}

.sample-picker-section-title {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8b949e;
  margin-bottom: 8px;
}

.sample-card {
  display: block;
  position: relative;
  width: 100%;
  background: #161b22;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  white-space: normal;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    box-shadow 0.15s;
}

.sample-card + .sample-card {
  margin-top: 8px;
}

.sample-card:hover {
  background: #1a212b;
  border-color: #58a6ff66;
}

.sample-card.selected {
  background: #1a2533;
  border-color: #58a6ff;
  box-shadow:
    inset 0 0 0 1px #58a6ff,
    0 0 0 3px #58a6ff22;
}

.sample-card:focus-within {
  border-color: #58a6ff;
  outline: 2px solid #58a6ff55;
  outline-offset: 1px;
}

.sample-card-radio {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.sample-card-top {
  display: block;
}

.sample-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e6edf3;
  line-height: 1.35;
}

.sample-card-top > .sample-pill.featured {
  margin-left: 8px;
  vertical-align: top;
  white-space: nowrap;
}

.sample-card-summary {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #8b949e;
}

.sample-card-badges,
.sample-preview-badges {
  display: block;
}

.sample-card-badges {
  margin-top: 10px;
}

.sample-pill {
  display: inline-block;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid #30363d;
  color: #c9d1d9;
  background: #0d1117;
  line-height: 18px;
  vertical-align: top;
}

.sample-card-badges > .sample-pill,
.sample-preview-badges > .sample-pill {
  margin: 0 6px 6px 0;
}

.sample-pill.featured {
  color: #e6d5b8;
  border-color: #c9a87c66;
  background: #c9a87c12;
}

.sample-pill.backend {
  color: #79c0ff;
  border-color: #58a6ff55;
}

.sample-picker-empty {
  margin-top: 10px;
  font-size: 0.82rem;
  color: #8b949e;
}

/* ── form elements ── */

select,
button {
  font-family: inherit;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
}

select {
  background: #161b22;
  color: #c9d1d9;
  border: 1px solid #30363d;
  padding: 6px 10px;
}

select:focus,
.code-editor textarea:focus {
  outline: none;
  border-color: #58a6ff;
}

select option:disabled {
  color: #484f58;
}

button {
  font-weight: 600;
  background: #238636;
  color: #fff;
  border: 1px solid #2ea043;
  padding: 6px 20px;
}

button:hover:not(:disabled) {
  background: #2ea043;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sample-preview {
  display: block;
  padding-bottom: 18px;
}

.sample-preview-title {
  display: inline-block;
  vertical-align: top;
  margin: 0 10px 6px 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #e6edf3;
}

.sample-preview-summary {
  display: inline-block;
  vertical-align: top;
  margin: 0 10px 6px 0;
  font-size: 0.82rem;
  color: #8b949e;
}

.sample-preview-badges {
  display: inline-block;
  vertical-align: top;
}

#sample-picker-current {
  display: table-cell;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── editor ── */

.editor {
  display: table;
  width: 100%;
  height: 100%;
  table-layout: fixed;
}

.editor-labels {
  display: table-row;
}

.pane-header {
  display: table-cell;
  width: 50%;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #8b949e;
  cursor: default;
  white-space: nowrap;
  padding-bottom: 10px;
}

.editor-labels > .pane-header:first-child,
.editor-pane:first-child {
  padding-right: 12px;
}

.editor-labels > .pane-header:last-child,
.editor-pane:last-child {
  padding-left: 12px;
}

.pane-header > span,
.pane-header > select {
  vertical-align: middle;
}

.pane-header select {
  margin-left: 8px;
}

.editor-panes {
  display: table-row;
  height: 100%;
}

.editor-pane {
  display: table-cell;
  vertical-align: top;
  width: 50%;
  height: 100%;
}

/* ── code editor ── */

.code-editor {
  position: relative;
  height: 100%;
  min-height: 0;
}

.code-editor textarea,
.code-editor pre {
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  position: absolute;
  inset: 0;
  padding: 12px;
  border: 1px solid #30363d;
  border-radius: 6px;
}

.code-editor code {
  font-family: inherit;
}

.code-editor textarea {
  background: transparent;
  color: transparent;
  caret-color: #e6edf3;
  resize: none;
  z-index: 1;
}

.code-editor pre {
  background: #161b22;
  color: #c9d1d9;
  overflow: auto;
  pointer-events: none;
}

/* ── syntax tokens ── */

.hl-comment {
  color: #8b949e;
  font-style: italic;
}
.hl-string {
  color: #a5d6ff;
}
.hl-keyword {
  color: #ff7b72;
}
.hl-type {
  color: #79c0ff;
}
.hl-number {
  color: #d2a8ff;
}
.hl-var {
  color: #ffa657;
}

/* ── footer ── */

.footer-bar {
  display: table;
  width: 100%;
  padding-top: 14px;
}

#status {
  display: table-cell;
  font-size: 0.78rem;
  color: #8b949e;
  vertical-align: middle;
  width: 50%;
}

#status.error {
  color: #f85149;
}
#status.success {
  color: #3fb950;
}

.footer-sponsor {
  display: table-cell;
  line-height: 0;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  width: 1%;
}

.footer-sponsor img {
  display: block;
  height: 28px;
  margin: 0 auto;
}

#version {
  display: table-cell;
  font-size: 0.75rem;
  color: #e6edf3;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  width: 50%;
}

/* ── responsive ── */

@media (max-width: 720px) {
  body {
    min-height: 100svh;
    height: auto;
    overflow: auto;
    padding: 16px;
  }

  .page-shell {
    height: auto;
    min-height: calc(100svh - 32px);
  }

  .page-row-editor {
    height: auto;
  }

  /* Header */
  .header-main,
  .header-labels,
  .header-version {
    display: block;
    width: auto;
    white-space: normal;
  }

  .header-labels > h1 {
    display: block;
  }

  .github-link {
    display: block;
    padding-left: 0;
    margin: 10px 0;
  }

  .header-version {
    text-align: left;
    padding-left: 0;
    margin-top: 14px;
  }

  .badge-strip {
    margin-top: 14px;
  }

  .badge-strip > .badge-link {
    margin-right: 6px;
    margin-bottom: 6px;
  }

  /* Controls */
  .controls {
    display: block;
  }

  .controls > label,
  .controls > .btn-cell,
  .controls > .sample-picker-cell {
    display: block;
    padding: 0 0 10px 0;
  }

  .controls > label.checkbox-label {
    padding-bottom: 10px;
  }

  .controls > label > select {
    width: 100%;
  }

  .sample-picker-cell {
    min-width: 0;
  }

  button.sample-picker-btn {
    width: 100%;
  }

  .sample-picker-popover {
    position: static;
    width: auto;
    margin-top: 10px;
  }

  .controls > .btn-cell {
    padding: 4px 0 0 0;
  }

  .controls > .btn-cell > button {
    width: 100%;
    padding: 10px 20px;
  }

  .sample-preview {
    padding-bottom: 16px;
  }

  /* Editor */
  .editor {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: auto;
  }

  .editor-labels,
  .editor-panes {
    display: contents;
  }

  .pane-header,
  .editor-labels > .pane-header,
  .editor-labels > .pane-header:first-child,
  .editor-labels > .pane-header:last-child {
    display: block;
    width: auto;
    white-space: normal;
    padding: 0 0 10px 0;
  }

  .editor-labels > .pane-header:first-child {
    order: 1;
  }

  .editor-panes > .editor-pane:first-child {
    order: 2;
  }

  .editor-labels > .pane-header:last-child {
    order: 3;
    padding-top: 14px;
  }

  .editor-panes > .editor-pane:last-child {
    order: 4;
  }

  .editor-pane,
  .editor-pane:first-child,
  .editor-pane:last-child {
    display: block;
    width: auto;
    padding: 0;
  }

  .pane-header select {
    margin-left: 6px;
  }

  .code-editor {
    height: 40svh;
    min-height: 220px;
  }

  /* Footer */
  .footer-bar,
  #status,
  .footer-sponsor,
  #version {
    display: block;
    width: auto;
  }

  #status {
    padding-bottom: 10px;
  }

  .footer-sponsor {
    text-align: left;
  }

  .footer-sponsor img {
    margin: 0;
  }

  #version {
    padding-top: 10px;
    text-align: left;
  }
}
