:root {
    color-scheme: light dark;
    --bg: #0f172a;
    --bg-panel: rgba(15, 23, 42, 0.75);
    --bg-panel-light: rgba(15, 23, 42, 0.55);
    --bg-panel-hover: rgba(148, 163, 184, 0.15);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --danger: #f87171;
    --success: #34d399;
    --border: rgba(148, 163, 184, 0.35);
    --shadow: 0 10px 35px rgba(15, 23, 42, 0.45);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    font-family: 'Roboto', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 20% -10%, rgba(56, 189, 248, 0.35), transparent 55%),
        radial-gradient(circle at 80% 0%, rgba(129, 140, 248, 0.35), transparent 40%),
        linear-gradient(160deg, #0b1120 0%, #111c34 45%, #0f172a 100%);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 32px clamp(16px, 5vw, 48px) 48px;
}

.app-header {
    text-align: center;
    max-width: 960px;
    margin: 0 auto;
}

.app-header h1 {
    margin: 0 0 12px;
    font-size: clamp(32px, 5vw, 48px);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.app-header p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 1.05rem;
}

.layout {
    display: grid;
    gap: 24px;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

.panel {
    background: var(--bg-panel);
    backdrop-filter: blur(18px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px clamp(20px, 4vw, 32px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel h2,
.panel h3 {
    margin: 0;
    font-weight: 600;
}

.input-controls {
    display: flex;
    justify-content: flex-end;
}

button {
    appearance: none;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--bg-panel-light);
    color: var(--text-primary);
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

button:hover:not(:disabled) {
    background: var(--bg-panel-hover);
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.primary {
    background: var(--accent);
    color: #022c3a;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: 0 8px 20px rgba(14, 165, 233, 0.35);
}

.primary:hover {
    background: var(--accent-strong);
}

.secondary {
    background: transparent;
    border: 1px solid var(--border);
}

.card-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.55);
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: var(--text-primary);
    font-family: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
    padding: 18px;
    resize: vertical;
    min-height: 320px;
}

.card-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.set-search {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

#setSearch {
    flex: 1;
    min-width: 220px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.55);
    color: var(--text-primary);
    font-size: 1rem;
}

#setSearch:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.set-results {
    max-height: 280px;
    overflow-y: auto;
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(15, 23, 42, 0.45);
    padding: 4px;
    display: grid;
    gap: 6px;
}

.set-item {
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    padding: 10px 12px;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.set-item label {
    display: flex;
    gap: 10px;
    align-items: center;
    cursor: pointer;
}

.set-item:hover {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.25);
}

.set-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.set-item.already-selected {
    opacity: 0.5;
    cursor: not-allowed;
}

.set-item.pending-selection {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.35);
}

.set-name {
    flex: 1;
    font-weight: 500;
}

.set-code {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.selected-sets-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.selected-sets-header {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
}

.selected-sets-header p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.selected-sets {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 48px;
}

.selected-set {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(15, 23, 42, 0.55);
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.25);
    padding: 12px 16px;
    transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.selected-set.dragging {
    opacity: 0.75;
    border-style: dashed;
    border-color: rgba(56, 189, 248, 0.6);
}

.selected-set.drag-over {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.45);
}

.selected-set-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.selected-set-name {
    font-weight: 600;
}

.selected-set-code {
    color: var(--text-secondary);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}

.remove-set {
    background: transparent;
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: var(--danger);
    padding: 6px 10px;
    border-radius: 999px;
}

.remove-set:hover {
    background: rgba(248, 113, 113, 0.15);
}

.actions {
    max-width: 1100px;
    margin: 0 auto;
    flex-direction: row;
    align-items: center;
    gap: 16px;
}

.loading {
    color: var(--accent);
    font-weight: 500;
}

.progress-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 400px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(15, 23, 42, 0.55);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-strong));
    border-radius: 999px;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.progress-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
}

.hidden {
    display: none !important;
}

.results {
    max-width: 1100px;
    margin: 0 auto;
}

.tabs {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.tab-btn {
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 999px;
    padding: 8px 18px;
    font-size: 0.95rem;
}

.tab-btn.active {
    background: var(--accent);
    color: #03141f;
}

.tab-content {
    margin-top: 16px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.card-list {
    display: grid;
    gap: 12px;
}

.card-result {
    background: rgba(15, 23, 42, 0.55);
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.2);
    padding: 16px;
    display: grid;
    gap: 6px;
}

.card-result.unavailable {
    border-color: rgba(248, 113, 113, 0.45);
}

.card-result.random {
    border-color: rgba(56, 189, 248, 0.35);
}

.card-name {
    font-weight: 600;
    font-size: 1.05rem;
}

.card-set,
.conversion-info {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.app-footer {
    text-align: center;
    color: var(--text-secondary);
}

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

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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 768px) {
    body {
        padding: 24px 16px 36px;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .actions button {
        width: 100%;
        justify-content: center;
    }
}
