:root {
  --page: #f7f4ee;
  --paper: #fffdf8;
  --ink: #1f1d1a;
  --muted: #6e675f;
  --line: #d8d0c4;
  --soft-line: #ebe4d8;
  --accent: #1f6f68;
  --accent-soft: #e2f0ec;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.page {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 42px 20px 64px;
  min-width: 0;
}

.page-header {
  margin-bottom: 26px;
}

.page-header h1 {
  margin: 0;
  font-size: 2.1rem;
  line-height: 1.05;
}

.page-header p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
  font-weight: 650;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.theme-sidebar,
.preview-column,
.example-panel,
.theme-editor-panel {
  min-width: 0;
}

.example-panel,
.theme-editor-panel {
  margin-bottom: 34px;
}

.example-panel h2,
.theme-editor-panel h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.theme-drawer > summary {
  margin: 0 0 12px;
  color: var(--ink);
  cursor: default;
  font-size: 1.15rem;
  font-weight: 750;
  list-style: none;
}

.theme-drawer:not([open]) > summary {
  display: none;
}

.theme-drawer > summary::-webkit-details-marker {
  display: none;
}

label {
  min-width: 0;
  display: grid;
  gap: 6px;
}

label > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
}

input[type="number"],
input[type="text"],
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select {
  height: 40px;
  padding: 0 10px;
}

input[type="number"],
input[type="text"] {
  height: 38px;
  padding: 0 10px;
}

input[type="color"] {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px;
  background: #fff;
}

textarea {
  min-height: 300px;
  resize: vertical;
  padding: 13px;
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.55;
}

input[type="number"]:focus,
input[type="text"]:focus,
input[type="color"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.panel-heading-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.editor-actions {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: end;
  justify-content: end;
  gap: 8px;
  min-width: 0;
}

.compact-field {
  flex: 1 1 220px;
  max-width: 360px;
}

.editor-actions button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 750;
}

.editor-actions button:hover {
  border-color: #bdb3a5;
}

.editor-actions button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

#customThemeButton {
  display: inline-grid;
  grid-template-columns: 16px auto;
  align-items: center;
  gap: 7px;
}

