/* ================================================================
   Task Quest — TMA Stylesheet
   Uses Telegram CSS variables exclusively for theming.
   Accent: purple (#7C3AED / #8B5CF6)
   ================================================================ */

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

:root {
  --accent: #7C3AED;
  --accent-light: #8B5CF6;
  --accent-glow: rgba(124, 58, 237, 0.25);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI',
               Roboto, Oxygen, sans-serif;
  background: var(--tg-theme-bg-color, #0f0f1a);
  color: var(--tg-theme-text-color, #e4e4e7);
  overflow: hidden; 
  height: 100vh;
  height: var(--tg-viewport-height, 100vh); 
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ────────────────────────────────────────────────────── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 12px;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-greeting {
  font-size: 22px;
  font-weight: 700;
}

.header-subtitle {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #71717a);
}

.header-score {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.score-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-light);
}

.score-icon {
  font-size: 18px;
}

/* ── Tabs ──────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  margin: 8px 20px 16px;
  padding: 4px;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: var(--radius-md);
}

.tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  background: transparent;
  color: var(--tg-theme-hint-color, #71717a);
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* ── Screens ───────────────────────────────────────────────────── */
.screen {
  display: none;
  padding: 0 16px;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Section titles ────────────────────────────────────────────── */
.task-section {
  margin-bottom: 20px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  padding: 0 4px 10px;
  color: var(--tg-theme-text-color, #e4e4e7);
}

/* ── Task list / cards ─────────────────────────────────────────── */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  transition: transform 0.15s ease, opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.task-card:active {
  transform: scale(0.98);
}

.task-card.completing {
  animation: completeSlide 0.45s ease forwards;
}

@keyframes completeSlide {
  0%   { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(80px); opacity: 0; max-height: 0; padding: 0; margin: 0; overflow: hidden; }
}

.task-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.task-info {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-meta {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #71717a);
  margin-top: 2px;
}

.task-points {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-light);
  flex-shrink: 0;
}

.task-check {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid var(--tg-theme-hint-color, #52525b);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.task-check:active {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.task-check.done {
  border-color: var(--accent);
  background: var(--accent);
  animation: pop 0.3s ease;
}

.task-check.done::after {
  content: '✓';
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 28px 16px;
  font-size: 14px;
  color: var(--tg-theme-hint-color, #71717a);
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: var(--radius-md);
  opacity: 0.7;
}

/* ── Scoreboard ────────────────────────────────────────────────── */
.scoreboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: var(--radius-md);
}

.score-rank {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  flex-shrink: 0;
}

.score-rank.gold   { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1a1a2e; }
.score-rank.silver { background: linear-gradient(135deg, #d1d5db, #9ca3af); color: #1a1a2e; }
.score-rank.other  { background: var(--accent-glow); color: var(--accent-light); }

.score-name {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
}

.score-pts {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent-light);
}

/* ── Feed list ─────────────────────────────────────────────────── */
.feed-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: var(--radius-md);
}

.feed-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.feed-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.4;
}

.feed-text strong {
  font-weight: 600;
}

.feed-pts {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-light);
  white-space: nowrap;
}

.feed-time {
  font-size: 11px;
  color: var(--tg-theme-hint-color, #71717a);
}

/* ── Shop ──────────────────────────────────────────────────────── */
.shop-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-buy-shop {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.btn-buy-shop:active {
  transform: scale(0.95);
}

.btn-buy-shop:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--tg-theme-bg-color, #0f0f1a);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  color: var(--tg-theme-hint-color, #71717a);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Form ──────────────────────────────────────────────────────── */
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-theme-hint-color, #71717a);
  margin-bottom: 6px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-input, .form-select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  color: var(--tg-theme-text-color, #e4e4e7);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease;
  -webkit-appearance: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent);
}

.form-input::placeholder {
  color: var(--tg-theme-hint-color, #52525b);
}

/* Icon picker */
.icon-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 2.5px solid transparent;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* Type toggle */
.type-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: var(--radius-sm);
}

.toggle-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  background: transparent;
  color: var(--tg-theme-hint-color, #71717a);
  -webkit-tap-highlight-color: transparent;
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Regularity group */
.form-group.hidden {
  display: none;
}

.form-group {
  animation: fadeIn 0.25s ease;
}

/* Actions */
.form-actions {
  display: flex;
  gap: 10px;
  position: sticky;
  bottom: calc(-24px - var(--safe-bottom));
  background: var(--tg-theme-bg-color, #0f0f1a);
  padding: 16px 20px calc(24px + var(--safe-bottom));
  margin: 24px -20px calc(-24px - var(--safe-bottom)) -20px;
  z-index: 10;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn-cancel {
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  color: var(--tg-theme-text-color, #e4e4e7);
}

.btn-submit {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-submit:disabled {
  opacity: 0.5;
}

/* ── Points toast ──────────────────────────────────────────────── */
.points-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-size: 32px;
  font-weight: 800;
  color: var(--accent-light);
  pointer-events: none;
  opacity: 0;
  z-index: 200;
  text-shadow: 0 0 20px var(--accent-glow);
}

.points-toast.show {
  animation: toastPop 1s ease forwards;
}

@keyframes toastPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  40%  { transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

/* ── Skeleton loading ──────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--tg-theme-secondary-bg-color, #1a1a2e) 25%,
    rgba(255,255,255,0.06) 50%,
    var(--tg-theme-secondary-bg-color, #1a1a2e) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
  height: 64px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Add reminder link button ─────────────────────────────────── */
.btn-add-reminder {
  display: inline-block;
  margin-top: 10px;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent-light);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-add-reminder:active {
  opacity: 0.6;
}

.btn-add-reminder.hidden {
  display: none;
}

/* ── Regular task completed state ─────────────────────────────── */
.task-card.completed-regular {
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

/* ── Modal inner scroll ───────────────────────────────────────── */
.modal {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 20px;
}

/* ── Scrolling Fix ────────────────────────────────────────── */
.content-wrapper {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 90px; /* Space for floating button */
}

/* ── Floating Action Button ───────────────────────────────── */
.add-task-btn-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  justify-content: center;
}

.add-task-btn {
  width: 100%;
  max-width: 400px;
  height: 54px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 4px 12px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

.add-task-btn:active {
  transform: scale(0.98);
  background: var(--accent-light);
}
