/* CSS Variables for theming */
:root {
    --primary: #5e35b1;
    --primary-dark: #4527a0;
    --primary-light: #7e57c2;
    --secondary: #26a69a;
    --error: #e53935;
    --warning: #fb8c00;
    --success: #43a047;
    --bg: #f5f5f5;
    --surface: #ffffff;
    --text: #212121;
    --text-secondary: #757575;
    --border: #e0e0e0;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-raised: 0 4px 8px rgba(0, 0, 0, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121212;
        --surface: #1e1e1e;
        --text: #e0e0e0;
        --text-secondary: #b0b0b0;
        --border: #333333;
        --shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        --shadow-raised: 0 4px 8px rgba(0, 0, 0, 0.4);
    }
}

/* Base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 20px 0;
    margin-bottom: 30px;
}

h1 {
    font-size: 28px;
    color: var(--primary);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Card component */
.card {
    background: var(--surface);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 20px;
    margin-bottom: 15px;
    color: var(--primary);
}

/* Form elements */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

select,
input[type="number"],
input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
}

select:focus,
input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(94, 53, 177, 0.2);
}

/* Enchantment grid */
.enchantment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.enchantment-item {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
    user-select: none;
}

.enchantment-item:hover {
    background: rgba(94, 53, 177, 0.05);
    border-color: var(--primary-light);
}

.enchantment-item.selected {
    background: rgba(94, 53, 177, 0.1);
    border-color: var(--primary);
}

.enchantment-item.incompatible {
    opacity: 0.5;
    cursor: not-allowed;
}

.enchantment-item.incompatible::after {
    content: " (Incompatible)";
    color: var(--error);
    font-size: 12px;
}

.enchantment-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.enchantment-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.enchantment-name {
    font-weight: 500;
    flex: 1;
}

.enchantment-description {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 30px;
    /* Align with text, past checkbox */
    margin-bottom: 8px;
    line-height: 1.4;
}

.level-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.level-selector input {
    width: 60px;
}

/* Button */
.btn {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--primary-dark);
}

.btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--secondary);
}

/* Results */
.results {
    margin-top: 30px;
}

.step {
    padding: 15px;
    background: var(--bg);
    border-radius: 4px;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary);
}

.step-number {
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 5px;
}

.step-description {
    margin-bottom: 5px;
}

.step-cost {
    color: var(--text-secondary);
    font-size: 14px;
}

.step.too-expensive {
    border-left-color: var(--error);
    background: rgba(229, 57, 53, 0.05);
}

.total-cost {
    font-size: 20px;
    font-weight: bold;
    color: var(--primary);
    margin-top: 20px;
    padding: 15px;
    background: var(--bg);
    border-radius: 4px;
    text-align: center;
}

/* Version toggle */
.version-toggle {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
}

.version-toggle label {
    margin: 0;
}

/* Accordion */
.accordion {
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.accordion-item {
    border-bottom: 1px solid var(--border);
}

.accordion-item:last-child {
    border-bottom: none;
}

.accordion-header {
    width: 100%;
    padding: 15px;
    background: var(--surface);
    border: none;
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    font-size: 16px;
    color: var(--text);
    transition: background 0.2s;
}

.accordion-header:hover {
    background: rgba(0, 0, 0, 0.02);
}

.accordion-content {
    display: none;
    padding: 15px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.accordion-content.active {
    display: block;
}

.accordion-icon {
    transition: transform 0.2s;
}

.accordion-header.active .accordion-icon {
    transform: rotate(180deg);
}

/* Visual Tree */
.tree-container {
    margin-top: 20px;
    padding: 20px;
    background: var(--bg);
    border-radius: 4px;
    overflow-x: auto;
}

.tree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 10px;
    margin: 0 10px;
}

.tree-content {
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    text-align: center;
    min-width: 120px;
    box-shadow: var(--shadow);
    z-index: 1;
}

.tree-content.book {
    border-color: var(--secondary);
}

.tree-content.item {
    border-color: var(--primary);
}

.tree-children {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    position: relative;
}

.tree-children::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    width: 2px;
    height: 10px;
    background: var(--border);
}

.tree-node::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 10px;
    background: var(--border);
}

/* Connectors for children */
.tree-children>.tree-node::after {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    width: 50%;
    height: 2px;
    background: var(--border);
}

.tree-children>.tree-node:first-child::after {
    left: 50%;
    width: 50%;
}

.tree-children>.tree-node:last-child::after {
    left: 0;
    width: 50%;
}

.tree-children>.tree-node:only-child::after {
    display: none;
}

/* XP Calculator */
.xp-calculator {
    margin-top: 15px;
    padding: 15px;
    background: rgba(38, 166, 154, 0.1);
    border-radius: 4px;
    border-left: 4px solid var(--secondary);
}

/* Library & Loadouts */
.library-list,
.loadouts-list {
    margin-top: 15px;
    display: grid;
    gap: 10px;
}

.library-item,
.loadout-item {
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.loadout-actions {
    display: flex;
    gap: 5px;
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-danger {
    background: var(--error);
}

/* Responsive */
@media (max-width: 768px) {
    .enchantment-grid {
        grid-template-columns: 1fr;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

.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;
}

/* Test output */
.test-output {
    margin-top: 30px;
    padding: 15px;
    background: #f0f0f0;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    white-space: pre-wrap;
    color: #333;
    max-height: 400px;
    overflow-y: auto;
}

@media (prefers-color-scheme: dark) {
    .test-output {
        background: #1a1a1a;
        color: #e0e0e0;
    }
}

.magical-text {
    color: #9c27b0;
    text-shadow: 0 0 5px rgba(156, 39, 176, 0.3);
    font-weight: bold;
}

@media (prefers-color-scheme: dark) {
    .magical-text {
        color: #e1bee7;
        text-shadow: 0 0 8px rgba(225, 190, 231, 0.4);
    }
}

/* Cost Color Coding */
.cost-low {
    color: var(--success);
    font-weight: bold;
}

.cost-medium {
    color: var(--warning);
    font-weight: bold;
}

.cost-high {
    color: var(--error);
    font-weight: bold;
}

/* Flowchart Visualization */
.flowchart-container {
    margin-top: 30px;
    padding: 30px;
    background: linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%);
    border-radius: 12px;
    overflow-x: auto;
    border: 2px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.flowchart-container h3 {
    margin-bottom: 25px;
    color: var(--primary);
    font-size: 20px;
    font-weight: 600;
    text-align: center;
}

.flowchart-svg {
    display: block;
    margin: 0 auto;
}

.flowchart-node {
    transition: transform 0.2s ease;
}

.flowchart-node:hover {
    transform: scale(1.05);
}

.node-rect {
    fill: #ffffff;
    stroke: #2c3e50;
    stroke-width: 2;
    filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.15));
    transition: all 0.2s ease;
}

.flowchart-node:hover .node-rect {
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.25));
}

.node-label {
    fill: #2c3e50;
    font-size: 13px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    pointer-events: none;
    user-select: none;
}

.connection {
    stroke: #c53030;
    stroke-width: 3;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.connection-cost {
    fill: #2c3e50;
    font-size: 13px;
    font-weight: 700;
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
    filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.8));
}

@media (prefers-color-scheme: dark) {
    .flowchart-container {
        background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
        border-color: #444;
    }

    .node-rect {
        fill: #2a2a2a;
        stroke: #ffffff;
    }

    .node-label {
        fill: #ffffff;
    }

    .connection-cost {
        fill: #ffffff;
        filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
    }
}