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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1c1c1c;
  --accent: #ff1e1e;
  --accent2: #ff4444;
  --text: #f1f1f1;
  --subtext: #888;
  --danger: #ff1e1e;
  --success: #4ade80;
  --border: #2a2a2a;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }

/* AUTH */
.auth-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 40px 24px;
  max-width: 400px;
  width: 100%;
  margin: auto;
}

.app-title {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}

.app-sub {
  text-align: center;
  color: var(--subtext);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

input, textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 14px 16px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  width: 100%;
}

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

textarea {
  resize: none;
  height: 70px;
  border-radius: 16px !important;
}

select {
  background: var(--surface2);
}

button {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

button.secondary {
  background: var(--surface2);
  color: var(--subtext);
}

button.danger { background: var(--danger); color: #fff; }

.error { color: var(--danger); font-size: 0.85rem; text-align: center; min-height: 20px; }

/* TOPBAR */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: #111;
  border-bottom: 1px solid #333;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  position: fixed;
}
.topbar-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.topbar button { width: auto; padding: 8px 14px; font-size: 0.85rem; }

/* BOTTOM NAV */
.bottom-nav {
  display: flex;
  flex-direction: column;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #000;
  z-index: 100;
}

.bottom-nav-buttons {
  display: flex;
  align-items: center;
  margin: 8px 12px 4px;
  background: #000;
  border: 1px solid #333;
  border-radius: 16px;
  overflow: visible;
  padding: 4px;
  gap: 2px;
}

.bottom-nav-bar {
  height: max(env(safe-area-inset-bottom), 40px);
  background: #000;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.8rem, 3vw, 1rem);
}

.bottom-nav .nav-btn {
  flex: 1;
  background: none;
  color: var(--subtext);
  border-radius: 12px;
  padding: 10px 2px;
  font-size: clamp(0.55rem, 3.5vw, 0.85rem);
  font-weight: 500;
  border: none;
  overflow: visible;
  white-space: nowrap;
  min-width: 0;
}

.bottom-nav .nav-btn:last-child { border-right: none; }
.bottom-nav .nav-btn.active {
  color: #fff;
  background: var(--accent);
  border-radius: 16px;
  font-weight: 700;
  border: none;
  margin: -10px -4px;
  padding: 18px 4px;
  z-index: 2;
  position: relative;
  box-shadow: 0 0 12px rgba(255,30,30,0.6), 0 0 28px rgba(255,30,30,0.3);
}

/* TABS */
.tab-content {
  flex: 1;
  padding: 20px 16px 120px;
  overflow-y: auto;
  margin-top: 60px;
}

.tab { display: none; }
.tab.active { display: block; }

/* SECTIONS */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-header h2 { font-size: 1.3rem; font-weight: 700; }

.icon-btn {
  width: auto;
  padding: 8px 16px;
  font-size: 0.85rem;
}

.section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--subtext);
  margin: 20px 0 10px;
}

.task-section { margin-bottom: 8px; }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
}

.form-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.form-card label {
  font-size: 0.8rem;
  color: var(--subtext);
  margin-bottom: -4px;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions button { flex: 1; }

.hidden { display: none !important; }

/* TASK CARD */
.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
}

.task-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.task-card-title { font-weight: 600; font-size: 0.95rem; }

.task-badge {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 600;
}

