/* Studio Khat — bagian dari PahamWeb Studio. Warna dasar diambil dari ../shared/studio.css */
:root {
  --bg: var(--s-bg);
  --surface: var(--s-1);
  --surface-2: var(--s-2);
  --surface-3: var(--s-3);
  --line: var(--s-line);
  --text: var(--s-tx);
  --muted: var(--s-tx2);
  --gold: var(--c-khat);
  --gold-2: var(--c-khat2);
  --gold-ink: var(--c-khat-ink);
  --danger: #e2656b;
  --radius: 12px;
  --tabs-w: 78px;
  --panel-w: 360px;
  --top-h: var(--s-top);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 var(--s-font);
  overflow: hidden; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button > svg, .ico { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--top-h); display: flex; align-items: center; gap: 10px;
  padding: 0 10px; background: var(--s-bar); border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.topbar .ibtn { width: 36px; height: 36px; border-radius: 9px; color: var(--muted); }
.topbar .ibtn:hover { color: var(--text); }
.topbar .ibtn svg { width: 19px; height: 19px; }
.topbar .btn { height: 36px; border-radius: 9px; padding: 0 14px; font-weight: 700; }
.topbar .btn.ghost { border-color: var(--line); background: var(--surface-2); }
.topbar .btn.ghost:hover { background: var(--surface-3); }
.ibtn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px;
  background: transparent; border: 0; color: var(--text);
}
.ibtn:hover { background: var(--surface-2); }
.ibtn:disabled { opacity: .35; cursor: default; background: transparent; }
.ibtn svg { width: 21px; height: 21px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600;
}
.btn:hover { background: var(--surface-3); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--gold-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 46px; min-width: 230px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px; box-shadow: 0 12px 40px #0009;
}
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; }
.menu button:hover { background: var(--surface-3); }

/* ---------- Layout ---------- */
.app {
  height: calc(100% - var(--top-h)); display: grid;
  grid-template-columns: var(--tabs-w) var(--panel-w) 1fr; grid-template-areas: "tabs panel stage";
}
.tabs { grid-area: tabs; background: var(--s-bar); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 8px 6px; gap: 2px; overflow-y: auto; }
.tabs button {
  border: 0; background: none; border-radius: 10px; padding: 9px 2px 7px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--muted); font-size: 11px; line-height: 1.1;
}
.tabs button svg { width: 22px; height: 22px; }
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.on { color: var(--gold-2); background: var(--surface-2); }
.panel { grid-area: panel; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; padding: 16px 16px 40px; overscroll-behavior: contain; }
.stage { grid-area: stage; position: relative; overflow: hidden; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: radial-gradient(circle at 50% 40%, #1c2027, #0d0f12 70%); }
.canvas-wrap { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; }
#art, #overlay { position: absolute; box-shadow: 0 18px 60px #000a; touch-action: none; }
#art { background: repeating-conic-gradient(#d8d8d8 0 25%, #f4f4f4 0 50%) 0 0 / 22px 22px; }
#overlay { box-shadow: none; overflow: visible; cursor: default; }
.stage-bar { display: flex; justify-content: center; gap: 8px; padding: 10px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); font-size: 13px;
}
.chip svg { width: 16px; height: 16px; }
.chip:hover { background: var(--surface-3); }
.chip.danger { color: var(--danger); }

/* ---------- Panel ---------- */
.panel h3 { margin: 0 0 12px; font-size: 16px; font-weight: 650; }
.panel h4 { margin: 20px 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.hint { color: var(--muted); font-size: 12.5px; margin: -4px 0 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.field { display: grid; gap: 6px; margin: 10px 0; }
.field > span { font-size: 13px; color: var(--muted); }
input[type=text], input[type=number], select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
textarea.arab {
  min-height: 108px; resize: vertical; font-size: 26px; line-height: 1.7; direction: rtl; text-align: center; padding: 10px 12px;
}
.slider { display: grid; grid-template-columns: 92px 1fr 46px; align-items: center; gap: 10px; margin: 10px 0; }
.slider > span { font-size: 13px; color: var(--muted); }
.slider output { font-size: 12.5px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--gold); height: 26px; }
input[type=color] { width: 40px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); padding: 2px; cursor: pointer; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; border: 1px solid var(--line); }
.seg > button, .seg > label { flex: 1; border: 0; background: none; border-radius: 8px; padding: 7px 6px; font-size: 13px; color: var(--muted); text-align: center; cursor: pointer; }
.seg > button.on, .seg > label:has(input:checked) { background: var(--surface-3); color: var(--gold-2); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg small { display: block; font-size: 11px; color: var(--muted); }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 7px; }
.sw { aspect-ratio: 1; border-radius: 50%; border: 2px solid #ffffff22; cursor: pointer; padding: 0; }
.sw.on { outline: 2px solid var(--gold-2); outline-offset: 2px; }
.color-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.color-row span { color: var(--muted); font-size: 13px; }

.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); }
.toggle b { font-weight: 600; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: var(--surface-3); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + i { background: var(--gold); }
.switch input:checked + i::after { transform: translateX(18px); }
.sub { padding: 0 0 10px; }

/* kartu */
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius); padding: 0; overflow: hidden; text-align: left;
  display: flex; flex-direction: column; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: #4a5160; }