.theme-editor-grid {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.editor-section {
  min-width: 0;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.editor-section:last-child {
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading h3 {
  margin: 0;
  font-size: 0.94rem;
}

.theme-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 700;
}

.theme-stats strong {
  color: var(--ink);
  font-family: var(--mono);
}

.canvas-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}

.color-field {
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 6px 8px;
  align-items: center;
}

.color-field > span {
  grid-column: 1 / -1;
}

.token-editor-section {
  padding-bottom: 0;
}

.token-controls {
  display: grid;
  gap: 1px;
  max-height: 560px;
  margin: 0 -16px;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.token-row {
  display: grid;
  grid-template-columns: minmax(178px, 0.8fr) minmax(0, 1.6fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 12px 16px;
  background: var(--paper);
}

.token-row-heading {
  display: grid;
  grid-template-columns: minmax(52px, auto) minmax(0, 1fr);
  gap: 2px 9px;
  align-items: center;
  min-width: 0;
}

.token-sample {
  display: inline-grid;
  grid-row: 1 / span 2;
  place-items: center;
  min-width: 52px;
  min-height: 28px;
  border-radius: 4px;
  padding: 3px 6px;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: nowrap;
}

.token-title {
  min-width: 0;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.token-row-heading code {
  min-width: 0;
  color: var(--muted);
  font-size: 0.7rem;
  overflow-wrap: anywhere;
}

.token-row-controls {
  display: grid;
  grid-template-columns: minmax(128px, 1fr) minmax(128px, 1fr) auto;
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.token-color-field input[type="text"] {
  font-family: var(--mono);
  font-size: 0.78rem;
}

.token-toggles {
  display: flex;
  gap: 4px;
  min-width: 0;
}

.token-toggles label {
  position: relative;
  display: block;
  width: 34px;
  min-width: 34px;
  height: 38px;
}

.token-toggles input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.token-toggles label > span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: none;
}

.token-toggles input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.token-toggles input:focus-visible + span {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.css-output {
  margin: 0;
}

.css-output textarea {
  min-height: 190px;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
}

.theme-list,
.code-tabs {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.theme-set + .theme-set {
  margin-top: 14px;
}

.theme-set h2 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
  text-transform: uppercase;
}

.theme-list button {
  display: inline-grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px 5px 6px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.84rem;
  text-align: left;
}

.theme-list button:hover {
  border-color: #bdb3a5;
  color: var(--ink);
}

.theme-list button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.swatch {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--swatch-bg) 0 50%, var(--swatch-fg) 50% 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.theme-name {
  min-width: 0;
  flex: 1 1 auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.theme-mode {
  flex: 0 0 auto;
  align-self: start;
  padding-top: 1px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 750;
  text-transform: uppercase;
}

.theme-list button.is-active .theme-mode {
  color: var(--accent);
}

.more-themes {
  margin-top: 12px;
}

.more-themes summary {
  width: fit-content;
  border-radius: 5px;
  padding: 5px 0;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.more-themes summary:hover {
  color: var(--ink);
}

.more-themes summary span {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.84rem;
}

.more-themes .theme-list {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--soft-line);
}

.code-group {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f4f5;
}

.code-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  min-height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: #f4f4f5;
}

.code-tabs button {
  min-height: 48px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0 13px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.code-tabs button:hover {
  color: var(--ink);
}

.code-tabs button.is-active {
  border-bottom-color: #3451b2;
  background: transparent;
  color: var(--ink);
}

.highlight {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--active-code-bg, var(--paper));
  color: var(--active-code-fg, var(--ink));
  overflow: hidden;
}

.highlight pre {
  margin: 0;
  overflow: auto;
  padding: 18px;
  background: inherit;
}

.highlight code {
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1px;
  background: var(--line);
}

.code-entry,
.preview-pane {
  min-width: 0;
  background: var(--paper);
}

.code-entry {
  padding: 16px;
}

.code-entry textarea {
  min-height: 260px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 8px 0 0;
  resize: vertical;
}

.code-entry textarea:focus {
  box-shadow: none;
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--active-code-bg, var(--paper));
  color: var(--active-code-fg, var(--ink));
}

.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: #f4f4f5;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
}

.preview-heading #previewLanguage {
  font-family: var(--mono);
  text-transform: none;
}

.example-output {
  min-height: 100%;
  border: 0;
  border-radius: 0;
}

.example-output pre {
  min-height: 560px;
}

@media (min-width: 721px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .page {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    padding: 34px 20px 0;
  }

  .page-header {
    margin-bottom: 24px;
  }

  .layout {
    min-height: 0;
    overflow: hidden;
  }

  .theme-sidebar,
  .preview-column {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  .theme-sidebar {
    padding: 0 8px 48px 0;
  }

  .preview-column {
    padding: 0 8px 56px 0;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 24px 12px 56px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .theme-sidebar {
    min-width: 0;
  }

  .theme-drawer {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
  }

  .theme-drawer > summary {
    display: revert;
    margin: 0;
    padding: 12px 14px;
    cursor: pointer;
    list-style: none;
  }

  .theme-drawer:not([open]) > summary {
    display: revert;
  }

  .theme-drawer > summary::-webkit-details-marker {
    display: none;
  }

  .theme-drawer > summary::before {
    content: "▶ ";
  }

  .theme-drawer[open] > summary::before {
    content: "▼ ";
  }

  .theme-drawer .theme-set,
  .theme-drawer .theme-list,
  .theme-drawer .more-themes {
    margin: 0 12px 12px;
  }

  .theme-drawer .theme-set .theme-list {
    margin: 0;
  }

  .theme-drawer:not([open]) {
    margin-bottom: 0;
  }

  .panel-heading-row {
    display: grid;
    align-items: stretch;
  }

  .editor-actions {
    justify-content: stretch;
  }

  .compact-field {
    max-width: none;
  }

  .editor-actions button {
    flex: 1 1 auto;
  }

  .section-heading {
    display: grid;
  }

  .theme-stats {
    justify-content: start;
  }

  .token-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .token-row-controls {
    grid-template-columns: 1fr;
  }

  .token-toggles {
    width: 100%;
  }

  .token-toggles label {
    flex: 1 1 0;
  }

  .example-output pre {
    min-height: 380px;
  }

  .code-entry textarea {
    min-height: 260px;
  }

  .theme-list button {
    width: 100%;
  }

  .theme-name {
    max-width: none;
  }

}
