:root[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f3f3f5;
  --text: #111;
  --text-muted: #666;
  --box: #ffffff;
  --border: #e2e2e2;
  --primary: #0066ff;
  --primary-hover: #0053d6;
}

:root[data-theme="dark"] {
  --bg: #0e0e12;
  --bg2: #17171c;
  --text: #ffffff;
  --text-muted: #bbb;
  --box: #17171c;
  --border: #222;
  --primary: #2b6bff;
  --primary-hover: #1f54d6;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  height: 100%;
}

.hidden { 
  display: none !important; 
}

/* Splash Screen - 2 ثانیه انیمیشن */
#splash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg);
  z-index: 10000;
}

.splash-logo {
  width: 120px;
  height: 120px;
  border-radius: 20px;
  animation: splashPulse 1.5s ease-in-out infinite;
}

@keyframes splashPulse {
  0% { 
    transform: scale(1); 
    opacity: 1; 
  }
  50% { 
    transform: scale(1.1); 
    opacity: 0.8; 
  }
  100% { 
    transform: scale(1); 
    opacity: 1; 
  }
}

/* Main App Layout */
#app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  min-height: 100vh;
  position: relative;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  margin-right: 10px;
}

.brand h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
}

.actions {
  display: flex;
  gap: 8px;
}

/* Tab System */
.tab-content {
  display: none;
  padding: 16px;
  padding-bottom: 80px;
  background: var(--bg);
  min-height: calc(100vh - 70px);
}

.tab-content.active-tab {
  display: block;
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Boxes */
.box {
  background: var(--box);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

/* Profile */
.profile {
  display: flex;
  align-items: center;
}

.profile img {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 14px;
  border: 2px solid var(--border);
}

.p-info {
  flex: 1;
}

.p-info .p-line {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.name { 
  font-weight: 600; 
  font-size: 16px; 
  margin-right: 8px; 
}

.handle { 
  color: var(--text-muted); 
  font-size: 14px; 
}

.wallet .mono { 
  font-family: monospace; 
  font-size: 13px;
}

/* Buttons */
button {
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.ghost-btn {
  background: var(--bg2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
}

.ghost-btn:active {
  opacity: 0.7;
  transform: scale(0.98);
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
}

.primary-btn:active {
  background: var(--primary-hover);
  transform: scale(0.98);
}

.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Tasks */
.task {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--bg2);
}

.task .t-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.task .t-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.task a {
  text-decoration: none;
  color: var(--primary);
  font-weight: 500;
}

.t-actions {
  display: flex;
  gap: 8px;
}

/* XP Bar */
.row-space {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.xp-bar {
  height: 8px;
  background: var(--bg2);
  border-radius: 6px;
  overflow: hidden;
  margin: 12px 0;
}

#xpFill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 6px;
  transition: width 0.5s ease;
}

.tip {
  font-size: 12px;
  color: var(--text-muted);
}

.small {
  font-size: 13px;
  color: var(--text-muted);
}

/* Referral */
.copy-row {
  display: flex;
  gap: 10px;
  margin: 16px 0;
}

.copy-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  background: var(--bg2);
  color: var(--text);
  font-family: monospace;
}

.stats {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin-top: 16px;
}

.stats div {
  font-size: 18px;
  font-weight: 600;
}

.stats label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--box);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  z-index: 1000;
}

.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: 12px 0;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 0;
}

.bottom-nav button.active {
  color: var(--primary);
  font-weight: 600;
}

.bottom-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Collection */
.nft-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.nft {
  background: var(--bg2);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  border: 1px solid var(--border);
  transition: transform 0.2s ease;
}

.nft:active {
  transform: scale(0.95);
}

.nft img {
  width: 100%;
  border-radius: 8px;
  height: 120px;
  object-fit: cover;
  margin-bottom: 8px;
}

.nft-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

/* Market - Lottery Box */
.lottery-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  margin: 20px 0;
}

.lottery-box .nft-rand {
  width: 120px;
  height: 120px;
  border-radius: 12px;
  object-fit: cover;
  margin: 0 auto 16px;
  display: block;
  border: 2px solid var(--primary);
}

.lottery-box .info {
  margin-bottom: 20px;
}

.lottery-box .info div {
  margin-bottom: 8px;
  font-size: 15px;
}

.lottery-box .info b {
  color: var(--primary);
}

.lottery-box #countdown {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
  margin: 12px 0;
}

.lottery-box #ticketsLeft {
  font-size: 14px;
  color: var(--text-muted);
  margin: 8px 0;
}

.lottery-box #userTickets {
  font-size: 15px;
  font-weight: 500;
  margin: 12px 0;
}

#buyTicket {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 10px;
}

/* Results Box */
#resultsBox {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.5;
}

/* Utility Classes */
.muted {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.4;
}

.mono {
  font-family: monospace;
}

.msg {
  font-size: 14px;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
}

/* Scrollbar Styling */
.tab-content::-webkit-scrollbar {
  width: 4px;
}

.tab-content::-webkit-scrollbar-track {
  background: var(--bg2);
}

.tab-content::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 2px;
}

/* Responsive Design */
@media (max-width: 480px) {
  .tab-content {
    padding: 16px 12px 80px;
  }
  
  .box {
    padding: 14px;
    margin-bottom: 14px;
  }
  
  .nft-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .nft img {
    height: 100px;
  }
  
  .lottery-box {
    padding: 16px;
  }
  
  .lottery-box .nft-rand {
    width: 100px;
    height: 100px;
  }
}

@media (max-width: 380px) {
  .tab-content {
    padding: 16px 10px 80px;
  }
  
  header {
    padding: 14px 12px 10px;
  }
  
  .brand h1 {
    font-size: 18px;
  }
  
  .brand img {
    width: 32px;
    height: 32px;
  }
  
  .task {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .t-actions {
    align-self: stretch;
    justify-content: space-between;
  }
  
  .t-actions button {
    flex: 1;
  }
  
  .nft-grid {
    grid-template-columns: 1fr;
  }
  
  .stats div {
    font-size: 16px;
  }
  
  .lottery-box .nft-rand {
    width: 80px;
    height: 80px;
  }
}

@media (max-width: 320px) {
  .profile {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }
  
  .profile img {
    margin-right: 0;
  }
  
  .copy-row {
    flex-direction: column;
  }
}

/* Safe area support for notch devices */
@supports (padding: max(0px)) {
  .tab-content {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(80px, env(safe-area-inset-bottom));
  }

  .bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}
