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

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --secondary-color: #6b7280;
    --success-color: #16a34a;
    --success-hover: #15803d;
    --bg-color: #f9fafb;
    --card-bg: #ffffff;
    --text-color: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
    --primary-color: #6366f1;
    --primary-hover: #818cf8;
    --danger-color: #ef4444;
    --danger-hover: #f87171;
    --secondary-color: #94a3b8;
    --success-color: #22c55e;
    --success-hover: #4ade80;
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

* {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

main {
    margin-top: 6rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.125rem;
}

.links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.link-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
    display: block;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) and (pointer: fine) {
    .link-card:hover {
        transform: translateY(-4px);
        box-shadow: var(--shadow-lg);
        border-color: var(--primary-color);
    }
    
    .icon-option:hover {
        border-color: var(--primary-color);
        transform: scale(1.05);
    }
}

.link-card:active {
    transform: scale(0.98);
}

.link-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.link-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.link-url {
    font-size: 0.875rem;
    color: var(--text-secondary);
    word-break: break-all;
    margin-bottom: 0.5rem;
}

.link-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.admin-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
}

.admin-link:hover {
    color: var(--primary-color);
}

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.875rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #4b5563;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: var(--danger-hover);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.alert-error {
    background-color: #fef2f2;
    color: var(--danger-color);
    border: 1px solid #fecaca;
}

.login-footer {
    margin-top: 2rem;
    text-align: center;
}

.login-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
}

.login-footer a:hover {
    color: var(--primary-color);
}

.login-footer .hint {
    margin-top: 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.admin-header h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.admin-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.admin-user {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.admin-panel {
    display: grid;
    gap: 2rem;
}

.add-link-section,
.links-list-section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

.add-link-section h2,
.links-list-section h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    color: var(--text-color);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.link-form .btn-primary {
    width: auto;
}

.links-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.link-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.link-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.link-info {
    flex: 1;
}

.link-info h3 {
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
    color: var(--text-color);
}

.link-actions {
    display: flex;
    gap: 0.5rem;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 1.5rem;
    margin: 0;
}

.close {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--text-color);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.modal-actions .btn {
    width: auto;
}

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }
    
    header h1 {
        font-size: 1.75rem;
    }
    
    .subtitle {
        font-size: 0.875rem;
    }
    
    .links-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .link-card {
        padding: 1rem;
    }
    
    .link-card h3 {
        font-size: 1.125rem;
    }
    
    .login-box {
        padding: 1.5rem;
    }
    
    .admin-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .admin-header h1 {
        font-size: 1.5rem;
    }
    
    .admin-actions {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .admin-actions .btn {
        width: 100%;
        text-align: center;
    }
    
    .admin-user {
        width: 100%;
        text-align: center;
        padding: 0.5rem;
        background: var(--bg-color);
        border-radius: 0.5rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .add-link-section,
    .links-list-section {
        padding: 1rem;
    }
    
    .add-link-section h2,
    .links-list-section h2 {
        font-size: 1.25rem;
    }
    
    .link-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding: 1rem;
    }
    
    .link-info h3 {
        font-size: 1rem;
    }
    
    .link-actions {
        width: 100%;
        flex-direction: column;
    }
    
    .link-actions button {
        width: 100%;
    }
    
    .icon-selector {
        gap: 0.375rem;
        padding: 0.375rem;
        max-height: 300px;
        overflow-y: auto;
    }
    
    .icon-option {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.25rem;
    }
    
    .modal-content {
        width: 95%;
        padding: 1.5rem;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .modal-header h2 {
        font-size: 1.25rem;
    }
    
    .modal-actions {
        flex-direction: column-reverse;
    }
    
    .modal-actions .btn {
        width: 100%;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 1.5rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .links-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }
    
    .admin-header {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .admin-actions {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .link-item {
        flex-direction: row;
        align-items: center;
    }
    
    .link-actions {
        flex-direction: row;
    }
    
    .icon-selector {
        max-height: 350px;
        overflow-y: auto;
    }
    
    .modal-content {
        width: 90%;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 960px;
    }
    
    .links-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .form-row {
        grid-template-columns: 1fr 1fr;
    }
}

@media (min-width: 1025px) {
    .links-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    }
    
    .icon-selector {
        max-height: 400px;
        overflow-y: auto;
    }
}

.icon-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    background-color: var(--bg-color);
    border-radius: 0.5rem;
    -webkit-overflow-scrolling: touch;
}

.icon-selector::-webkit-scrollbar {
    width: 8px;
}

.icon-selector::-webkit-scrollbar-track {
    background: var(--bg-color);
    border-radius: 4px;
}

.icon-selector::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.icon-selector::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.icon-selector input[type="radio"] {
    display: none;
}

.icon-option {
    display: grid;
    place-items: center;
    place-content: center;
    width: 3rem;
    height: 3rem;
    cursor: pointer;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    background-color: var(--card-bg);
    transition: all 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.icon-glyph {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
    font-size: 1.5rem;
    line-height: 1;
    width: 100%;
    height: 100%;
}

.icon-selector input[type="radio"]:checked + .icon-option {
    border-color: var(--primary-color);
    background-color: rgba(79, 70, 229, 0.1);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.link-icon-preview {
    font-size: 2rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
}

.theme-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background-color: var(--card-bg);
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    z-index: 500;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
    border-color: var(--primary-color);
}

.theme-toggle:active {
    transform: scale(0.95);
}

@media (max-width: 480px) {
    .theme-toggle {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 3rem;
        height: 3rem;
        font-size: 1.25rem;
    }
}
