:root {
  --night: #1A2238;
  --night-deep: #101626;
  --amber: #F4B942;
  --amber-soft: #FFE19C;
  --ticket: #F5EFE0;
  --paper: #EAE0CA;
  --ink: #1C1B22;
  --stamp: #C93B2B;
  --peron: #2D6A4F;
  --mint: #CDEBD5;
  --muted: #6C635A;
  --display: 'Bungee', 'Arial Black', Impact, system-ui, sans-serif;
  --hand: 'Patrick Hand', 'Comic Sans MS', system-ui, sans-serif;
  --ui: 'Inter', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--night-deep); color: var(--ink); font-family: var(--ui); user-select: none; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; overflow: hidden; background: var(--night); }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#game.dragging { cursor: grabbing; }
#fxCanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 14; }
#fade { position: absolute; inset: 0; background: var(--night-deep); opacity: 0; pointer-events: none; z-index: 25; transition: opacity 0.25s ease; }
#fade.on { opacity: 1; }

/* Floating 3D-projected speech bubbles */
#bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 6; overflow: hidden; }
.bubble {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  width: max-content; max-width: min(240px, 68vw);
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 6px 11px; font-family: var(--hand); font-size: 16px; line-height: 1.2;
  color: var(--ink); box-shadow: 3px 3px 0 rgba(28,27,34,0.28); text-align: center;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -11px; margin-left: -8px;
  border: 8px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}
.bubble::before {
  content: ""; position: absolute; left: 50%; bottom: -7px; margin-left: -5px;
  border: 5px solid transparent; border-top-color: #fff; border-bottom: 0; z-index: 1;
}

/* HUD */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(10px, env(safe-area-inset-top)) 10px 0;
  pointer-events: none; gap: 6px;
}
.hud-col { display: flex; flex-direction: column; gap: 6px; pointer-events: auto; }
.hud-row { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.hud-col.right { align-items: flex-end; }

.chip {
  font-family: var(--display); font-size: clamp(10px, 2.5vw, 12.5px); letter-spacing: 0.04em;
  background: var(--ink); color: var(--ticket); border: 2.5px solid var(--ink);
  border-radius: 999px; padding: 5px 10px; white-space: nowrap;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.35);
}
.chip.light { background: var(--ticket); color: var(--ink); cursor: pointer; }
.chip.amber { background: var(--amber); color: var(--ink); cursor: pointer; }
.chip.peron { background: var(--peron); color: var(--ticket); cursor: pointer; }
.chip:active { transform: translate(1px, 1px); }

/* Right-side map/zoom tools (like koskosan.online) */
.tools {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 7px; z-index: 10;
}
.tool {
  font-family: var(--display); font-size: 13px; border: 3px solid var(--ink);
  border-radius: 12px; background: var(--ticket); color: var(--ink);
  padding: 7px 10px; cursor: pointer; box-shadow: 3px 3px 0 rgba(0,0,0,0.35);
  min-width: 44px; text-align: center;
}
.tool.gold { background: var(--amber); font-size: 11px; }
.tool:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0,0,0,0.35); }

/* Toast & Stamp */
#toast {
  position: absolute; top: 88px; left: 50%; transform: translateX(-50%);
  z-index: 16; background: var(--ink); color: var(--amber-soft);
  font-family: var(--hand); font-size: 18px; padding: 7px 16px;
  border-radius: 12px; border: 2.5px solid var(--amber);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.4); opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease; max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; }

#stampFx {
  position: absolute; left: 50%; top: 34%; z-index: 18;
  font-family: var(--display); font-size: clamp(28px, 8vw, 52px);
  border: 5px solid var(--ink); border-radius: 16px; padding: 6px 18px;
  background: var(--amber); color: var(--ink);
  box-shadow: 5px 5px 0 rgba(0,0,0,0.35);
  transform: translate(-50%, -50%) rotate(-7deg) scale(0.5);
  opacity: 0; pointer-events: none; transition: all 0.18s cubic-bezier(.2,1.4,.4,1);
}
#stampFx.show { opacity: 1; transform: translate(-50%, -50%) rotate(-7deg) scale(1); }
#stampFx.red { background: var(--stamp); color: #fff; }
#stampFx.green { background: var(--peron); color: #fff; }

