/* ==========================================================
   1. Design tokens (light / dark)
   ========================================================== */
:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #fbf4ea;
  --panel: rgba(255, 255, 255, .82);
  --ink: #2a2230;
  --muted: #7a6f82;
  --border: rgba(60, 40, 80, .12);
  --accent: #ff6a3d;
  --accent-2: #ff3d8b;
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  --canvas-bg: #efe9df;
  --shadow: 0 10px 30px rgba(80, 40, 90, .12);
  --radius: 18px;
  --ease: cubic-bezier(.2, .9, .3, 1.2);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17131f; --panel: rgba(38, 32, 52, .82); --ink: #f4eefc; --muted: #a79bb8;
    --border: rgba(255, 255, 255, .1); --canvas-bg: #26202f; --shadow: 0 10px 30px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #17131f; --panel: rgba(38, 32, 52, .82); --ink: #f4eefc; --muted: #a79bb8;
  --border: rgba(255, 255, 255, .1); --canvas-bg: #26202f; --shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
html { overflow: hidden; height: 100%; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
* { box-sizing: border-box; }
body {
  margin: 0; padding: 12px; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink); font-family: var(--font);
  overflow: hidden;
}

/* ==========================================================
   2. Animated background & header
   ========================================================== */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg i { position: absolute; width: 46vmax; height: 46vmax; border-radius: 50%; filter: blur(70px); opacity: .35; animation: drift 18s ease-in-out infinite alternate; }
.bg i:nth-child(1) { background: #ff9a5c; top: -15vmax; left: -12vmax; }
.bg i:nth-child(2) { background: #ff5fa2; bottom: -18vmax; right: -10vmax; animation-delay: -6s; }
.bg i:nth-child(3) { background: #7a6bff; top: 30%; left: 40%; width: 30vmax; height: 30vmax; opacity: .22; animation-delay: -11s; }
/* Tema gelap: sisi kiri dibuat hitam, glow warna dipindah ke sisi kanan */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bg i:nth-child(1) { left: auto; right: -12vmax; }
  :root:not([data-theme="light"]) .bg i:nth-child(3) { left: auto; right: 5%; }
}
:root[data-theme="dark"] .bg i:nth-child(1) { left: auto; right: -12vmax; }
:root[data-theme="dark"] .bg i:nth-child(3) { left: auto; right: 5%; }

.hero { width: 100%; flex: none; max-width: none; margin: 0 auto 10px; display: flex; align-items: center; justify-content: space-between; gap: 14px; animation: rise .6s var(--ease) both; }
.hero-left { display: flex; align-items: center; gap: 14px; }
.logo {
  flex: none; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 1.7rem;
  background:white; box-shadow: 0 8px 20px rgba(255, 80, 90, .35); animation: wobble 4s ease-in-out infinite;
}
.hero h1 {
  margin: 0; font-size: clamp(1.35rem, 4vw, 1.9rem); font-weight: 800; letter-spacing: .2px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.theme-toggle { background: var(--panel); border: 1px solid var(--border); padding: 8px 12px; border-radius: 12px; cursor: pointer; font-size: 1rem; color: var(--ink); box-shadow: var(--shadow); transition: transform .15s; }
.theme-toggle:active { transform: scale(0.92); }

/* ==========================================================
   3. Layout
   ========================================================== */
.app { width: 100%; flex: 1; min-height: 0; max-width: none; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) clamp(292px, 22vw, 380px); grid-template-rows: minmax(0, 1fr); gap: 16px; align-items: stretch; }
.panel { display: flex; flex-direction: column; gap: 12px; min-height: 0; height: 100%; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 2px 4px 8px 2px; scrollbar-width: thin; }
.panel > * { flex: none; }
@media (max-width: 800px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 56fr) minmax(0, 44fr); gap: 10px; }
  .s-tools { order: 1; } .s-pal { order: 2; } .s-proj { order: 3; } .s-adv { order: 4; }
  .hero p { display: none; }
}

