/* ============================================================
   Tarakarta War Legacy — UI Stylesheet
   ============================================================ */

:root {
  --gold: #ffd94a;
  --gold-dark: #c9a227;
  --blue: #4a90d9;
  --red: #d94a3d;
  --panel: rgba(18, 24, 33, 0.92);
  --panel-border: rgba(255, 217, 74, 0.25);
  --font-title: 'Luckiest Guy', 'Trebuchet MS', cursive;
  --font-body: 'Rubik', 'Segoe UI', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #1a2633;
  font-family: var(--font-body);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game { position: fixed; inset: 0; display: block; cursor: grab; }
#game:active { cursor: grabbing; }

/* ================= HUD ================= */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }

body.demo #topbar .res, body.demo #bottombar, body.demo .statue-hp, body.demo #mmWrap { display: none; }

/* --- bar atas --- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 8px 10px;
}
.hud-left { display: flex; gap: 8px; flex-wrap: wrap; }
.res {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: #fff; font-weight: 600; font-size: 15px;
  padding: 6px 12px;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.res.gold { color: var(--gold); font-weight: 800; font-size: 17px; }
.res.lvl { font-size: 13px; color: #cfe0f5; }
.hud-right { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: #fff; font-size: 18px;
  cursor: pointer;
  transition: transform .08s, background .15s;
}
.icon-btn:hover { background: rgba(50, 65, 90, 0.95); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.active { background: var(--gold); color: #1a2633; border-color: var(--gold); }

/* --- HP patung --- */
.statue-hp {
  position: absolute; top: 54px;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.statue-hp.left { left: 10px; }
.statue-hp.right { right: 10px; flex-direction: row-reverse; }
.statue-hp .tag { font-size: 10px; font-weight: 800; letter-spacing: 0.5px; }
.tag.blue { color: #7fc4ff; }
.tag.red { color: #ff9f8f; }
.statue-hp .bar {
  width: 120px; height: 12px;
  background: rgba(0,0,0,0.55);
  border-radius: 6px; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}
.statue-hp .fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #57c15c, #8fe08f);
  border-radius: 6px;
  transition: width .25s;
}
.statue-hp.right .fill { background: linear-gradient(270deg, #d95f4c, #e88f7f); }
.hpnum { font-size: 12px; color: #dfe8f3; font-weight: 700; min-width: 34px; text-align: center; }

/* --- minimap --- */
#mmWrap {
  position: absolute; top: 54px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
}
#minimap {
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.pan-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: #fff; font-size: 20px; line-height: 1;
  cursor: pointer;
}
.pan-btn:active { background: var(--gold); color: #1a2633; }

/* --- bar bawah --- */
#bottombar {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: flex-end; justify-content: center;
  gap: 12px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(10,14,20,0) 0%, rgba(10,14,20,0.72) 55%);
  flex-wrap: wrap;
}

#cmdButtons { display: flex; gap: 6px; }
.cmd-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 66px;
  padding: 8px 8px 6px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.18);
  background: var(--panel);
  color: #fff; font-size: 20px;
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform .08s, border-color .15s;
}
.cmd-btn span { font-size: 10px; font-weight: 800; letter-spacing: 0.5px; }
.cmd-btn:active { transform: scale(0.93); }
.cmd-btn.atk { border-color: rgba(217,74,61,0.5); }
.cmd-btn.atk.active { background: #a83228; border-color: #ff9f8f; box-shadow: 0 0 14px rgba(255,110,90,0.45); }
.cmd-btn.def { border-color: rgba(74,144,217,0.5); }
.cmd-btn.def.active { background: #2a5e94; border-color: #7fc4ff; box-shadow: 0 0 14px rgba(90,170,255,0.45); }
.cmd-btn.gar.active { background: #4c6b4a; border-color: #a8e09f; box-shadow: 0 0 14px rgba(140,220,120,0.4); }

#unitButtons { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.unit-btn {
  position: relative;
  width: 74px;
  padding: 4px 4px 5px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.18);
  background: var(--panel);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  transition: transform .08s, border-color .15s, opacity .2s;
  overflow: hidden;
}
.unit-btn:active { transform: scale(0.93); }
.unit-btn .portrait { width: 52px; height: 52px; }
.unit-btn .cost {
  font-size: 12px; font-weight: 800; color: var(--gold);
  display: flex; align-items: center; gap: 2px;
}
.unit-btn .uname {
  font-size: 10px; font-weight: 700; color: #cfe0f5;
  white-space: nowrap;
}
.unit-btn .hotkey {
  position: absolute; top: 3px; left: 5px;
  font-size: 10px; font-weight: 800; color: #fff;
  background: rgba(0,0,0,0.5);
  border-radius: 5px; padding: 1px 5px;
}
.unit-btn .lock {
  display: none;
  position: absolute; inset: 0;
  background: rgba(10,14,20,0.82);
  color: #9fb0c5; font-size: 12px; font-weight: 800;
  align-items: center; justify-content: center;
}
.unit-btn.locked { pointer-events: none; }
.unit-btn.locked .lock { display: flex; }
.unit-btn.poor .cost { color: #ff7f6f; }
.unit-btn.poor { opacity: 0.75; }
.unit-btn.shake { animation: btnshake .3s; border-color: #ff7f6f !important; }
@keyframes btnshake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ================= banner level ================= */
#levelBanner {
  position: fixed; top: 18%; left: 50%;
  transform: translateX(-50%);
  z-index: 30; text-align: center;
  pointer-events: none;
}
#levelBanner.hidden { display: none; }
#levelBanner .lb-title {
  font-family: var(--font-title);
  font-size: clamp(26px, 5vw, 44px);
  color: var(--gold);
  text-shadow: 0 3px 0 #7a5c10, 0 6px 18px rgba(0,0,0,0.6);
  letter-spacing: 1px;
}
#levelBanner .lb-sub {
  margin-top: 6px;
  color: #eaf2fb; font-size: clamp(13px, 2.2vw, 17px);
  background: rgba(10,14,20,0.72);
  padding: 6px 16px; border-radius: 10px;
  max-width: min(88vw, 560px);
}
#levelBanner.anim { animation: bannerIn 4.2s forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateX(-50%) translateY(-16px); }
  8% { opacity: 1; transform: translateX(-50%) translateY(0); }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

