*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}

button, a { touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
input { font-size: 16px; font-family: var(--font-body); }
[hidden] { display: none !important; }

.app {
  width: 100%;
  max-width: var(--max-w);
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow-x: clip;
}

/* ---------- 3D dugme ---------- */

.btn3d {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--r-btn);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.02em;
  transition: transform var(--t-press), box-shadow var(--t-press), background-color var(--t);
}
.btn3d:active { transform: translateY(3px); }
.btn3d--mint { background: var(--mint); color: #fff; box-shadow: 0 4px 0 var(--mint-shadow); }
.btn3d--mint:active { box-shadow: 0 1px 0 var(--mint-shadow); }
.btn3d:disabled { opacity: 0.6; cursor: default; }

/* ---------- Login ---------- */

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.login__card {
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: 0 4px 0 var(--border-strong);
  padding: 32px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  text-align: center;
  color: var(--violet);
}
.login__sub { margin: -6px 0 6px; text-align: center; color: var(--muted); font-size: 14px; }
.login__input {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 2px solid var(--border-strong);
  border-radius: var(--r-input);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.4em;
  text-align: center;
  outline: none;
  transition: border-color var(--t), background-color var(--t);
}
.login__input:focus { border-color: var(--violet); background: var(--surface); }
.login__error { min-height: 18px; margin: -4px 0 0; color: var(--danger); font-size: 13px; font-weight: 600; text-align: center; }
.login .btn3d { width: 100%; }

/* ---------- Shell ---------- */

.shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}
.shell > * { min-width: 0; }

.hdr {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: calc(20px + env(safe-area-inset-top)) 20px 12px;
}
.hdr__level { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hdr__level > * { min-width: 0; }
.level-badge {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--violet);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--violet-shadow);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}
.hdr__lvl-label { font-size: 12px; color: var(--muted); }
.hdr__lvl-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hdr__money { text-align: right; flex: none; }
.hdr__total { font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1.1; }
.hdr__month { font-size: 12px; font-weight: 600; color: var(--mint-shadow); }

.scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: clip;
  padding: 14px 20px 20px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.scroller::-webkit-scrollbar { display: none; }

/* ---------- Bottom nav ---------- */

.tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--surface);
  border-top: 2px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.tab {
  min-width: 0;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  transition: color var(--t), background-color var(--t);
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current='page'] { color: var(--mint-shadow); }

/* ---------- Empty state ---------- */

.empty {
  margin-top: 40px;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-card);
}
.empty h2 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 700; font-size: 22px; }
.empty p { margin: 0; color: var(--muted); }

/* ---------- Quest: segmented ---------- */

.quest { display: flex; flex-direction: column; gap: 14px; }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px 4px 8px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-btn);
}
.seg__btn {
  min-width: 0;
  min-height: 40px;
  border-radius: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--muted);
  transition: background-color var(--t), color var(--t), box-shadow var(--t), transform var(--t-press);
}
.seg__btn[aria-pressed='true'] {
  background: var(--violet);
  color: #fff;
  box-shadow: 0 4px 0 var(--violet-shadow);
}
.seg__btn[aria-pressed='true']:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--violet-shadow); }

/* ---------- Quest: sledeća nagrada ---------- */

.next {
  background: var(--gold);
  color: var(--gold-text);
  border-radius: var(--r-card);
  box-shadow: 0 4px 0 var(--gold-shadow);
  padding: 16px 18px 18px;
  margin-bottom: 4px;
}
.next__top { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }
.next__eta { text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.next__title { margin: 4px 0 2px; font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.next__reward { font-size: 14px; }
.bar { margin-top: 12px; height: 12px; border-radius: 6px; background: var(--gold-light); overflow: hidden; }
.bar__fill { height: 100%; width: 0; border-radius: 6px; background: var(--gold-shadow); transition: width var(--t-fill); }

/* ---------- Quest: mapa ---------- */

.map {
  position: relative;
  margin: 0 -20px -20px;
  border-radius: 28px 28px 0 0;
  background: #DDF7E9; /* gradijent po svetovima stiže inline iz scene.js */
  overflow: clip;
}
.map__inner { position: absolute; top: 40px; bottom: 40px; left: 0; right: 0; }

/* ---------- Quest: pejzaž (Faza 2) ---------- */

.scene { position: absolute; inset: 0; pointer-events: none; contain: layout paint; }
.scene > *, .worlds { pointer-events: none; }
.star { animation: twinkle 3s ease-in-out infinite alternate; }
.cloud { animation: drift 13s ease-in-out infinite alternate; }

@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }
@keyframes drift { from { transform: translateX(-14px); } to { transform: translateX(14px); } }

@supports not ((backdrop-filter: grayscale(1)) or (-webkit-backdrop-filter: grayscale(1))) {
  .fog { background: rgba(247, 245, 255, 0.7); }
}
.fog {
  position: absolute;
  left: 0;
  right: 0;
  top: -40px;
  bottom: 0;
  background: rgba(247, 245, 255, 0.42);
  -webkit-backdrop-filter: grayscale(0.9);
  backdrop-filter: grayscale(0.9);
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 70px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 70px), transparent);
  transition: bottom var(--t-fill);
  pointer-events: none;
}
.world {
  position: absolute;
  right: 14px;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.85);
  color: #4A4470;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.track, .fill {
  position: absolute;
  left: 42px;
  width: 14px;
  border-radius: 7px;
}
.track { top: 0; bottom: 0; background: #fff; border: 2px solid var(--border-strong); }
.fill {
  bottom: 0;
  height: 0;
  background: var(--mint);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
  transition: height var(--t-fill);
}

.here {
  position: absolute;
  right: 20px;
  bottom: 0;
  transform: translateY(50%);
  padding: 5px 10px;
  border-radius: 10px;
  background: var(--mint);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  box-shadow: 0 3px 0 var(--mint-shadow);
  transition: bottom var(--t-fill);
  z-index: 3;
}

.node {
  position: absolute;
  left: 30px;
  width: 38px;
  height: 38px;
  transform: translateY(50%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  z-index: 2;
}
.node svg { width: 20px; height: 20px; }
.node--intro { animation: node-in 200ms cubic-bezier(0.4, 0, 0.2, 1) both; }
@keyframes node-in {
  from { opacity: 0; transform: translateY(50%) scale(0.6); }
  to { opacity: 1; transform: translateY(50%) scale(1); }
}
.node--done { background: var(--mint); color: #fff; box-shadow: 0 3px 0 var(--mint-shadow); }
.node--next { background: var(--gold); color: var(--gold-text); box-shadow: 0 3px 0 var(--gold-shadow); }
.node--locked { background: #fff; border: 2px solid var(--border-strong); color: var(--lock); }

.mlabel {
  position: absolute;
  left: 82px;
  max-width: 190px;
  transform: translateY(50%);
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--border);
  border-radius: 12px;
  z-index: 2;
}
.mlabel__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.mlabel__reward { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.mlabel__subs { margin-top: 2px; font-size: 11px; font-weight: 600; color: var(--violet-shadow); }
.mlabel--locked .mlabel__title { color: var(--muted); }
.mlabel--next .mlabel__title { color: #92400E; }

.map-empty { padding: 40px 20px; text-align: center; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .fill, .here, .bar__fill, .fog { transition: none; }
  .star, .cloud, .node--intro { animation: none; }
}
