/* ============================================================
   BouncingCubes – Telegram Mini App  |  styles.css
   ============================================================ */

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Telegram theme mapping ───────────────────────────────── */
/* TG SDK injects --tg-theme-* vars; we map them to our tokens */
:root {
  /* Colours — fall back to dark theme values */
  --bg:       var(--tg-theme-bg-color,                #1c1c1e);
  --surface:  var(--tg-theme-secondary-bg-color,      #2c2c2e);
  --surface2: var(--tg-theme-section-bg-color,        #3a3a3c);
  --border:   var(--tg-theme-section-separator-color, #38383a);
  --accent:   var(--tg-theme-button-color,            #2481cc);
  --btn-txt:  var(--tg-theme-button-text-color,       #ffffff);
  --text:     var(--tg-theme-text-color,              #ffffff);
  --muted:    var(--tg-theme-hint-color,              #8e8e93);
  --link:     var(--tg-theme-link-color,              #2481cc);
  --sub-text: var(--tg-theme-subtitle-text-color,     #8e8e93);

  /* Static colours (game-specific, not themed) */
  --success:  #30d158;
  --danger:   #ff453a;
  --warn:     #ffd60a;
  --accent2:  #5e5ce6;

  /* Layout */
  --radius:   12px;
  --tab-h:    52px;

  /* Safe area (filled by JS via TG.safeAreaInsets; fallback to env()) */
  --tg-safe-top:    env(safe-area-inset-top,    0px);
  --tg-safe-bottom: env(safe-area-inset-bottom, 0px);
  --tg-safe-left:   env(safe-area-inset-left,   0px);
  --tg-safe-right:  env(safe-area-inset-right,  0px);
}

/* Light theme overrides when Telegram is in light mode */
[data-tg-scheme="light"] {
  --surface2: #f2f2f7;
  --border:   #c6c6c8;
  --warn:     #ff9500;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  font-size: 14px;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* Respect Telegram safe areas */
  padding-top:    var(--tg-safe-top);
  padding-bottom: var(--tg-safe-bottom);
  padding-left:   var(--tg-safe-left);
  padding-right:  var(--tg-safe-right);
}

/* ── App shell ─────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ── Tab contents ──────────────────────────────────────────── */
.tab-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--tab-h);
  display: flex;
  flex-direction: column;
}
.tab-content.hidden { display: none !important; }

/* ── Tab bar ───────────────────────────────────────────────── */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--tab-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  transition: color .2s;
  padding: 4px 2px;
  min-width: 0;
  overflow: hidden;
}
.tab-btn.active { color: var(--accent); }
.tab-btn:hover  { color: var(--text); }

/* Profile chip removed — use Home tab profile banner instead */

/* ── Buttons ───────────────────────────────────────────────── */
button { cursor: pointer; border: none; border-radius: var(--radius); font-size: 14px; }

.btn-primary {
  background: var(--accent);
  color: var(--btn-txt);
  padding: 10px 20px;
  font-weight: 600;
  transition: filter .15s;
}
.btn-primary:active { filter: brightness(0.9); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 20px;
}
.btn-secondary:active { opacity: 0.7; }
.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 10px 20px;
  font-weight: 600;
}
.btn-danger:active { filter: brightness(0.9); }
.btn-large { padding: 14px 28px; font-size: 16px; width: 100%; margin: 8px 0; }

/* ── Inputs ────────────────────────────────────────────────── */
input[type=text], input[type=number] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  width: 100%;
}
input:focus { border-color: var(--accent); }

/* ── Panel header ──────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.panel-header h2 { font-size: 18px; }

.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 8px 0; }

/* ══════════════════════════════════════════════════════════════
   GAME TAB
   ══════════════════════════════════════════════════════════════ */

/* Info bar */
#game-info {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 4px;
  gap: 2px;
}
.info-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.info-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.info-block span:last-child,
#info-level, #info-score, #info-target, #info-time, #info-combo {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
#info-combo { color: var(--warn); }

/* Next preview */
#next-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
#next-cubes { display: flex; gap: 4px; }
.next-cube-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: inline-block;
}

/* Canvas wrap */
#canvas-wrap {
  flex: 1;
  position: relative;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
#game-canvas {
  display: block;
  border-radius: 4px;
  touch-action: none;
  cursor: crosshair;
}

/* Freeze overlay */
#overlay-freeze {
  position: absolute;
  inset: 0;
  background: rgba(0, 150, 255, 0.12);
  pointer-events: none;
  border: 3px solid rgba(0, 150, 255, 0.6);
  animation: freeze-pulse 0.8s ease-in-out infinite alternate;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10px;
}
#overlay-freeze.hidden { display: none !important; }
#freeze-counter {
  background: rgba(0, 80, 180, 0.75);
  color: #e0f0ff;
  font-size: 17px;
  font-weight: 700;
  padding: 3px 14px;
  border-radius: 20px;
  letter-spacing: 1px;
}
@keyframes freeze-pulse {
  from { opacity: 0.4; } to { opacity: 1; }
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay.hidden { display: none; }
.overlay-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: pop-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.overlay-box h2 { font-size: 22px; }
.overlay-box p  { color: var(--muted); }
#result-elo { font-size: 13px; font-weight: 600; }
#result-mp  { font-size: 12px; }

/* Button bar */
#game-buttons {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
#game-buttons button { flex: 1; }
.hidden { display: none !important; }

/* Log panel */
#log-panel {
  height: 110px;
  overflow-y: auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 4px 8px;
  flex-shrink: 0;
}
.log-entry {
  font-size: 12px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-positive { color: #4ade80; }
.log-negative { color: #f87171; }
.log-special  { color: #fbbf24; }
.log-neutral  { color: var(--muted); }

/* ══════════════════════════════════════════════════════════════
   SHOP TAB
   ══════════════════════════════════════════════════════════════ */
#shop-currency { display: flex; gap: 12px; font-weight: 600; }
#shop-categories {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.cat-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 6px 14px;
  white-space: nowrap;
  transition: all .2s;
}
.cat-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

#shop-items {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 12px;
}
.shop-item {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color .2s;
}
.shop-item.owned   { border-color: var(--success); }
.shop-item.equipped{ border-color: var(--accent); background: rgba(59,130,246,.1); }
.shop-item-preview { font-size: 36px; }
.shop-item-name    { font-weight: 600; font-size: 13px; }
.shop-item-price   { color: var(--warn); font-size: 12px; }
.shop-item-btn     { margin-top: 4px; padding: 7px; font-size: 12px; border-radius: 8px; }

/* ══════════════════════════════════════════════════════════════
   MULTIPLAYER TAB
   ══════════════════════════════════════════════════════════════ */
#tab-multi { padding: 16px; gap: 12px; }
#my-elo-block { text-align: center; margin-bottom: 8px; }
#my-elo { font-size: 32px; font-weight: 700; color: var(--accent); }

.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

#multi-scores {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 16px;
  background: var(--surface2);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.player-score-block { text-align: center; }
.player-name  { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.player-score { display: block; font-size: 28px; font-weight: 700; }
.vs-label     { font-size: 20px; font-weight: 700; color: var(--muted); }

/* ══════════════════════════════════════════════════════════════
   ALLIANCE TAB
   ══════════════════════════════════════════════════════════════ */
#tab-alliance { padding: 0; }
#alliance-none, #alliance-create, #alliance-search, #alliance-mine {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.al-tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}
.alliance-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.alliance-card-info h4 { font-size: 14px; }
.alliance-card-info p  { font-size: 12px; color: var(--muted); }
.roster-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
}
.role-leader  { color: var(--warn);  border-color: var(--warn); }
.role-officer { color: var(--accent); border-color: var(--accent); }

#alliance-search-bar { display: flex; gap: 8px; }
#al-search-input     { flex: 1; }

/* ══════════════════════════════════════════════════════════════
   LEADERBOARD TAB
   ══════════════════════════════════════════════════════════════ */
#tab-leaderboard { padding: 0; }
#lb-filters {
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#lb-scope-btns, #lb-period-btns { display: flex; gap: 6px; }
.filter-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
}
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#lb-list { padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.lb-row.is-me    { border-color: var(--accent); background: rgba(59,130,246,.12); }
.lb-rank         { width: 28px; text-align: right; color: var(--muted); font-weight: 700; }
.lb-rank.top3    { color: var(--warn); }
.lb-name         { flex: 1; font-size: 13px; }
.lb-score        { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-elo          { font-size: 12px; color: var(--muted); }
#lb-pagination   { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 12px; }
#lb-page-info    { font-size: 14px; color: var(--muted); }

/* ══════════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-box h2 { font-size: 20px; margin-bottom: 4px; }

/* Cubes info list */
.cube-info-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cube-info-dot {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}
.cube-info-text h4  { font-size: 13px; font-weight: 600; }
.cube-info-text p   { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Profile modal */
#profile-info { background: var(--surface2); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.profile-row  { display: flex; justify-content: space-between; font-size: 13px; }
.profile-val  { font-weight: 600; color: var(--accent); }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ══════════════════════════════════════════════════════════════
   HOME TAB
   ══════════════════════════════════════════════════════════════ */

#home-profile-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 10px;
  background: linear-gradient(135deg, #1a2332, #1f2b3e);
  border-bottom: 1px solid var(--border);
  position: relative;
}
#home-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  overflow: hidden;
}
#home-profile-info { flex: 1; min-width: 0; }
#home-username {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#home-stats-row { display: flex; gap: 10px; font-size: 12px; color: var(--muted); margin: 2px 0; }
#home-currency  { display: flex; gap: 10px; font-size: 13px; font-weight: 600; color: var(--warn); }

.btn-icon {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  opacity: 0.7;
  transition: opacity .2s;
  position: absolute;
  top: 10px;
  right: 10px;
}
.btn-icon:hover { opacity: 1; }

.tg-badge {
  background: #2481cc;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 4px;
}

#home-quick-stats {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.stat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  border-right: 1px solid var(--border);
}
.stat-card:last-child { border-right: none; }
.stat-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.home-section {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.home-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.section-link {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.section-link:hover { text-decoration: underline; }

#game-modes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}
.game-mode-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.game-mode-card:hover  { border-color: var(--accent); }
.game-mode-card.active-mode {
  border-color: var(--accent);
  background: rgba(59,130,246,.15);
}
.mode-icon { font-size: 26px; }
.mode-name { font-weight: 700; font-size: 13px; }
.mode-desc { font-size: 11px; color: var(--muted); }

#home-skins {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
}
.home-skin-item {
  width: 44px;
  height: 44px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.home-skin-item.equipped { border-color: var(--accent); background: rgba(59,130,246,.12); }

#daily-challenge-card {
  background: linear-gradient(135deg, #1a2332, #1e2d3d);
  border: 1px solid #2d4a6b;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dc-header  { display: flex; justify-content: space-between; align-items: center; }
.dc-title   { font-weight: 700; font-size: 14px; color: var(--warn); }
.dc-timer   { font-size: 11px; color: var(--muted); }
.dc-task    { font-size: 13px; }
.dc-reward  { font-size: 12px; color: #22c55e; font-weight: 600; }
