:root {
  color-scheme: light;
  --bg: #efeeda;
  --ink: #11130f;
  --panel: #faf9ed;
  --line: #cbc7ac;
  --muted: #686650;
  --paper: #fffef5;
  --soft: #e2dfc7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  min-height: 100vh;
}

.app.is-gallery,
.app.is-about {
  grid-template-columns: 1fr;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  padding: 28px;
  gap: 22px;
}

.editor-view {
  display: grid;
  align-content: center;
  gap: 16px;
  width: 100%;
  place-items: center;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  justify-self: start;
  width: min(620px, 100%);
}

.view-tab {
  min-height: 36px;
  background: transparent;
}

.view-tab.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.preview-shell {
  width: min(100%, 1180px);
  aspect-ratio: 1200 / 650;
  /* border: 1px solid color-mix(in srgb, var(--line), transparent 30%); */
  background: var(--bg);
}

.preview {
  display: block;
  width: 100%;
  height: 100%;
}

.preview-actions {
  display: grid;
  grid-template-columns: minmax(132px, 160px) repeat(2, 42px) minmax(92px, 0.8fr) minmax(130px, 1.15fr) repeat(3, minmax(104px, 1fr));
  align-items: end;
  gap: 10px;
  width: min(100%, 1040px);
}

.direction-control {
  display: grid;
  gap: 4px;
}

.direction-control span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
  line-height: 1;
  text-transform: uppercase;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 100vh;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
}

.app.is-gallery .panel,
.app.is-about .panel {
  display: none;
}

.field {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 28px 48px;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
  letter-spacing: 0;
  line-height: 1.15;
  text-transform: uppercase;
}