/* Controls */
.controls {
  position: absolute; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 10; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 14px; pointer-events: none;
}
.dpad {
  display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px);
  gap: 5px; pointer-events: auto;
}
.dpad button {
  font-family: var(--display); font-size: 17px; background: rgba(245,239,224,0.92);
  color: var(--ink); border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.35); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.dpad button:active, .dpad button.active { background: var(--amber); transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0,0,0,0.35); }
.dpad .empty { visibility: hidden; }

.act-col { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: auto; }
.act-btn {
  font-family: var(--display); font-size: clamp(12.5px, 3.4vw, 15.5px); letter-spacing: 0.03em;
  background: var(--amber); color: var(--ink); border: 3px solid var(--ink);
  border-radius: 14px; padding: 10px 15px; cursor: pointer;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.35); white-space: nowrap;
}
.act-btn.secondary { background: var(--ticket); font-size: 12px; padding: 7px 12px; }
.act-btn.peron { background: var(--peron); color: #fff; }
.act-btn.sprint-on { background: var(--stamp); color: #fff; }
.act-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(0,0,0,0.35); }

/* Hias Kabin Bottom Bar */
#decorBar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--ticket); border-top: 3.5px solid var(--ink);
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  box-shadow: 0 -6px 20px rgba(0,0,0,0.35);
}
.decor-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.decor-cats { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 4px; }
.decor-cat {
  font-family: var(--display); font-size: 11px; padding: 6px 10px;
  border-radius: 9px; border: 2px solid var(--ink); background: var(--paper); cursor: pointer; white-space: nowrap;
}
.decor-cat.sel { background: var(--amber); }
.decor-items { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 6px; }
.decor-card {
  min-width: 124px; background: #fff; border: 2.5px solid var(--ink); border-radius: 12px;
  padding: 8px; flex-shrink: 0; display: flex; flex-direction: column; justify-content: space-between; gap: 5px;
}
.decor-card b { font-size: 12px; line-height: 1.2; }
.decor-card span { font-size: 11px; color: var(--muted); }
.decor-card button {
  font-family: var(--display); font-size: 10.5px; padding: 5px 6px; border-radius: 8px;
  border: 2px solid var(--ink); background: var(--amber); cursor: pointer;
}
.decor-card button.owned { background: var(--mint); color: var(--peron); }
.decor-move {
  display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 10px; padding: 6px; margin-bottom: 6px;
}
.decor-move button {
  font-family: var(--display); font-size: 12px; padding: 5px 10px;
  border-radius: 8px; border: 2px solid var(--ink); background: #fff; cursor: pointer;
}
.decor-move button.danger { background: var(--stamp); color: #fff; }

/* Modals */
.scrim {
  position: fixed; inset: 0; z-index: 30; background: rgba(16,22,38,0.78);
  display: flex; align-items: center; justify-content: center; padding: 14px;
  overflow-y: auto; backdrop-filter: blur(3px);
}
.card {
  width: 100%; max-width: 430px; background: var(--ticket); color: var(--ink);
  border: 3.5px solid var(--ink); border-radius: 20px; padding: 18px;
  box-shadow: 7px 7px 0 rgba(0,0,0,0.45); position: relative; max-height: 92vh; overflow-y: auto;
}
.card-tag { font-family: var(--display); font-size: 11px; color: var(--stamp); letter-spacing: 0.08em; margin-bottom: 4px; }
.card h2 { font-family: var(--display); font-size: clamp(20px, 5.5vw, 25px); margin: 0 0 8px; line-height: 1.15; }
.card p { margin: 0 0 12px; font-size: 14px; line-height: 1.45; color: #36302B; }
.close-x {
  position: absolute; right: 12px; top: 12px; width: 34px; height: 34px;
  border-radius: 10px; border: 2.5px solid var(--ink); background: var(--paper);
  font-family: var(--display); font-size: 14px; cursor: pointer;
}

.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 14px; }
.stat-box { background: var(--paper); border: 2.5px solid var(--ink); border-radius: 12px; padding: 8px 6px; text-align: center; }
.stat-box b { display: block; font-family: var(--display); font-size: 18px; color: var(--night); }
.stat-box span { font-size: 11px; color: var(--muted); font-weight: 600; }

.btn {
  width: 100%; font-family: var(--display); font-size: 14.5px; letter-spacing: 0.04em;
  background: var(--amber); color: var(--ink); border: 3px solid var(--ink);
  border-radius: 13px; padding: 11px 14px; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink); margin-top: 6px;
}
.btn.dark { background: var(--night); color: var(--amber-soft); }
.btn.paper { background: var(--paper); color: var(--ink); }
.btn.peron { background: var(--peron); color: #fff; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.tab-btn { font-family: var(--display); font-size: 13px; padding: 8px; border-radius: 10px; border: 2.5px solid var(--ink); background: var(--paper); cursor: pointer; }
.tab-btn.active { background: var(--amber); }

label.fld { display: block; font-size: 11px; font-weight: 800; letter-spacing: 0.05em; margin: 8px 0 4px; text-transform: uppercase; }
input.inp { width: 100%; padding: 10px 12px; font-size: 15px; font-family: var(--ui); font-weight: 600; border: 2.5px solid var(--ink); border-radius: 11px; background: #fff; color: var(--ink); }
.err-msg { color: var(--stamp); font-size: 12px; font-weight: 700; margin-top: 6px; min-height: 16px; }

.swatches { display: flex; gap: 7px; flex-wrap: wrap; margin: 6px 0 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2.5px solid var(--ink); cursor: pointer; }
.swatch.sel { outline: 3px solid var(--stamp); outline-offset: 2px; }
.style-pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.pill { font-family: var(--ui); font-weight: 700; font-size: 12px; padding: 8px 6px; border-radius: 10px; border: 2.5px solid var(--ink); background: var(--paper); cursor: pointer; }
.pill.sel { background: var(--amber); }

.code-box { font-family: var(--display); font-size: clamp(16px, 4.5vw, 20px); text-align: center; background: #fff; border: 3px dashed var(--stamp); border-radius: 12px; padding: 12px; letter-spacing: 0.08em; margin: 10px 0; color: var(--night); }

.streak-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.day-card { background: var(--paper); border: 2px solid var(--ink); border-radius: 10px; padding: 7px 4px; text-align: center; font-size: 11px; font-weight: 700; }
.day-card b { display: block; font-family: var(--display); font-size: 12px; color: var(--peron); margin-top: 2px; }
.day-card.done { background: var(--mint); border-color: var(--peron); }
.day-card.today { background: var(--amber); border-width: 3px; }
.day-card.day7 { grid-column: span 2; background: #FFE6B3; }

#ticketPreview { width: 100%; max-width: 220px; display: block; margin: 6px auto 10px; border: 3px solid var(--ink); border-radius: 14px; box-shadow: 4px 4px 0 rgba(0,0,0,0.25); }
.link-copy { display: flex; gap: 6px; align-items: center; background: #fff; border: 2px dashed var(--ink); border-radius: 10px; padding: 6px 8px; margin-bottom: 8px; }
.link-copy input { flex: 1; border: 0; font-size: 12px; font-family: var(--ui); font-weight: 600; color: var(--muted); background: transparent; outline: none; min-width: 0; }
.link-copy button { font-family: var(--display); font-size: 11px; padding: 5px 9px; border-radius: 8px; border: 2px solid var(--ink); background: var(--paper); cursor: pointer; }

.rule-item, .job-card {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: var(--paper); border: 2.5px solid var(--ink); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.rule-num { width: 26px; height: 26px; flex-shrink: 0; border-radius: 50%; background: var(--stamp); color: #fff; font-family: var(--display); font-size: 13px; display: flex; align-items: center; justify-content: center; }
.mission-row { display: flex; justify-content: space-between; align-items: center; background: var(--paper); border: 2px solid var(--ink); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; font-weight: 700; }
.mission-row.done { background: var(--mint); color: var(--peron); }

/* Mini-game Prama Restorasi */
.order-banner {
  background: var(--night); color: var(--amber-soft); border: 3px solid var(--ink);
  border-radius: 14px; padding: 12px; text-align: center; margin-bottom: 10px;
}
.order-banner b { display: block; font-family: var(--display); font-size: 18px; color: var(--amber); margin-top: 4px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-btn {
  background: #fff; border: 2.5px solid var(--ink); border-radius: 12px; padding: 10px 8px;
  cursor: pointer; text-align: center; box-shadow: 2px 2px 0 var(--ink);
}
.menu-btn b { display: block; font-family: var(--display); font-size: 12px; margin-top: 4px; }
.menu-btn span { font-size: 11px; color: var(--muted); }
.menu-btn:active { transform: translate(2px, 2px); background: var(--amber-soft); }
