:root {
  --bg: #0f0e17;
  --bg-soft: #17162280;
  --panel: #1a1926;
  --panel-2: #21202f;
  --line: #2c2b3d;
  --ink: #ecebf5;
  --ink-dim: #9d9ab5;
  --brand: #7c6bff;
  --brand-2: #a48bff;
  --gold: #ffc857;
  --green: #48d597;
  --red: #ff6b6b;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* v režimu na ploše se nesmí dát „přetáhnout" celá stránka jako v prohlížeči */
  overscroll-behavior-y: none;
}

/* Na ploše iPadu/iPhonu jede obsah pod výřezem a domovskou lištou — odsadit. */
.topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
.wrap { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
.foot { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.auth { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.modal-backdrop { padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); }

/* Dotykové ovládání: nic pod 44 px a žádný modrý záblesk při ťuknutí. */
@media (pointer: coarse) {
  .btn, .tab, .result, .iconbtn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  input, select, textarea { font-size: 16px; } /* iOS jinak stránku přiblíží */
}
button, a, .result { -webkit-tap-highlight-color: transparent; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 500px at 12% -10%, #7c6bff26, transparent 60%),
    radial-gradient(700px 400px at 95% 0%, #ffc85718, transparent 55%);
  pointer-events: none;
  z-index: 0;
}

.hidden, [hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
.muted { color: var(--ink-dim); }
.small { font-size: 13px; }
.eyebrow { margin: 0 0 2px; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-dim); }

/* ------------------------------------------------------------ controls */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
  color: var(--ink);
  background: var(--panel-2);
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 6px 20px #7c6bff40; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-dim); }
.btn.ghost:hover { color: var(--ink); border-color: var(--brand); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.danger { background: transparent; border-color: #ff6b6b55; color: var(--red); }
.linkbtn { background: none; border: 0; color: var(--brand-2); font: inherit; font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; }
.iconbtn { background: none; border: 0; color: var(--ink-dim); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.iconbtn:hover { color: var(--ink); background: var(--panel-2); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; flex: 1 1 180px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-dim); }
input, select, textarea {
  background: #12111b;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px #7c6bff30; }
textarea { resize: vertical; min-height: 110px; }
.counter { font-size: 12px; color: var(--ink-dim); text-align: right; }
.counter.ok { color: var(--green); }

.alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; background: var(--panel-2); border: 1px solid var(--line); }
.alert.error { background: #ff6b6b1a; border-color: #ff6b6b55; color: #ffb3b3; }
.alert.ok { background: #48d5971a; border-color: #48d59755; color: #a8f0cd; }

/* --------------------------------------------------------------- auth */
.auth { position: relative; z-index: 1; display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.auth-art { display: flex; align-items: center; padding: 6vh 6vw; background: linear-gradient(150deg, #241f47, #14121f 60%); border-right: 1px solid var(--line); }
.auth-art-inner { max-width: 460px; }
.auth-art h1 { font-size: clamp(38px, 6vw, 62px); letter-spacing: -.02em; margin: 24px 0; }
.auth-perks { list-style: none; padding: 0; margin: 0 0 28px; }
.auth-perks li { padding: 10px 0 10px 30px; position: relative; color: var(--ink-dim); }
.auth-perks li::before { content: "✓"; position: absolute; left: 0; color: var(--green); font-weight: 700; }
.auth-perks b { color: var(--gold); }
.auth-coins { font-size: 26px; letter-spacing: 8px; opacity: .8; }
.auth-form-wrap { display: flex; align-items: center; justify-content: center; padding: 6vh 6vw; }
.auth-form { width: 100%; max-width: 360px; }
.switch { margin-top: 16px; font-size: 14px; color: var(--ink-dim); text-align: center; }

.logo { font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.logo span { background: linear-gradient(120deg, var(--brand-2), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* --------------------------------------------------------- app shell */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 12px 24px;
  background: #0f0e17e6;
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab { background: none; border: 0; color: var(--ink-dim); font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 9px; cursor: pointer; }
.tab:hover { color: var(--ink); background: var(--panel-2); }
.tab.active { color: #fff; background: var(--brand); }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.who { font-size: 14px; color: var(--ink-dim); }

.wrap { position: relative; z-index: 1; max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; display: flex; flex-direction: column; gap: 20px; }
.view { display: flex; flex-direction: column; gap: 20px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* --------------------------------------------------------------- hero */
.hero {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px;
  background: linear-gradient(135deg, #2a2350, #191826 65%);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; box-shadow: var(--shadow);
}
.bignum { font-size: clamp(40px, 7vw, 64px); font-weight: 800; letter-spacing: -.03em; color: var(--gold); line-height: 1.05; }
.hero-main .btn { margin-top: 18px; }
.koef {
  display: inline-flex; align-items: center; gap: 7px;
  margin: 8px 0 2px; padding: 5px 12px; border-radius: 99px;
  background: #7c6bff1f; border: 1px solid #7c6bff55;
  font-size: 13px; font-weight: 600; color: var(--brand-2);
}
.koef b { color: var(--ink); }
.koef.plna { background: #48d5971a; border-color: #48d59744; color: var(--green); }
.hero-side { display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.minicard { background: #ffffff0a; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; display: flex; flex-direction: column; }
.minicard.highlight { border-color: #48d59755; background: #48d5970f; }
.mini-label { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .07em; }
.mini-value { font-size: 24px; font-weight: 700; }
.minicard.highlight .mini-value { color: var(--green); }
.mini-hint { font-size: 11px; color: var(--ink-dim); }

/* -------------------------------------------------------------- level */
.level-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.level-head .streak { text-align: center; background: #ffc8571a; border: 1px solid #ffc85744; border-radius: 12px; padding: 8px 14px; }
.streak-flame { font-size: 20px; display: block; }
.streak-num { font-size: 22px; font-weight: 800; color: var(--gold); }
.streak-label { display: block; font-size: 11px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .06em; }
.streak.cold { filter: grayscale(1); opacity: .6; }

.bar { height: 10px; background: #ffffff12; border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--gold)); border-radius: 99px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }

/* ---------------------------------------------------------- řada dní */
.streak-panel { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.streak-today { display: flex; align-items: center; gap: 10px; font-size: 14px; margin-bottom: 12px; }
.streak-today .dot { width: 10px; height: 10px; border-radius: 99px; background: var(--ink-dim); flex: 0 0 auto; }
.streak-today.done .dot { background: var(--green); box-shadow: 0 0 0 4px #48d59726; }
.streak-today.todo .dot { background: var(--gold); box-shadow: 0 0 0 4px #ffc85726; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px #ffc85712; } }
.streak-today b { color: var(--ink); }

.ladder { display: flex; gap: 6px; }
.ladder-step {
  flex: 1; text-align: center; padding: 9px 4px; border-radius: 10px;
  background: #ffffff08; border: 1px solid var(--line);
}
.ladder-step.now { border-color: var(--gold); background: #ffc8571a; }
.ladder-step .l-day { display: block; font-size: 10px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .05em; }
.ladder-step .l-czk { display: block; font-size: 15px; font-weight: 800; color: var(--gold); }
.ladder-step.free .l-czk { color: var(--ink-dim); }

.feed-item.streak-bonus { border-left-color: var(--gold); background: linear-gradient(90deg, #ffc85712, transparent 60%); }

.quick-stats { display: flex; gap: 8px; margin-top: 16px; }
.quick-stats > div { flex: 1; background: #ffffff08; border-radius: 10px; padding: 10px; text-align: center; }
.quick-stats b { display: block; font-size: 20px; }
.quick-stats span { font-size: 11px; color: var(--ink-dim); }

/* -------------------------------------------- nejblíž k odemčení */
.near { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 14px; }
.near-item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: #ffffff08; border: 1px solid var(--line); border-radius: 11px; }
.near-icon { font-size: 22px; flex: 0 0 auto; }
.near-body { flex: 1; min-width: 0; }
.near-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.near-name { font-weight: 700; font-size: 14px; }
.near-reward { font-weight: 800; color: var(--gold); font-size: 14px; white-space: nowrap; }
.near .bar { height: 6px; margin: 6px 0 4px; }
.near-left { font-size: 11px; color: var(--ink-dim); }

/* ------------------------------------------------------------ trofeje */
.trophy-group { margin-bottom: 18px; }
.trophy-group:last-child { margin-bottom: 0; }
.trophy-group-name {
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-dim); margin: 0 0 9px;
}
.trophies { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.trophy {
  display: flex; gap: 12px; padding: 14px;
  background: #ffffff07; border: 1px solid var(--line); border-radius: 12px;
}
.trophy.done { border-color: #ffc85766; background: linear-gradient(140deg, #ffc85714, transparent 70%); }
.trophy-icon { font-size: 26px; line-height: 1; flex: 0 0 auto; }
.trophy.locked .trophy-icon { filter: grayscale(1); opacity: .5; }
.trophy-body { min-width: 0; flex: 1; }
.trophy-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.trophy-name { font-weight: 700; font-size: 14px; }
.trophy-reward { font-weight: 800; color: var(--gold); white-space: nowrap; font-size: 14px; }
.trophy-cond { font-size: 12px; color: var(--ink-dim); margin: 3px 0 8px; }
.trophy .bar { height: 6px; margin: 0 0 5px; }
.trophy-progress { font-size: 11px; color: var(--ink-dim); }
.trophy.done .trophy-progress { color: var(--green); }

.feed-item.trophy-win { border-left-color: var(--gold); background: linear-gradient(90deg, #ffc85718, transparent 60%); }

/* -------------------------------------------------------------- books */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.book { display: flex; gap: 14px; background: #ffffff07; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.book.done { border-color: #48d59744; background: #48d5970d; }
.book-cover { width: 62px; height: 92px; border-radius: 6px; object-fit: cover; background: var(--panel-2); flex: 0 0 auto; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.book-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.book-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-author { font-size: 12px; color: var(--ink-dim); margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { font-size: 12px; color: var(--ink-dim); display: flex; justify-content: space-between; margin-top: 6px; }
.book-worth { color: var(--gold); font-weight: 700; }
.book-actions { display: flex; gap: 6px; margin-top: 10px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--green); color: #06301f; }

/* --------------------------------------------------------------- feed */
.feed { display: flex; flex-direction: column; gap: 10px; }
.feed-item { background: #ffffff07; border: 1px solid var(--line); border-left: 3px solid var(--brand); border-radius: 10px; padding: 14px 16px; }
.feed-item.finish { border-left-color: var(--gold); background: #ffc8570f; }
.feed-item.payment { border-left-color: var(--green); background: #48d5970d; }
.feed-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.feed-book { font-weight: 700; }
.feed-when { font-size: 12px; color: var(--ink-dim); white-space: nowrap; }
.feed-pages { font-size: 13px; color: var(--ink-dim); margin: 3px 0 8px; }
.feed-amount { font-weight: 800; color: var(--gold); white-space: nowrap; }
.feed-amount.paid { color: var(--green); }
.feed-summary { font-size: 14px; color: #cdcbdd; white-space: pre-wrap; border-top: 1px solid var(--line); padding-top: 9px; margin-top: 4px; }
.empty { color: var(--ink-dim); font-size: 14px; text-align: center; padding: 28px; border: 1px dashed var(--line); border-radius: 12px; }

/* ------------------------------------------------------------- search */
.search-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.search-status { font-size: 13px; color: var(--ink-dim); white-space: nowrap; }
.results { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; margin-bottom: 16px; }
.result { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; text-align: left; background: none; color: inherit; font: inherit; width: 100%; }
.result:hover { background: var(--panel-2); border-color: var(--brand); }
.result img, .result .noimg { width: 34px; height: 50px; border-radius: 4px; object-fit: cover; background: var(--panel-2); flex: 0 0 auto; }
.result-info { min-width: 0; }
.result-title { font-weight: 600; font-size: 14px; }
.result-sub { font-size: 12px; color: var(--ink-dim); }
.book-form { border-top: 1px solid var(--line); padding-top: 16px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.form-actions { display: flex; align-items: center; gap: 14px; justify-content: space-between; }
.cover-preview img { height: 60px; border-radius: 5px; }

/* -------------------------------------------------------------- modal */
.modal-backdrop { position: fixed; inset: 0; background: #06050ccc; backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 60; overflow-y: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 520px; box-shadow: var(--shadow); animation: pop .22s ease; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
@keyframes pop { from { transform: translateY(14px) scale(.97); opacity: 0; } }

.entry-progress { background: #ffffff08; border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; font-size: 13px; color: var(--ink-dim); }
.payout-preview { background: linear-gradient(135deg, #7c6bff22, #ffc85718); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.payout-preview b { color: var(--gold); font-size: 18px; }

/* ---------------------------------------------------------- celebrate */
.celebrate { position: fixed; inset: 0; background: #06050ce6; display: flex; align-items: center; justify-content: center; z-index: 80; }
.celebrate-card { text-align: center; background: linear-gradient(150deg, #2d2456, #191826); border: 1px solid var(--line); border-radius: 20px; padding: 40px 48px; box-shadow: var(--shadow); animation: pop .3s ease; }
.celebrate-emoji { font-size: 62px; animation: bounce .7s ease infinite alternate; }
.celebrate-card h2 { font-size: 44px; color: var(--gold); margin: 8px 0; }
@keyframes bounce { to { transform: translateY(-12px); } }

/* --------------------------------------- prohlížení cizího účtu */
.impbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(90deg, #b8860b, #ffc857);
  color: #2b1d00; font-size: 14px; font-weight: 600;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .45);
}
.impbar .btn { background: #2b1d00; color: #ffe6a8; border: 0; }
.impbar .btn:hover { filter: brightness(1.3); }
body.impersonating .wrap { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
body.impersonating .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); color: var(--ink); padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow); z-index: 90; font-size: 14px; }
.toast.err { border-color: #ff6b6b66; color: #ffb3b3; }

/* -------------------------------------------------------------- admin */
.admin-user { margin-bottom: 20px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-money { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 14px 0; }
.admin-money > div { background: #ffffff08; border-radius: 10px; padding: 10px 12px; }
.admin-money b { display: block; font-size: 19px; }
.admin-money.owed b { color: var(--gold); }
.koef-form { border-top: 1px solid var(--line); }
.imp-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.pay-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 14px; }
.pay-form .field { margin-bottom: 0; }
.paylist { margin-top: 12px; font-size: 13px; }
.paylist div { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); color: var(--ink-dim); }

.foot { position: relative; z-index: 1; text-align: center; padding: 20px; border-top: 1px solid var(--line); color: var(--ink-dim); font-size: 13px; display: flex; flex-direction: column; gap: 4px; }

@media (max-width: 820px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 40px 24px; border-right: 0; border-bottom: 1px solid var(--line); }
  .hero, .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .topbar-right { margin-left: auto; }
  .wrap { padding: 18px 14px 50px; }
  .card { padding: 18px; }
}
