:root {
  --bg:#f7f8fb;
  --card:#fff;
  --text:#111;
  --muted:#6b7280;
  --primary:#2563eb;
  --primary-fore:#fff;
  --border:#e5e7eb;
}

/* ========== Base / Layout ========== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji","Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
}

.view { display: flex; align-items: center; justify-content: center; padding: 24px; }
.hidden { display: none !important; }

.container { max-width: 1000px; margin: 24px auto; padding: 0 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; }

.topbar {
  position: sticky; top: 0;
  background: rgba(255,255,255,.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 700; }

/* ========== Typography / Cards ========== */
h1, h2, h3 { margin: 0 0 12px; }
.muted { color: var(--muted); margin: 0 0 16px; }
.big { font-size: 42px; font-weight: 800; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 560px; width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,.04);
}

/* ========== Forms / Buttons / Tabs ========== */
.form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
label { font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
input {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  outline: none; font-size: 16px; background: #fff;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

.primary {
  background: var(--primary); color: var(--primary-fore);
  border: none; padding: 12px 16px; border-radius: 10px;
  font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: .6; cursor: wait; }
.ghost { background: transparent; border: 1px solid var(--border); padding: 10px 14px; border-radius: 10px; cursor: pointer; }

.tabs { display: flex; gap: 8px; margin: 8px 0 10px; }
.tab { border: 1px solid var(--border); background: #fff; padding: 8px 12px; border-radius: 999px; cursor: pointer; }
.tab.active { border-color: var(--primary); color: var(--primary); }

.msg { margin-top: 10px; min-height: 20px; font-size: 14px; }
.msg.error { color: #b91c1c; }
.msg.ok    { color: #065f46; }

/* ========== Lists / Leaderboard ========== */
.list { margin: 0; padding-left: 18px; }
.list li { margin: 6px 0; }

#lb-list { counter-reset: rank; }
#lb-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0;
  transition: transform .3s ease, background-color .3s ease;
}
#lb-list li .rank { width: 2ch; text-align: right; font-variant-numeric: tabular-nums; opacity: .7; }
#lb-list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-list li .pts  { font-variant-numeric: tabular-nums; font-weight: 600; }
#lb-list li.bump  { background: #f5faff; }

/* ========== Points ========== */
#p-points, .points { font-size: 42px; font-weight: 800; }

/* ========== Badges (Sasniegumi) ========== */
.badges-module { padding: 16px; }

.badges-grid {
  display: grid;
  grid-template-columns: repeat(6, 56px);
  gap: 12px;
  margin-top: 12px;
}

.badge {
  width: 56px; height: 56px; border-radius: 50%;
  border: 2px solid #e5e7eb; background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; position: relative;
  cursor: default; transition: transform .15s ease;
}
.badge:hover { transform: scale(1.05); }

/* earned vs locked + effects */
.badge.earned {
  border-color: #FFD700;
  box-shadow: 0 0 12px rgba(255,215,0,.7), 0 0 24px rgba(255,215,0,.4);
}
.badge.locked { filter: grayscale(100%); opacity: .35; }

@keyframes badge-flash {
  0% { transform: scale(1);   box-shadow: 0 0 0 rgba(255,215,0,0); }
  30%{ transform: scale(1.25); box-shadow: 0 0 18px rgba(255,215,0,1); }
  60%{ transform: scale(1.15); box-shadow: 0 0 28px rgba(255,215,0,.8); }
  100%{transform: scale(1);   box-shadow: 0 0 0 rgba(255,215,0,0); }
}
.badge.flash { animation: badge-flash 1s ease-out; z-index: 100; }

/* tooltip */
.badge::after{
  content: attr(data-tooltip);
  position: absolute; bottom: -44px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; font-size: 12px;
  padding: 6px 8px; border-radius: 6px; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .15s ease; z-index: 30;
}
.badge:hover::after{ opacity: 1; }

/* ========== Books: helper UI (autocomplete) ========== */
.book-title { font-weight: 500; }
.pts-chip {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 12px;
  background: #e0f2fe; color: #0369a1; font-weight: 600; font-size: .85rem; cursor: help;
}

#title-suggest {
  position: absolute; top: 48px; left: 0; width: 100%; max-height: 220px; overflow-y: auto;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1); z-index: 2000;
}
.suggest-item { padding: 8px 12px; cursor: pointer; }
.suggest-item:hover { background: #f3f4f6; }
.no-results { padding: 8px 12px; color: #888; }

/* ========== Profile layout container (to stack new blocks) ========== */
#profile-view { display: flex; flex-direction: column; align-items: stretch; }

/* ========== HERO (new header) ========== */
#kp-hero {
  width: 100%; background: #4db6ff; color: #fff;
  padding: 20px 24px; border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  margin: 0 0 16px 0;
}
#kp-hero .kp-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
#kp-hero .kp-left h2 { margin: 0 0 10px 0; }

#kp-hero .kp-xp { width: 260px; height: 12px; background: rgba(255,255,255,.35); border-radius: 8px; overflow: hidden; margin: 6px 0; }
/* allow either #p-xp-fill or .kp-xp-fill */
#kp-hero .kp-xp-fill, #p-xp-fill {
  height: 100%; background: #22c55e; width: 0%; transition: width .3s ease;
}

#kp-hero .kp-right { display: flex; align-items: center; gap: 14px; }
#kp-hero .kp-avatar {
  width: 56px; height: 56px; border-radius: 50%; border: 3px solid #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  background: rgba(255,255,255,.15);
}
#kp-hero .kp-points-bubble {
  background: #ffeb3b; color: #333; font-weight: 800;
  padding: 8px 14px; border-radius: 999px; box-shadow: 0 4px 10px rgba(0,0,0,.15);
}

