:root {
  --bg: #0d0d12;
  --surface: rgba(255, 255, 255, 0.03);
  --border: rgba(255, 255, 255, 0.05);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --accent: #6C5CE7;
  --accent-glow: rgba(108, 92, 231, 0.4);
  --danger: #ff4757;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Inter', sans-serif; background-color: var(--bg); color: var(--text-primary); min-height: 100vh; overflow-x: hidden; user-select: none; }

.bg-glow { position: fixed; width: 300px; height: 300px; border-radius: 50%; filter: blur(100px); z-index: -1; opacity: 0.5; pointer-events: none; }
.glow-1 { top: -50px; left: -50px; background: var(--accent-glow); }
.glow-2 { bottom: -100px; right: -50px; background: rgba(255, 71, 87, 0.2); }

.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.sidebar { position: fixed; top: 0; left: -280px; width: 280px; height: 100vh; background: var(--bg); border-right: 1px solid var(--border); z-index: 1001; transition: left 0.3s; display: flex; flex-direction: column; }
.sidebar.open { left: 0; }
.sidebar-header { padding: 1.5rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.sidebar-nav { padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.sidebar-item { background: transparent; border: none; color: var(--text-secondary); padding: 1rem; text-align: left; border-radius: var(--radius-md); font-size: 1rem; cursor: pointer; display: flex; align-items: center; gap: 1rem; transition: all 0.2s; }
.sidebar-item:hover, .sidebar-item.active { background: var(--surface); color: var(--text-primary); }
.sidebar-item .badge { background: var(--danger); color: #fff; font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; margin-left: auto; }
hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

.top-nav { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; background: rgba(13, 13, 18, 0.8); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.logo { font-weight: 700; font-size: 1.2rem; display: flex; align-items: center; gap: 1rem; }
.nav-actions { display: flex; gap: 0.5rem; }
.icon-btn { background: transparent; border: none; color: var(--text-primary); width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; }
.icon-btn.primary { background: var(--accent); border: none; }
.icon-btn:active { transform: scale(0.9); }
#toggle-select.active { background: var(--text-primary); color: var(--bg); }
body.blindfold-active #toggle-blindfold { color: var(--accent); border-color: var(--accent); }

.container { padding: 1.5rem; max-width: 800px; margin: 0 auto; padding-bottom: 80px; }

.action-bar { position: fixed; bottom: -80px; left: 0; width: 100%; padding: 1rem 1.5rem; background: rgba(13, 13, 18, 0.9); backdrop-filter: blur(10px); border-top: 1px solid var(--border); z-index: 900; display: flex; justify-content: space-between; align-items: center; transition: bottom 0.3s; }
.action-bar.open { bottom: 0; }
.btn-danger { background: rgba(255, 71, 87, 0.2); color: var(--danger); border: 1px solid rgba(255, 71, 87, 0.5); padding: 0.8rem 1.2rem; border-radius: 30px; font-weight: 600; cursor: pointer; }
.btn-cancel { background: transparent; color: var(--text-secondary); border: none; padding: 0.8rem; cursor: pointer; font-weight: 500; }

.ad-banner { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-md); padding: 1.5rem; text-align: center; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 1.5rem; }

.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
@media(min-width: 600px){ .link-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }

.link-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; position: relative; cursor: pointer; transition: transform 0.2s; }
.link-card:active { transform: scale(0.95); }
.link-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); transform: scale(0.95); }
.link-thumb { width: 100%; aspect-ratio: 16/9; background: #2a2a35; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.link-thumb img { width: 100%; height: 100%; object-fit: cover; transition: filter 0.3s; }
.link-info { display: flex; align-items: center; gap: 0.8rem; padding: 0.8rem; }
.link-favicon { width: 20px; height: 20px; border-radius: 4px; flex-shrink: 0; background: var(--surface); }
.link-info-text { flex: 1; overflow: hidden; }
.link-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-url { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-checkbox { position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
body.select-mode .card-checkbox { opacity: 1; }
.link-card.selected .card-checkbox { background: var(--accent); border-color: var(--accent); }
.link-card.selected .card-checkbox::after { content: "✓"; color: #fff; font-size: 14px; font-weight: bold; }

body.blindfold-active .link-card .link-thumb img { filter: blur(15px) grayscale(100%); opacity: 0.3; }
body.blindfold-active .link-card .link-title { filter: blur(4px); opacity: 0.8; }

/* Ranking UI */
.ranking-list { display: flex; flex-direction: column; gap: 0.8rem; }
.rank-item { display: flex; align-items: center; background: var(--surface); padding: 1rem; border-radius: var(--radius-md); border: 1px solid var(--border); }
.rank-num { font-size: 1.5rem; font-weight: 800; width: 40px; text-align: center; color: var(--text-secondary); }
.rank-item:nth-child(1) .rank-num { color: #ffd700; }
.rank-item:nth-child(2) .rank-num { color: #c0c0c0; }
.rank-item:nth-child(3) .rank-num { color: #cd7f32; }
.rank-details { flex: 1; margin: 0 1rem; overflow: hidden; }
.rank-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-url { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-badge { background: rgba(108, 92, 231, 0.2); color: var(--accent); font-size: 0.75rem; padding: 4px 10px; border-radius: 12px; font-weight: 600; white-space: nowrap; }

/* Friends UI */
.friend-list { display: flex; flex-direction: column; gap: 1rem; }
.friend-item { display: flex; background: var(--surface); padding: 1rem; border-radius: var(--radius-md); border: 1px solid var(--border); align-items: flex-start; }
.friend-avatar { width: 45px; height: 45px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #ff4757); display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 1.2rem; margin-right: 1rem; flex-shrink: 0; color: #fff; }
.friend-info { flex: 1; overflow: hidden; }
.friend-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.3rem; }
.friend-action { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.4; }
.friend-link { background: rgba(255,255,255,0.05); padding: 0.8rem; border-radius: 8px; margin-top: 0.8rem; font-size: 0.85rem; border: 1px solid var(--border); cursor: pointer; transition: background 0.2s; }
.friend-link:active { background: rgba(255,255,255,0.1); }
.friend-link strong { display: block; margin-bottom: 0.2rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-link span { color: var(--text-secondary); font-size: 0.75rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px); display: flex; align-items: flex-end; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.modal.open { opacity: 1; pointer-events: auto; }
@media(min-width: 600px){ .modal { align-items: center; } }
.modal-content { background: var(--bg); width: 100%; max-width: 500px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 2rem; transform: translateY(100%); transition: transform 0.4s; border: 1px solid var(--border); border-bottom: none; }
@media(min-width: 600px){ .modal-content { border-radius: var(--radius-lg); border-bottom: 1px solid var(--border); transform: translateY(20px) scale(0.95); } }
.modal.open .modal-content { transform: translateY(0) scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.close-btn { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; }
.input-group { margin-bottom: 1.2rem; }
.input-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.input-group input { width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text-primary); padding: 0.8rem 1rem; border-radius: var(--radius-md); font-size: 1rem; outline: none; transition: border-color 0.2s; }
.input-group input:focus { border-color: var(--accent); }
.btn-submit { width: 100%; background: var(--accent); color: #fff; border: none; padding: 1rem; border-radius: var(--radius-md); font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.2s; }

.preview-modal { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.85); backdrop-filter: blur(15px); display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.preview-modal.active { opacity: 1; pointer-events: auto; }
.preview-iframe-wrapper { width: 90%; height: 80%; background: var(--bg); border-radius: var(--radius-lg); overflow: hidden; transform: scale(0.9); transition: transform 0.3s; position: relative; }
.preview-modal.active .preview-iframe-wrapper { transform: scale(1); }
#preview-iframe { width: 100%; height: 100%; background: #fff; }
.preview-hint { margin-top: 1.5rem; color: var(--text-secondary); font-size: 0.9rem; animation: pulse 2s infinite; }
.preview-loader { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: var(--accent); }
.spin { animation: rotate 1s linear infinite; }
@keyframes rotate { 100% { transform: rotate(360deg); } }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--text-primary); color: var(--bg); padding: 12px 24px; border-radius: 30px; font-size: 0.9rem; font-weight: 500; z-index: 10000; transition: transform 0.3s; }
.toast.show { transform: translateX(-50%) translateY(0); }
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--text-secondary); }

.tutorial-overlay { position: fixed; inset: 0; z-index: 10000; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; }
.tutorial-card { background: var(--bg); border: 1px solid var(--border); padding: 2rem; border-radius: var(--radius-lg); width: 90%; max-width: 400px; text-align: center; }
.tutorial-card h2 { margin-bottom: 1rem; color: var(--text-primary); }
.tutorial-card p { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.5; margin-bottom: 1.5rem; }
.tut-dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 1.5rem; }
.tut-dots .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); transition: background 0.3s; }
.tut-dots .dot.active { background: var(--accent); }

/* Tutorial Icon */
.tut-icon-container { width: 70px; height: 70px; background: rgba(108, 92, 231, 0.1); border: 1px solid var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 1.5rem; color: var(--accent); animation: float 3s ease-in-out infinite; }
.tut-icon-container i { width: 32px; height: 32px; }
@keyframes float { 0% { transform: translateY(0px); } 50% { transform: translateY(-8px); } 100% { transform: translateY(0px); } }

/* Add Modal Preview */
.add-preview-container { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 1.2rem; overflow: hidden; position: relative; min-height: 100px; display: flex; align-items: center; justify-content: center; }
.add-preview-loader { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 0.85rem; }
.add-preview-content { width: 100%; height: 120px; }
.add-preview-content img { width: 100%; height: 100%; object-fit: cover; }

/* Preview Modal Header */
.preview-modal.active .preview-iframe-wrapper { display: flex; flex-direction: column; }
.preview-header { padding: 0.8rem 1rem; background: var(--bg); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.8rem; flex-shrink: 0; }
.preview-favicon { width: 24px; height: 24px; border-radius: 4px; background: var(--surface); }
.preview-header-text { flex: 1; overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.preview-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-url { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#preview-iframe { flex: 1; }
