:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --secondary-bg: #f5f5f7;
  --text: #1d1d1f;
  --hint: #86868b;
  --separator: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --button: #0071e3;
  --button-text: #ffffff;
  --destructive: #ff3b30;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D0E15;
    --secondary-bg: #151722;
    --text: #f5f5f7;
    --hint: #9fa2ad;
    --separator: rgba(255, 255, 255, 0.08);
    --accent: #2997ff;
    --button: #2997ff;
    --button-text: #ffffff;
    --destructive: #ff453a;
    --glass-bg: rgba(21, 23, 34, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
  }
}

/* Base */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; min-height: 100%;
  background-color: var(--secondary-bg);
  color: var(--text);
  font-family: 'Outfit', 'Apple Color Emoji', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overflow-x: hidden;
}

/* Headings */
h1, h2, h3, p { margin: 0; }
.page-title {
  font-size: 34px; font-weight: 800;
  letter-spacing: -0.03em;
  margin: 16px 16px 8px;
  background: linear-gradient(135deg, var(--text) 0%, var(--hint) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: fade-in-up 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.page-subtitle {
  margin: 0 16px 24px; color: var(--hint);
  font-size: 16px; font-weight: 500;
  animation: fade-in-up 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.section-title {
  margin: 28px 16px 12px; color: var(--hint);
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Layout */
main {
  max-width: 600px; margin: auto;
  padding: calc(16px + var(--safe-top)) 0 calc(100px + var(--safe-bottom));
  animation: fade-in 0.5s ease;
}
.section {
  background: var(--bg);
  border-radius: 20px;
  margin: 0 16px 24px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.04);
  border: 1px solid var(--separator);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.section-pad { padding: 20px; }

/* Animations */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-glow {
  0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.4); }
  70% { box-shadow: 0 0 0 16px rgba(255, 193, 7, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); }
}
@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
  100% { transform: translateY(0px); }
}

/* List Rows & Cards */
.battle-card, .list-row, .setting-row {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 20px;
  background: var(--bg);
  position: relative;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.battle-card:not(:last-child)::after,
.list-row:not(:last-child)::after,
.setting-row:not(:last-child)::after {
  content: '';
  position: absolute; left: 80px; right: 0; bottom: 0;
  height: 1px; background: var(--separator);
}
.setting-row:not(:last-child)::after { left: 60px; }
.form-row:not(:last-child)::after {
  content: ''; position: absolute; left: 20px; right: 0; bottom: 0;
  height: 1px; background: var(--separator);
}

.battle-card:active, .list-row:active, .setting-row:active {
  background-color: var(--secondary-bg);
  transform: scale(0.98);
}

/* Avatar */
.avatar {
  width: 48px; height: 48px; flex-shrink: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #FF6B6B 0%, #845EC2 100%);
  color: white; font-size: 20px; font-weight: 700;
  box-shadow: 0 4px 15px rgba(132, 94, 194, 0.3);
}
.avatar.large {
  width: 96px; height: 96px; font-size: 40px;
  margin: 8px auto 20px;
}

/* Content */
.card-content { min-width: 0; flex: 1; display: flex; flex-direction: column; justify-content: center; }
.card-title { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: center; gap: 12px; margin-top: 4px; color: var(--hint); font-size: 14px; font-weight: 500; }
.card-side { display: grid; justify-items: end; gap: 8px; }

/* Chips */
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; padding: 6px 12px;
  background: color-mix(in srgb, var(--hint) 12%, transparent);
  color: var(--hint); font-size: 12px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.chip.active { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.chip.finished { opacity: 0.6; }

/* Icons */
.icon { width: 22px; height: 22px; display: inline-block; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon.small { width: 16px; height: 16px; stroke-width: 2.5; }
.stars { display: flex; align-items: center; gap: 6px; color: #FFB020; font-weight: 700; font-size: 16px; }
.stars .icon { stroke: none; fill: currentColor; filter: drop-shadow(0 2px 4px rgba(255, 176, 32, 0.4)); }

/* Navigation */
.nav {
  position: fixed; z-index: 40; left: 50%; bottom: max(16px, var(--safe-bottom));
  transform: translateX(-50%); width: calc(100% - 32px); max-width: 400px;
  display: flex; justify-content: space-around;
  background: var(--glass-bg);
  padding: 8px 12px;
  border-radius: 24px;
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}
.nav button {
  border: 0; background: none; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 16px; font-size: 11px; font-weight: 700;
  border-radius: 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav button:active { transform: scale(0.85); }
.nav button.active { color: var(--text); background: rgba(255,255,255,0.1); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.nav button .icon { width: 26px; height: 26px; stroke-width: 2.2; }

/* Summary Stats */
.summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--separator); }
.summary-item { padding: 20px; text-align: center; background: var(--bg); }
.summary-item b { display: block; font-size: 28px; font-weight: 800; color: var(--text); }
.summary-item span { display: block; color: var(--hint); font-size: 13px; font-weight: 600; margin-top: 6px; text-transform: uppercase; letter-spacing: 0.05em; }

/* Empty & Casino */
.empty { padding: 60px 20px; text-align: center; color: var(--hint); font-size: 16px; font-weight: 500; }

.casino-wrapper {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 70vh; padding: 20px; text-align: center;
}
.casino-icon {
  width: 100px; height: 100px;
  background: linear-gradient(135deg, #FF9A9E 0%, #FECFEF 100%);
  border-radius: 30px; display: grid; place-items: center;
  margin-bottom: 28px;
  box-shadow: 0 20px 40px rgba(255, 154, 158, 0.4);
  animation: float 4s ease-in-out infinite;
}
.casino-icon svg { width: 50px; height: 50px; fill: white; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15)); }
.casino-title { font-size: 32px; font-weight: 800; background: linear-gradient(135deg, #FF9A9E 0%, #FECFEF 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin-bottom: 16px; }
.casino-desc { color: var(--hint); font-size: 16px; font-weight: 500; line-height: 1.6; max-width: 300px; }

/* Buttons */
button { font: inherit; cursor: pointer; outline: none; }
.primary, .danger {
  width: calc(100% - 32px); margin: 12px 16px;
  border: 0; border-radius: 18px;
  padding: 18px; font-size: 17px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.primary { 
  background: linear-gradient(135deg, var(--button) 0%, color-mix(in srgb, var(--button) 80%, #000) 100%); 
  color: var(--button-text); 
  box-shadow: 0 8px 24px color-mix(in srgb, var(--button) 40%, transparent); 
}
.primary:active { transform: scale(0.96); box-shadow: 0 4px 12px color-mix(in srgb, var(--button) 20%, transparent); filter: brightness(0.9); }
.primary:disabled { opacity: 0.5; filter: grayscale(1); box-shadow: none; }
.danger { 
  background: linear-gradient(135deg, var(--destructive) 0%, color-mix(in srgb, var(--destructive) 70%, #000) 100%); 
  color: #fff; 
  box-shadow: 0 8px 24px color-mix(in srgb, var(--destructive) 40%, transparent); 
}
.danger:active { transform: scale(0.96); box-shadow: 0 4px 12px color-mix(in srgb, var(--destructive) 20%, transparent); }
.action-icon { stroke-width: 2.5; }

.back {
  display: inline-flex; align-items: center; gap: 4px;
  border: 0; background: none; color: var(--text);
  padding: 8px 16px 20px; font-size: 18px; font-weight: 700;
  transition: opacity 0.2s;
}
.back:active { opacity: 0.6; }
.back .icon { margin-left: -8px; width: 28px; height: 28px; stroke-width: 3; }

/* Progress */
.hint { font-size: 14px; font-weight: 500; color: var(--hint); text-align: center; }

/* Profile */
.profile { text-align: center; padding: 40px 16px; display: flex; flex-direction: column; align-items: center; }
.profile h1 { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.profile-role { color: var(--accent); font-size: 15px; font-weight: 700; background: color-mix(in srgb, var(--accent) 15%, transparent); padding: 4px 12px; border-radius: 99px; }

.icon-box {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--button); color: white; margin-right: 16px;
}
.icon-box.admin { background: linear-gradient(135deg, #FF9500 0%, #FF5E3A 100%); }
.icon-box.participant { background: linear-gradient(135deg, #34C759 0%, #30A14E 100%); }
.icon-box.id { background: linear-gradient(135deg, #007AFF 0%, #0056B3 100%); }

.setting-label { display: flex; align-items: center; font-size: 17px; font-weight: 600; }
.profile-note { color: var(--hint); font-size: 14px; font-weight: 500; padding: 0 16px; text-align: center; margin-top: -12px; }

/* Forms */
.form-row { padding: 14px 20px; }
.form-row label { display: block; color: var(--hint); font-size: 13px; font-weight: 700; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.form-row input, .form-row textarea {
  width: 100%; border: 0; outline: 0; background: transparent;
  color: var(--text); font-size: 18px; font-weight: 500;
}
.form-row textarea { height: 80px; resize: none; font-family: inherit; }
.form-row input::placeholder, .form-row textarea::placeholder { color: color-mix(in srgb, var(--hint) 50%, transparent); }
.form-hint { padding: 12px 20px 20px; color: var(--hint); font-size: 14px; font-weight: 500; line-height: 1.5; }

/* Toast */
#toast {
  position: fixed; z-index: 1000;
  top: calc(16px + var(--safe-top)); left: 16px; right: 16px;
  max-width: 400px; margin: auto; padding: 16px 20px;
  border-radius: 16px;
  background: var(--text); color: var(--bg);
  font-size: 15px; font-weight: 600; text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,0.2);
  transform: translateY(-120px) scale(0.9); opacity: 0;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s;
}
#toast.show { transform: translateY(0) scale(1); opacity: 1; }
.hidden { display: none !important; }

.username { font-size: 18px; font-weight: 600; gap: 6px; }
.subline { display: block; color: var(--hint); font-size: 13px; font-weight: 600; margin-top: 4px; }
.score { font-size: 18px; font-weight: 700; color: var(--text); }

/* Loader */
.loader { height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; color: var(--hint); font-size: 16px; font-weight: 600; }
.loader i { width: 44px; height: 44px; border: 4px solid var(--separator); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Giveaway Redesign */
.giveaway-hero {
  background: linear-gradient(135deg, #FFB020 0%, #F57C00 100%);
  border-radius: 28px;
  padding: 40px 24px;
  text-align: center;
  color: white;
  margin: 0 16px 32px;
  box-shadow: 0 20px 40px rgba(245, 124, 0, 0.3), inset 0 2px 0 rgba(255,255,255,0.2);
  position: relative;
  overflow: hidden;
}
.giveaway-hero::before {
  content: '';
  position: absolute; top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 60%);
  animation: rotate 15s linear infinite;
  pointer-events: none;
}

.hero-chip {
  background: rgba(0, 0, 0, 0.25);
  display: inline-block;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 24px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.hero-prize {
  font-size: 48px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
  text-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.hero-icon {
  width: 110px;
  height: 110px;
  background: rgba(255,255,255,0.2);
  border-radius: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), 0 8px 24px rgba(0,0,0,0.1);
  animation: pulse-glow 2s infinite;
}
.hero-icon svg { width: 60px; height: 60px; fill: white; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2)); }
.hero-title { font-size: 26px; font-weight: 800; margin-bottom: 12px; }
.hero-subtitle { font-size: 17px; font-weight: 500; opacity: 0.9; margin-bottom: 32px; }

.timer {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
}
.timer-block {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 12px 0;
  width: 56px;
  font-size: 30px;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.timer-sep {
  font-size: 30px;
  font-weight: 800;
  padding-top: 10px;
  opacity: 0.7;
}

.hero-footer {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 16px;
  padding: 16px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.modal-content {
  background: var(--bg);
  width: 100%;
  border-radius: 32px 32px 0 0;
  padding: 32px 24px calc(32px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
}
.modal-overlay.show .modal-content {
  transform: translateY(0);
}
.modal-header { text-align: left; margin-bottom: 24px; }
.modal-title { font-size: 28px; font-weight: 800; margin-bottom: 8px; }
.modal-desc { color: var(--hint); font-size: 15px; font-weight: 500; line-height: 1.4; }

.channel-list { margin-bottom: 32px; }
.channel-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px;
  background: var(--secondary-bg);
  border-radius: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--separator);
  transition: transform 0.2s;
}
.channel-row:active { transform: scale(0.96); }
.channel-info { display: flex; align-items: center; gap: 14px; font-weight: 600; font-size: 17px; }
.channel-info .avatar { width: 44px; height: 44px; font-size: 18px; }
.channel-btn {
  background: var(--button);
  color: var(--button-text);
  border: none; border-radius: 12px;
  padding: 8px 16px; font-size: 15px; font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--button) 30%, transparent);
}
.channel-btn:active { transform: scale(0.95); }
.channel-check { color: var(--hint); font-size: 20px; font-weight: bold; padding-right: 12px; }
