/* Theme variables */
:root {
    --bg-body: #f5f5f5;
    --bg-recap: #ecf0f1;
    --bg-recap-zone: #dfe6e9;
    --bg-recap-item: #ecf0f1;
    --bg-editor: #fff;
    --bg-tabs: #ecf0f1;
    --bg-card: #f9f9f9;
    --bg-input: #ecf0f1;
    --bg-equipped: #eaf2f8;
    --bg-hover-remove: #fdedec;
    --bg-active-tier: #d4efdf;
    --bg-invested: #f0f7fd;
    --border-default: #bdc3c7;
    --border-subtle: #dce1e3;
    --border-table: #f0f0f0;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-muted: #95a5a6;
    --text-placeholder: #bdc3c7;
    --text-recap: #2c3e50;
    --text-color: #2c3e50;
    --color-accent: #3498db;
    --color-success: #27ae60;
    --color-danger: #e74c3c;
    --resizer-bg: #bdc3c7;
    --leek-center-bg: #d5e1ea;
    --slot-empty-border: #b0bec5;
    --slot-hover: #cfd8dc;
    --tab-hover: #d5dbdb;
}

[data-theme="dark"] {
    --bg-body: #1a1a2e;
    --bg-recap: #0f1b2d;
    --bg-recap-zone: #16213e;
    --bg-recap-item: #0f1b2d;
    --bg-editor: #1e1e3a;
    --bg-tabs: #16213e;
    --bg-card: #22224a;
    --bg-input: #2a2a5a;
    --bg-equipped: #1a2a4a;
    --bg-hover-remove: #3a1a1a;
    --bg-active-tier: #1a3a2a;
    --bg-invested: #1a2a4a;
    --border-default: #3a3a6a;
    --border-subtle: #2a2a5a;
    --border-table: #2a2a5a;
    --text-primary: #e0e0f0;
    --text-secondary: #a0a0c0;
    --text-muted: #7878a0;
    --text-placeholder: #5a5a8a;
    --text-recap: #e0e0f0;
    --text-color: #e0e0f0;
    --resizer-bg: #0a0a1e;
    --leek-center-bg: #0f1b2d;
    --slot-empty-border: #3a3a6a;
    --slot-hover: #2a3a5a;
    --tab-hover: #2a2a5a;
}

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

html, body {
    height: 100%;
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
}

.container {
    display: flex;
    height: 100vh;
}

/* Recap Section - Left 1/3 */
.recap {
    width: 33%;
    min-width: 150px;
    background-color: var(--bg-recap);
    color: var(--text-recap);
    padding: 20px;
    overflow-y: auto;
    container-type: inline-size;
    container-name: recap;
}

.recap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--color-accent);
}

.recap-header h2 {
    margin: 0;
}

.level-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.level-input label {
    font-size: 14px;
    color: var(--text-secondary);
}

.level-input input {
    width: 60px;
    padding: 4px 8px;
    font-size: 14px;
    border: 1px solid var(--border-default);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    text-align: center;
}

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

.recap-content {
    padding: 10px 0;
}

.recap-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    grid-template-rows: auto auto;
    gap: 10px;
}

.recap-zone {
    background-color: var(--bg-recap-zone);
    border-radius: 6px;
    padding: 15px;
}

.recap-zone h3 {
    font-size: 22px;
    margin-bottom: 10px;
    color: var(--color-accent);
}

.recap-zone h3.error {
    color: var(--color-danger);
}

/* Zone 1 - Always sacred, shares row with Zone 2 */
.zone-1 {
    grid-column: 1;
    grid-row: 1;
}

/* Zone-1 name + level header */
.zone-1-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}

.zone-1-header h3 {
    margin-bottom: 0;
}

.recap-leek-level {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: normal;
}

/* Leek Display - Central leek with 8 components in circle */
.leek-display {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
}

.leek-slot {
    position: absolute;
    background-color: var(--bg-recap-item);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 6px;
    border-radius: 8px;
}

.leek-slot.component:not(.empty) {
    cursor: pointer;
    transition: background 0.2s;
}

.leek-slot.component:not(.empty):hover {
    background-color: var(--slot-hover);
}

.leek-slot.empty {
    background-color: var(--bg-recap-item);
    border: 2px dashed var(--slot-empty-border);
}

