:root {
  --bg: #0b0b0e;
  --panel: #131319;
  --panel-2: #1a1a22;
  --line: #262632;
  --line-2: #33333f;
  --text: #e8e8ea;
  --muted: #888892;
  --accent: #7dd3fc;
  --accent-2: #a78bfa;
  --ok: #86efac;
  --mono-default: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Consolas, Menlo, monospace;
  --mono: var(--mono-default);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "Inter", system-ui, sans-serif;
  font-size: 13px; line-height: 1.45;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(180deg, #101015, #0b0b0e);
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-family: var(--mono); color: var(--accent); font-size: 22px; letter-spacing: -3px; }
.topbar h1 { margin: 0; font-size: 14px; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.hint { color: var(--muted); font-size: 11px; font-family: var(--mono); }

.app { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.panel {
  border-right: 1px solid var(--line);
  overflow-y: auto; padding: 10px;
  background: var(--panel);
}
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid var(--panel); }

.group {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px; margin-bottom: 10px;
}
.group h2 {
  margin: 0 0 10px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--muted);
}

label {
  display: block; margin-bottom: 9px;
  font-size: 11px; color: var(--muted);
}
label:has(input[type="range"]) {
  display: grid; grid-template-columns: 1fr auto;
  align-items: center; column-gap: 8px; row-gap: 4px;
}
label output {
  font-family: var(--mono); font-size: 11px;
  color: var(--text); text-align: right;
  min-width: 44px;
  background: var(--panel); padding: 2px 6px; border-radius: 4px;
}
label input[type="range"] { grid-column: 1 / -1; }

input[type="text"], input[type="url"], textarea, select {
  width: 100%;
  background: #07070a; border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 9px; border-radius: 6px;
  font-family: var(--mono); font-size: 12px;
  margin-top: 4px;
  transition: border-color 120ms;
}
textarea { resize: vertical; min-height: 70px; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0; }
input[type="color"] {
  width: 28px; height: 22px; padding: 0;
  border: 1px solid var(--line); border-radius: 4px;
  background: transparent; cursor: pointer;
}

button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line);
  padding: 6px 11px; border-radius: 6px;
  font-size: 11px; cursor: pointer;
  font-family: inherit; font-weight: 500;
  transition: all 120ms;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent); color: #0a0a0d; border-color: var(--accent); font-weight: 600;
}
button.primary:hover { background: #38bdf8; color: #000; }
button.tiny { padding: 2px 6px; font-size: 10px; }
button.big { padding: 10px 18px; font-size: 13px; width: 100%; }

.drop {
  border: 1px dashed var(--line-2); border-radius: 8px;
  padding: 14px; text-align: center;
  color: var(--muted);
  background: #07070a; display: block; margin-bottom: 8px;
  transition: all 120ms;
}
.drop .dropMsg { margin-top: 10px; font-size: 11px; }
.drop.drag { border-color: var(--accent-2); color: var(--accent-2); background: rgba(167,139,250,0.06); }
.file-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row.compact { gap: 10px; }
.row input[type="url"] { flex: 1; }
.chk {
  display: inline-flex; align-items: center; gap: 5px;
  margin: 0; cursor: pointer; color: var(--text);
  user-select: none;
}
.chk input { margin: 0; accent-color: var(--accent); }
.color-lbl { display: inline-flex; align-items: center; gap: 5px; margin: 0; }

.modes {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px; margin-bottom: 10px;
}
.modes label {
  display: flex; align-items: center; gap: 4px;
  margin: 0; cursor: pointer;
  padding: 6px 8px; border-radius: 6px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 11px;
  transition: all 120ms;
}
.modes label:has(input:checked) {
  background: rgba(125,211,252,0.08);
  border-color: var(--accent); color: var(--accent);
}
.modes input { display: none; }

.mode-opts {
  border-top: 1px solid var(--line);
  padding-top: 10px; margin-top: 6px;
}

.presets { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.presets button { padding: 3px 7px; font-size: 10px; }

.thumb {
  display: flex; gap: 10px; align-items: center;
  font-size: 10px; color: var(--muted);
  margin-top: 8px; padding: 8px;
  background: var(--panel); border-radius: 6px;
  border: 1px solid var(--line);
}
.thumb img { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.thumb > div:last-child { flex: 1; display: flex; justify-content: space-between; align-items: center; }

.exports {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 5px;
}
.exports button:first-child { grid-column: 1 / -1; }

.stage {
  display: flex; flex-direction: column;
  min-width: 0; background: var(--bg);
}
.stage-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
#stats { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.stage-tools { display: flex; gap: 10px; align-items: center; }
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom button { padding: 2px 10px; font-size: 14px; line-height: 1; }
.zoom output { font-family: var(--mono); font-size: 11px; min-width: 44px; text-align: center; color: var(--text); }

.viewer {
  flex: 1; overflow: auto;
  padding: 20px;
  background: var(--bg-out, var(--bg));
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}
.viewer::-webkit-scrollbar { width: 10px; height: 10px; }
.viewer::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid var(--bg); }

#output {
  font-family: var(--mono); white-space: pre; margin: 0;
  font-size: calc(10px * var(--zoom, 1));
  line-height: var(--leading, 1);
  letter-spacing: var(--tracking, 0);
  color: var(--fg-out, var(--text));
  display: inline-block;
  user-select: text;
  -webkit-user-select: text;
  /* Help maintain grid with non-monospace fonts */
  font-variant-ligatures: none;
  font-feature-settings: "kern" 0, "calt" 0, "liga" 0;
  text-rendering: optimizeSpeed;
}

/* Note: RTL mode will mirror the ASCII art horizontally. 
   This is necessary for Dhivehi text to flow correctly (right-to-left). */
#output[dir="rtl"] {
  text-align: right;
}
