@import url("https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&display=swap");

:root {
  --bg: #fff6e6;
  --panel: #ffffff;
  --ink: #2b2240;
  --muted: #7a6f8f;
  --accent: #ff7a45;
  --accent-ink: #ffffff;
  --line: #efe3cf;
  --shadow: 0 6px 18px rgba(80, 50, 20, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

/* ---------- Halaman mewarnai ---------- */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}

.topbar .judul { flex: 1; min-width: 0; line-height: 1.1; }
.topbar .judul small { display: block; color: var(--muted); font-size: 13px; font-weight: 500; }
.topbar .judul strong { display: block; font-size: 20px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-simpan {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 16px;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.btn-simpan:active { transform: scale(0.96); }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 16px;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.kanvas {
  position: relative;
  flex: none;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transform-origin: center center;
  will-change: transform;
}

.zoom {
  position: absolute;
  right: 22px;
  top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}
.zoom button {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--ink);
}
.zoom button svg { width: 22px; height: 22px; stroke: currentColor; }
.zoom button:disabled { opacity: 0.35; }
.zoom button:active { transform: scale(0.92); }
.kanvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.kanvas .garis { pointer-events: none; }

.memuat {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); font-weight: 700;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 18px rgba(80, 50, 20, 0.08);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.alat { display: flex; gap: 8px; }
.alat button {
  flex: 1;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 6px 2px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 0;
  font-size: 12px; font-weight: 700; color: var(--muted);
  cursor: pointer;
}
.alat button svg { width: 24px; height: 24px; stroke: currentColor; }
.alat button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: #fff3ec; }
.alat button:disabled { opacity: 0.35; }
.alat button:active { transform: scale(0.95); }

.ukuran { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); font-weight: 700; }
.ukuran input { flex: 1; accent-color: var(--accent); }
.ukuran[hidden] { display: none; }

.palet {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
}
.palet button {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--line);
  cursor: pointer;
  padding: 0;
}
.palet button[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.08); }
.palet label {
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
  box-shadow: 0 0 0 2px var(--line);
  border: 3px solid #fff;
  position: relative;
  cursor: pointer;
}
.palet label input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

@media (max-width: 380px) {
  .palet { grid-template-columns: repeat(9, 1fr); gap: 5px; }
}

/* ---------- Layar Selesai ---------- */
.layar {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(43, 34, 64, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  overflow-y: auto;
}
.layar[hidden] { display: none; }
.konfeti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 12; }
.sheet {
  position: relative; z-index: 11;
  background: var(--panel);
  width: 100%; max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 20px 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  text-align: center;
  animation: naik 0.35s cubic-bezier(.2, .9, .3, 1.2);
  margin-top: auto;
}
@keyframes naik { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 560px) {
  .layar { align-items: center; padding: 24px; }
  .sheet { border-radius: 24px; margin-top: 0; }
}
.bintang { font-size: 44px; line-height: 1; color: #ffc531; letter-spacing: 6px; }
.bintang span { display: inline-block; animation: loncat 0.6s ease-out backwards; text-shadow: 0 3px 0 #e8a400; }
.bintang span:nth-child(2) { animation-delay: 0.12s; font-size: 54px; }
.bintang span:nth-child(3) { animation-delay: 0.24s; }
@keyframes loncat { from { transform: scale(0) rotate(-30deg); } 70% { transform: scale(1.3); } }
.sheet h2 { margin: 0; font-size: 28px; font-weight: 800; }
.lencana { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.lencana span { background: #fff3ec; color: #c2552a; font-weight: 700; font-size: 14px; padding: 4px 12px; border-radius: 999px; }
.nama { display: flex; flex-direction: column; gap: 4px; text-align: left; font-weight: 700; }
.nama input { font: inherit; font-size: 18px; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--line); outline: none; }
.nama input:focus { border-color: var(--accent); }
.pratinjau { width: 100%; max-height: 32vh; object-fit: contain; border-radius: 12px; background: var(--bg); }
.tombol-hasil { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tombol-hasil button, .btn-lembar, .btn-lanjut {
  border: 0; border-radius: 14px; padding: 12px 6px; font-weight: 800; font-size: 15px; cursor: pointer;
}
.tombol-hasil button { background: var(--accent); color: var(--accent-ink); }
.tombol-hasil button:disabled { opacity: 0.6; }
.btn-lembar { background: #e9f8ef; color: #1f8a4f; }
.btn-lanjut { background: transparent; color: var(--muted); }
.info-lembar { margin: 0; color: var(--muted); font-size: 14px; }

.cetak { display: none; }
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; height: auto; }
  body > *:not(.cetak) { display: none !important; }
  .cetak { display: block; }
  .cetak img { width: 100%; height: auto; display: block; }
}

/* ---------- Halaman daftar & QR ---------- */
.halaman { max-width: 860px; margin: 0 auto; padding: 24px 16px 48px; }
.halaman h1 { font-size: 32px; margin: 0 0 4px; font-weight: 800; }
.halaman p.lead { color: var(--muted); margin: 0 0 20px; }

.grid-kartu {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.kartu-item {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  text-decoration: none;
  color: inherit;
  display: flex; flex-direction: column; gap: 6px;
}
.kartu-item img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 12px; border: 2px solid var(--line); }
.kartu-item small { color: var(--muted); }
.kartu-item strong { font-size: 18px; }

.qr-form { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 18px; }
.qr-form label { font-weight: 700; display: block; margin-bottom: 6px; }
.qr-form input { width: 100%; font: inherit; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); }
.qr-form .catatan { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.peringatan { background: #fff0d6; border: 2px solid #ffd28a; border-radius: 14px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }

.qr-item { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.qr-item canvas { width: 100%; height: auto; image-rendering: pixelated; border-radius: 8px; }
.qr-item code { font-size: 12px; word-break: break-all; color: var(--muted); }
.qr-item .aksi { display: flex; gap: 8px; }
.qr-item .aksi button { flex: 1; border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 6px; font-weight: 700; cursor: pointer; }
.qr-item .aksi button:hover { border-color: var(--accent); color: var(--accent); }

.tautan { display: inline-block; margin-top: 24px; color: var(--accent); font-weight: 700; }
