:root {
  --coffee-900: #2f1d11;
  --coffee-800: #3e2615;
  --coffee-600: #6b4226;
  --coffee-400: #a87a52;
  --cream-50: #fffaf1;
  --cream-100: #f8efdf;
  --cream-200: #efe2c9;
  --cream-300: #e2cfae;
  --green-600: #3f7f5e;
  --green-500: #4d9470;
  --terracotta: #c0583a;
  --gold: #f0b04a;
  --ink: #3b2a20;
  --muted: #8a7462;
  --stage-bg: #e9dcc4;
  --hud-h: 58px;
  --tabs-h: 62px;
  --radius: 14px;
  font-size: 16px;
}
html[data-text='kecil'] { font-size: 14px; }
html[data-text='besar'] { font-size: 18px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--stage-bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: var(--hud-h) 1fr var(--tabs-h);
  overflow: hidden;
}

/* ---------------- HUD ---------------- */
#hud {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--coffee-800);
  color: var(--cream-100);
  z-index: 3;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-weight: 600;
  font-size: 1.15rem;
  white-space: nowrap;
  margin-right: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-cup {
  width: 22px; height: 18px; flex: none;
  background: var(--cream-50);
  border-radius: 3px 3px 8px 8px;
  position: relative;
  box-shadow: inset 0 4px 0 var(--coffee-400);
}
.brand-cup::after {
  content: ''; position: absolute; right: -7px; top: 3px;
  width: 6px; height: 8px; border: 2.5px solid var(--cream-50); border-left: 0; border-radius: 0 6px 6px 0;
}
.hud-stat { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.hud-val { font-family: 'Fredoka', 'Nunito', sans-serif; font-weight: 600; font-size: 1.2rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hud-sub { font-size: 0.75rem; color: var(--cream-300); white-space: nowrap; font-variant-numeric: tabular-nums; }
.money .hud-val { color: #ffe3a3; }
.stars { display: inline-flex; gap: 1px; font-size: 1.05rem; line-height: 1.15; }
.star { position: relative; color: rgba(255, 255, 255, 0.22); }
.star i { position: absolute; left: 0; top: 0; overflow: hidden; color: var(--gold); font-style: normal; }
.clock { text-align: right; align-items: flex-end; }

/* ---------------- panggung ---------------- */
#stage { position: relative; overflow: hidden; background: var(--stage-bg); touch-action: manipulation; }
#cv { display: block; position: absolute; inset: 0; touch-action: none; }
#loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: 'Fredoka', sans-serif; font-size: 1.2rem; color: var(--coffee-600);
}

/* ---------------- tab bawah ---------------- */
#tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background: var(--cream-50);
  border-top: 1px solid var(--cream-300);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 3;
}
#tabs button {
  border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  position: relative;
}
#tabs svg { width: 22px; height: 22px; fill: currentColor; }
#tabs button.active { color: var(--coffee-800); }
#tabs button.active::before {
  content: ''; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--terracotta);
}
#tabs button .dot {
  position: absolute; top: 8px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%;
  background: var(--terracotta); box-shadow: 0 0 0 2px var(--cream-50);
}

/* ---------------- panel ---------------- */
#panel {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: var(--cream-100);
  box-shadow: 0 10px 40px rgba(47, 29, 17, 0.25);
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1), visibility 0.28s;
  visibility: hidden;
  left: 0; right: 0;
  bottom: var(--tabs-h);
  height: min(62%, 560px);
  border-radius: 18px 18px 0 0;
  transform: translateY(105%);
}
#panel.open { visibility: visible; transform: none; }
@media (min-width: 900px) {
  #panel {
    left: auto; right: 14px; top: calc(var(--hud-h) + 14px); bottom: calc(var(--tabs-h) + 14px);
    width: 410px; height: auto; border-radius: 18px;
    transform: translateX(calc(100% + 24px));
  }
  #tabs { grid-template-columns: repeat(6, minmax(0, 110px)); justify-content: center; }
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px 10px 16px;
  border-bottom: 1px solid var(--cream-300);
}
.panel-head h2 { margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.2rem; margin-right: auto; color: var(--coffee-800); }
.icon-btn { border: 0; background: var(--cream-200); width: 32px; height: 32px; border-radius: 50%; font-size: 0.9rem; color: var(--coffee-600); }
.seg { display: inline-flex; background: var(--cream-200); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 800; color: var(--muted); }
.seg button.on { background: var(--coffee-800); color: var(--cream-50); }
.seg[hidden] { display: none; }
.panel-body { overflow-y: auto; padding: 10px 12px 18px; -webkit-overflow-scrolling: touch; }