/* ==========================================================
   4. Canvas stage
   ========================================================== */
.cv {
  position: relative; height: 100%; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: var(--radius);
  background: var(--canvas-bg); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: rise .6s .1s var(--ease) both;
}
.empty {
  position: absolute; inset: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 20px; color: var(--muted); border: 2px dashed var(--border); border-radius: calc(var(--radius) - 4px);
  animation: breathe 3s ease-in-out infinite;
}
.empty .big { font-size: 3.2rem; animation: float 3s ease-in-out infinite; }
.wrap { position: absolute; left: 0; top: 0; display: none; transform-origin: 0 0; background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .22); will-change: transform; }
.wrap.pop { animation: canvasIn .55s ease; }
.wrap canvas { display: block; width: 100%; height: 100%; }
#overlay { position: absolute; inset: 0; pointer-events: none; }
#sbuf { position: absolute; inset: 0; pointer-events: none; }
#sbuf.over { z-index: 5; } /* pratinjau goresan transparan tampil di atas objek saat menggambar */
#lines, #manual { position: absolute; inset: 0; mix-blend-mode: multiply; pointer-events: none; }
.cv.tool-fill { cursor: pointer; }
.cv.tool-brush, .cv.tool-erase, .cv.tool-pen, .cv.tool-lerase, .cv.tool-lasso, .cv.tool-lfix, .cv.tool-shape, .cv.tool-bezier { cursor: crosshair; }
.cv.tool-select { cursor: default; }
.cv.tool-text { cursor: text; }
.cv.tool-pan, .cv.space { cursor: grab; }
.cv.grabbing { cursor: grabbing; }
.selbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5; display: none; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 94%; padding: 6px; border-radius: 14px; background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); }
.selbar button { padding: 6px 8px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font: inherit; font-size: .72rem; font-weight: 700; cursor: pointer; transition: transform .15s var(--ease); }
.selbar button:active { transform: scale(.92); }
.selbar .go { background: var(--grad); color: #fff; border-color: transparent; }
select.sel { width: 100%; padding: 9px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font: inherit; font-size: .85rem; font-weight: 700; margin-bottom: 6px; }
.sb { position: absolute; z-index: 4; display: none; border-radius: 99px; background: rgba(120, 100, 140, .12); opacity: .85; transition: opacity .2s; }
.sb:hover { opacity: 1; }
.sb i { position: absolute; border-radius: 99px; background: var(--accent); opacity: .75; cursor: grab; touch-action: none; }
.sb i:active { cursor: grabbing; opacity: 1; }
.sb-h { left: 12px; right: 12px; bottom: 3px; height: 9px; }
.sb-h i { top: 0; height: 100%; }
.sb-v { top: 12px; bottom: 12px; right: 3px; width: 9px; }
.sb-v i { left: 0; width: 100%; }
.busy { position: absolute; inset: 0; z-index: 6; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(255, 255, 255, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); font-weight: 800; color: #2a2230; }
.busy i { width: 38px; height: 38px; border-radius: 50%; border: 4px solid rgba(0, 0, 0, .12); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.zctl { position: absolute; right: 12px; bottom: 12px; z-index: 5; display: none; align-items: center; gap: 6px; padding: 6px; border-radius: 14px; background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); }
.zctl button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font: inherit; font-weight: 800; cursor: pointer; transition: transform .15s var(--ease); }
.zctl button:active { transform: scale(.88); }
.zctl span { min-width: 46px; text-align: center; font-size: .75rem; font-weight: 800; color: var(--muted); }
#ring { position: fixed; left: 0; top: 0; border: 2px solid #fff; box-shadow: 0 0 0 1.5px #000; border-radius: 50%; pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 15; }

/* ==========================================================
   5. Panel cards & controls
   ========================================================== */
.sec {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
  animation: rise .55s var(--ease) both; animation-delay: calc(var(--n, 0) * 90ms + 150ms);
}
.sec h2 { margin: 0 0 10px; font-size: .72rem; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.sec h2.sub { margin-top: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row + .row { margin-top: 8px; }
.small { font-size: .75rem; color: var(--muted); margin: 6px 0 0; }
.chk { display: flex; gap: 8px; align-items: center; font-size: .8rem; margin-top: 10px; cursor: pointer; }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }

button.b, label.b {
  position: relative; overflow: hidden; flex: 1; min-width: 0; text-align: center; cursor: pointer;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); color: var(--ink);
  font: inherit; font-size: .85rem; font-weight: 700;
  transition: transform .18s var(--ease), box-shadow .2s, background .25s, color .2s;
}
button.b:hover, label.b:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(80, 40, 90, .16); }
button.b:active, label.b:active { transform: scale(.95); }
button.b::after, label.b::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(255, 255, 255, .55) 0%, transparent 60%); opacity: 0; transition: opacity .35s; }
button.b:active::after, label.b:active::after { opacity: 1; transition: none; }
button.b.on, .pri { background: var(--grad) !important; border-color: transparent !important; color: #fff !important; box-shadow: 0 6px 16px rgba(255, 80, 90, .35); }
.pri { text-decoration: none; }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tools button.b { padding: 10px 4px; display: flex; flex-direction: column; gap: 2px; align-items: center; font-size: .72rem; }
.tools button.b span { font-size: 1.25rem; transition: transform .25s var(--ease); }
.tools button.b.on span { transform: scale(1.2) rotate(-8deg); }
#bs { overflow: hidden; animation: expand .35s var(--ease); }

input[type=range] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
input[type=color] { width: 44px; height: 36px; border: 2px solid var(--border); border-radius: 10px; padding: 0; background: none; cursor: pointer; }
.cur { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); font-weight: 700; }
#cdot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .3); transition: background .25s, transform .3s var(--ease); }