.card.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.card > span { padding: 7px 9px; font-size: 12.5px; }
.card small { color: var(--muted); display: block; font-size: 11px; }
.thumb { aspect-ratio: 1; background: #0c0d10; display: grid; place-items: center; overflow: hidden; }
.thumb svg { width: 100%; height: 100%; display: block; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.loading::after { content: ""; width: 22px; height: 22px; border: 2px solid #ffffff33; border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
.frame-thumb { aspect-ratio: 1; background: #23262d; }
.frame-thumb svg { width: 100%; height: 100%; display: block; }
.grad-bar { height: 34px; }
.orn-thumb { aspect-ratio: 1; display: grid; place-items: center; padding: 16px; color: var(--gold-2); background: #23262d; }
.orn-thumb svg { width: 100%; height: 100%; display: block; }

.font-filter { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.font-filter button { flex: none; border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; padding: 5px 12px; font-size: 12.5px; color: var(--muted); }
.font-filter button.on { color: var(--gold-ink); background: var(--gold); border-color: var(--gold); }
.fonts { display: grid; gap: 8px; }
.font-card { border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; text-align: right; }
.font-card:hover { border-color: #4a5160; }
.font-card.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.font-card .sample { font-size: 30px; line-height: 1.6; direction: rtl; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #f3eee0; min-height: 48px; }
.font-card .meta { display: flex; justify-content: space-between; align-items: baseline; direction: ltr; text-align: left; font-size: 12.5px; }
.font-card .meta small { color: var(--muted); }
.badge { font-size: 10.5px; padding: 2px 7px; border-radius: 99px; background: var(--surface-3); color: var(--gold-2); margin-left: 6px; }

.phrases { display: flex; flex-wrap: wrap; gap: 6px; }
.phrase { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 5px 10px; text-align: center; }
.phrase b { display: block; font-family: "kf-amiri", serif; font-weight: 400; font-size: 19px; line-height: 1.5; direction: rtl; }
.phrase small { color: var(--muted); font-size: 11px; }
.phrase:hover { border-color: var(--gold); }

.kbd { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; direction: rtl; margin-top: 10px; }
.kbd button { height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-family: "kf-amiri", serif; font-size: 21px; padding: 0; }
.kbd button:active { background: var(--gold); color: var(--gold-ink); }
.kbd button.h { font-size: 26px; color: var(--gold-2); }
.kbd button.wide { grid-column: span 3; font-family: inherit; font-size: 13px; }
.kbd button.fn { font-family: inherit; font-size: 13px; }

.layer-list { display: grid; gap: 8px; }
.layer-item { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 6px 6px 6px 10px; cursor: pointer; }
.layer-item.on { border-color: var(--gold); }
.layer-item .lt { flex: 1; min-width: 0; text-align: right; direction: rtl; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-item .ibtn { width: 34px; height: 34px; }
.layer-item .ibtn svg { width: 17px; height: 17px; }
.layer-item.off .lt { opacity: .4; }

.box { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-top: 10px; }
.warn { background: #3a2a12; border: 1px solid #6b4c17; color: #f6d79a; padding: 9px 12px; border-radius: 10px; font-size: 13px; margin: 8px 0; }

/* ---------- Dialog ---------- */
.dlg { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
.dlg::backdrop { background: #000a; backdrop-filter: blur(3px); }
.dlg-body { padding: 22px; }
.dlg h2 { margin: 0 0 16px; font-size: 19px; }
.dlg p { color: #cfd2d8; }
.fmt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.fmt { position: relative; cursor: pointer; }
.fmt input { position: absolute; opacity: 0; }
.fmt span { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); height: 100%; }
.fmt b { display: block; margin-bottom: 4px; }
.fmt.wide { grid-column: 1 / -1; }
.fmt.wide b { color: var(--gold-2); }
.fmt small { color: var(--muted); font-size: 12px; }
.fmt input:checked + span { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.lbl { font-size: 13px; color: var(--muted); margin: 6px 0 6px; }
.check { display: flex; align-items: center; gap: 10px; margin: 14px 0 4px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--gold); }
.note { font-size: 12.5px; color: var(--muted) !important; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px); background: #2b2f38; border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading { position: fixed; inset: 0; background: var(--bg); display: grid; place-content: center; justify-items: center; gap: 10px; z-index: 80; transition: opacity .3s; }
.loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 38px; height: 38px; border: 3px solid #ffffff22; border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) { :root { --panel-w: 320px; --tabs-w: 70px; } }

/* ---------- HP & tablet tegak ---------- */
@media (max-width: 820px) {
  :root { --top-h: 52px; }
  .btn.primary span { display: inline; }
  .app {
    grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas: "stage" "panel" "tabs";
  }
  .stage-bar { padding: 6px 8px 8px; gap: 6px; }
  .chip { height: 32px; padding: 0 10px; font-size: 12px; }
  .panel { border-right: 0; border-top: 1px solid var(--line); max-height: 42vh; max-height: 42dvh; padding: 14px 14px 24px; }
  .panel.collapsed { display: none; }
  .tabs {
    flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    overflow-x: auto; scrollbar-width: none;
  }
  .tabs button { flex: 1 0 64px; padding: 6px 2px; }
  .slider { grid-template-columns: 80px 1fr 40px; }
  .grid3 { grid-template-columns: repeat(4, 1fr); }
  .grid2 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .grid3 { grid-template-columns: repeat(3, 1fr); }
  .grid2 { grid-template-columns: repeat(2, 1fr); }
  .swatches { grid-template-columns: repeat(8, 1fr); gap: 5px; }
  .fmt-grid { grid-template-columns: 1fr; }
  .kbd button { height: 38px; font-size: 19px; }
}

/* Kredit PahamWeb */
a.by { white-space: nowrap; color: var(--muted); font-size: 11.5px; text-decoration: none; letter-spacing: .2px; }
a.by:hover { color: var(--gold-2); text-decoration: underline; }
.dlg a.by { font-size: inherit; color: var(--gold-2); }
.loading small.by { color: var(--muted); font-size: 12px; }
.menu-link { display: block; padding: 10px 12px; border-radius: 8px; color: var(--gold-2); text-decoration: none; border-top: 1px solid var(--line); margin-top: 4px; }
.menu-link:hover { background: var(--surface-3); }
@media (max-width: 860px) { .hide-sm { display: none !important; } }
@media (max-width: 820px) { .topbar { gap: 6px; padding: 0 6px; } .top-actions { gap: 2px; } }