.sec-title {
  margin: 14px 4px 8px; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.sec-title:first-child { margin-top: 4px; }
.sec-note { margin: -4px 4px 10px; font-size: 0.8rem; color: var(--muted); }

.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--cream-50);
  border-radius: var(--radius);
  padding: 10px 10px 10px 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 0 var(--cream-300);
}
.row.dim { opacity: 0.62; }
.row.owned { background: #f1f6ec; }
.row .ico { width: 40px; height: 40px; border-radius: 12px; background: var(--cream-200); display: grid; place-items: center; overflow: hidden; }
.row .ico canvas { width: 40px; height: 40px; }
.row .ico.glyph { font-family: 'Fredoka', sans-serif; font-weight: 600; color: var(--coffee-600); font-size: 1.05rem; }
.row .txt { min-width: 0; }
.row .name { font-weight: 800; font-size: 0.95rem; line-height: 1.2; }
.row .name small { font-weight: 700; color: var(--muted); margin-left: 4px; font-size: 0.75rem; }
.row .desc { font-size: 0.78rem; color: var(--muted); line-height: 1.3; margin-top: 2px; }
.row .fx { font-size: 0.78rem; font-weight: 700; color: var(--green-600); margin-top: 3px; }
.row .fx.lock { color: var(--terracotta); }
.row .btns { display: flex; flex-direction: column; gap: 5px; align-items: stretch; }

.buy {
  border: 0;
  min-width: 98px;
  padding: 7px 10px;
  border-radius: 11px;
  background: var(--green-600);
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  line-height: 1.15;
  box-shadow: 0 2px 0 #2d5e45;
  transition: transform 0.08s;
  font-variant-numeric: tabular-nums;
}
.buy small { display: block; font-weight: 700; font-size: 0.68rem; opacity: 0.85; }
.buy:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 #2d5e45; }
.buy:disabled { background: var(--cream-300); color: var(--muted); box-shadow: none; }
.buy.alt { background: var(--coffee-600); box-shadow: 0 2px 0 var(--coffee-800); }
.buy.alt:disabled { background: var(--cream-300); box-shadow: none; }
.tag-done { font-size: 0.78rem; font-weight: 800; color: var(--green-600); padding: 0 6px; }

.soon {
  text-align: center; padding: 34px 18px; color: var(--muted);
}
.soon .big { font-family: 'Fredoka', sans-serif; font-size: 1.15rem; color: var(--coffee-600); margin-bottom: 6px; }

/* pengaturan */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--cream-50); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.set-row label { font-weight: 700; font-size: 0.9rem; }
.set-row select, .set-row input[type='text'] {
  font: inherit; font-size: 0.88rem; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--cream-300); background: #fff; color: var(--ink); max-width: 55%;
}
.btn-line { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.btn-line .buy { flex: 1; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; background: var(--cream-50); border-radius: var(--radius); padding: 12px; font-size: 0.86rem; }
.stats span:nth-child(even) { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }

/* toast */
#toasts {
  position: absolute; z-index: 5; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + 12px);
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none;
  width: min(92vw, 380px);
}
@media (min-width: 900px) { #toasts { left: 16px; transform: none; align-items: flex-start; } }
.toast {
  background: rgba(47, 29, 17, 0.9); color: var(--cream-50);
  padding: 8px 14px; border-radius: 999px; font-size: 0.85rem; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  animation: toastIn 0.3s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* modal */
.modal { position: absolute; inset: 0; z-index: 10; background: rgba(47, 29, 17, 0.45); display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card {
  width: min(100%, 420px); background: var(--cream-50); border-radius: 20px; padding: 22px 20px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); animation: pop 0.25s ease-out;
}
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }
.modal-card h3 { margin: 0 0 8px; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.3rem; color: var(--coffee-800); }
.modal-card p { margin: 0 0 10px; line-height: 1.45; }
.modal-card .big-money { font-family: 'Fredoka', sans-serif; font-size: 1.7rem; color: var(--green-600); margin: 6px 0 10px; }
.modal-card textarea {
  width: 100%; height: 120px; font-family: ui-monospace, monospace; font-size: 0.72rem; border-radius: 10px; border: 1px solid var(--cream-300); padding: 8px; resize: vertical;
}
.modal-card .note { font-size: 0.8rem; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.modal-actions .buy { min-width: 110px; padding: 10px 14px; font-size: 0.9rem; }

@media (max-width: 600px) {
  :root { --hud-h: 54px; --tabs-h: 58px; }
  #hud { gap: 12px; padding: 0 12px; }
  .brand #shopName { display: none; }
  .brand { margin-right: 0; }
  .money { margin-right: auto; }
  .hud-val { font-size: 1.05rem; }
  .stars { font-size: 0.9rem; }
  #tabs button { font-size: 0.64rem; }
}
@media (max-width: 380px) {
  .clock .hud-sub { display: none; }
  .seg button { padding: 4px 7px; }
}

/* ---------------- tombol HUD ---------------- */
.hud-btns { display: flex; gap: 6px; }
.hud-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, 0.1); color: var(--cream-100);
  display: grid; place-items: center;
}
.hud-btn:hover { background: rgba(255, 255, 255, 0.18); }
.hud-btn svg { width: 18px; height: 18px; fill: currentColor; }
#btnMute .ic-off { display: none; }
#btnMute.muted .ic-on { display: none; }
#btnMute.muted .ic-off { display: block; }

