:root {
  color-scheme: dark;
  --bg: #0d0f13;
  --panel: #15181e;
  --panel-2: #1a1e25;
  --panel-3: #20252e;
  --border: #2a303a;
  --border-soft: #222831;
  --text: #f4f6f8;
  --muted: #8f98a7;
  --muted-2: #687181;
  --accent: #7fdb69;
  --accent-2: #5fbe52;
  --accent-ink: #0d160c;
  --danger: #ff6b6b;
  --shadow: 0 18px 55px rgba(0, 0, 0, .32);
  --radius: 14px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 1000px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}
button, input, select { font: inherit; }
button { color: inherit; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app { height: 100%; display: grid; grid-template-rows: 72px minmax(0, 1fr); }
.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 21, 26, .96);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.brand-mark {
  width: 36px; height: 36px; padding: 7px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
  border-radius: 9px; background: var(--accent); box-shadow: 0 0 0 1px rgba(255,255,255,.06) inset;
}
.brand-mark span { background: var(--accent-ink); border-radius: 1px; }
.brand-mark span:nth-child(2), .brand-mark span:nth-child(3) { opacity: .58; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.pack-meta { text-align: right; max-width: 340px; }
.pack-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
.pack-stats { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }

.button {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  transition: .16s ease;
  user-select: none;
}
.button svg { font-size: 16px; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { opacity: .38; cursor: default; }
.button-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 16px rgba(127, 219, 105, .16); }
.button-primary:hover:not(:disabled) { background: #91e77b; }
.button-ghost { background: var(--panel-3); color: var(--text); border-color: var(--border); }
.button-ghost:hover:not(:disabled) { background: #282e38; border-color: #38404c; }
.button-small { padding: 8px 11px; font-size: 11px; }

.workspace { min-height: 0; display: grid; grid-template-columns: 350px minmax(0, 1fr); }
.sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(230px, 42%) minmax(0, 58%);
  border-right: 1px solid var(--border);
  background: var(--panel);
}
.sidebar-section { min-height: 0; padding: 18px 14px 14px; display: flex; flex-direction: column; }
.fonts-section { border-bottom: 1px solid var(--border); }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; padding: 0 4px 12px; }
.section-heading h2, .sequence-header h2 { margin: 3px 0 0; font-size: 14px; letter-spacing: -.01em; }
.eyebrow { color: var(--muted-2); font-size: 9px; line-height: 1; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.count-badge { min-width: 25px; padding: 4px 7px; border-radius: 999px; background: var(--panel-3); color: var(--muted); font: 700 10px var(--mono); text-align: center; }
.search-field { position: relative; margin-bottom: 10px; }
.search-field svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted-2); font-size: 15px; }
.search-field input {
  width: 100%; height: 36px; padding: 0 10px 0 34px;
  border: 1px solid var(--border-soft); border-radius: 9px;
  outline: none; background: #11141a; color: var(--text); font-size: 11px;
}
.search-field input:focus { border-color: #4a5564; box-shadow: 0 0 0 3px rgba(127, 219, 105, .06); }
.search-field input:disabled { opacity: .4; }
.search-field input::placeholder { color: #606978; }
.font-list, .texture-list { min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: #343b47 transparent; }
.empty-list { display: grid; place-items: center; }
.empty-small { max-width: 220px; padding: 24px 12px; color: var(--muted-2); font-size: 11px; line-height: 1.5; text-align: center; }

.font-button {
  width: 100%; margin-bottom: 5px; padding: 10px 10px;
  display: grid; grid-template-columns: 31px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  border: 1px solid transparent; border-radius: 9px; background: transparent; cursor: pointer; text-align: left;
  transition: .14s ease;
}
.font-button:hover { background: var(--panel-2); }
.font-button.active { background: rgba(127, 219, 105, .09); border-color: rgba(127, 219, 105, .26); }
.font-icon { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 7px; background: var(--panel-3); color: var(--muted); font: 800 12px var(--mono); }
.font-button.active .font-icon { background: var(--accent); color: var(--accent-ink); }
.font-copy { min-width: 0; }
.font-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 12px var(--mono); }
.font-subtitle { display: block; margin-top: 3px; color: var(--muted-2); font-size: 9px; }
.font-arrow { color: var(--muted-2); font-size: 15px; }

.texture-list { display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 8px; padding: 1px 2px 12px; }
.texture-list.empty-list { display: grid; grid-template-columns: 1fr; }
.texture-card {
  min-width: 0; padding: 8px;
  border: 1px solid var(--border-soft); border-radius: 10px;
  background: #11141a; cursor: pointer; text-align: left; transition: .14s ease;
}
.texture-card:hover { border-color: #3b4552; background: #181c23; transform: translateY(-1px); }
.texture-card:active { transform: translateY(0); }
.texture-preview {
  position: relative; aspect-ratio: 1; overflow: hidden; margin-bottom: 7px;
  border-radius: 7px;
  background-color: #1b1f26;
  background-image: linear-gradient(45deg, #232831 25%, transparent 25%), linear-gradient(-45deg, #232831 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #232831 75%), linear-gradient(-45deg, transparent 75%, #232831 75%);
  background-size: 12px 12px; background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}
.texture-preview img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; display: block; }
.texture-symbol { position: absolute; top: 5px; left: 5px; min-width: 22px; height: 22px; padding: 0 5px; display: grid; place-items: center; border-radius: 5px; background: rgba(10, 12, 15, .86); color: var(--accent); font: 800 11px var(--mono); box-shadow: 0 1px 7px rgba(0,0,0,.35); }
.texture-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 700; }
.texture-path { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; color: var(--muted-2); font-size: 8px; }
.texture-card.title-like .texture-symbol { color: #83bfff; }

.editor { min-width: 0; min-height: 0; display: grid; grid-template-rows: 64px minmax(300px, 1fr) minmax(238px, 34%); background: #101318; }
.editor-toolbar { padding: 0 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-soft); background: #13161c; }
.selected-font-block { min-width: 0; }
.selected-font-line { margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.selected-font-line strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 12px var(--mono); }
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.toolbar-label { color: var(--muted); font-size: 10px; }
.select-compact { height: 32px; padding: 0 28px 0 9px; border: 1px solid var(--border); border-radius: 8px; outline: 0; background: var(--panel-3); color: var(--text); font-size: 10px; }
.icon-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; border-radius: 6px; }
.icon-button:hover:not(:disabled) { background: var(--panel-3); color: var(--text); }
.icon-button:disabled { opacity: .3; cursor: default; }
.icon-button.tiny { width: 25px; height: 25px; font-size: 14px; }

.stage-wrap { min-height: 0; padding: 18px 22px 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.stage {
  position: relative;
  width: min(54vh, calc(100vw - 450px), 440px);
  height: min(40vh, 280px);
  max-width: 100%;
  max-height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed #303744;
  border-radius: 14px;
  background: rgba(20, 24, 30, .42);
  box-shadow: 0 16px 46px rgba(0, 0, 0, .18);
}
.stage.has-preview {
  flex: 0 0 auto;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.stage-empty { position: absolute; inset: 0; z-index: 0; padding: 34px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.stage-empty-icon { width: 52px; height: 52px; margin-bottom: 14px; display: grid; place-items: center; border: 1px solid #3b4350; border-radius: 13px; background: rgba(17,20,26,.58); color: var(--accent); font-size: 25px; }
.stage-empty strong { color: #d9dde3; font-size: 13px; }
.stage-empty span { max-width: 290px; margin-top: 7px; font-size: 10px; line-height: 1.55; }
.preview-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, .34));
}
.stage-caption { max-width: 100%; padding: 9px 1px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted-2); font-size: 9px; }
.stage-size { flex: 0 0 auto; font-family: var(--mono); }

.sequence-panel { min-height: 0; padding: 15px 20px 18px; border-top: 1px solid var(--border); background: var(--panel); overflow: hidden; display: flex; flex-direction: column; }
.sequence-header { display: flex; align-items: flex-end; justify-content: space-between; }
.sequence-actions { display: flex; gap: 7px; }
.sequence-value {
  flex: 0 0 auto;
  min-height: 44px; margin-top: 11px; padding: 11px 13px;
  display: flex; align-items: center;
  overflow-x: auto; white-space: pre;
  border: 1px solid var(--border); border-radius: 9px;
  background: #0d1015; color: var(--accent); font: 700 15px var(--mono); letter-spacing: .04em;
  scrollbar-width: thin;
}
.sequence-value.is-placeholder { color: var(--muted-2); font: 400 10px var(--font); letter-spacing: 0; }
.layers-list { min-height: 0; margin-top: 10px; overflow: auto; scrollbar-width: thin; scrollbar-color: #343b47 transparent; }
.layers-empty { padding: 13px 4px; color: var(--muted-2); font-size: 10px; }
.layer-row {
  min-width: 690px; height: 43px; margin-bottom: 6px; padding: 5px 6px;
  display: grid; grid-template-columns: 24px 32px minmax(180px, 1fr) 90px 50px 68px 68px; align-items: center; gap: 8px;
  border: 1px solid var(--border-soft); border-radius: 9px; background: #11141a;
  transition: .14s ease;
}
.layer-row:hover { border-color: #333b47; }
.layer-row.dragging { opacity: .35; }
.layer-row.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(127,219,105,.08); }
.drag-handle { height: 100%; display: grid; place-items: center; color: #555f6d; cursor: grab; font-size: 13px; }
.drag-handle:active { cursor: grabbing; }
.layer-thumb { width: 32px; height: 32px; border-radius: 6px; object-fit: contain; background: #20252d; image-rendering: pixelated; }
.layer-info { min-width: 0; }
.layer-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 700; }
.layer-meta { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; color: var(--muted-2); font: 9px var(--mono); }
.shift-control { display: grid; grid-template-columns: 25px 1fr 25px; align-items: center; height: 29px; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.shift-control button { height: 100%; border: 0; background: var(--panel-3); color: var(--muted); cursor: pointer; }
.shift-control button:hover { background: #2a303a; color: var(--text); }
.shift-value { height: 100%; display: grid; place-items: center; background: #0e1116; color: var(--accent); font: 800 12px var(--mono); }
.layer-char { justify-self: center; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: #0e1116; color: #dbe0e7; font: 800 12px var(--mono); }
.layer-order, .layer-actions { display: flex; justify-content: flex-end; gap: 4px; }
.row-button { width: 29px; height: 29px; padding: 0; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 7px; background: var(--panel-3); color: var(--muted); cursor: pointer; font-size: 13px; }
.row-button:hover:not(:disabled) { background: #2a303a; color: var(--text); }
.row-button:disabled { opacity: .3; cursor: default; }
.row-button.danger:hover { color: var(--danger); border-color: rgba(255,107,107,.35); }
.row-button.active { color: var(--accent); }

.drop-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(8, 10, 13, .82); backdrop-filter: blur(10px); }
.drop-card { min-width: 330px; padding: 30px; display: flex; flex-direction: column; align-items: center; border: 1px solid rgba(127,219,105,.38); border-radius: 18px; background: #15191f; box-shadow: var(--shadow); text-align: center; }
.drop-icon { width: 58px; height: 58px; margin-bottom: 14px; display: grid; place-items: center; border-radius: 15px; background: var(--accent); color: var(--accent-ink); font-size: 28px; }
.drop-card strong { font-size: 15px; }
.drop-card span { margin-top: 6px; color: var(--muted); font-size: 10px; }
.toast { position: fixed; z-index: 120; left: 50%; bottom: 24px; transform: translate(-50%, 20px); padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px; background: #20252d; color: var(--text); box-shadow: var(--shadow); font-size: 11px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255,107,107,.45); color: #ffaaaa; }

@media (max-height: 800px) {
  .app { grid-template-rows: 62px minmax(0, 1fr); }
  .editor { grid-template-rows: 56px minmax(270px, 1fr) minmax(220px, 38%); }
  .stage-wrap { padding-top: 10px; }
  .sidebar-section { padding-top: 13px; }
}

/* GitHub-backed version */
.sync-line { display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; }
.sync-indicator {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(127, 219, 105, .10);
}
.sync-indicator.syncing { animation: sync-pulse 1s ease-in-out infinite; }
.sync-indicator.error { background: var(--danger); box-shadow: 0 0 0 3px rgba(255, 107, 107, .10); }
#refreshButton.is-loading svg { animation: sync-spin .8s linear infinite; }
#refreshButton:disabled { opacity: .62; cursor: wait; }
@keyframes sync-spin { to { transform: rotate(360deg); } }
@keyframes sync-pulse { 50% { opacity: .35; transform: scale(.78); } }
