/* Antarmuka editor. Tidak memengaruhi hasil render chatlog (lihat app.css). */

:root {
  --bg: #0a0b10;
  --panel: #0f1118;
  --panel-2: #141722;
  --panel-3: #1b1f2e;
  --border: #252a3d;
  --border-soft: #1a1e2c;
  --accent: #b69cff;
  --accent-2: #e59df0;
  --accent-soft: rgba(182, 156, 255, .12);
  --accent-ring: rgba(182, 156, 255, .38);
  --accent-grad: linear-gradient(135deg, #a994ff 0%, #e59df0 100%);
  --danger: #ff6b7a;
  --text: #eef0f8;
  --text-dim: #a0a6bd;
  --text-faint: #5f657d;
  --mono: 'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace;
  --ui: 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.35);
  --shadow-2: 0 24px 60px rgba(0,0,0,.45);
  --ease: cubic-bezier(.22,.8,.3,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(182,156,255,.07), transparent 60%),
    radial-gradient(700px 480px at -5% 110%, rgba(229,157,240,.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--ui);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; width: 100%; height: 100vh; animation: appIn .5s var(--ease) both; }
@keyframes appIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

::selection { background: var(--accent-ring); color: #fff; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- SCROLLBARS ---------- */
* { scrollbar-width: thin; scrollbar-color: #2f3448 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #272c3f; border-radius: 20px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4160; background-clip: content-box; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  --sidebar-width: 350px;
  width: var(--sidebar-width);
  min-width: 270px;
  background: linear-gradient(180deg, rgba(20,23,34,.9), rgba(15,17,24,.96));
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--border-soft);
  overflow-y: auto;
  padding: 18px 16px 48px;
}

.sidebar-resizer {
  flex: 0 0 1px;
  position: relative;
  cursor: col-resize;
  background: var(--border-soft);
  transition: background .2s var(--ease), box-shadow .2s var(--ease);
}
.sidebar-resizer::after { content: ''; position: absolute; inset: 0 -4px; }
.sidebar-resizer:hover,
body.resizing-sidebar .sidebar-resizer { background: var(--accent); box-shadow: 0 0 14px var(--accent-ring); }
body.resizing-sidebar { cursor: col-resize; user-select: none; }

/* Accordion */
details {
  position: relative;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: var(--panel-2);
  overflow: hidden;
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease), transform .25s var(--ease);
}
details:hover { border-color: var(--border); }
details[open] { border-color: var(--border); box-shadow: var(--shadow-1); }
details[open]::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-ring), transparent);
}
details > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -.005em;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background .2s var(--ease), color .2s var(--ease), padding-left .25s var(--ease);
}
details > summary:hover { background: rgba(255,255,255,.025); padding-left: 19px; color: #fff; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after {
  content: '';
  width: 7px; height: 7px;
  flex: none;
  margin-left: 10px;
  border-right: 2px solid var(--text-faint);
  border-bottom: 2px solid var(--text-faint);
  transform: rotate(45deg);
  transition: transform .25s var(--ease), border-color .2s var(--ease);
}
details > summary:hover::after { border-color: var(--accent); }
details[open] > summary::after { transform: rotate(-135deg); }
.details-body { padding: 2px 16px 18px; animation: bodyIn .3s var(--ease) both; }
@keyframes bodyIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

label.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 16px 0 8px;
}
label.field-label:first-child { margin-top: 0; }

textarea, input[type=text], input[type=number] {
  width: 100%;
  background: rgba(6,7,11,.7);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 10px 12px;
  resize: vertical;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
}
textarea { min-height: 170px; line-height: 1.6; }
textarea:hover, input[type=text]:hover, input[type=number]:hover, select:hover { border-color: #343a54; }
textarea:focus, input[type=text]:focus, input[type=number]:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(6,7,11,.9);
  box-shadow: 0 0 0 4px var(--accent-soft), 0 0 24px -6px var(--accent-ring);
}
textarea::placeholder, input::placeholder { color: var(--text-faint); }

.hint-text {
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text-faint);
  margin-top: 12px;
}
.hint-text code {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 5px;
}

/* Sliders */
input[type=range] {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 4px;
  background: var(--panel-3);
  outline: none;
  cursor: pointer;
  margin: 10px 0 2px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent-grad);
  border: 3px solid var(--panel-2);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 10px rgba(0,0,0,.4);
  cursor: pointer;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.18); box-shadow: 0 0 0 1px var(--accent), 0 0 0 6px var(--accent-soft); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.3); box-shadow: 0 0 0 1px var(--accent), 0 0 0 9px var(--accent-soft); }