/* ================= toast ================= */
#toast {
  position: fixed; bottom: 172px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(10,14,20,0.9);
  border: 1px solid var(--panel-border);
  color: #fff; font-size: 14px; font-weight: 600;
  padding: 8px 18px; border-radius: 20px;
  opacity: 0; transition: opacity .25s, transform .25s;
  z-index: 40; pointer-events: none;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= overlay umum ================= */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 12, 18, 0.55);
  backdrop-filter: blur(3px);
  padding: 14px;
}
.overlay.hidden { display: none; }
.panel {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 20px;
  padding: 26px 30px;
  text-align: center;
  color: #e8eff8;
  max-width: min(92vw, 560px);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 18px 60px rgba(0,0,0,0.55);
  animation: panelIn .3s ease-out;
}
@keyframes panelIn {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* --- menu --- */
.menu-panel { padding: 30px 34px; }
.title-wrap { margin-bottom: 20px; }
.game-title {
  font-family: var(--font-title);
  font-size: clamp(34px, 7vw, 58px);
  line-height: 1.02;
  color: #f4f8fd;
  text-shadow: 0 4px 0 #22303f, 0 8px 24px rgba(0,0,0,0.6);
  letter-spacing: 2px;
}
.game-title span {
  display: block;
  color: var(--gold);
  text-shadow: 0 4px 0 #7a5c10, 0 8px 24px rgba(0,0,0,0.6);
}
.tagline {
  margin-top: 8px;
  color: #9fb8d4; font-size: 14px;
  font-style: italic;
}

.big-btn {
  display: block; width: 100%;
  margin: 6px auto;
  padding: 14px 22px;
  font-family: var(--font-body);
  font-size: 19px; font-weight: 800;
  color: #241a04;
  background: linear-gradient(180deg, #ffe27a, #f4b942 60%, #d99a24);
  border: none; border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 5px 0 #9a6f12, 0 10px 24px rgba(0,0,0,0.35);
  transition: transform .1s, box-shadow .1s;
}
.big-btn:hover { filter: brightness(1.05); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #9a6f12; }

.med-btn {
  padding: 10px 18px;
  font-family: var(--font-body);
  font-size: 15px; font-weight: 700;
  color: #e8eff8;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.med-btn:hover { background: rgba(255,255,255,0.16); }
.med-btn:active { transform: scale(0.95); }

#levelGrid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 8px; margin: 14px 0 4px;
}
.lvl-btn {
  aspect-ratio: 1;
  font-size: 18px; font-weight: 800;
  font-family: var(--font-body);
  color: #fff;
  background: rgba(74,144,217,0.25);
  border: 1px solid rgba(127,196,255,0.4);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.lvl-btn:hover { background: rgba(74,144,217,0.5); }
.lvl-btn:active { transform: scale(0.92); }
.lvl-btn.locked {
  background: rgba(255,255,255,0.05);
  color: #5c6b7d;
  border-color: rgba(255,255,255,0.1);
  cursor: not-allowed;
  font-size: 13px;
}
.menu-row { margin-top: 10px; display: flex; gap: 10px; justify-content: center; }
.credits { margin-top: 16px; font-size: 12px; color: #8ba0b8; line-height: 1.7; }
.kbd {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 5px; padding: 1px 6px;
  font-size: 11px; font-weight: 700;
}

/* --- hasil --- */
#resultOverlay .panel { min-width: min(88vw, 420px); }
#resTitle {
  font-family: var(--font-title);
  font-size: clamp(30px, 6vw, 46px);
  margin-bottom: 10px;
  letter-spacing: 1px;
}
#resTitle.win { color: var(--gold); text-shadow: 0 3px 0 #7a5c10; }
#resTitle.lose { color: #ff7f6f; text-shadow: 0 3px 0 #6b1e14; }
#resStats { font-size: 15px; line-height: 1.8; margin-bottom: 16px; color: #cfe0f3; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn-row.col { flex-direction: column; align-items: stretch; }

/* --- bantuan --- */
.help-panel { text-align: left; max-width: min(94vw, 620px); }
.help-panel h2 { text-align: center; margin-bottom: 12px; font-family: var(--font-title); color: var(--gold); letter-spacing: 1px; }
.help-body p { font-size: 14px; line-height: 1.65; margin-bottom: 10px; color: #d7e2ef; }
.unit-table {
  width: 100%; border-collapse: collapse;
  margin: 8px 0 12px; font-size: 13px;
}
.unit-table th, .unit-table td {
  padding: 5px 8px; text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.unit-table th { color: var(--gold); font-weight: 800; }
.unit-table td { color: #cfe0f3; }
.help-panel .big-btn { margin-top: 8px; }

/* ================= responsif ================= */
@media (max-width: 720px) {
  .statue-hp .bar { width: 58px; }
  .statue-hp .hpnum { display: none; }
  #mmWrap { top: auto; bottom: 118px; } /* dioverride JS mengikuti tinggi bar bawah */
  #minimap { width: 190px; height: auto; }
  .pan-btn { width: 30px; height: 30px; font-size: 16px; }
  #bottombar { gap: 6px; padding: 8px 6px calc(6px + env(safe-area-inset-bottom)); }
  #unitButtons { gap: 4px; }
  .unit-btn { width: 54px; padding: 3px 2px 4px; border-radius: 10px; }
  .unit-btn .portrait { width: 36px; height: 36px; }
  .unit-btn .cost { font-size: 10px; }
  .unit-btn .uname { font-size: 8.5px; transform: scale(0.92); }
  .cmd-btn { min-width: 52px; padding: 6px 6px 5px; font-size: 16px; border-radius: 10px; }
  .cmd-btn span { font-size: 9px; }
  .menu-panel { padding: 22px 18px; }
  #levelGrid { grid-template-columns: repeat(5, 1fr); }
}
@media (max-height: 480px) {
  #bottombar { padding-bottom: 6px; }
  .unit-btn { width: 58px; padding: 2px; }
  .unit-btn .portrait { width: 38px; height: 38px; }
}
