:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #dbeafe;
    --border: #e2e8f0;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #60a5fa;
    --accent-hover: #3b82f6;
    --accent-light: #1e3a5f;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

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

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

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--accent), #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.builder-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    border: 1px solid var(--border);
}

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

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

label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    flex-wrap: wrap;
}

.required {
    color: var(--error);
}

.param-tag {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
}

input[type="text"],
input[type="url"] {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

input.error {
    border-color: var(--error);
}

input.valid {
    border-color: var(--success);
}

.hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.hint.error {
    color: var(--error);
}

.params-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.result-section {
    margin: 1.5rem 0;
}

.result-section label {
    margin-bottom: 0.75rem;
}

.url-output {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.url-display {
    flex: 1;
    padding: 1rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
    word-break: break-all;
    min-height: 56px;
    display: flex;
    align-items: center;
}

.url-display .placeholder {
    color: var(--text-muted);
    font-family: inherit;
    font-style: italic;
}

.url-display .url-base {
    color: var(--text-secondary);
}

.url-display .url-params {
    color: var(--accent);
}

.copy-btn {
    padding: 0 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.copy-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.copy-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.copy-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.copy-btn.copied {
    background: var(--success);
}

.actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.action-btn {
    flex: 1;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.action-btn.secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.action-btn.secondary:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.action-btn.primary {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.action-btn.primary:hover:not(:disabled) {
    background: var(--accent);
    color: white;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.history-section {
    margin-top: 2rem;
    display: none;
}

.history-section.visible {
    display: block;
}

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

.history-header h2 {
    font-size: 1.1rem;
}

.clear-history {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.clear-history:hover {
    border-color: var(--error);
    color: var(--error);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.history-item .url {
    flex: 1;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item .copy-small {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item .copy-small:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.info-section {
    margin-top: 2rem;
}

.info-section h2 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.info-section > p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.info-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.info-card h3 {
    font-size: 0.9rem;
    font-family: 'Monaco', 'Menlo', monospace;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.info-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

footer {
    text-align: center;
    margin-top: 3rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

.theme-toggle {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    font-size: 1.25rem;
    transition: transform 0.2s;
    z-index: 100;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

@media (max-width: 480px) {
    .container {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    .builder-card {
        padding: 1.5rem;
    }

    .url-output {
        flex-direction: column;
    }

    .copy-btn {
        justify-content: center;
        padding: 0.875rem;
    }

    .actions {
        flex-direction: column;
    }

    .params-grid {
        grid-template-columns: 1fr;
    }
}