input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--panel-2);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--panel-3); }

.range-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.range-value {
  color: var(--accent);
  font-weight: 700;
  font-family: var(--mono);
  font-size: 11px;
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.sidebar-panel { display: block; }
.sidebar-panel[hidden] { display: none; }

.chip-row { display: flex; gap: 8px; }
.chip-row input { flex: 1; }

/* Buttons: spotlight mengikuti kursor (--mx/--my diisi oleh app.js) */
.btn {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: var(--panel-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: transform .2s var(--ease), border-color .2s var(--ease), box-shadow .25s var(--ease), background .2s var(--ease);
}
.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0;
  background: radial-gradient(120px circle at var(--mx, 50%) var(--my, 50%), rgba(182,156,255,.28), transparent 70%);
  transition: opacity .25s var(--ease);
}
.btn:hover { transform: translateY(-2px); border-color: var(--accent-ring); box-shadow: 0 8px 22px -8px rgba(0,0,0,.6), 0 0 0 1px var(--accent-soft); }
.btn:hover::before { opacity: 1; }
.btn:active { transform: translateY(0) scale(.98); box-shadow: none; }
.btn.primary {
  background: var(--accent-grad);
  border-color: transparent;
  color: #140f24;
}
.btn.primary::before { background: radial-gradient(120px circle at var(--mx, 50%) var(--my, 50%), rgba(255,255,255,.45), transparent 70%); }
.btn.primary:hover { box-shadow: 0 10px 28px -8px rgba(182,156,255,.7), 0 0 0 1px rgba(255,255,255,.15) inset; }
.btn.block { width: 100%; margin-top: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  animation: chipIn .25s var(--ease) both;
  transition: border-color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}
@keyframes chipIn { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
.chip:hover { border-color: var(--accent-ring); background: var(--accent-soft); transform: translateY(-1px); }
.chip button {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 50%;
  transition: color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}
.chip button:hover { color: var(--danger); background: rgba(255,107,122,.14); transform: rotate(90deg); }

.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type=color] {
  width: 38px; height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  transition: transform .2s var(--ease), border-color .2s var(--ease);
}
.color-row input[type=color]:hover { transform: scale(1.06); border-color: var(--accent); }
.color-row input[type=text] { width: auto; flex: 1; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.checkbox-row input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.checkbox-row label { cursor: pointer; }

select {
  width: 100%;
  background: rgba(6,7,11,.7);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.export-row { display: flex; gap: 10px; margin-top: 14px; }
.export-row .btn { flex: 1; }

/* ---------- STAGE ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: 32px 40px;
}
.stage-header { margin-bottom: 22px; }
.stage-header h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 6px;
  letter-spacing: -.02em;
  color: var(--text);
}
.stage-header p { font-size: 13px; color: var(--text-faint); margin: 0; max-width: 60ch; line-height: 1.6; }

/*
  Kanvas pratinjau. Tidak ikut diekspor; hanya latar titik-titik halus
  supaya area chatlog yang transparan tetap terbaca.
*/
.stage-canvas {
  align-self: flex-start;
  position: relative;
  width: 1000px;
  max-width: 100%;
  padding: 18px 20px;
  border-radius: 16px;
  border: 1px solid var(--border-soft);
  background-color: #0d0f16;
  background-image: radial-gradient(rgba(255,255,255,.055) 1px, transparent 1px);
  transition: border-color .3s var(--ease), box-shadow .3s var(--ease);
}
.stage-canvas:hover { border-color: var(--border); box-shadow: var(--shadow-2), 0 0 60px -30px var(--accent-ring); }

/* Export-critical: jangan diubah (lihat catatan zoom pada download-img.js). */
#output {
  width: 1000px;
  max-width: none;
  position: relative;
  z-index: 1;
  font-size: 12.5px;
  --chatlog-line-height: 14px;
  --chatlog-box-width: 11px;
  --chatlog-box-left: 4px;
  --chatlog-box-height: 6px;
  zoom: 1.35;
}

.preview-panel[hidden] { display: none; }

/* ---------- TABS & MAKER CONTROLS ---------- */
.tabs {
  position: relative;
  display: flex;
  gap: 2px;
  padding: 4px;
  margin-bottom: 16px;
  background: rgba(6,7,11,.7);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
}
.tab {
  appearance: none;
  flex: 1;
  text-align: center;
  padding: 9px 0;
  border-radius: 9px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .25s var(--ease), color .2s var(--ease), box-shadow .25s var(--ease), transform .2s var(--ease);
}
.tab:hover { color: var(--text); background: rgba(255,255,255,.04); }
.tab:active { transform: scale(.97); }
.tab.active {
  background: var(--accent-grad);
  color: #140f24;
  box-shadow: 0 6px 18px -8px rgba(182,156,255,.8);
}

.image-size-row { display: flex; gap: 10px; }
.image-size-row label { flex: 1; font-size: 12px; color: var(--text-dim); font-weight: 600; }
.image-size-row input[type=number] { width: 100%; margin-top: 6px; }

.upload-control {
  display: block;
  padding: 18px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s var(--ease), background .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}
.upload-control:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); transform: translateY(-2px); }
.upload-control input { display: none; }

