:root {
  --bg: #1d1915;
  --hud: #2a231e;
  --panel: #2b2520;
  --card: #382f28;
  --card-hi: #43392f;
  --line: #4d4238;
  --ink: #f7efe3;
  --muted: #b9ab99;
  --orange: #f28c28;
  --orange-dk: #c96c14;
  --yellow: #f6c12b;
  --blue: #3a78c2;
  --green: #7bd36a;
  --red: #e2574c;
  --fs: 16px;
  --panel-w: 390px;
  color-scheme: dark;
}
:root[data-text="kecil"] { --fs: 14px; }
:root[data-text="besar"] { --fs: 18px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font: 600 var(--fs)/1.35 Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
b, h2, h3, .ct { font-family: "Baloo 2", Nunito, sans-serif; }

#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; }

/* ---------- HUD ---------- */
#hud {
  display: flex; align-items: center; gap: 1.1rem;
  padding: .45rem .9rem .5rem;
  background: var(--hud);
  border-bottom: 4px solid transparent;
  border-image: repeating-linear-gradient(-45deg, var(--yellow) 0 10px, #2b2b2b 10px 20px) 4;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: .4rem; font: 800 1.15rem "Baloo 2", sans-serif; color: var(--orange); white-space: nowrap; margin-right: .3rem; }
.logo { font-size: 1.2rem; }
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat .lbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); white-space: nowrap; }
.stat .lbl em { font-style: normal; color: var(--yellow); }
.stat b { font-size: 1.12rem; white-space: nowrap; line-height: 1.15; }
.stat.money b { color: var(--yellow); font-size: 1.3rem; }
.stars { position: relative; font-size: .95rem; line-height: 1; letter-spacing: 1px; }
.stars .off { color: #5a4e42; }
.stars .on { position: absolute; left: 0; top: 0; overflow: hidden; white-space: nowrap; color: var(--yellow); width: 20%; }
.repbar { display: block; height: 4px; background: #4a3f35; border-radius: 3px; margin-top: 3px; width: 86px; overflow: hidden; }
.repbar i { display: block; height: 100%; width: 0; background: var(--orange); border-radius: 3px; transition: width .4s; }
.clock { margin-left: auto; text-align: right; }
.icon-btn { background: var(--card); border: 1px solid var(--line); border-radius: 10px; width: 2.3rem; height: 2.3rem; display: grid; place-items: center; font-size: 1.05rem; }
.icon-btn:hover { background: var(--card-hi); }

/* ---------- Tengah ---------- */
#mid { position: relative; display: flex; min-height: 0; }
#stage { position: relative; flex: 1; min-width: 0; overflow: hidden; background: #1a1613; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 2rem; color: var(--muted); background: var(--bg); }
#loading code { color: var(--yellow); }

#eventBanner {
  position: absolute; top: .6rem; left: .6rem;
  background: rgba(42, 35, 30, .92); border: 1px solid var(--orange); color: var(--ink);
  padding: .3rem .9rem; border-radius: 999px; font-size: .85rem; white-space: nowrap; max-width: calc(100% - 2rem);
  overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}

#toasts { position: absolute; right: .7rem; bottom: .7rem; display: flex; flex-direction: column; gap: .4rem; align-items: flex-end; pointer-events: none; max-width: min(360px, calc(100% - 1.4rem)); }
.toast {
  background: rgba(42, 35, 30, .94); border-left: 4px solid var(--orange); padding: .5rem .8rem; border-radius: 10px;
  font-size: .88rem; box-shadow: 0 6px 18px rgba(0, 0, 0, .35); animation: toastIn .3s ease-out; transition: opacity .5s, transform .5s;
}
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Panel ---------- */
#panel {
  width: var(--panel-w); flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line);
}
#panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .8rem .4rem 1rem; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 1.25rem; color: var(--orange); }
#panelBody { overflow-y: auto; padding: .3rem .8rem 1.2rem; flex: 1; overscroll-behavior: contain; }
#panelBody h3 { margin: 1rem 0 .45rem; font-size: 1rem; color: var(--yellow); }