.badge-pending { background: #854d0e; color: #fef08a; }
.badge-active { background: #1e3a5f; color: #93c5fd; }
.badge-overdue { background: #7f1d1d; color: #fca5a5; }
.badge-approved { background: #14532d; color: #86efac; }
.badge-waiting { background: #1e3a5f; color: #93c5fd; }

.task-meta {
  font-size: 0.78rem;
  color: var(--subtext);
  margin-bottom: 10px;
}

.task-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.task-actions button { flex: 1; padding: 8px; font-size: 0.8rem; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-box h3 { font-size: 1.1rem; font-weight: 700; }
.modal-box img { width: 100%; border-radius: 10px; max-height: 300px; object-fit: cover; }
#proof-preview-wrap img { width: 100%; border-radius: 10px; margin-top: 8px; }

/* REWARD CARD */
.reward-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
}

.reward-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.reward-card-title { font-weight: 600; font-size: 0.95rem; }
.reward-cost { color: var(--accent); font-weight: 700; font-size: 0.9rem; }
.reward-meta { font-size: 0.78rem; color: var(--subtext); margin-bottom: 10px; }

/* PUNISHMENT CARD */
.punishment-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
}

.punishment-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.punishment-card-title { font-weight: 600; font-size: 0.95rem; }
.restore-pct { color: var(--success); font-weight: 700; font-size: 0.9rem; }
.punishment-meta { font-size: 0.78rem; color: var(--subtext); margin-bottom: 10px; }
.badge-active-punishment { background: #4a1942; color: #f0abfc; }

.empty { color: var(--subtext); font-size: 0.85rem; padding: 8px 0; }

/* LEADERBOARD */
.leaderboard-scores {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.score-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}

.score-card.winner {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(192, 132, 252, 0.15);
}

.score-name {
  font-size: 0.75rem;
  color: var(--subtext);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-points {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.score-label {
  font-size: 0.7rem;
  color: var(--subtext);
  margin-top: 2px;
}

.score-crown { font-size: 1.2rem; margin-bottom: 4px; }

/* HISTORY DROPDOWNS */
.history-section { margin-bottom: 12px; }

.history-toggle {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.history-toggle .chevron { transition: transform 0.2s; font-style: normal; }
.history-toggle.open .chevron { transform: rotate(180deg); }

.history-items {
  display: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
}

.history-items.open { display: block; }

.history-item {
  padding: 10px 16px;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text);
}

.history-item:last-child { border-bottom: none; }
.history-item .hi-pts { font-weight: 600; white-space: nowrap; margin-left: 8px; }
.history-item .hi-pts.positive { color: var(--success); }
.history-item .hi-pts.negative { color: var(--danger); }
.history-item .hi-meta { color: var(--subtext); font-size: 0.75rem; }

/* iOS INSTALL BANNER */
.install-banner {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 150;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 4px 24px rgba(192,132,252,0.2);
}

.install-banner p {
  font-size: 0.82rem;
  color: var(--text);
  flex: 1;
}

.install-banner button {
  width: auto;
  padding: 8px 14px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.install-banner .dismiss {
  background: none;
  color: var(--subtext);
  padding: 4px 8px;
  font-size: 1rem;
  width: auto;
}

#notif-btn {
  width: auto;
  padding: 8px 12px;
  font-size: 1rem;
  background: var(--surface2);
}

/* BARGAIN */
.bargain-history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.bargain-history-item .bh-who {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.bargain-history-item .bh-changes {
  color: var(--text);
  margin-bottom: 2px;
}

.bargain-history-item .bh-note {
  color: var(--subtext);
  font-style: italic;
}

.btn-bargain {
  background: var(--surface2) !important;
  border: 1px solid var(--accent) !important;
  color: var(--accent) !important;
}

.topbar-title {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}


/* BEBAS NEUE HEADERS */
h1, h2, h3,
.app-title,
.section-header h2,
.task-card-title,
.reward-card-title,
.punishment-card-title,
.score-points,
.topbar-title,
.history-toggle span,
.bottom-nav .nav-btn {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.12em;
}

.app-title {
  font-size: 2.4rem;
  letter-spacing: 0.08em;
}

.topbar-title {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.12em;
  font-size: clamp(1rem, 5vw, 1.6rem);
}



/* BADGE COLORS */
.badge-active { background: rgba(74,222,128,0.15) !important; color: #4ade80 !important; }
.badge-overdue { background: rgba(255,30,30,0.15) !important; color: var(--accent) !important; }
.badge-pending { background: rgba(250,204,21,0.15) !important; color: #facc15 !important; }
.badge-waiting { background: rgba(100,100,100,0.2) !important; color: #888 !important; }
.badge-active-punishment { background: rgba(255,30,30,0.15) !important; color: var(--accent) !important; }

.history-section {
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  margin-bottom: 12px;
}
.history-toggle {
  background: #1a1a1a;
  border: none;
  border-radius: 14px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  transition: background 0.15s;
}
.history-toggle.open {
  border-radius: 14px 14px 0 0;
}
.history-toggle:hover {
  background: #222;
}
.history-toggle span:first-child {
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}
.history-items {
  background: #161616;
  border: none;
  border-radius: 0 0 14px 14px;
  padding: 8px;
}

.history-items .task-card:last-child {
  margin-bottom: 0;
}
.history-items .task-card,
.history-items .reward-card,
.history-items .punishment-card {
  margin-bottom: 6px;
}

@keyframes flash {
  0%, 100% { 
    opacity: 1; 
    color: #ff2020;
    text-shadow: 0 0 10px #ff0000, 0 0 30px #ff0000, 0 0 60px #ff0000, 0 0 100px #ff1e1e, 0 0 200px #ff1e1e;
  }
  50% { opacity: 0; text-shadow: none; }
}
.loading-word {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 23vw;
  line-height: 0.9;
  letter-spacing: 0.08em;
  color: #ff2020;
  animation: flash 0.25s ease-in-out infinite;
  text-align: center;
  width: 100%;
}

.user-btn-wrap {
  position: relative;
}
.user-circle-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  width: 38px !important;
  overflow: visible;
  box-shadow: 0 0 10px rgba(255,30,30,0.4);
  line-height: 0;
}
.user-dropdown {
  position: absolute;
  top: 48px;
  left: 0;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 14px;
  padding: 14px 16px;
  min-width: 180px;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.user-dropdown.hidden { display: none; }
.user-dropdown-name {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  letter-spacing: 0.08em;
  color: #fff;
  margin-bottom: 12px;
}
.user-dropdown-logout {
  width: 100%;
  padding: 10px;
  font-size: 0.85rem;
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 0 10px rgba(255,30,30,0.3);
}


/* ── CHAT ── */
.chat-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 0 10px rgba(255,30,30,0.4);
  color: #000;
  flex-shrink: 0;
}
.chat-btn:active { background: rgba(255,30,30,0.12); }
.chat-unread {
  position: absolute;
  top: 0; right: 0;
  background: var(--accent);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 0.6rem;
  font-weight: 700;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  align-items: flex-end;
  justify-content: center;
}
.chat-overlay.open {
  display: flex;
}
.chat-panel {
  width: 100%;
  max-width: 520px;
  height: 91vh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -4px 40px rgba(0,0,0,0.6);
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-title {
  font-family: 'Bebas Neue', cursive;
  font-size: 1.4rem;
  color: var(--accent);
  letter-spacing: 0.08em;
}
.chat-close {
  background: none;
  border: none;
  color: var(--subtext);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: color 0.15s;
}
.chat-close:active { color: var(--text); }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-loading {
  color: var(--subtext);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 40px;
}
.chat-day-label {
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  color: var(--subtext);
  margin: 10px 0 4px;
  letter-spacing: 0.05em;
}
.bubble-row {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  position: relative;
}
.bubble-row.mine {
  align-self: flex-end;
  align-items: flex-end;
}
.bubble-row.theirs {
  align-self: flex-start;
  align-items: flex-start;
}
.bubble-sender {
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  color: var(--subtext);
  margin-bottom: 2px;
  padding: 0 4px;
}
.bubble {
  padding: 9px 13px;
  border-radius: 18px;
  font-family: 'Inter', sans-serif;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--text);
  word-break: break-word;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}
.bubble-row.mine .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-row.theirs .bubble {
  background: var(--surface2);
  border-bottom-left-radius: 4px;
}
.bubble-time {
  font-family: 'Inter', sans-serif;
  font-size: 0.64rem;
  color: var(--subtext);
  padding: 0 4px;
  margin-top: 2px;
}
.bubble-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
  padding: 0 2px;
}
.reaction-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 3px;
}
.reaction-chip:active { background: var(--border); }
.reaction-chip .rcount {
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  color: var(--subtext);
}
.reaction-picker {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  display: flex;
  gap: 6px;
  z-index: 1100;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.reaction-picker button {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 2px;
  border-radius: 8px;
  transition: transform 0.1s;
}
.reaction-picker button:active { transform: scale(1.3); }
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  padding: 10px 16px;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
  background: var(--accent);
  border: none;
  border-radius: 999px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.chat-send:active { background: var(--accent2); transform: scale(0.95); }

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-btn {
  width: 38px !important;
  height: 38px !important;
  min-width: 38px !important;
  min-height: 38px !important;
}