/* ---------------- mode Layar Kedua ---------------- */
#secondExit {
  display: none; position: absolute; top: 10px; right: 10px; z-index: 4;
  border: 0; border-radius: 999px; padding: 7px 14px; font-weight: 800; font-size: 0.8rem;
  background: rgba(47, 29, 17, 0.75); color: var(--cream-50);
  opacity: 0; transition: opacity 0.3s;
}
#hud { grid-row: 1; }
#stage { grid-row: 2; }
#tabs { grid-row: 3; }
body.second #app { grid-template-rows: 0 1fr 0; }
body.second #hud, body.second #tabs, body.second #panel, body.second #toasts { display: none; }
body.second #secondExit { display: block; }
body.second #stage:hover #secondExit, body.second #secondExit:focus-visible, body.second.touch #secondExit { opacity: 1; }

/* ---------------- mode dekor ---------------- */
#decorTray {
  position: absolute; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: 12px; width: min(calc(100% - 24px), 760px);
  background: var(--cream-50); border-radius: 18px; padding: 12px 14px;
  box-shadow: 0 10px 34px rgba(47, 29, 17, 0.28);
}
#decorTray[hidden] { display: none; }
#decorTray.drop { outline: 3px dashed var(--terracotta); outline-offset: -6px; }
body.decor-mode #tabs { visibility: hidden; }
body.decor-mode #panel { display: none; }
.tray-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.tray-head strong { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.05rem; color: var(--coffee-800); margin-right: 8px; }
.tray-hint { font-size: 0.78rem; color: var(--muted); }
.tray-items { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; min-height: 64px; padding-bottom: 2px; }
.tray-empty { font-size: 0.82rem; color: var(--muted); align-self: center; }
.chip {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 74px; padding: 6px 4px; border-radius: 12px; background: var(--cream-200);
  border: 0; font-size: 0.68rem; font-weight: 700; color: var(--ink); touch-action: none; cursor: grab;
}
.chip canvas { width: 40px; height: 40px; pointer-events: none; }
.chip span { pointer-events: none; text-align: center; line-height: 1.1; }

/* ---------------- kontrol pengaturan ---------------- */
.set-row input[type='range'] { width: 46%; accent-color: var(--coffee-600); }
.set-row input[type='checkbox'] { width: 20px; height: 20px; accent-color: var(--green-600); }
.suasana-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--coffee-800); color: var(--cream-50); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px;
}
.suasana-card .big { font-family: 'Fredoka', sans-serif; font-size: 1.35rem; line-height: 1.1; }
.suasana-card small { display: block; color: var(--cream-300); font-size: 0.78rem; }
.buy.ghost { background: var(--cream-200); color: var(--coffee-800); box-shadow: none; }
@media (max-width: 600px) {
  .hud-btn { width: 30px; height: 30px; }
  .tray-hint { display: none; }
  .tray-items { min-height: 56px; margin-top: 8px; }
}

.pbar { height: 6px; border-radius: 3px; background: var(--cream-200); overflow: hidden; margin: 6px 0 2px; }
.pbar i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 3px; transition: width 0.3s; }
.row.owned .pbar i { background: var(--green-600); }
.modal-card { max-height: calc(100% - 32px); overflow-y: auto; }

/* ---------------- event ---------------- */
.event-badge {
  border: 0; border-radius: 999px; padding: 5px 12px; font-weight: 800; font-size: 0.78rem; white-space: nowrap;
  background: linear-gradient(90deg, #2f6db5, #3f86d4); color: #fff; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25);
  animation: badgePulse 2.4s ease-in-out infinite;
}
.event-badge[hidden] { display: none; }
@keyframes badgePulse { 50% { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25), 0 0 0 4px rgba(63,134,212,0.25); } }
.event-strip {
  background: linear-gradient(90deg, #2f6db5, #3f86d4); color: #fff; border-radius: 12px;
  padding: 8px 12px; margin-bottom: 8px; font-size: 0.82rem; font-weight: 700;
}
.event-card { background: linear-gradient(135deg, #2f6db5, #24548c); color: #fff; border-radius: var(--radius); padding: 14px; margin-bottom: 8px; }
.event-card h3 { margin: 0 0 4px; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.25rem; }
.event-card p { margin: 0 0 8px; font-size: 0.85rem; opacity: 0.92; line-height: 1.4; }
.event-card ul { margin: 0 0 10px; padding-left: 18px; font-size: 0.84rem; line-height: 1.5; }
.event-card .row-end { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.event-card .left { font-size: 0.8rem; opacity: 0.9; }
.event-card .buy { background: #e0a526; box-shadow: 0 2px 0 #a8791a; color: #3b2a20; }
.event-card .buy:disabled { background: rgba(255,255,255,0.25); color: rgba(255,255,255,0.8); box-shadow: none; }
@media (max-width: 600px) { .event-badge { padding: 4px 9px; font-size: 0.7rem; } }