.card { display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .6rem; align-items: center; background: var(--card); border-radius: 12px; padding: .6rem .65rem; margin-bottom: .45rem; border: 1px solid transparent; }
.card:hover { border-color: var(--line); }
.card.locked-card { background: #322a24; }
.ci { font-size: 1.45rem; text-align: center; }
.ct { font-size: 1rem; font-weight: 800; line-height: 1.2; }
.lv { font: 700 .72rem Nunito, sans-serif; color: var(--muted); background: #2a231e; border-radius: 6px; padding: .05rem .4rem; margin-left: .2rem; white-space: nowrap; }
.cd { font-size: .82rem; color: #e3d8c8; margin-top: .1rem; }
.fx { font-size: .78rem; color: var(--green); margin-top: .15rem; }
.fx.dim { color: var(--muted); }
.cbtn { align-self: center; }

.buy {
  min-width: 6.2rem; padding: .45rem .6rem; border: 0; border-radius: 10px;
  background: var(--orange); color: #2a1a08; font: 800 .86rem "Baloo 2", Nunito, sans-serif; white-space: nowrap;
  box-shadow: 0 3px 0 var(--orange-dk); transition: transform .08s, filter .15s;
}
.buy:hover:not(:disabled) { filter: brightness(1.08); }
.buy:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--orange-dk); }
.buy:disabled { background: #4a4037; color: #a59683; box-shadow: none; cursor: default; }
.buy.locked { background: #3a312a; color: var(--muted); }
.buy.max { background: #31402c; color: var(--green); }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

.hint { font-size: .82rem; padding: .55rem .7rem; border-radius: 10px; margin: .6rem 0 .2rem; }
.hint.busy { background: #3d2a1c; border-left: 4px solid var(--orange); }
.hint.calm { background: #26332c; border-left: 4px solid var(--green); }
.hint.event { background: #3a2c1a; border-left: 4px solid var(--yellow); }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

.staff { display: grid; grid-template-columns: 3.4rem 1fr; gap: .65rem; background: var(--card); border-radius: 12px; padding: .6rem .65rem; margin-bottom: .45rem; }
.face { width: 3.4rem; height: 3.4rem; border-radius: 50%; }
.srow { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .35rem; font-size: .84rem; }
.srow em { display: block; font-style: normal; color: var(--green); font-size: .74rem; }
.srow .buy { min-width: 5.6rem; font-size: .8rem; padding: .35rem .5rem; }

.supplier { background: var(--card); border-radius: 12px; padding: .65rem .75rem; margin-top: .6rem; font-size: .88rem; }
.part { display: grid; grid-template-columns: 2rem 1fr; gap: .55rem; align-items: center; background: var(--card); border-radius: 12px; padding: .55rem .65rem; margin-bottom: .4rem; }
.part.unused { opacity: .55; }
.pi { font-size: 1.3rem; text-align: center; }
.pt { display: flex; justify-content: space-between; font-weight: 800; font-size: .92rem; }
.pt span { color: var(--muted); font-size: .82rem; }
.bar { height: 7px; background: #2a231e; border-radius: 4px; overflow: hidden; margin: .25rem 0 .1rem; }
.bar i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width .4s; }

.soon { text-align: center; padding: 1.5rem .6rem; }
.soon .big { font-size: 3rem; }
.soon h3 { color: var(--orange) !important; }
.soon p { color: #e3d8c8; font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; margin: .8rem 0; }
.chip { background: var(--card); border-radius: 999px; padding: .2rem .6rem; font-size: .78rem; }

.set { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid #3a312a; font-size: .9rem; }
.set.check { justify-content: flex-start; }
.set select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .4rem; }
.set input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--orange); }
.wide { width: 100%; padding: .65rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card); text-align: left; margin-bottom: .4rem; }
.wide small { color: var(--muted); }
.wide:hover { background: var(--card-hi); }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.btns button { padding: .55rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.btns button:hover { background: var(--card-hi); }
.btns .danger, .modal-actions .danger { color: #ffb3a8; border-color: #6b3a32; }
.stat-row { display: flex; justify-content: space-between; gap: 1rem; font-size: .86rem; padding: .3rem 0; border-bottom: 1px dashed #3a312a; }
.stat-row span { color: var(--muted); }

/* ---------- Tab bawah ---------- */
#tabs {
  display: flex; justify-content: center; gap: .15rem; padding: .3rem .5rem calc(.3rem + env(safe-area-inset-bottom));
  background: var(--hud); border-top: 1px solid var(--line); overflow-x: auto; scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: 0 0 5.4rem; display: flex; flex-direction: column; align-items: center; gap: .1rem;
  padding: .25rem .2rem .3rem; border: 0; border-radius: 8px; background: transparent; color: var(--muted);
}
.tab .ic { font-size: .95rem; line-height: 1.2; filter: saturate(.75); }
.tab .lb { font-size: .68rem; font-weight: 700; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab:hover .ic, .tab.active .ic { filter: none; }
.tab.active { color: var(--orange); }
.tab.active::after { content: ''; position: absolute; left: 30%; right: 30%; bottom: 0; height: 2px; border-radius: 2px; background: var(--orange); }
.tab .dot { position: absolute; top: .2rem; left: calc(50% + .45rem); width: .42rem; height: .42rem; border-radius: 50%; background: var(--red); display: none; }
.tab.hot .dot { display: block; }

/* ---------- Modal ---------- */
#modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(15, 11, 8, .62); z-index: 20; padding: 1rem; }
#modal[hidden] { display: none; }
.modal-card { width: min(440px, 100%); background: var(--panel); border-radius: 18px; padding: 1.2rem 1.3rem 1rem; border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(0, 0, 0, .5); animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.modal-card h2 { margin: 0 0 .5rem; color: var(--orange); font-size: 1.35rem; }
.modal-body p { margin: .4rem 0; }
.modal-body .big-text { font-size: 1.05rem; }
.modal-body .money { color: var(--yellow); white-space: nowrap; }
.modal-body textarea { width: 100%; background: #1f1a16; border: 1px solid var(--line); border-radius: 10px; padding: .5rem; font: 600 .75rem ui-monospace, monospace; resize: vertical; }
.modal-body .err { color: #ffb3a8; font-size: .85rem; }
.modal-body .tips { padding-left: 1.1rem; color: #e3d8c8; font-size: .9rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.modal-actions button { padding: .55rem 1.1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 800; }
.modal-actions .primary { background: var(--orange); color: #2a1a08; border: 0; box-shadow: 0 3px 0 var(--orange-dk); }

/* ---------- Mode Layar Kedua ---------- */
#mini {
  position: absolute; left: .6rem; top: .6rem; display: flex; gap: .7rem; align-items: center;
  background: rgba(30, 25, 21, .6); padding: .25rem .6rem; border-radius: 10px; font: 800 .85rem "Baloo 2", sans-serif;
}
#mini[hidden] { display: none; }
#miniMoney { color: var(--yellow); }
#miniExit { border: 0; background: transparent; color: var(--muted); opacity: 0; transition: opacity .2s; padding: 0 .2rem; }
#mini:hover #miniExit { opacity: 1; }
body.second #hud, body.second #tabs, body.second #panel, body.second #eventBanner { display: none !important; }
body.second #app { grid-template-rows: 1fr; }

/* ---------- Responsif ---------- */
@media (max-width: 1100px) {
  #hud { gap: .8rem; }
  .brand #gameName { display: none; }
}
@media (max-width: 760px) {
  #hud { gap: .55rem; padding: .35rem .55rem .4rem; flex-wrap: wrap; row-gap: .2rem; }
  .brand { display: none; }
  .stat b { font-size: 1rem; }
  .stat.money b { font-size: 1.12rem; }
  .repbar { width: 64px; }
  #period { display: none; }
  #panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: 62%;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; z-index: 5;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .4);
  }
  #tabs { justify-content: flex-start; }
  .tab { flex-basis: 4.3rem; }
  .card { grid-template-columns: 1.8rem 1fr; }
  .cbtn { grid-column: 1 / -1; }
  .cbtn .buy { width: 100%; }
  #toasts { bottom: auto; top: 3rem; }
}
@media (max-width: 420px) {
  .stat.rep .lbl { display: none; }
  .icon-btn { width: 2rem; height: 2rem; }
}