.maker-preview.stage-canvas {
  border: 0;
  border-radius: 3px;
  background: linear-gradient(160deg, #1b2029 0%, #12151b 55%, #0a0b0e 100%);
  box-shadow: none;
}
.maker-preview.stage-canvas:hover { box-shadow: none; }

/* ---------- SERVER SELECTOR ---------- */
.server-selector {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(700px 420px at 50% 0%, rgba(182,156,255,.14), transparent 65%),
    radial-gradient(600px 400px at 50% 110%, rgba(229,157,240,.08), transparent 65%),
    var(--bg);
}
.server-selector[hidden] { display: none; }
.server-selector-card {
  width: min(700px, 100%);
  padding: 44px 40px 40px;
  border: 1px solid var(--border-soft);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(20,23,34,.85), rgba(15,17,24,.9));
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-2), 0 0 0 1px rgba(255,255,255,.02) inset;
  text-align: center;
  animation: cardIn .7s var(--ease) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(18px) scale(.98); } to { opacity: 1; transform: none; } }
.server-selector-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border: 1px solid var(--accent-ring);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}
.server-selector-kicker::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: 0 0 10px var(--accent);
}
.server-selector-card h1 {
  margin: 18px 0 10px;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -.035em;
  line-height: 1.1;
  background: linear-gradient(180deg, #fff 30%, #b9bdd4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.server-selector-card > p {
  margin: 0 auto 32px;
  max-width: 46ch;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.65;
}
.server-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.server-choice {
  appearance: none;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  padding: 26px 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .25s var(--ease), transform .3s var(--ease), box-shadow .3s var(--ease);
}
.server-choice::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0;
  background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%), rgba(182,156,255,.22), transparent 70%);
  transition: opacity .3s var(--ease);
}
.server-choice::after {
  content: '';
  position: absolute;
  right: 20px; top: 22px;
  width: 9px; height: 9px;
  border-top: 2px solid var(--text-faint);
  border-right: 2px solid var(--text-faint);
  transform: rotate(45deg) translate(-4px, 4px);
  opacity: 0;
  transition: opacity .25s var(--ease), transform .3s var(--ease), border-color .25s var(--ease);
}
.server-choice:hover {
  border-color: var(--accent-ring);
  transform: translateY(-4px);
  box-shadow: 0 22px 40px -18px rgba(0,0,0,.7), 0 0 40px -14px var(--accent-ring);
}
.server-choice:hover::before { opacity: 1; }
.server-choice:hover::after { opacity: 1; transform: rotate(45deg) translate(0, 0); border-color: var(--accent); }
.server-choice:active { transform: translateY(-1px) scale(.99); }
.server-choice-name {
  display: block;
  margin-bottom: 8px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.02em;
}
.server-choice-desc {
  display: block;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
}

.selected-server-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 12px 10px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
}
.selected-server-bar::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #5be3a4;
  box-shadow: 0 0 10px #5be3a4;
}
.selected-server-bar strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .01em;
}
.change-server-btn {
  margin-left: auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 5px 11px;
  border-radius: 999px;
  transition: color .2s var(--ease), background .2s var(--ease), border-color .2s var(--ease);
}
.change-server-btn:hover { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-ring); }

@media (max-width: 780px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
  }
  .sidebar-resizer { display: none; }
  .stage { padding: 22px; }
}

@media (max-width: 640px) {
  .server-selector-card { padding: 30px 20px; }
  .server-selector-card h1 { font-size: 32px; }
  .server-choice-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