.field.is-locked span {
  color: var(--ink);
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group + .control-group {
  margin-top: 8px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 2px;
}

.group-title span {
  order: 1;
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.group-title::after {
  display: block;
  flex: 1;
  height: 1px;
  order: 2;
  background: var(--line);
  content: "";
}

select,
input[type="number"],
input[type="search"],
.select-like {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 10px;
}

.select-like {
  min-height: 38px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#fontSource {
  display: none;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
}

.actions {
  display: grid;
  gap: 10px;
}

.actions {
  margin-top: auto;
}

button {
  position: relative;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-weight: 680;
}

.preview-actions > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  min-height: 18px;
  border: 1px solid color-mix(in srgb, currentColor, transparent 65%);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 780;
  line-height: 1;
  opacity: 0.68;
}

button:hover {
  border-color: #918d73;
}

button.is-danger {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

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

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.icon-button kbd {
  position: absolute;
  right: 3px;
  bottom: 3px;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  font-size: 8px;
  line-height: 1;
}

.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.lock-control {
  width: 48px;
  min-height: 30px;
  border-color: var(--soft);
  padding: 0;
  font-size: 11px;
  text-transform: uppercase;
}

.group-lock-control {
  min-height: 26px;
  min-width: 54px;
  order: 3;
  border-color: var(--soft);
  padding: 0 8px;
  font-size: 10px;
  text-transform: uppercase;
}

.group-lock-control.is-locked {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.group-lock-control.is-mixed {
  border-color: var(--ink);
  background: color-mix(in srgb, var(--ink), var(--paper) 84%);
  color: var(--ink);
}

.info-control {
  position: relative;
  width: 28px;
  min-height: 28px;
  border-color: var(--soft);
  border-radius: 50%;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.info-control::after {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 10;
  width: 236px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: var(--panel);
  content: attr(data-tooltip);
  font-size: 12px;
  font-weight: 620;
  line-height: 1.35;
  opacity: 0;
  padding: 9px 10px;
  pointer-events: none;
  text-align: left;
  text-transform: none;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.info-control:hover::after,
.info-control:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.lock-control.is-locked {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.gallery-view {
  width: min(100%, 1220px);
  align-self: stretch;
  justify-self: center;
}

.animator-view {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 0;
  align-self: stretch;
}

.animator-stage {
  display: grid;
  min-height: 0;
  place-items: center;
}

.animator-preview {
  display: grid;
  width: min(100%, 1180px);
  min-height: min(58vh, 620px);
  aspect-ratio: 1200 / 650;
  place-items: center;
  overflow: hidden;
  background: var(--bg);
}

.animator-preview svg {
  display: block;
  width: min(88%, 980px);
  max-height: 76%;
}

.animator-status {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  width: min(100%, 1180px);
  justify-self: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.animation-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.animation-mode-grid label {
  position: relative;
  display: grid;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 720;
  user-select: none;
}

.animation-mode-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.animation-mode-grid label:has(input:checked) {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.animation-options {
  display: grid;
  gap: 8px;
}

.animation-options .field,
.animator-field {
  grid-template-columns: 104px minmax(0, 1fr) 52px;
}

.animation-options output {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-align: right;
}

.animation-options input[type="color"] {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  padding: 3px;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.toggle-field input {
  margin: 0;
  accent-color: var(--ink);
}

.code-field {
  align-items: start;
  grid-template-columns: 104px minmax(0, 1fr);
}

.code-field textarea {
  width: 100%;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
  padding: 9px 10px;
}

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.gallery-head h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1;
}

.gallery-actions {
  display: flex;
  gap: 10px;
}

.gallery-actions button {
  min-width: 120px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.gallery-tile {
  display: grid;
  gap: 10px;
  min-height: 0;
  border: 1px solid color-mix(in srgb, var(--line), transparent 12%);
  border-radius: 6px;
  background: var(--paper);
  padding: 10px;
  text-align: left;
}

.gallery-tile:hover {
  border-color: var(--ink);
}

.gallery-open {
  display: grid;
  gap: 10px;
  min-height: 0;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.gallery-art {
  aspect-ratio: 1200 / 650;
  border: 1px solid var(--soft);
  background: var(--bg);
  overflow: hidden;
}

.gallery-art svg {
  display: block;
  width: 100%;
  height: 100%;
}

.gallery-meta,
.gallery-params {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.35;
}

.gallery-meta {
  color: var(--ink);
}

.gallery-tile-actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.gallery-tile-actions button {
  min-height: 30px;
  padding: 0 6px;
  font-size: 11px;
}

.gallery-empty {
  margin: 18vh auto 0;
  color: var(--muted);
  font-weight: 650;
  text-align: center;
}

.about-view {
  width: min(100%, 920px);
  align-self: stretch;
  justify-self: center;
}

.about-content {
  display: grid;
  gap: 12px;
  border: 1px solid color-mix(in srgb, var(--line), transparent 12%);
  border-radius: 8px;
  background: var(--paper);
  padding: 28px;
  color: var(--ink);
}

.about-content h1,
.about-content h2,
.about-content h3,
.about-content p,
.about-content ul {
  margin: 0;
}

.about-content h1 {
  font-size: 32px;
  line-height: 1;
}

.about-content h2 {
  margin-top: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--soft);
  font-size: 18px;
  line-height: 1.1;
}

.about-content h3 {
  margin-top: 4px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.1;
}

.about-content p,
.about-content li {
  color: var(--muted);
  font-size: 14px;
  font-weight: 560;
  line-height: 1.5;
}

.about-content ul {
  display: grid;
  gap: 6px;
  padding-left: 20px;
}

.about-content code {
  border: 1px solid var(--soft);
  border-radius: 4px;
  background: var(--bg);
  padding: 1px 4px;
  color: var(--ink);
  font-size: 0.92em;
}

.font-picker {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  background: color-mix(in srgb, var(--bg), transparent 12%);
  padding: 24px;
}

.font-picker-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  width: min(1180px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  box-shadow: 0 24px 80px color-mix(in srgb, var(--ink), transparent 82%);
}

.font-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.font-picker-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1;
}

.font-picker-tools {
  display: grid;
  gap: 10px;
}

.font-list-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.font-list-tools select {
  flex: 0 0 auto;
  width: auto;
  min-width: 132px;
  min-height: 30px;
  padding: 4px 8px;
  font-size: 11px;
}

.font-list-filter {
  display: flex;
  flex-wrap: wrap;
  flex: 1 1 auto;
  gap: 6px;
  min-width: 0;
}

.font-list-filter label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  padding: 0 10px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.font-list-filter label:has(input:checked) {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.font-list-filter input {
  margin: 0;
}

.font-family-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.font-family-tabs button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 11px;
  text-transform: uppercase;
}

.font-family-tabs button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.font-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  align-items: start;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.font-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 244px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  overflow: hidden;
  padding: 10px;
  text-align: left;
}

.font-tile-select {
  display: block;
  width: 100%;
  height: 160px;
  min-height: 160px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  overflow: hidden;
  padding: 0;
}

.font-tile-select:focus-visible {
  outline: 0;
}

.font-tile-select:focus-visible .font-tile-art {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.font-tile.is-active {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.font-tile.is-whitelisted {
  border-color: color-mix(in srgb, var(--ink), var(--line) 45%);
}

.font-tile.is-blacklisted {
  opacity: 0.46;
}

.font-tile-art {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: 1200 / 650;
  border: 1px solid var(--soft);
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}

.font-tile-art svg {
  display: block;
  width: 100%;
  height: 100%;
  transform: scale(0.92);
  transform-origin: center;
}

.font-tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.font-tile-name {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.font-tile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.font-tile-actions button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 11px;
}

.font-tile-actions button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }

  .workspace {
    min-height: 52vh;
    padding: 16px;
  }

  .panel {
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .animator-preview {
    min-height: 360px;
  }

  .actions {
    margin-top: 0;
  }
}

@media (max-width: 520px) {
  .field {
    grid-template-columns: 88px minmax(0, 1fr) 26px 44px;
  }

  .gallery-grid {
    grid-template-columns: 1fr;
  }

  .preview-actions {
    grid-template-columns: 1fr;
  }

  .font-picker {
    padding: 10px;
  }

  .font-picker-panel {
    max-height: calc(100vh - 20px);
  }
}