/* Layers */
#lyl { max-height: 230px; overflow: auto; margin-top: 8px; }
.ly { display: flex; align-items: center; gap: 6px; padding: 6px 8px; margin-top: 5px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: .78rem; font-weight: 700; cursor: pointer; }
.ly.on { border-color: #8b3dff; background: rgba(139, 61, 255, .14); }
.ly span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ly button { border: 0; background: none; color: inherit; cursor: pointer; font-size: .9rem; padding: 0 2px; }
.selbar .go2 { background: #8b3dff; color: #fff; border-color: transparent; }

/* Palette */
.pal { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.sw {
  aspect-ratio: 1; border-radius: 50%; padding: 0; cursor: pointer; border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .2), 0 2px 5px rgba(0, 0, 0, .15);
  transition: transform .2s var(--ease), box-shadow .25s;
  animation: swIn .45s var(--ease) both; animation-delay: calc(var(--i) * 20ms + 300ms);
}
.sw:hover { transform: scale(1.18); }
.sw:active { transform: scale(.9); }
.sw.on { transform: scale(1.2); box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--cur), 0 4px 12px rgba(0, 0, 0, .25); }

/* Advanced settings */
details.sec summary { cursor: pointer; list-style: none; font-size: .72rem; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
details.sec summary::-webkit-details-marker { display: none; }
details.sec summary::after { content: "▾"; transition: transform .3s var(--ease); }
details.sec[open] summary::after { transform: rotate(180deg); }
details.sec[open] > div { animation: expand .35s var(--ease); }

/* ==========================================================
   6. Modals, toast, effects
   ========================================================== */
.modal { position: fixed; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center; padding: 14px; background: rgba(20, 10, 30, .55); backdrop-filter: blur(4px); animation: fade .25s both; }
.mc { width: 100%; max-width: 470px; max-height: 86vh; overflow: auto; padding: 18px; border-radius: 22px; background: var(--bg); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .4); animation: modalIn .4s var(--ease) both; }
.mc h3 { margin: 0 0 10px; font-size: 1.15rem; }
.mc input[type=text] { width: 100%; padding: 11px 12px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--ink); font: inherit; }
.mc img.preview { max-width: 100%; border: 1px solid var(--border); border-radius: 10px; }
.mc input[type=number] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--ink); font: inherit; }
.cs-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cs-grid button.b { padding: 8px 4px; font-size: .78rem; line-height: 1.25; }
.cs-grid button.b small { display: block; font-size: .66rem; font-weight: 700; opacity: .75; }
.pj { display: flex; gap: 10px; align-items: center; margin-top: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); animation: rise .4s var(--ease) both; }
.pj:nth-child(2) { animation-delay: .05s; } .pj:nth-child(3) { animation-delay: .1s; } .pj:nth-child(4) { animation-delay: .15s; } .pj:nth-child(n+5) { animation-delay: .2s; }
.pj img { width: 64px; height: 48px; flex: none; object-fit: cover; background: #fff; border-radius: 8px; }
.pj .i { flex: 1; min-width: 0; font-size: .85rem; }
.pj .i b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pj .i span { color: var(--muted); font-size: .72rem; }
.pj button { flex: none; padding: 7px 10px; font-size: .78rem; }

#toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); z-index: 30; padding: 10px 18px; border-radius: 999px; background: #241c2c; color: #fff; font-size: .85rem; font-weight: 700; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); opacity: 0; pointer-events: none; transform: translate(-50%, 20px) scale(.9); transition: opacity .25s, transform .35s var(--ease); }
#toast.on { opacity: 1; transform: translate(-50%, 0) scale(1); }

.splash { position: fixed; width: 0; height: 0; pointer-events: none; z-index: 20; }
.splash::before { content: ""; position: absolute; left: -8px; top: -8px; width: 16px; height: 16px; border-radius: 50%; background: var(--c); opacity: .5; animation: ripple .6s ease-out forwards; }
.splash i { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--c); animation: burst .7s ease-out forwards; }

