: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%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* بهبود کیفیت تصاویر در همه جا */
img {
  max-width: 100%;
  height: auto;
  display: block;
  -webkit-user-select: none;
  user-select: none;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.hidden { 
  display: none !important; 
}

/* Splash Screen - Professional & Optimized */
#splash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--bg);
  z-index: 10000;
  transition: opacity 0.3s ease-out;
}

#splash.hidden {
  opacity: 0;
  pointer-events: none;
}

.splash-logo {
  width: clamp(100px, 30vw, 140px);
  height: clamp(100px, 30vw, 140px);
  object-fit: contain;
  border-radius: 0;
  background: transparent;
  mix-blend-mode: normal;
  box-shadow: none;
  animation: splashPulse 2s ease-in-out infinite;
  padding: clamp(4px, 1vw, 6px);
}

@keyframes splashPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.95;
  }
}

/* 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: clamp(12px, 3vw, 16px) clamp(12px, 4vw, 16px) clamp(10px, 2.5vw, 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: clamp(32px, 8vw, 38px);
  height: clamp(32px, 8vw, 38px);
  border-radius: clamp(8px, 2vw, 10px);
  margin-right: clamp(8px, 2vw, 10px);
  object-fit: contain;
  background: transparent;
}

.brand h1 {
  font-size: clamp(16px, 4.5vw, 20px);
  margin: 0;
  font-weight: 600;
}

.actions {
  display: flex;
  gap: 8px;
}

/* Tab System */
.tab-content {
  display: none;
  padding: clamp(12px, 4vw, 16px);
  padding-bottom: clamp(70px, 18vw, 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: clamp(12px, 3vw, 14px);
  padding: clamp(14px, 4vw, 16px);
  margin-bottom: clamp(12px, 3.5vw, 16px);
}

/* Profile - نسخه بهبود یافته */
.profile {
  display: flex;
  align-items: center;
  gap: 15px;
}

.profile img {
  width: clamp(42px, 11vw, 50px);
  height: clamp(42px, 11vw, 50px);
  border-radius: 50%;
  object-fit: contain;
  object-position: center;
  flex-shrink: 0;
  border: 2px solid var(--border);
  background: transparent;
  padding: clamp(2px, 0.5vw, 3px);
}

.p-info {
  flex: 1;
  min-width: 0;
}

.p-info .p-line {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
  gap: 6px;
}

.p-info .p-line:last-child {
  margin-bottom: 0;
}

.name {
  font-weight: 600;
  font-size: clamp(13px, 3.5vw, 14px);
}

.handle {
  color: var(--text-muted);
  font-size: clamp(11px, 3vw, 12px);
}

.p-line.wallet {
  font-size: clamp(12px, 3.2vw, 13px);
}

.p-line.wallet span:first-child {
  font-weight: 500;
  color: var(--text-muted);
}

.wallet .mono {
  font-family: 'Courier New', monospace;
  font-size: clamp(11px, 2.8vw, 12px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: clamp(120px, 40vw, 180px);
}

/* Buttons */
button {
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.ghost-btn {
  background: var(--bg2);
  color: var(--text);
  border-radius: clamp(8px, 2vw, 10px);
  padding: clamp(8px, 2.5vw, 10px) clamp(12px, 4vw, 16px);
  font-size: clamp(13px, 3.5vw, 14px);
  font-weight: 500;
}

.ghost-btn:active {
  opacity: 0.7;
  transform: scale(0.98);
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border-radius: clamp(8px, 2vw, 10px);
  padding: clamp(8px, 2.5vw, 10px) clamp(12px, 4vw, 16px);
  font-size: clamp(13px, 3.5vw, 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: clamp(6px, 2vw, 8px) 0;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: clamp(10px, 3vw, 12px) 0;
  font-size: clamp(13px, 3.5vw, 14px);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(2px, 1vw, 4px);
}

.bottom-nav button i {
  font-size: clamp(18px, 5vw, 20px);
}

.bottom-nav button span {
  font-size: clamp(10px, 2.8vw, 11px);
  white-space: nowrap;
}

.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(auto-fit, minmax(clamp(140px, 40vw, 180px), 1fr));
  gap: clamp(10px, 3vw, 12px);
  margin-top: clamp(12px, 4vw, 16px);
}

.nft {
  background: var(--bg2);
  border-radius: clamp(10px, 2.5vw, 12px);
  padding: clamp(10px, 3vw, 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: clamp(6px, 2vw, 8px);
  height: clamp(120px, 35vw, 150px);
  object-fit: cover;
  object-position: center;
  margin-bottom: clamp(6px, 2vw, 8px);
  background: var(--bg2);
  image-rendering: auto;
  display: block;
}

.nft-name {
  font-size: clamp(12px, 3.2vw, 13px);
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
}

/* 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: clamp(100px, 28vw, 120px);
  height: clamp(100px, 28vw, 120px);
  border-radius: clamp(10px, 3vw, 12px);
  object-fit: cover;
  object-position: center;
  margin: 0 auto clamp(12px, 4vw, 16px);
  display: block;
  border: 2px solid var(--primary);
  background: var(--bg2);
}

.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;
}

/* Verified button state */
.verified {
  background-color: #10b981 !important;
  color: white !important;
  opacity: 0.7;
  cursor: not-allowed;
}

.verified:hover {
  opacity: 0.8;
}

/* Verified state */
.verified-state {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(16, 185, 129, 0.1);
  border-radius: 10px;
  border: 1px solid #10b981;
}

/* Bottom Navigation Disabled Hover */
.bottom-nav button[disabled]:hover {
  position: relative;
  cursor: not-allowed;
}

.bottom-nav button[disabled]:hover::after {
  content: '🚫';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* Responsive Design - Extra Small Devices Only */
@media (max-width: 360px) {
  .task {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .t-actions {
    align-self: stretch;
    justify-content: space-between;
    width: 100%;
  }

  .t-actions button {
    flex: 1;
  }

  .stats div {
    font-size: clamp(14px, 4vw, 16px);
  }

  .copy-row {
    flex-direction: column;
    gap: 8px;
  }

  .copy-row input,
  .copy-row button {
    width: 100%;
  }
}

/* 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));
  }
}