/* ⚔️ Писательский турнир — тёмная игровая тема */

:root {
  --bg: #0b0b12;
  --bg-card: #14141f;
  --bg-elevated: #1b1b2b;
  --border: #262638;
  --text: #e8e8f0;
  --text-dim: #8a8aa3;
  --accent: #8b5cf6;          /* электрический фиолет */
  --accent2: #06b6d4;         /* циан */
  --gold: #fbbf24;
  --danger: #f43f5e;
  --ok: #34d399;
  --fire: #fb923c;
  --grad: linear-gradient(135deg, var(--accent), var(--accent2));
  --grad-gold: linear-gradient(135deg, #f59e0b, #fde047);
  --r: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }

body {
  background: var(--bg);
  background-image:
    radial-gradient(800px 400px at 80% -10%, rgba(139, 92, 246, .12), transparent),
    radial-gradient(600px 300px at 10% 0%, rgba(6, 182, 212, .08), transparent);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }

h1, h2, .logo, .timer-label, .vs-text { font-family: "Unbounded", "Inter", sans-serif; }

h2 { font-size: 15px; letter-spacing: .08em; margin-bottom: 14px; color: var(--text); }

#confetti-canvas {
  position: fixed; inset: 0; pointer-events: none; z-index: 9000;
}

/* ---------- логин ---------- */

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 24px;
  padding: 40px 32px; width: 100%; max-width: 380px; text-align: center;
  box-shadow: 0 0 80px rgba(139, 92, 246, .15);
}
.login-logo { font-size: 56px; margin-bottom: 8px; animation: float 3s ease-in-out infinite; }
.login-card h1 { font-size: 22px; line-height: 1.3; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-sub { color: var(--text-dim); font-size: 13px; margin: 10px 0 24px; }
.login-card input {
  width: 100%; margin-bottom: 12px; padding: 14px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); font-size: 16px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ---------- каркас ---------- */

#app { max-width: 760px; margin: 0 auto; padding: 0 14px 60px; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 16px 2px;
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.logo { font-size: 17px; font-weight: 900; }
.logo span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.bank-pill {
  margin-left: auto; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font-weight: 800; font-size: 14px;
  font-family: "JetBrains Mono", monospace;
}
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; width: 38px; height: 38px; font-size: 16px; cursor: pointer;
  transition: transform .1s;
}
.icon-btn:active { transform: scale(.92); }

.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r);
  padding: 20px; margin-bottom: 16px;
}

/* ---------- таймер ---------- */

.timer-block { text-align: center; padding: 18px 0 26px; }
.timer-label { font-size: 11px; letter-spacing: .25em; color: var(--text-dim); }
.timer {
  font-family: "JetBrains Mono", monospace; font-weight: 700;
  font-size: clamp(48px, 14vw, 84px); line-height: 1.1;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  font-variant-numeric: tabular-nums;
}
.timer.danger {
  background: linear-gradient(135deg, #f43f5e, #fb923c);
  -webkit-background-clip: text; background-clip: text;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.game-day-label { color: var(--text-dim); font-size: 12px; margin-top: 6px; }

/* ---------- VS ---------- */

.vs-block { display: flex; gap: 10px; align-items: stretch; margin-bottom: 16px; }
.player-card {
  flex: 1; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r); padding: 18px 14px; text-align: center; position: relative;
  transition: border-color .3s, box-shadow .3s;
}
.player-card.met { border-color: rgba(251, 191, 36, .5); box-shadow: 0 0 24px rgba(251, 191, 36, .12); }
.player-card.me::after {
  content: "ТЫ"; position: absolute; top: 10px; right: 10px; font-size: 9px; font-weight: 800;
  letter-spacing: .1em; color: var(--accent2); border: 1px solid var(--accent2);
  border-radius: 6px; padding: 2px 6px;
}
.avatar {
  width: 84px; height: 84px; border-radius: 50%; object-fit: cover;
  border: 3px solid var(--border); display: block; margin: 0 auto 10px;
  background: var(--bg-elevated);
}
.player-card.met .avatar { border-color: var(--gold); box-shadow: 0 0 18px rgba(251, 191, 36, .35); }
.avatar-fallback {
  width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center; font-size: 36px;
  background: var(--bg-elevated); border: 3px solid var(--border);
}
.player-name { font-weight: 800; font-size: 15px; margin-bottom: 2px; }
.player-chars {
  font-family: "JetBrains Mono", monospace; font-size: 26px; font-weight: 700;
  font-variant-numeric: tabular-nums; margin: 8px 0 2px;
}
.player-chars small { font-size: 11px; color: var(--text-dim); font-family: "Inter"; }
.progress {
  height: 10px; background: var(--bg-elevated); border-radius: 999px; overflow: hidden;
  margin: 10px 0 6px; position: relative;
}
.progress-fill {
  height: 100%; border-radius: 999px; background: var(--grad);
  transition: width .6s cubic-bezier(.22, 1, .36, 1); width: 0;
}
.progress-fill.gold { background: var(--grad-gold); }
.progress-pct { font-size: 11px; color: var(--text-dim); }
.overdrive {
  display: inline-block; margin-top: 4px; font-size: 10px; font-weight: 800; letter-spacing: .08em;
  color: #0b0b12; background: var(--grad-gold); padding: 3px 8px; border-radius: 6px;
  animation: shine 2s linear infinite;
}
@keyframes shine { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.25); } }
.streak { margin-top: 8px; font-weight: 800; font-size: 14px; }
.streak .flame { display: inline-block; animation: flicker 1.4s ease-in-out infinite; }
@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(-3deg); }
  30% { transform: scale(1.15) rotate(3deg); }
  60% { transform: scale(.95) rotate(-2deg); }
}
.streak-zero { color: var(--text-dim); font-weight: 400; font-size: 12px; }
.today-books { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.today-books .mini-chip {
  font-size: 10px; background: var(--bg-elevated); border-radius: 6px; padding: 2px 7px;
  color: var(--text-dim); border: 1px solid var(--border);
}

.vs-divider { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 44px; }
.vs-bolt { font-size: 22px; animation: flicker 2s ease-in-out infinite; }
.vs-text { font-size: 16px; font-weight: 900; color: var(--text-dim); }

/* ---------- ввод ---------- */

.staged-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.staged-amount {
  font-family: "JetBrains Mono", monospace; font-size: 34px; font-weight: 700;
  font-variant-numeric: tabular-nums; flex: 1;
}
.staged-amount small { font-size: 12px; color: var(--text-dim); font-family: "Inter"; }
.quick-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.chip-btn {
  background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 10px; font-size: 14px; font-weight: 700; cursor: pointer;
  transition: transform .08s, border-color .2s; white-space: nowrap;
}
.chip-btn:hover { border-color: var(--accent); }
.chip-btn:active { transform: scale(.94); }
.chip-btn.ghost { background: transparent; color: var(--text-dim); }
.manual-row { display: flex; gap: 8px; margin-bottom: 12px; }
.manual-row input {
  flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 16px;
}
.manual-row input:focus { outline: none; border-color: var(--accent); }

.book-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.book-chip {
  font-size: 12px; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-dim);
}
.book-chip.active { border-color: var(--accent); color: var(--text); background: rgba(139, 92, 246, .15); }

