:root {
  --ink: #1f2430;
  --paper: #fffaf0;
  --panel: rgba(255, 250, 240, 0.94);
  --panel-line: rgba(31, 36, 48, 0.12);
  --accent: #2f8f6b;
  --accent-ink: #ffffff;
  --gold: #f2b632;
  --gold-dark: #b37a12;
  --danger: #d9534f;
  --muted: #6b7080;
  --shadow: 0 6px 18px rgba(20, 24, 32, 0.25);
  --bg: #2b2f36;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1efe9;
    --paper: #23262d;
    --panel: rgba(30, 33, 40, 0.94);
    --panel-line: rgba(255, 255, 255, 0.12);
    --muted: #a7abb6;
    --bg: #15171b;
  }
}
:root[data-theme="dark"] {
  --ink: #f1efe9;
  --paper: #23262d;
  --panel: rgba(30, 33, 40, 0.94);
  --panel-line: rgba(255, 255, 255, 0.12);
  --muted: #a7abb6;
  --bg: #15171b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: "Baloo 2", system-ui, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#game.grabbing { cursor: grabbing; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- horní lišta ---------- */
#topbar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}
#topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
#avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  background: #444;
  object-fit: cover;
  flex: none;
  transition: transform 0.15s ease;
}
#avatar.pop { transform: scale(1.12) rotate(-4deg); }

.title {
  font-weight: 800;
  font-size: 22px;
  line-height: 1;
  color: #fff;
  background: rgba(20, 24, 32, 0.62);
  padding: 8px 14px 6px;
  border-radius: 14px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.35);
  white-space: nowrap;
}
.title span { color: #ffe08a; }

.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px 0 8px;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.pill.bump { animation: bump 0.25s ease; }
@keyframes bump { 50% { transform: scale(1.12); } }

.coin {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b8 0 18%, var(--gold) 40%, var(--gold-dark) 100%);
  box-shadow: inset 0 0 0 2px rgba(120, 70, 0, 0.35);
  flex: none;
}

.round {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 18px;
  display: grid;
  place-items: center;
  padding: 0;
}
.round:active { transform: scale(0.94); }
.round.off { opacity: 0.55; }

/* ---------- spodní lišta ---------- */
#toolbar {
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(640px, calc(100% - 32px));
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 5;
}
#cats {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.cat {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 4px 6px;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat.active {
  background: var(--accent);
  color: var(--accent-ink);
}
#items {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.item {
  position: relative;
  border: 2px solid var(--panel-line);
  border-radius: 14px;
  background: var(--paper);
  padding: 4px 2px 2px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
}
.item .ico { font-size: 28px; line-height: 1.1; }
.item .nm {
  font-size: 12px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 2px;
}
.item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
}
.item.locked .ico { filter: grayscale(1); opacity: 0.45; }
.item .price {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 800;
  color: var(--gold-dark);
}
.item .price .coin { width: 12px; height: 12px; }
.item.confirm { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.item.shake { animation: shake 0.3s ease; }
@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- hint, bublina, letící texty ---------- */
#hint {
  position: fixed;
  left: 50%;
  top: 92px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  text-align: center;
  padding: 6px 14px;
  border-radius: 14px;
  background: rgba(20, 24, 32, 0.6);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.6s ease;
}
#hint.gone { opacity: 0; }

#bubble {
  position: fixed;
  left: 0;
  top: 0;
  max-width: 240px;
  padding: 8px 14px;
  border-radius: 18px;
  background: #fff;
  color: #1f2430;
  font-weight: 700;
  font-size: 17px;
  line-height: 1.15;
  box-shadow: var(--shadow);
  transform: translate(-50%, -100%) scale(0.6);
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
  z-index: 4;
  text-align: center;
}
#bubble.show {
  opacity: 1;
  transform: translate(-50%, -100%) scale(1);
}
#bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  margin-left: -10px;
  border: 10px solid transparent;
  border-bottom: 0;
  border-top-color: #fff;
}

#floaters {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}
.floater {
  position: absolute;
  font-weight: 800;
  font-size: 20px;
  color: #ffd84d;
  text-shadow: 0 2px 0 #7a4b00, 0 0 6px rgba(0,0,0,0.4);
  transform: translate(-50%, -50%);
  animation: floatUp 0.9s ease-out forwards;
  white-space: nowrap;
}
.floater.big { font-size: 28px; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -260%) scale(1); }
}

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}

/* ---------- obchod ---------- */
#shop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.55);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 16px;
}
#shop.hidden, #error.hidden { display: none; }
.panel {
  width: min(560px, 100%);
  max-height: min(640px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--panel-line);
}
.panel-head h2 {
  margin: 0;
  font-size: 24px;
  flex: 1;
}
.panel-head .round { box-shadow: none; border: 1px solid var(--panel-line); }
#shopList {
  overflow-y: auto;
  padding: 10px 14px 16px;
}
.shop-cat {
  font-weight: 800;
  font-size: 15px;
  color: var(--muted);
  margin: 10px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.shop-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-line);
}
.shop-row .ico { font-size: 30px; width: 40px; text-align: center; flex: none; }
.shop-row .txt { flex: 1; min-width: 0; }
.shop-row .txt b { display: block; font-size: 17px; }
.shop-row .txt small { color: var(--muted); font-size: 13px; line-height: 1.2; display: block; }
.buy {
  border: 0;
  border-radius: 12px;
  padding: 6px 12px;
  font-weight: 800;
  background: var(--gold);
  color: #3a2600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.buy .coin { width: 14px; height: 14px; }
.buy:disabled { background: var(--panel-line); color: var(--muted); cursor: not-allowed; }
.owned {
  font-weight: 800;
  font-size: 14px;
  color: var(--accent);
}

#error {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 40%;
  padding: 16px;
  border-radius: 16px;
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  text-align: center;
  z-index: 20;
}

@media (max-width: 560px) {
  .title { font-size: 17px; }
  #avatar { width: 52px; height: 52px; }
  .round { width: 36px; height: 36px; font-size: 16px; }
  .pill { height: 36px; font-size: 17px; }
  .item .ico { font-size: 24px; }
  .item .nm { font-size: 11px; }
  .item { min-height: 58px; }
  .cat { font-size: 13px; }
  #hint { top: 84px; font-size: 13px; }
}
@media (max-width: 420px) {
  .cat .ci { display: none; }
}
@media (max-width: 400px) {
  .title { display: none; }
}