.leek-slot img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Central leek image */
.leek-center {
    width: 40%;
    height: 40%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-color: var(--color-accent);
    background-color: var(--leek-center-bg);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.leek-center:hover {
    background-color: var(--slot-hover);
}

/* Component slots - positioned in circle around leek */
.component {
    width: 20%;
    height: 20%;
}

/* Top side - 2 components */
.component[data-slot="component-1"] { top: 5%; left: 25%; }
.component[data-slot="component-2"] { top: 5%; right: 25%; }

/* Right side - 2 components */
.component[data-slot="component-3"] { top: 25%; right: 5%; }
.component[data-slot="component-4"] { bottom: 25%; right: 5%; }

/* Bottom side - 2 components */
.component[data-slot="component-5"] { bottom: 5%; right: 25%; }
.component[data-slot="component-6"] { bottom: 5%; left: 25%; }

/* Left side - 2 components */
.component[data-slot="component-7"] { bottom: 25%; left: 5%; }
.component[data-slot="component-8"] { top: 25%; left: 5%; }

/* Recap Stats - compact display */
.recap-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    font-size: 18px;
}

.recap-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    background-color: var(--bg-recap-item);
    border-radius: 3px;
}

.recap-stat img {
    width: 24px;
    height: 24px;
}

.recap-stat span {
    font-weight: bold;
}

/* Zone 2 - Shares first row with Zone 1 */
.zone-2 {
    grid-column: 2;
    grid-row: 1;
}

/* Zone 3 - Second row, full width by default */
.zone-3 {
    grid-column: 1 / -1;
    grid-row: 2;
}

/* Zone 4 - Item detail, third row, full width */
.zone-4 {
    grid-column: 1 / -1;
    grid-row: 3;
}

.item-detail {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.detail-icon {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.detail-icon-weapon {
    width: 96px;
    height: 48px;
}

.detail-name {
    font-size: 16px;
    font-weight: 600;
    text-transform: capitalize;
    display: block;
}

.detail-level {
    font-size: 12px;
    color: var(--text-muted);
}

.detail-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.detail-meta-entry {
    display: flex;
    align-items: center;
    gap: 3px;
}

.detail-meta-entry img {
    width: 14px;
    height: 14px;
}

.detail-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.detail-stat img {
    width: 18px;
    height: 18px;
}

/* Recap Items */
.recap-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.recap-weapons-list,
.recap-chips-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.recap-item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: var(--bg-recap-item);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.recap-item:hover {
    background: var(--slot-hover);
}

.recap-item img {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.recap-weapons-list .recap-item {
    width: 128px;
    height: 64px;
}

.recap-weapons-list .recap-item img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

/* When recap is narrow, stack all zones */
@container recap (max-width: 400px) {
    .recap-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
    }

    .zone-1 {
        grid-column: 1;
        grid-row: 1;
    }

    .zone-2 {
        grid-column: 1;
        grid-row: 2;
    }

    .zone-3 {
        grid-column: 1;
        grid-row: 3;
    }

    .zone-4 {
        grid-column: 1;
        grid-row: 4;
    }
}

/* Resizer Handle */
.resizer {
    width: 6px;
    background-color: var(--resizer-bg);
    cursor: col-resize;
    transition: background-color 0.2s;
}

.resizer:hover,
.resizer.active {
    background-color: var(--color-accent);
}

/* Editor Section - Right 2/3 */
.editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-editor);
    min-width: 200px;
}

/* Tabs Navigation */
.tabs {
    display: flex;
    background-color: var(--bg-tabs);
    border-bottom: 2px solid var(--border-default);
}

.tab {
    padding: 15px 30px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    display: flex;
    align-items: center;
}

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


.tab img {
    height: 26px;
    margin: 2px;
}

.tab.active {
    color: var(--text-primary);
    background-color: var(--bg-editor);
    border-bottom: 3px solid var(--color-accent);
}

.tab.error span {
    color: var(--color-danger);
}

.tab.active.error span {
    color: var(--color-danger);
}

/* Tab Content */
.tab-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.tab-panel {
    display: none;
}

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

.tab-panel h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
}

.wip-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--color-accent);
    color: white;
    vertical-align: middle;
}

/* Computed toggle */
.computed-toggle {
    background: none;
    border: 1px solid var(--slot-empty-border);
    font-size: 11px;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px;
    color: var(--text-recap);
    transition: all 0.2s;
    opacity: 0.6;
}

.computed-toggle:hover {
    opacity: 0.9;
}

.computed-toggle.active {
    opacity: 1;
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
}

/* Range toggle */
.range-toggle {
    background: none;
    border: 1px solid var(--slot-empty-border);
    font-size: 11px;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px;
    color: var(--text-recap);
    transition: all 0.2s;
    opacity: 0.6;
}