.btn-primary {
  width: 100%; border: none; border-radius: 14px; padding: 16px;
  font-family: "Unbounded", sans-serif; font-size: 15px; font-weight: 700; letter-spacing: .05em;
  background: var(--grad); color: white; cursor: pointer;
  transition: transform .1s, filter .2s, opacity .2s;
}
.btn-primary:hover { filter: brightness(1.15); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .35; cursor: default; transform: none; filter: none; }
.btn-big { font-size: 17px; padding: 18px; }
.edit-row { text-align: center; margin-top: 10px; }
.edit-row a { color: var(--text-dim); font-size: 12px; }

/* ---------- лидерборд ---------- */

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab {
  flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text-dim); font-weight: 700; font-size: 13px; cursor: pointer;
}
.tab.active { background: var(--grad); color: white; border-color: transparent; }

.lb-score {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  font-family: "JetBrains Mono", monospace; font-size: 15px; margin-bottom: 14px;
  font-variant-numeric: tabular-nums;
}
.lb-score .num { font-size: 30px; font-weight: 700; }
.lb-score .colon { color: var(--text-dim); font-size: 24px; }
.lb-score .leader-num { background: var(--grad-gold); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lb-name { font-family: "Inter"; font-size: 12px; color: var(--text-dim); text-align: center; }
.lb-stats { width: 100%; border-collapse: collapse; font-size: 13px; }
.lb-stats td { padding: 6px 4px; border-top: 1px solid var(--border); }
.lb-stats td:first-child { color: var(--text-dim); }
.lb-stats td:not(:first-child) { text-align: center; font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; }
.lb-stats .win { color: var(--gold); font-weight: 700; }

.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 14px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-family: "JetBrains Mono", monospace; position: relative;
  background: var(--bg-elevated); color: var(--text-dim); border: 1px solid transparent;
}
.cal-cell.met { background: rgba(52, 211, 153, .18); color: var(--ok); }
.cal-cell.fail { background: rgba(244, 63, 94, .15); color: var(--danger); }
.cal-cell.win { border-color: var(--gold); box-shadow: inset 0 0 8px rgba(251, 191, 36, .25); }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.future { opacity: .3; }
.cal-cell .crown { position: absolute; top: -4px; right: -2px; font-size: 10px; }

/* ---------- ачивки ---------- */