/* ==========================================================
   7. Keyframes
   ========================================================== */
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(30px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes canvasIn { from { opacity: 0; filter: blur(6px); } to { opacity: 1; filter: none; } }
@keyframes expand { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes swIn { from { opacity: 0; transform: scale(.3); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes breathe { 0%, 100% { border-color: var(--border); } 50% { border-color: var(--accent); } }
@keyframes wobble { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg) scale(1.06); } }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.15); } }
@keyframes ripple { to { transform: scale(7); opacity: 0; } }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ==========================================================
   Splash / loading screen
   ========================================================== */
#splash { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; background: var(--bg); color: var(--ink); touch-action: none; user-select: none; -webkit-user-select: none; transition: opacity .6s ease, transform .6s ease, visibility .6s; }
#splash.out { opacity: 0; visibility: hidden; transform: scale(1.05); pointer-events: none; }
#sp-cv { position: absolute; inset: 0; width: 100%; height: 100%; }
.sp-logo { position: relative; z-index: 1; width: 104px; height: 104px; display: grid; place-items: center; font-size: 3.4rem; border-radius: 30px; background:white; box-shadow: 0 16px 40px rgba(255, 80, 90, .4); animation: spBounce 1.8s ease-in-out infinite; cursor: pointer; }
.sp-logo::before { content: ""; position: absolute; inset: -9px; border-radius: 38px; background: conic-gradient(from 0deg, #ff6a3d, #ffd23f, #43aa8b, #1e90ff, #8e44ad, #ff3d8b, #ff6a3d); -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px)); mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px)); animation: spin 3s linear infinite; }
.sp-logo.pop { animation: spPop .5s var(--ease); }
.sp-title { position: relative; z-index: 1; margin: 6px 0 0; font-size: clamp(1.6rem, 6vw, 2.3rem); font-weight: 800; letter-spacing: .5px; display: flex; flex-wrap: wrap; justify-content: center; }
.sp-title span { display: inline-block; animation: spWave 1.4s ease-in-out infinite; animation-delay: calc(var(--i) * 70ms); }
.sp-bar { position: relative; z-index: 1; width: min(300px, 74vw); height: 12px; border-radius: 99px; background: var(--border); }
.sp-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 99px; background: linear-gradient(90deg, #ffd23f, #ff6a3d, #ff3d8b, #8e44ad); }
.sp-bar b { position: absolute; top: -17px; left: 0; font-size: 1.5rem; font-weight: 400; transform: translateX(-50%) rotate(-25deg); filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .25)); }
.sp-pct { position: relative; z-index: 1; font-size: .85rem; font-weight: 800; color: var(--muted); }
.sp-hint { position: relative; z-index: 1; margin: 0; font-size: .8rem; color: var(--muted); text-align: center; animation: spFade 2.4s ease-in-out infinite; }
@keyframes spBounce { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-14px) rotate(4deg); } }
@keyframes spPop { 0% { transform: scale(.8) rotate(-12deg); } 60% { transform: scale(1.18) rotate(8deg); } 100% { transform: scale(1); } }
@keyframes spWave { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes spFade { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
#install-btn { font-size: .85rem; font-weight: 800; background: var(--grad); color: #fff; border-color: transparent; }
/* ===== Editor gradasi (ala CorelDRAW) ===== */
.gbarw { position: relative; padding: 0 9px 22px; margin-top: 6px; }
.gbar { position: relative; height: 26px; border-radius: 8px; border: 1px solid var(--border); touch-action: none; cursor: copy; }
.gstop { position: absolute; top: 18px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .55), 0 2px 5px rgba(0, 0, 0, .3); cursor: grab; touch-action: none; }
.gstop.sel { box-shadow: 0 0 0 2.5px #8b3dff, 0 2px 6px rgba(0, 0, 0, .35); z-index: 2; }
.gstop:active { cursor: grabbing; }
.gpre { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.gpb { width: 44px; height: 24px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; padding: 0; transition: transform .15s var(--ease); }
.gpb:hover { transform: translateY(-2px); }
#gdel:disabled { opacity: .4; cursor: not-allowed; }

/* ==========================================================
   Tab kanvas (multi-kanvas)
   ========================================================== */
.cvcol { display: flex; flex-direction: column; gap: 6px; min-width: 0; min-height: 0; height: 100%; }
.cvcol > .cv { flex: 1; height: auto; min-height: 0; }
.tabbar { flex: none; display: flex; align-items: flex-end; gap: 4px; min-width: 0; }
.tabs { display: flex; align-items: flex-end; gap: 4px; min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 2px 2px 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: 0 1 170px; min-width: 96px; max-width: 200px; height: 36px; display: flex; align-items: center; gap: 6px;
  padding: 0 6px 0 10px; border-radius: 12px 12px 0 0; border: 1px solid var(--border); border-bottom: 0;
  background: var(--panel); color: var(--muted); font-size: .8rem; font-weight: 700; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background .15s var(--ease), color .15s var(--ease), transform .15s var(--ease);
}
.tab:hover { color: var(--ink); background: var(--bg); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab.on { background: var(--canvas-bg); color: var(--ink); box-shadow: 0 -2px 0 var(--accent) inset; }
.tab-ic { flex: none; font-size: .9rem; }
.tab-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-x {
  flex: none; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: inherit; font: inherit; font-size: 1.05rem; line-height: 1; cursor: pointer; transition: background .15s;
}
.tab-x:hover { background: rgba(127, 127, 127, .25); }
.tab-add {
  flex: none; width: 32px; height: 32px; margin-bottom: 2px; display: grid; place-items: center; padding: 0; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink); font: inherit; font-size: 1.3rem; font-weight: 800; line-height: 1; cursor: pointer;
  transition: transform .15s var(--ease), background .15s, color .15s;
}
.tab-add:hover:not(:disabled) { background: var(--grad); color: #fff; transform: scale(1.1); }
.tab-add:disabled { opacity: .4; cursor: not-allowed; }
@media (max-width: 800px) { .tab { min-width: 84px; flex-basis: 130px; height: 34px; } }

/* ==========================================================
   Responsive HP / tablet kecil (hanya aktif di layar <= 800px)
   ========================================================== */
@media (max-width: 800px) {
  body { padding: 8px; padding-left: max(8px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); }

  /* Header lebih ringkas */
  .hero { margin-bottom: 6px; gap: 8px; }
  .hero-left { gap: 8px; min-width: 0; }
  .hero .logo { width: 40px !important; height: 40px !important; border-radius: 12px; }
  .hero .logo img { width: 100% !important; height: auto; }
  .hero h1 { font-size: clamp(17px, 6vw, 24px) !important; letter-spacing: -1px !important; }
  .hero > div:last-child { gap: 6px !important; flex: none; }
  .theme-toggle { padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
  #install-btn { font-size: .78rem; }

  /* Pembagian tinggi kanvas dan panel */
  .app { grid-template-rows: minmax(0, 46fr) minmax(0, 54fr); gap: 8px; }
  .cvcol { gap: 4px; }
  .tab { height: 32px; font-size: .75rem; }
  .tab-add { width: 30px; height: 30px; }

  /* Tampilan awal (belum ada gambar): ringkas, 2 kolom, bisa digulir */
  .empty { inset: 8px; padding: 10px; gap: 8px; flex-direction: row; flex-wrap: wrap; align-content: safe center; justify-content: center; overflow-y: auto; font-size: .82rem; }
  .empty .big { width: 100%; font-size: 2.2rem; line-height: 1; }
  .empty > div:not(.big) { width: 100%; line-height: 1.35; }
  .empty .b { flex: 1 1 calc(50% - 6px) !important; padding: 9px 8px !important; font-size: .78rem; }
  .empty label.b { flex-basis: 100% !important; padding: 11px 8px !important; }

  /* Panel: lebih padat */
  .panel { gap: 8px; padding: 2px 2px 8px 0; }
  .sec { padding: 10px; border-radius: 14px; }
  .sec h2 { margin-bottom: 8px; }
  .tools { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .tools button.b { padding: 8px 2px; font-size: .64rem; line-height: 1.15; }
  .tools button.b span { font-size: 1.15rem; }
  .pal { grid-template-columns: repeat(8, 1fr); gap: 6px; }
  button.b, label.b { padding: 9px 8px; font-size: .8rem; }

  /* Bilah aksi objek: satu baris, bisa digeser ke samping */
  .selbar { top: 6px; max-width: calc(100% - 16px); flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; padding: 5px; gap: 5px; }
  .selbar::-webkit-scrollbar { display: none; }
  .selbar button { flex: none; white-space: nowrap; padding: 6px 7px; }

  /* Kontrol zoom */
  .zctl { right: 8px; bottom: 14px; gap: 4px; padding: 4px; }
  .zctl button { width: 30px; height: 30px; }
  .zctl span { min-width: 40px; font-size: .7rem; }

  /* Dialog */
  .modal { padding: 8px; }
  .mc { max-height: 92vh; max-height: 92dvh; padding: 14px; border-radius: 18px; }
  .cs-grid { grid-template-columns: repeat(2, 1fr); }
  .pj img { width: 52px; height: 40px; }
  .pj { gap: 6px; padding: 6px; }
  .pj button { padding: 6px 8px; font-size: .72rem; }
}

/* HP layar sangat sempit */
@media (max-width: 360px) {
  .hero h1 { font-size: 16px !important; }
  .tools { grid-template-columns: repeat(3, 1fr); }
  .pal { grid-template-columns: repeat(6, 1fr); }
}

/* HP posisi landscape: kanvas di kiri, panel di kanan */
@media (max-width: 950px) and (max-height: 500px) and (orientation: landscape) {
  body { padding: 6px; }
  .hero { margin-bottom: 4px; }
  .hero .logo { width: 32px !important; height: 32px !important; }
  .hero h1 { font-size: 18px !important; }
  .app { grid-template-columns: minmax(0, 1fr) clamp(250px, 38vw, 320px); grid-template-rows: minmax(0, 1fr); gap: 8px; }
  .tools { grid-template-columns: repeat(3, 1fr); }
}