/* Kampung Pixel — gaya acuan: wireframes/mobile-hifi.html (MVP 1: mobile view saja). */

@font-face {
  font-family: "Jersey 10";
  src: url("assets/fonts/Jersey10-Regular.woff2") format("woff2");
  font-display: block;
}

/* Palet "Kartu pos" (siang): retro seperti kartu pos lama, nyaman dilihat. Oranye bata untuk aksi, biru langit untuk
   area luas; permukaan krem netral agar cocok dengan diorama apa pun. Aturan pakai: halaman design-system/. */
:root {
  --paper: #f6efe1;        /* latar utama */
  --paper-hi: #fcf8ef;
  --paper-lo: #ece2cf;
  --line: #e3d7bf;
  --ink: #36343f;          /* teks; juga warna kunci ikon tombol (tools/import_icons.py) */
  --ink-soft: #6a6470;     /* teks sekunder, ≥ 4.5:1 di paper */
  --story: #8a5a3c;        /* suara cerita ("aku", kenangan, sapaan): cokelat hangat, ≥ 4.5:1 di kertas */
  /* halaman buku tulis bergaris: permukaan suara "aku" (selesai puzzle, penutup diorama) */
  --notebook: linear-gradient(90deg, transparent 27px, #e8a3a3 27px 29px, transparent 29px),
    repeating-linear-gradient(180deg, transparent 0 22px, #d6e0ee 22px 24px), #fbf7ec;
  --outline: #9c8a76;      /* garis komponen */
  --shade: #d9c9ad;        /* bayangan keras */
  --dark: #4d4a58;
  --primary: #de7330;      /* oranye bata: ajakan utama, satu per layar */
  --primary-dark: #ad5320;
  --secondary: #4b88bd;    /* biru: pilihan, fokus */
  --secondary-text: #2f6a9c;
  --success: #79a957;
  --success-dark: #4a7531; /* juga teks hijau, ≥ 4.5:1 */
  --gold: #f0be4a;
  --gold-dark: #c99a3a;
  --gold-soft: #fff6dc;
  --bad: #d65a4c;
  --mustard: #dfae3a;      /* kesulitan Sedang (bukan oranye, agar tidak tertukar dengan tombol utama) */
  --sky: #86bfe3;          /* langit siang, atas */
  --sky-horizon: #dde8e2;  /* langit dekat cakrawala */
  --sky-ink: #2e4560;      /* outline judul di langit, garis header, latar luar kolom */
  --font: "Jersey 10", system-ui, sans-serif;
  /* Jersey 10 berhuruf kecil (x-height 0.43 em): ukuran di bawah sudah ×1.45 dari ukuran desain. */
  --notch: polygon(2px 0, calc(100% - 2px) 0, calc(100% - 2px) 2px, 100% 2px, 100% calc(100% - 2px),
    calc(100% - 2px) calc(100% - 2px), calc(100% - 2px) 100%, 2px 100%, 2px calc(100% - 2px), 0 calc(100% - 2px), 0 2px, 2px 2px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 20px/1.25 var(--font);
  color: var(--ink);
  background: var(--sky-ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-synthesis: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg.px { display: block; image-rendering: pixelated; }
/* ikon piksel di tengah baris teks (centang di info barang dan progres warna) */
#sel-info2 svg.px, .sw-wrap small svg.px { display: inline-block; vertical-align: middle; }
[hidden] { display: none !important; }

/* MVP 1 hanya mobile: di layar lebar tampil sebagai kolom mobile di tengah. */
#app {
  position: relative;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  overflow: hidden;
}
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.error { padding: 24px; color: var(--bad); }

/* ---------- bingkai pixel 9-slice (sumber SVG: src/pixel-ui.js) ---------- */
.pf, .btn, .icon-btn, .pill, .mchip, .swatch, .dock-item, .g-card, .sel-card, .level-card, .modal,
.seg, .tool.active, .hint, .zoom-tag, .minimap, .sheet, .toast, .hero-stats .stat {
  border-style: solid; border-color: transparent; border-width: 6px; border-radius: 0;
  border-image-source: var(--f); border-image-slice: 6 fill;
  background: none;
}
/* timbul: bayangan pixel 2 unit di bawah (bingkai dengan depth 2 di pixel-ui.js harus memakai irisan ini) */
.btn, .icon-btn, .mchip, .swatch, .dock-item, .g-card, .sel-card, .level-card, .modal, .hero-stats .stat,
.demo-end, .wallet, .shop-pill, .hint.voice {
  border-bottom-width: 10px; border-image-slice: 6 6 10 6 fill;
}
/* isi sendiri (gradien/arsir) di dalam cincin bingkai */
.dock-item, .g-card.hidden { border-image-slice: 6 6 10 6; background-clip: padding-box; }
.notch { clip-path: var(--notch); }

/* ---------- tombol ---------- */
.btn {
  --f: var(--f-white);
  height: 52px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 22px; white-space: nowrap;
}
.btn.primary { --f: var(--f-primary); color: #fff; text-shadow: 1px 0 #8f3f12, -1px 0 #8f3f12, 0 1px #8f3f12, 0 -1px #8f3f12, 0 2px 0 #8f3f12; }
.btn.ok { --f: var(--f-success); color: #fff; text-shadow: 1px 0 #3d6427, -1px 0 #3d6427, 0 1px #3d6427, 0 -1px #3d6427, 0 2px 0 #3d6427; }
.btn.sm { height: 46px; font-size: 20px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }
.btn:active { transform: translateY(2px); }
.text-btn { border: 0; background: none; font-size: 19px; color: var(--ink-soft); min-height: 44px; padding: 0 12px; }
.icon-btn {
  --f: var(--f-white);
  flex: 0 0 auto; width: 44px; height: 48px; padding: 0;
  display: grid; place-items: center; color: var(--ink);
}
.icon-btn.flat { border: 0; border-image: none; width: 44px; height: 44px; margin: 0 -6px; }
.pill {
  --f: var(--f-flat-ink);
  position: relative; height: 34px; padding: 0 6px;
  display: inline-flex; align-items: center; gap: 6px; font-size: 17px; color: var(--ink);
}
.pill::after { content: ""; position: absolute; inset: -11px -8px; } /* area sentuh 44px */

/* ---------- top bar ---------- */
.topbar {
  flex: 0 0 auto; min-height: 60px;
  display: flex; align-items: center; gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  background: var(--paper-hi); border-bottom: 2px solid var(--outline);
  position: relative; z-index: 2;
}
.topbar:has(+ .pz-status) { border-bottom-color: var(--line); }
.title { flex: 1; min-width: 0; font-size: 25px; line-height: 1.1; }
.title .diff { margin-left: 6px; vertical-align: 3px; }
/* Saldo di header diorama: bintang + koin, ketuk = Toko */
.wallet { --f: var(--f-gold); flex: 0 0 auto; height: 40px; gap: 10px; padding: 0 8px; font-size: 20px; }
.wallet > span:not(.badge) { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- kesulitan & bintang ---------- */
.diff { display: inline-flex; align-items: center; gap: 2px; vertical-align: middle; }
.diff i { width: 6px; height: 6px; background: var(--line); }
.diff.d1 { --diff: var(--success); --diff-text: #4a7531; }
.diff.d2 { --diff: var(--mustard); --diff-text: #7d600f; }
.diff.d3 { --diff: var(--bad); --diff-text: #b0402f; }
.diff i.on { background: var(--diff); }
.diff em { font-style: normal; font-size: 15px; color: var(--diff-text); margin-left: 3px; }
.stars { display: inline-flex; gap: 1px; vertical-align: middle; }
.stars svg { filter: drop-shadow(0 1px 0 rgba(185, 130, 26, .6)); }

/* ---------- hint, toast ---------- */
.hint {
  --f: var(--f-dark);
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3;
  /* Teks panjang (mis. sapaan warga) membungkus di layar sempit alih-alih terpotong. */
  padding: 1px 6px; color: var(--paper); font-size: 16px; width: max-content; max-width: calc(100% - 24px); text-align: center;
  pointer-events: none; transition: opacity .5s;
}
.hint.bottom { top: auto; bottom: 12px; }
/* Suara cerita ("aku", sapaan warga): kertas terang berkutip, beda dari petunjuk kontrol yang gelap. */
.hint.voice { --f: var(--f-paper); color: var(--story); font-size: 18px; line-height: 1.15; padding: 3px 8px; max-width: min(34ch, calc(100% - 24px)); }
.hint.gone { opacity: 0; }
.hint:empty { display: none; }
.toast {
  --f: var(--f-dark);
  position: fixed; top: 76px; left: 50%; z-index: 40;
  transform: translate(-50%, -10px); opacity: 0;
  padding: 2px 8px; color: var(--paper); font-size: 18px; white-space: nowrap;
  pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- splash ---------- */
.resuming .splash-screen { visibility: hidden; } /* refresh: splash tidak berkedip sebelum layar terakhir pulih */
.splash-screen, .statusbar-sky { --logo-ink: var(--sky-ink); }
.splash {
  flex: 1 1 auto; position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center;
  padding: env(safe-area-inset-top) 24px calc(20px + env(safe-area-inset-bottom)); text-align: center;
  /* langit siang bergaris (hard stop, tanpa gradasi halus) agar terasa pixel; header Pilih Diorama melanjutkannya */
  background: linear-gradient(var(--sky) 0 14%, #94c6e5 14% 26%, #a3cde7 26% 38%, #b4d5e8 38% 48%,
    #c8dfe7 48% 57%, var(--sky-horizon) 57%);
  cursor: pointer;
}
.cloud {
  position: absolute; left: -90px; width: 72px; height: 16px;
  background: var(--px-cloud) 0 0 / 72px 16px no-repeat;
  animation: drift 40s linear infinite;
}
@keyframes drift { to { transform: translateX(580px); } }
.skyline { position: absolute; left: 0; right: 0; bottom: 0; line-height: 0; }
.skyline svg { width: 100%; height: auto; image-rendering: pixelated; }
.logo { position: relative; margin: auto 0; padding-bottom: 150px; }
.logo {
  --ol: 2px 0 var(--logo-ink), -2px 0 var(--logo-ink), 0 2px var(--logo-ink), 0 -2px var(--logo-ink),
        2px 2px var(--logo-ink), -2px 2px var(--logo-ink), 2px -2px var(--logo-ink), -2px -2px var(--logo-ink);
}
.logo h1 {
  margin: 8px 0 0; font-size: 81px; line-height: .92; font-weight: 400; color: #fff8ee;
  text-shadow: var(--ol), 0 6px 0 var(--logo-ink), 2px 6px 0 var(--logo-ink), -2px 6px 0 var(--logo-ink), 0 10px 0 rgba(46, 69, 96, .35);
}
.logo .tag {
  display: inline-block; margin-top: 18px; padding: 0 12px;
  font-size: 19px; line-height: 28px; letter-spacing: 5px; color: #fff;
  background: var(--primary); border: 2px solid var(--logo-ink); clip-path: var(--notch);
}
.logo .lede { margin: 14px 0 0; font-size: 20px; letter-spacing: 1px; color: #ffe7b8; text-shadow: var(--ol); }
.splash .bottom { position: relative; width: 100%; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.loader { width: 100%; height: 12px; padding: 2px; border: 2px solid var(--sky-ink); background: #fff; clip-path: var(--notch); }
.loader i {
  display: block; width: 0; height: 100%;
  background: repeating-linear-gradient(90deg, var(--success) 0 8px, #97c178 8px 10px);
  transition: width .2s steps(8);
}
.splash .meta { font-size: 16px; color: #fff3e6; text-shadow: 0 1px 0 var(--logo-ink); }
.splash .btn.primary { --f: var(--f-primary-ground); }

/* ajakan mengetuk: kilau pixel, tangan pixel mengetuk, tombol tertekan */
.cta-wrap { position: relative; width: 100%; }
.btn.cta { position: relative; overflow: hidden; animation: cta-press 2.4s step-end infinite; }
.btn.cta::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -40px; width: 22px;
  background: linear-gradient(90deg, rgba(255,255,255,.4) 0 8px, transparent 8px 12px, rgba(255,255,255,.4) 12px 16px, transparent 16px);
  transform: skewX(-20deg);
  animation: cta-shine 2.4s steps(14, end) infinite;
}
@keyframes cta-shine { 0% { left: -40px; } 40%, 100% { left: 110%; } }
@keyframes cta-press {
  0% { transform: none; }
  62% { transform: translateY(3px); }
  72% { transform: translateY(-3px); }
  78% { transform: translateY(-1px); }
  84% { transform: none; }
}
.tap-hand {
  position: absolute; right: 30px; bottom: -26px; z-index: 2; pointer-events: none;
  filter: drop-shadow(0 3px 0 rgba(46, 69, 96, .45));
  animation: hand-tap 2.4s step-end infinite;
}
@keyframes hand-tap {
  0% { transform: translate(0, 0); }
  46% { transform: translate(-3px, -6px); }
  54% { transform: translate(-6px, -12px); }
  62% { transform: translate(-6px, -14px); }
  72% { transform: translate(-3px, -6px); }
  80% { transform: translate(0, 0); }
}
.cta-wrap::after {
  content: ""; position: absolute; right: 50px; top: 50%; width: 6px; height: 6px; margin-top: 4px;
  border: 2px solid #fff8ee; opacity: 0; pointer-events: none; z-index: 1;
  animation: tap-ripple 2.4s steps(3, end) infinite;
}
@keyframes tap-ripple {
  0%, 61% { opacity: 0; transform: scale(.5); }
  62% { opacity: 1; transform: scale(1); }
  80% { opacity: 0; transform: scale(3.5); }
  100% { opacity: 0; }
}

/* ---------- pilih diorama ---------- */
/* Langit siang dari splash berlanjut ke sini; kartu diorama bernomor tersusun dalam grid 2 kolom. */
.select-hero {
  --logo-ink: var(--sky-ink);
  flex: 0 0 auto; position: relative; overflow: hidden; z-index: 1;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(var(--sky) 0 22%, #94c6e5 22% 42%, #a3cde7 42% 60%, #b4d5e8 60% 78%, #c8dfe7 78%);
  border-bottom: 4px solid var(--logo-ink);
}
.select-hero h2 {
  position: relative; margin: 4px 2px 12px; font-size: 34px; font-weight: 400; line-height: 1; color: #fff8ee;
  text-shadow: 2px 0 var(--logo-ink), -2px 0 var(--logo-ink), 0 2px var(--logo-ink), 0 -2px var(--logo-ink), 0 4px 0 var(--logo-ink);
}
.hero-stats { position: relative; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; } /* 4 stat: 2×2 agar muat di 360px */
.stat { min-width: 0; display: flex; flex-direction: column; }
.stat small { font-size: 15px; line-height: 1; color: var(--ink-soft); white-space: nowrap; }
.stat span { display: flex; align-items: center; gap: 4px; font-size: 21px; line-height: 1.15; white-space: nowrap; }
.hero-stats .stat { --f: var(--f-paper); padding: 0 2px 1px; }

.list-body {
  flex: 1 1 auto; overflow: auto; padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; align-content: start;
  background:
    radial-gradient(rgba(91, 58, 38, .1) 1.2px, transparent 1.4px) 0 0 / 14px 14px,
    var(--paper);
}
/* Kaki daftar: masukan (demo), hapus progres, versi. */
.select-foot { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 8px; }
.select-foot .version { font-size: 15px; color: var(--ink-soft); }
/* Kartu grid: gambar diorama di atas, info di bawah, tombol main menempel di dasar kartu. */
.level-card {
  --f: var(--f-paper); position: relative; display: flex; flex-direction: column; min-width: 0;
  text-align: left; padding: 0; animation: card-in .3s steps(4, end) backwards;
}
.level-card:nth-child(2) { animation-delay: .06s; }
.level-card:nth-child(3) { animation-delay: .12s; }
.level-card:nth-child(4) { animation-delay: .18s; }
@keyframes card-in { from { transform: translateY(14px); opacity: 0; } }
.level-card:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; }
.level-card:active .btn { transform: translateY(2px); }
.level-card.focus { --f: var(--f-gold); }
.level-card.locked { --f: var(--f-hidden); }

.level-card .art {
  position: relative; display: grid; place-items: center; min-height: 120px; padding: 2px 0;
  border-bottom: 2px solid var(--line); clip-path: var(--notch);
  background:
    radial-gradient(rgba(91, 58, 38, .1) 1.2px, transparent 1.4px) 0 0 / 14px 14px,
    radial-gradient(ellipse at 50% 42%, #f6eddc 0, #dcc9a8 80%);
}
/* gambar diorama memenuhi lebar kartu (skala tak bulat; pixel tetap tajam lewat pixelated) */
.level-card canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.level-card.locked .art { background: repeating-linear-gradient(45deg, var(--paper-lo) 0 6px, var(--paper) 6px 12px); }
.level-card.locked .lock { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
/* "Segera hadir": satu panel arsir setinggi baris, isi di tengah */
.level-card.soon {
  min-height: 200px; align-items: center; justify-content: center; gap: 2px; padding: 12px 8px; text-align: center;
  border-image-slice: 6 6 10 6; background-clip: padding-box;
  background-image: repeating-linear-gradient(45deg, var(--paper-lo) 0 6px, var(--paper) 6px 12px);
}
.level-card.soon .mystery {
  width: 56px; height: 56px; margin-bottom: 6px; display: grid; place-items: center;
  font-size: 46px; line-height: 1; color: #b8a98c;
  background: var(--paper-hi); border: 2px dashed var(--shade); clip-path: var(--notch);
}
.level-card.soon b { font-size: 21px; }
.level-card.soon .meta { justify-content: center; margin-top: 0; font-size: 15px; }
/* nomor diorama di pojok gambar diorama */
.stop {
  position: absolute; top: 4px; left: 4px; z-index: 2; width: 28px; height: 28px;
  display: grid; place-items: center; font-size: 21px; line-height: 1; color: #fff;
  background: #b9a78e; border: 2px solid var(--paper-hi); clip-path: var(--notch);
}
.stop.now { background: var(--primary); }
.stop.done { background: var(--success-dark); }

.level-card .info { flex: 1 1 auto; display: flex; flex-direction: column; padding: 6px 4px 2px; }
.level-card b { display: block; font-size: 23px; font-weight: 400; line-height: 1.05; overflow-wrap: anywhere; }
.level-card.locked b { color: var(--ink-soft); }
.level-card .blurb { margin: 2px 0 4px; font-size: 16px; line-height: 1.1; color: var(--ink-soft); }
.card-stats { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 2px; font-size: 19px; line-height: 1.15; }
.card-stats > span { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.level-card .meta { display: flex; align-items: center; gap: 4px; font-size: 16px; line-height: 1.1; color: var(--ink-soft); margin-top: 4px; }
.level-card .meta.ok { color: var(--success-dark); }
.level-card .meta [data-icon] { flex: 0 0 auto; }
.level-card > .btn { margin-top: 6px; }

/* blok slot: progres furnitur per diorama */
.slots { display: flex; flex-direction: column; margin-top: 5px; }
.slot-bar { display: flex; gap: 1px; height: 12px; padding: 2px; border: 2px solid var(--outline); background: #fff; clip-path: var(--notch); }
.slot-bar i { flex: 1; min-width: 0; background: var(--paper-lo); }
.slot-bar i.on { background: var(--success); box-shadow: inset 0 -2px 0 var(--success-dark); }

/* ---------- stage (diorama & puzzle) ---------- */
.stage { flex: 1 1 auto; min-height: 0; position: relative; overflow: hidden; }
.stage.dotted {
  background:
    radial-gradient(rgba(91, 58, 38, .1) 1.2px, transparent 1.4px) 0 0 / 14px 14px,
    radial-gradient(ellipse at 50% 42%, #f6eddc 0, #dcc9a8 80%);
}
.stage.checker { background: repeating-conic-gradient(#efe6d4 0 25%, #f8f2e6 0 50%) 0 0 / 14px 14px; }
canvas.main { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.minimap { --f: var(--f-flat-ink); position: absolute; top: 12px; left: 12px; z-index: 2; width: 108px; padding: 0; line-height: 0; }
.minimap canvas { width: 96px; image-rendering: pixelated; }
.zoom-tag { --f: var(--f-dark); position: absolute; top: 12px; right: 12px; z-index: 2; padding: 0 4px; color: var(--paper); font-size: 19px; transition: opacity .4s; }
.zoom-tag.gone { opacity: 0; }

.sel-card {
  --f: var(--f-paper);
  position: absolute; left: 10px; right: 10px; bottom: 12px; z-index: 3;
  display: flex; align-items: center; gap: 10px; padding: 2px;
}
.sel-thumb {
  flex: 0 0 auto; width: 52px; height: 52px; display: grid; place-items: center;
  background: linear-gradient(#f3ead8 62%, #e6d8bd 62%); border: 2px solid var(--line); clip-path: var(--notch);
}
.sel-thumb img { image-rendering: pixelated; }
.sel-card .grow { flex: 1; min-width: 0; }
.sel-card b { display: block; font-size: 22px; font-weight: 400; }
.sel-card .meta { display: block; font-size: 16px; color: var(--ink-soft); margin-top: 1px; }

/* ---------- dock ---------- */
.dock-wrap { flex: 0 0 auto; position: relative; background: var(--paper-hi); border-top: 2px solid var(--outline); padding-bottom: env(safe-area-inset-bottom); }
.dock-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px 0 14px; font-size: 17px; color: var(--ink-soft); }
.dock-head b { color: var(--ink); font-size: 20px; font-weight: 400; margin-left: 2px; }
.dock { display: flex; gap: 10px; overflow-x: auto; padding: 16px 12px 14px; scrollbar-width: none; }
.dock-item {
  --f: var(--f-card);
  position: relative; flex: 0 0 76px; height: 90px; padding: 0 0 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px;
  background-image: linear-gradient(#fff 60%, #f1e7d4 60%);
}
/* area gambar mengisi ruang di atas label; sprite (sudah dipotong ke piksel terlihat) di tengahnya */
.dock-item .art { flex: 1; width: 100%; display: grid; place-items: center; padding-top: 6px; pointer-events: none; }
.dock-item img { image-rendering: pixelated; display: block; }
.dock-item small { font-size: 14px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; max-width: 64px; text-overflow: ellipsis; }
.dock-item .diff { position: absolute; top: 0; right: 0; }
.dock-item .count {
  position: absolute; top: -12px; left: -10px; min-width: 22px; height: 22px; padding: 0 4px;
  font-size: 16px; line-height: 18px; text-align: center; color: var(--gold-soft);
  background: var(--dark); border: 2px solid var(--paper-hi); clip-path: var(--notch);
}
.dock-item.ready { --f: var(--f-ready); touch-action: none; cursor: grab; }
.dock-item.ready::before {
  content: "SIAP"; position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  padding: 0 5px; font-size: 13px; line-height: 18px; color: #fff; background: var(--success-dark); clip-path: var(--notch);
}
.dock-item.sel { --f: var(--f-sel); }
.dock-item.ready.sel { animation: nudge 1.2s ease-in-out 2; }
@keyframes nudge { 50% { transform: translateY(-6px); } }
.dock-item.locked .lock { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); }
.dock-item.hidden { --f: var(--f-hidden); justify-content: center; background-image: repeating-linear-gradient(45deg, var(--paper-lo) 0 6px, var(--paper) 6px 12px); cursor: default; }
.dock-item .mystery { font-size: 40px; line-height: 1; color: #b8a98c; margin-top: auto; }
.dock-item.dragging { --f: var(--f-drag-secondary); background-image: none; }
.dock-item.dragging img { opacity: .25; }
.dock-item.dragging::before { display: none; }
.dock-empty { margin: auto; color: var(--ink-soft); font-size: 18px; }

/* ---------- galeri "Semua" ---------- */
.modal-dim { position: absolute; inset: 0; background: rgba(46, 69, 96, .55); z-index: 10; }
.sheet {
  --f: var(--f-sheet);
  position: absolute; left: 0; right: 0; bottom: 0; height: 84%; z-index: 11;
  border-bottom-width: 0; display: flex; flex-direction: column;
  animation: sheet-in .25s steps(5, end);
}
@keyframes sheet-in { from { transform: translateY(40%); opacity: 0; } }
.sheet-handle { width: 44px; height: 4px; background: var(--line); margin: 4px auto 2px; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 2px 6px 10px 10px; }
.sheet-head b { font-size: 26px; font-weight: 400; }
.sheet-head .sub { flex: 1; display: flex; align-items: center; gap: 4px; font-size: 17px; color: var(--ink-soft); }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 4px 8px calc(14px + env(safe-area-inset-bottom)); overflow: auto; }
.g-card { --f: var(--f-card); position: relative; padding: 2px 2px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.g-card .art { width: 100%; height: 84px; display: grid; place-items: center; background: linear-gradient(#f3ead8 66%, #e6d8bd 66%); clip-path: var(--notch); }
.g-card .art img { image-rendering: pixelated; display: block; }
.g-card b { font-size: 17px; font-weight: 400; margin-top: 2px; line-height: 1.05; }
.g-card small { font-size: 14px; color: var(--ink-soft); }
.g-card.placed { --f: var(--f-placed); }
.g-card.placed small, .g-card.ready small { color: var(--success-dark); }
.g-card.ready { --f: var(--f-ready); }
.g-card.hidden { --f: var(--f-hidden); background-image: repeating-linear-gradient(45deg, var(--paper-lo) 0 6px, var(--paper) 6px 12px); }
.g-card.hidden .art { background: none; }
.g-card .mystery { font-size: 46px; color: #b8a98c; }
.g-card .ribbon { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; display: grid; place-items: center; background: var(--success-dark); color: #fff; font-size: 16px; clip-path: var(--notch); }
.g-detail { grid-column: 1 / -1; }

/* ---------- selesai level ---------- */
.done-panel { flex: 0 0 auto; background: var(--paper-hi); border-top: 2px solid var(--outline); padding: 10px 0 env(safe-area-inset-bottom); }
.done-story { margin: 0 14px 6px; padding: 4px 8px 4px 36px; font-size: 20px; line-height: 24px; text-align: center; color: var(--ink); background: var(--notebook); }
/* Akhir demo: kartu ajakan masukan di bawah penutup cerita (PRD.md §15). */
.demo-end { --f: var(--f-paper); margin: 0 12px 8px; padding: 8px 10px 10px; text-align: center; }
.demo-end b { display: block; font-size: 24px; font-weight: 400; line-height: 1; }
.demo-end p { margin: 4px 0 8px; font-size: 18px; line-height: 1.1; color: var(--ink-soft); }
.demo-links { display: flex; gap: 8px; }
.demo-links .btn { flex: 1; min-width: 0; }
a.btn { color: inherit; text-decoration: none; }
a.btn.primary { color: #fff; }
.detail-art { display: grid; place-items: center; min-height: 100px; }
.detail-art img { image-rendering: pixelated; display: block; }
.detail-memory { max-width: 26ch; font-size: 20px; line-height: 1.15; color: var(--story); }
/* Toko karakter */
.shop-pill { --f: var(--f-gold); }
.shop-tabs { display: flex; gap: 8px; padding: 0 10px 10px; }
.shop-tab { --f: var(--f-white); position: relative; flex: 1; height: 40px; font-size: 19px; color: var(--ink-soft); border-style: solid; border-color: transparent; border-width: 6px 6px 10px; border-image-source: var(--f); border-image-slice: 6 6 10 6 fill; background: none; }
.shop-tab[aria-selected="true"] { --f: var(--f-gold); color: var(--ink); }
.shop-card .magic-art { background: linear-gradient(#fff6dc 66%, #f8e7b9 66%); }
.shop-card .have { color: var(--ink); }
.shop-note { margin: 2px 6px 0; font-size: 16px; line-height: 1.15; color: var(--ink-soft); text-align: center; }
.shop-list { display: flex; flex-direction: column; gap: 10px; padding: 4px 8px calc(14px + env(safe-area-inset-bottom)); overflow: auto; }
.shop-card { --f: var(--f-card); display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.shop-card .art { flex: 0 0 76px; height: 96px; display: grid; place-items: center; background: linear-gradient(#f3ead8 66%, #e6d8bd 66%); clip-path: var(--notch); }
.shop-card .art img { image-rendering: pixelated; display: block; }
.shop-card .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.shop-card b { font-size: 21px; font-weight: 400; line-height: 1; }
.shop-card small { font-size: 15px; line-height: 1.1; color: var(--ink-soft); }
.shop-card .btn { align-self: flex-start; margin-top: 6px; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.shop-card.owned .btn { color: var(--success-dark); }
.dock-actions { display: inline-flex; gap: 14px; }
.badge { position: absolute; top: -9px; right: -9px; min-width: 18px; height: 18px; padding: 0 4px; display: grid; place-items: center; background: var(--gold); color: var(--ink); font-size: 15px; line-height: 1; clip-path: var(--notch); animation: badge-pop .5s steps(4, end) 2; }
@keyframes badge-pop { 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .badge { animation: none; } }
#done-shop, .wallet { position: relative; }
.done-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 12px 10px; }
.done-actions .btn { flex: 1 1 auto; } /* turun ke baris kedua bila tidak muat (layar 360 px + tombol Toko) */

/* ---------- modal & overlay ---------- */
.overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(46, 69, 96, .6); }
.modal { --f: var(--f-paper); width: 100%; max-width: 320px; padding: 16px 12px 10px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.modal b { font-size: 32px; font-weight: 400; }
.modal p { margin: 0 0 6px; color: var(--ink-soft); font-size: 19px; }
.modal .btn { width: 100%; }
.reward { font-size: 19px; color: var(--success-dark); display: flex; align-items: center; gap: 6px; }
.buy-icon { line-height: 0; }
.buy-coins { display: flex; align-items: center; gap: 6px; font-size: 19px; }
.reveal-coins { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 17px; animation: reveal-pop .4s steps(5, end) backwards; animation-delay: .3s; }
/* Ada kenangan: kenangan tampil dulu (2,85 s), "Selesai" dan koin menyusul (PLACE_BTN_MS di puzzle-view.js). */
.reveal.has-memory .reveal-done { animation-delay: 3.35s; }
.reveal.has-memory .reveal-coins { animation-delay: 3.5s; }
.reveal-coins .reward { color: var(--ink); }
.reveal-coins .perfect { color: var(--success-dark); }

/* ---------- puzzle ---------- */
.pz-status {
  flex: 0 0 auto; height: 50px;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: var(--paper-hi); border-bottom: 2px solid var(--outline);
}
.coins { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; font-size: 19px; color: var(--ink); }
.pzbar { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.pzbar .track { flex: 1; height: 12px; border: 2px solid var(--line); background: var(--paper-lo); clip-path: var(--notch); overflow: hidden; }
.pzbar .track i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--gold) 0 6px, #f8dc8e 6px 8px); transition: width .35s steps(5); }
.pzbar small { min-width: 40px; font-size: 19px; }
.pzbar.done .track i { background: var(--success); }
.pzbar.done small { color: var(--success-dark); }
/* Gambar furnitur di strip status (bukan di atas grid agar tidak menutupi area mewarnai) */
.ref-btn { --f: var(--f-flat-ink); flex: 0 0 auto; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; }
.ref-btn canvas { display: block; image-rendering: pixelated; }
.ref-modal canvas { display: block; margin: 2px auto 0; image-rendering: pixelated; }
.ref-view { cursor: pointer; }
.dev-finish {
  position: absolute; top: 12px; right: 12px; z-index: 2; height: 34px; padding: 0 10px;
  border: 1px dashed #d9a400; background: rgba(255, 250, 240, .92); color: #8a6a00; font-size: 16px;
}

.controls { flex: 0 0 auto; background: var(--paper-hi); border-top: 2px solid var(--outline); padding-bottom: env(safe-area-inset-bottom); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 0; }
.seg { --f: var(--f-seg); display: flex; gap: 2px; padding: 0; }
.tool { height: 40px; padding: 0 8px; border: 0; background: transparent; display: flex; align-items: center; gap: 5px; font-size: 19px; color: var(--ink); }
.tool.active { --f: var(--f-dark); border-width: 6px; border-image-slice: 6 fill; padding: 0 2px; color: var(--paper); }
/* Alat + magic harus muat di 360px: di layar sempit label alat pindah ke bawah ikon. */
@media (max-width: 389px) {
  .tool { flex-direction: column; justify-content: center; gap: 1px; min-width: 46px; padding: 0 7px; font-size: 15px; line-height: 1; }
  .tool.active { padding: 0 1px; }
  .toolbar .magics { gap: 5px; }
}
.magics { position: relative; display: flex; gap: 8px; padding-bottom: 9px; }
.mchip { --f: var(--f-gold); position: relative; width: 44px; height: 48px; padding: 0; display: grid; place-items: center; touch-action: none; }
.mchip .count {
  position: absolute; top: -10px; right: -12px; min-width: 22px; height: 22px; padding: 0 4px;
  font-size: 17px; line-height: 18px; text-align: center; color: var(--gold-soft);
  background: var(--dark); border: 2px solid var(--paper-hi); clip-path: var(--notch);
}
/* Chip kosong tetap bisa diketuk untuk membeli */
.mchip.empty > span { filter: grayscale(1); opacity: .45; }
.mchip.dragging { --f: var(--f-drag-magic); }
.mchip.dragging svg { opacity: .25; }
.mchip.charged { animation: charged .6s steps(4, end); }
/* Tips magic: chip yang dibahas berkedip agar mudah ditemukan */
.mchip.tut-blink { animation: tut-blink .9s steps(2, jump-none) infinite; }
@keyframes tut-blink {
  0% { transform: translateY(0); box-shadow: 0 0 0 0 rgba(240, 190, 74, 0); }
  100% { transform: translateY(-4px); box-shadow: 0 0 0 4px rgba(240, 190, 74, .9), 0 0 0 8px rgba(240, 190, 74, .35); }
}
@keyframes charged { 50% { transform: translateY(-6px); } }
.dev-refill { position: absolute; left: -20px; bottom: 8px; width: 18px; height: 18px; padding: 0; border: 1px dashed #d9a400; background: transparent; color: #8a6a00; font-size: 14px; line-height: 1; }

.palette { display: flex; gap: 8px; overflow-x: auto; padding: 16px 12px 14px; scrollbar-width: none; }
.sw-wrap { position: relative; flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.swatch {
  width: 44px; height: 48px; padding: 0;
  font-size: 23px; color: #fff;
  /* garis tepi keras 1px tanpa blur; warna terang memakai angka gelap (swatchInk) */
  text-shadow: 1px 0 #36343f, -1px 0 #36343f, 0 1px #36343f, 0 -1px #36343f,
    1px 1px #36343f, -1px 1px #36343f, 1px -1px #36343f, -1px -1px #36343f;
}
.swatch.ink-dark { color: #36343f; text-shadow: none; }
.swatch.active { transform: translateY(-4px); } /* garis emasnya dari swatchFrame(css, true) */
.sw-wrap.active::before {
  content: ""; position: absolute; top: -14px; left: 50%; width: 10px; height: 6px; margin-left: -5px;
  background: var(--px-caret) center / 10px 6px no-repeat;
}
.swatch:disabled { opacity: .3; cursor: default; }
.swatch.locked, .tool.locked { opacity: .4; } /* tutorial: belum boleh dipilih (masih bisa diketuk untuk pesan) */
.swatch.just-done { animation: swatch-done .6s steps(4, end); }
@keyframes swatch-done { 40% { transform: scale(1.25); } }
.sw-wrap small { font-size: 15px; color: var(--ink-soft); }
.sw-wrap small.ok { color: var(--success-dark); }

/* momen sprite selesai */
.reveal {
  /* top diatur JS = tepat di bawah header; bisa digulir di layar pendek agar tombol tidak terpotong */
  position: absolute; left: 0; right: 0; bottom: 0; top: 0; z-index: 15; overflow-x: hidden; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 8px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  scrollbar-width: none;
  background: var(--notebook);
}
.reveal > *:not(.sparkle) { position: relative; }
.reveal .hero { image-rendering: pixelated; filter: drop-shadow(0 4px 0 rgba(92, 74, 64, .25)); animation: reveal-pop .5s steps(6, end); }
.reveal .lapse { cursor: pointer; }
@keyframes reveal-pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.08); } }
.reveal .name { font-size: 32px; }
/* Kenangan cerita: muncul setelah timelapse (2,85 s); tanpa animasi saat reduced motion. */
.reveal .memory {
  max-width: 28ch; margin: 2px 0 6px; font-size: 21px; line-height: 1.15; color: var(--story); text-align: center;
  animation: story-in .4s ease-out backwards; animation-delay: 2.85s;
}
.reveal-done { display: flex; align-items: center; gap: 6px; font-size: 24px; color: var(--success-dark); animation: reveal-pop .4s steps(5, end) backwards; animation-delay: .15s; }
.reveal-actions { display: flex; gap: 8px; width: 100%; max-width: 300px; margin-top: 12px; }
.reveal-actions .btn { flex: 1; }
.reveal-actions.in { animation: reveal-pop .4s steps(5, end); }
.sparkle { position: absolute; z-index: 1; animation: twinkle 1.6s ease-in-out infinite; }
.sparkle:nth-of-type(2n) { animation-delay: .6s; }
@keyframes twinkle { 50% { transform: scale(.5); opacity: .4; } }

.drag-ghost {
  position: fixed; z-index: 30; pointer-events: none;
  image-rendering: pixelated; transform-origin: 50% 100%;
  filter: drop-shadow(0 4px 0 rgba(92, 74, 64, .25));
}

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

/* ---------- pembuka cerita (src/story.js) ---------- */
/* Baris muncul bergiliran; `backwards` membuat teks tetap tampil saat animasi dimatikan (reduced motion). */
.story-intro {
  position: absolute; inset: 0; z-index: 45;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 36px;
  padding: max(24px, env(safe-area-inset-top)) 28px max(24px, env(safe-area-inset-bottom));
  background: #2a2433; color: #f4ecdf; text-align: center;
}
.story-lines p { margin: 0 0 18px; font-size: 26px; line-height: 1.2; animation: story-in .6s ease-out backwards; }
.story-intro .btn { min-width: 160px; animation: story-in .6s ease-out backwards; animation-delay: 2.9s; }
@keyframes story-in { from { opacity: 0; transform: translateY(6px); } }
/* pembuka memudar dan memperlihatkan ruangan abu-abu di belakangnya */
.story-intro { transition: opacity .9s ease-in; }
.story-intro.leaving { opacity: 0; pointer-events: none; }

/* Judul episode: ruangan tampil dulu tanpa UI, lalu nama tempat. Header dan dock masuk setelahnya. */
#diorama-screen .topbar, #diorama-screen .dock-wrap { transition: opacity .5s ease-out; }
#diorama-screen.arriving .topbar, #diorama-screen.arriving .dock-wrap { opacity: 0; pointer-events: none; }
.arrive {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); z-index: 6;
  padding: 14px 24px 12px; text-align: center; color: #f4ecdf;
  background: linear-gradient(90deg, transparent, rgba(42, 36, 51, .82) 18%, rgba(42, 36, 51, .82) 82%, transparent);
  animation: story-in .8s ease-out backwards; transition: opacity .5s ease-in;
}
.arrive.leaving { opacity: 0; }
.arrive b { display: block; font-size: 34px; font-weight: 400; line-height: 1.05; }
.arrive p { max-width: 26ch; margin: 6px auto 0; font-size: 20px; line-height: 1.15; color: #d9cfc0; animation: story-in .8s ease-out backwards; animation-delay: .6s; }

/* ---------- tutorial pertama kali (src/tutorial.js) ---------- */
.tut { position: absolute; inset: 0; z-index: 50; pointer-events: none; }
.tut-shade { position: absolute; background: rgba(46, 69, 96, .62); pointer-events: auto; }
.tut-ring {
  position: absolute; pointer-events: none;
  outline: 3px solid var(--gold); outline-offset: 0;
  box-shadow: 0 0 0 6px rgba(240, 190, 74, .35);
  animation: tut-pulse 1.2s steps(3, end) infinite alternate;
}
@keyframes tut-pulse { to { box-shadow: 0 0 0 10px rgba(240, 190, 74, .15); } }
.tut-bubble {
  --f: var(--f-paper);
  position: absolute; left: 12px; right: 12px; pointer-events: auto;
  border-style: solid; border-color: transparent; border-width: 6px 6px 10px; border-image-source: var(--f); border-image-slice: 6 6 10 6 fill;
  padding: 4px 6px 2px;
}
/* monolog "aku" (suara yang sama dengan kenangan barang), lalu petunjuk kontrol */
.tut-say { margin: 0 0 4px; font-size: 19px; line-height: 1.15; color: var(--story); }
.tut-say::before { content: "“"; }
.tut-say::after { content: "”"; }
.tut-text { margin: 0 0 6px; font-size: 21px; line-height: 1.2; }
.tut-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tut-actions .text-btn { padding: 0; font-size: 17px; }
.tut-ok { margin-left: auto; } /* tetap di kanan saat tombol lewati disembunyikan */
/* panah yang menunjuk titik aksi langkah ini; memantul ke arah sasaran */
.tut-arrow {
  position: absolute; width: 27px; height: 30px; pointer-events: none;
  background: var(--px-arrow) center / 100% 100% no-repeat; image-rendering: pixelated;
  filter: drop-shadow(0 2px 0 rgba(46, 69, 96, .35));
  --flip: 1; --bob: -7px;
  animation: tut-bob .7s steps(2, jump-none) infinite alternate;
}
.tut-arrow.up { --flip: -1; --bob: 7px; }
@keyframes tut-bob {
  from { transform: translateY(0) scaleY(var(--flip)); }
  to { transform: translateY(var(--bob)) scaleY(var(--flip)); }
}
@media (prefers-reduced-motion: reduce) { .tut-arrow { animation: none; transform: scaleY(var(--flip)); } }
/* menunggu event (mis. puzzle siap diwarnai): tutorial tidak menghalangi layar */
.tut.waiting .tut-shade, .tut.waiting .tut-ring, .tut.waiting .tut-bubble, .tut.waiting .tut-arrow,
.tut.lost .tut-shade, .tut.lost .tut-ring, .tut.lost .tut-bubble, .tut.lost .tut-arrow { display: none; }