.range-toggle:hover {
    opacity: 0.9;
}

.range-toggle.active {
    opacity: 1;
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
}

/* Language toggle */
.lang-toggle {
    background: none;
    border: 1px solid var(--slot-empty-border);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px;
    color: var(--text-recap);
    transition: all 0.2s;
    opacity: 0.6;
}

.lang-toggle:hover {
    opacity: 1;
}

.item-range {
    display: none;
}

body.show-range .item-range {
    display: flex;
}

/* Meta / effects separator */
.meta-separator {
    border: none;
    border-top: 1px solid var(--border-default);
    margin: 4px 0;
}

/* Theme toggle */
.theme-toggle {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
    transition: background 0.2s;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Mobile layout: recap on top, editor below */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        height: 100vh;
    }

    .recap {
        width: 100% !important;
        min-width: unset;
        padding: 10px 12px;
        overflow-y: visible;
        flex-shrink: 0;
    }

    .recap-header {
        margin-bottom: 8px;
        padding-bottom: 6px;
    }

    .recap-header h2 {
        font-size: 18px;
    }

    .recap-content {
        padding: 0;
    }

    .recap-grid {
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto auto;
        gap: 8px;
        align-items: start;
    }

    .zone-1 {
        grid-column: 1;
        grid-row: 1;
        padding: 8px;
    }

    .zone-1 .zone-1-header { display: none; }

    .leek-display {
        width: 80px;
        height: 80px;
    }

    .leek-center {
        width: 60%;
        height: 60%;
    }

    .component {
        width: 22%;
        height: 22%;
        padding: 2px;
        border-radius: 4px;
    }

    .zone-2 {
        grid-column: 2;
        grid-row: 1;
        padding: 8px;
    }

    .zone-2 h3 { display: none; }

    .recap-stats {
        grid-template-columns: repeat(4, 1fr);
        font-size: 12px;
        gap: 2px;
    }

    .recap-stat {
        padding: 2px 4px;
        gap: 3px;
    }

    .recap-stat img {
        width: 16px;
        height: 16px;
    }

    .recap-zone h3 {
        font-size: 14px;
        margin-bottom: 6px;
    }

    .zone-3 {
        grid-column: 1 / -1;
        grid-row: 2;
        padding: 8px;
    }

    .zone-3 h3 { display: none; }

    .recap-items {
        gap: 4px;
    }

    .recap-item img {
        width: 32px;
        height: 32px;
    }

    .recap-weapons-list .recap-item {
        width: 48px;
        height: 32px;
    }

    .zone-4 {
        grid-column: 1 / -1;
        grid-row: 3;
    }

    .resizer {
        display: none;
    }

    .editor {
        flex: 1;
        min-width: unset;
        overflow-y: auto;
    }

    .tabs {
        flex-shrink: 0;
    }

    .tab {
        padding: 10px 12px;
        font-size: 14px;
        flex: 1;
        justify-content: center;
    }

    .tab img {
        height: 20px;
    }

    .tab-content {
        padding: 12px;
    }
}

/* Leek Manager Modal */
.leek-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.leek-modal-overlay.open {
    display: block;
}

.leek-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-editor);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    padding: 20px;
    z-index: 101;
    min-width: 280px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.leek-modal.open {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.leek-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.leek-modal-header h3 {
    font-size: 18px;
    color: var(--text-primary);
}

.leek-modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

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

.leek-manager-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leek-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--bg-card);
    border: 2px solid transparent;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.leek-list-item:hover {
    background: var(--slot-hover);
}

.leek-list-item.active {
    border-color: var(--color-accent);
    cursor: default;
}

.leek-list-img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    flex-shrink: 0;
}

.leek-name-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: text;
}

.leek-name-input:focus {
    outline: 2px solid var(--color-accent);
}

.leek-delete-btn {
    background: none;
    border: 1px solid var(--border-default);
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 2px 8px;
    line-height: 1;
    flex-shrink: 0;
    transition: all 0.2s;
}

.leek-delete-btn:hover:not(:disabled) {
    background: var(--bg-hover-remove);
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.leek-delete-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.leek-type-select {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border-subtle);
    padding-top: 12px;
}

.leek-type-select-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.leek-type-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.leek-type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: 6px;
    cursor: pointer;
    font-size: 10px;
    color: var(--text-secondary);
    transition: all 0.2s;
    min-width: 56px;
}

.leek-type-btn img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.leek-type-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
    background: var(--bg-equipped);
}