.ach-feed { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.ach-card {
  min-width: 150px; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; text-align: center; flex-shrink: 0;
}
.ach-card .icon { font-size: 30px; }
.ach-card .name { font-size: 12px; font-weight: 700; margin-top: 6px; line-height: 1.25; }
.ach-card .who { font-size: 10px; color: var(--text-dim); margin-top: 4px; }
.ach-card.rare { border-color: rgba(6, 182, 212, .5); }
.ach-card.epic { border-color: rgba(139, 92, 246, .6); box-shadow: 0 0 12px rgba(139, 92, 246, .15); }
.ach-card.legendary { border-color: rgba(251, 191, 36, .7); box-shadow: 0 0 16px rgba(251, 191, 36, .25); animation: shine 2.5s linear infinite; }
.ach-card.fresh { animation: ach-in .6s cubic-bezier(.22, 1, .36, 1); }
@keyframes ach-in { from { transform: translateY(16px) scale(.9); opacity: 0; } }

details summary { cursor: pointer; color: var(--text-dim); font-size: 13px; margin-top: 10px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; }
.ach-grid .ach-card { min-width: 0; }
.ach-grid .ach-card.locked { opacity: .35; filter: grayscale(1); }
.ach-grid .desc { font-size: 10px; color: var(--text-dim); margin-top: 4px; }

/* попап ачивки */
.ach-modal {
  position: fixed; inset: 0; background: rgba(5, 5, 10, .85); z-index: 9500;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(6px);
}
.ach-modal-card {
  background: var(--bg-card); border: 1px solid var(--accent); border-radius: 24px;
  padding: 36px 28px; text-align: center; max-width: 340px; width: 100%;
  animation: modal-in .5s cubic-bezier(.22, 1.4, .36, 1);
  box-shadow: 0 0 60px rgba(139, 92, 246, .4);
}
.ach-modal-card.legendary { border-color: var(--gold); box-shadow: 0 0 80px rgba(251, 191, 36, .5); }
@keyframes modal-in { from { transform: scale(.6); opacity: 0; } }
.ach-modal-icon { font-size: 72px; animation: float 2s ease-in-out infinite; }
.ach-modal-rarity { font-size: 10px; letter-spacing: .3em; font-weight: 800; color: var(--accent2); margin: 8px 0; }
.ach-modal-card.legendary .ach-modal-rarity { color: var(--gold); }
.ach-modal-name { font-family: "Unbounded"; font-size: 19px; font-weight: 900; margin-bottom: 8px; }
.ach-modal-desc { color: var(--text-dim); font-size: 13px; margin-bottom: 22px; }

/* ---------- банк ---------- */

.bank-balances { display: flex; gap: 10px; margin-bottom: 14px; }
.balance-card { flex: 1; background: var(--bg-elevated); border-radius: 12px; padding: 12px; text-align: center; }
.balance-card .amount { font-family: "JetBrains Mono", monospace; font-size: 20px; font-weight: 700; }
.balance-card .amount.neg { color: var(--danger); }
.balance-card .amount.pos { color: var(--ok); }
.balance-card .who { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.bank-ledger { max-height: 220px; overflow-y: auto; font-size: 12px; }
.ledger-row { display: flex; gap: 8px; padding: 7px 2px; border-top: 1px solid var(--border); align-items: baseline; }
.ledger-row .amt { font-family: "JetBrains Mono", monospace; font-weight: 700; min-width: 64px; }
.ledger-row .amt.neg { color: var(--danger); }
.ledger-row .amt.pos { color: var(--ok); }
.ledger-row .note { color: var(--text-dim); flex: 1; }
.ledger-row .when { color: var(--text-dim); font-size: 10px; }
.settle-row { display: flex; gap: 8px; margin-top: 12px; }
.settle-row input {
  flex: 1; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text);
}

/* ---------- книги ---------- */

.books-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.book-row {
  display: flex; gap: 12px; background: var(--bg-elevated); border-radius: 12px; padding: 10px;
  align-items: center;
}
.book-cover { width: 44px; height: 62px; border-radius: 6px; object-fit: cover; background: var(--bg); flex-shrink: 0; }
.book-cover-fallback { width: 44px; height: 62px; border-radius: 6px; background: var(--bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.book-info { flex: 1; min-width: 0; }
.book-title { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.book-delta { color: var(--ok); font-weight: 700; }
.book-actions { display: flex; gap: 4px; }
.book-actions button { font-size: 12px; padding: 7px 9px; }
.import-row { display: flex; gap: 8px; margin-top: 8px; }
.import-row input {
  flex: 1; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 13px; min-width: 0;
}
.avatar-label { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- toast ---------- */

#toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 12px 20px; font-size: 14px; font-weight: 600;
  animation: toast-in .3s cubic-bezier(.22, 1, .36, 1); box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  max-width: 90vw;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--ok); }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }

.footer { text-align: center; color: var(--text-dim); font-size: 11px; padding: 24px 0; }

/* ---------- мобила ---------- */

@media (max-width: 560px) {
  .vs-block { gap: 6px; }
  .vs-divider { min-width: 32px; }
  .player-chars { font-size: 20px; }
  .avatar, .avatar-fallback { width: 64px; height: 64px; }
  .quick-buttons { grid-template-columns: repeat(2, 1fr); }
}