@media (max-width: 640px){
  #kp-hero .kp-row { flex-direction: column; align-items: flex-start; }
  #kp-hero .kp-xp { width: 100%; max-width: 420px; }
}

/* ========== DAILY (full width host, compact 5-in-a-row) ========== */
#kp-daily { background: transparent; padding: 0; margin: 0; border: 0; }
#kp-daily .kp-daily-inner { max-width: none; margin: 0; padding: 0; }

/* use your existing #daily-card but make it left-aligned & compact */
#kp-daily #daily-card.card{
  background: transparent !important;
  box-shadow: none !important;
  border: 0 !important; border-radius: 0 !important;
  margin: 0 0 0 10px !important; /* ~10px from left */
  padding: 0 !important;
  max-width: 680px; /* adjust if you want even tighter */
}

/* the 5 questions side-by-side */
#kp-daily #daily-pack{
  display: grid;
  grid-template-columns: repeat(5, minmax(210px, 1fr));
  gap: 12px; align-items: start;
}
/* compact question panels */
#kp-daily #daily-pack > *{ margin: 0 !important; padding: 12px !important; border-radius: 12px !important; }
/* smaller controls */
#kp-daily #daily-pack label,
#kp-daily #daily-pack .chip,
#kp-daily #daily-pack .choice,
#kp-daily #daily-pack button{ padding: 6px 10px !important; font-size: .95rem !important; border-radius: 10px !important; }
#kp-daily #daily-pack input[type="text"],
#kp-daily #daily-pack input[type="number"]{ height: 34px; padding: 6px 10px; font-size: .95rem; }

/* actions row */
#kp-daily #daily-card .row{
  display: flex; gap: 8px; align-items: center;
  margin: 12px 10px 0 10px !important;
}
#kp-daily #daily-card .msg{ margin-left: 10px; }

/* responsive wrapping */
@media (max-width: 1400px){ #kp-daily #daily-pack{ grid-template-columns: repeat(4, minmax(210px,1fr)); } }
@media (max-width: 1100px){ #kp-daily #daily-pack{ grid-template-columns: repeat(3, minmax(210px,1fr)); } }
@media (max-width: 800px) { #kp-daily #daily-pack{ grid-template-columns: repeat(2, minmax(210px,1fr)); } }
@media (max-width: 560px) { #kp-daily #daily-pack{ grid-template-columns: 1fr; } }

/* ========== TRIPLE (3 modules below daily) ========== */
#kp-triple { width: 100%; margin: 0; padding: 0; }
#kp-triple .kp-triple-inner { max-width: 1200px; margin: 0 auto; padding: 16px 20px; box-sizing: border-box; }
#kp-triple .kp-triple-row { display: flex; gap: 20px; align-items: stretch; }
#kp-triple .kp-third { flex: 1 1 33.333%; min-width: 0; }
#kp-triple .kp-third > .card { margin: 0; height: 100%; }

@media (max-width: 900px) {
  #kp-triple .kp-triple-row { flex-direction: column; }
  #kp-triple .kp-third { flex: 1 1 100%; }
}
