:root {
    --background: #000000;
    --bg-lighter: #0a0a0a;
    --card-bg: #111111;
    --card-elevated: #1a1a1a;
    --card-elevated-2: #242424;
    --card-elevated-3: #2e2e2e;
    --gray900: #3d3d3d;
    --gray700: #6b6b6b;
    --gray400: #a0a0a0;
    --gray200: #d0d0d0;
    --primary: #ffffff;
    --text: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #6b6b6b;
    --border: rgba(255, 255, 255, 0.15);
    --border-strong: rgba(255, 255, 255, 0.50);
    --danger: #ff3b3b;
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Space Grotesk', sans-serif;
    --font-mono: 'DM Mono', ui-monospace, monospace;
    --sp1: 0.5rem;
    --sp2: 0.75rem;
    --sp3: 1rem;
    --sp4: 1.5rem;
    --sp5: 2rem;
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-xl: 24px;
    --r-pill: 999px;
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 30px rgba(255, 255, 255, 0.15);
    --grad-surface: linear-gradient(135deg, #1a1a1a 0%, #000000 100%);
    --grad-primary-btn: linear-gradient(135deg, #ffffff 0%, #d0d0d0 100%);
    --grad-bg: linear-gradient(135deg, #000000 0%, #0a0a0a 100%);
}


.loading-screen {
    position: fixed; inset: 0;
    background: var(--background);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 9999;
    transition: opacity 0.6s ease-out, visibility 0.6s;
}
.loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-logo-wrap { position: relative; width: 100px; height: 100px; margin-bottom: 2rem; }
.loading-logo { width: 100%; height: 100%; border-radius: 50%; border: 1px solid var(--border-strong); display: flex; align-items: center; justify-content: center; background: var(--card-bg); overflow: hidden; }
.loading-logo img { width: 75%; height: 75%; object-fit: cover; border-radius: 50%; }
.loading-spinner { position: absolute; top: -8px; left: -8px; width: calc(100% + 16px); height: calc(100% + 16px); border-radius: 50%; border: 1px solid transparent; border-top-color: var(--primary); border-right-color: var(--border); animation: spin 1.2s linear infinite; }
.loading-spinner::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; border: 1px solid transparent; border-bottom-color: var(--border-strong); animation: spin 1.8s linear infinite reverse; }
.loading-title { font-family: var(--font-display); font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 700; letter-spacing: -0.02em; opacity: 0; animation: fadeUp 0.7s ease-out 0.3s forwards; }
.loading-sub { font-family: var(--font-body); font-size: 0.9rem; color: var(--text-muted); margin-top: 0.5rem; font-weight: 300; opacity: 0; animation: fadeUp 0.7s ease-out 0.5s forwards; }
.loading-track { position: absolute; bottom: 0; left: 0; width: 100%; height: 2px; background: var(--border); }
.loading-fill { height: 100%; background: var(--primary); animation: loadBar 1.4s ease-out forwards; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes loadBar { from { width: 0; } to { width: 100%; } }


* {
    box-sizing: border-box;
}
html,
body {
    margin: 0;
    padding: 0;
}
img {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

body {
    background: var(--grad-bg);
    color: var(--text);
    font-family: var(--font-body);
    min-height: 100vh;
}

.wrap {
    width: 100%;
    padding: 48px 24px 96px;
}


.topnav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 40px;
}
.topnav .nav-links {
    display: flex;
    gap: 22px;
}
.topnav .nav-links span {
    color: var(--text-secondary);
}
.topnav .nav-links span.active {
    color: var(--text);
}
.topnav .nav-links span.active::before {
    content: "[ ";
}
.topnav .nav-links span.active::after {
    content: " ]";
}


.eyebrow {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 0 0 14px;
}
.eyebrow::before {
    content: "♢ ";
    color: var(--text);
}
h1.title {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(28px, 4.2vw, 3.2rem);
    line-height: 1.1;
    margin: 0 0 14px;
    letter-spacing: 0.01em;
}
.subtitle {
    max-width: 64ch;
    color: var(--text-secondary);
    font-size: 1rem;
    margin: 0 0 40px;
}
.subtitle b {
    color: var(--text);
    font-weight: 700;
}


.card {
    position: relative;
    background: var(--grad-surface);
    border: 2px solid var(--border);
    border-radius: var(--r-sm);
    padding: 28px clamp(18px, 3vw, 32px);
    margin-bottom: 24px;
}
.card::before,
.card::after,
.card .bl,
.card .br {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border-color: var(--text);
    border-style: solid;
}
.card::before {
    top: -2px;
    left: -2px;
    border-width: 2px 0 0 2px;
}
.card::after {
    top: -2px;
    right: -2px;
    border-width: 2px 2px 0 0;
}
.card .bl {
    bottom: -2px;
    left: -2px;
    border-width: 0 0 2px 2px;
}
.card .br {
    bottom: -2px;
    right: -2px;
    border-width: 0 2px 2px 0;
}

.card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.3rem;
    margin: 0 0 4px;
}
.card-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 20px;
}
.label {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 8px;
}


.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
@media (max-width: 860px) {
    .grid-2col {
        grid-template-columns: 1fr;
    }
}


.toggle-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.toggle-btn {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-secondary);
    padding: 12px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all 0.12s;
}
.toggle-btn.active {
    background: var(--grad-primary-btn);
    color: #000;
    border-color: var(--primary);
}
.toggle-btn:hover:not(.active) {
    border-color: var(--border-strong);
    color: var(--text);
}


.craft-area {
    display: flex;
    align-items: center;
    gap: 28px;
    flex-wrap: wrap;
    justify-content: center;
}
.craft-grid {
    display: grid;
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: repeat(3, 64px);
    gap: 6px;
    padding: 10px;
    background: var(--bg-lighter);
    border: 2px solid var(--border);
    border-radius: var(--r-sm);
}
.arrow {
    width: 28px;
    height: 28px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.result-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.slot {
    width: 64px;
    height: 64px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}
.slot:hover {
    border-color: var(--border-strong);
    background: #181818;
}
.slot.armed-target {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary) inset;
}
.slot img {
    width: 42px;
    height: 42px;
}
.slot .fallback {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    padding: 2px;
    line-height: 1.2;
}
.slot .qty-badge {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
}
.result-slot {
    width: 72px;
    height: 72px;
}
.qty-stepper {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}
.qty-stepper button {
    width: 26px;
    height: 26px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qty-stepper button:hover {
    border-color: var(--border-strong);
}


.search-input {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 10px 12px;
    margin-bottom: 14px;
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
}
.search-input::placeholder {
    color: var(--text-secondary);
}

.armed-banner {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: #000;
    background: var(--primary);
    border-radius: var(--r-sm);
    padding: 8px 12px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.armed-banner button {
    background: transparent;
    border: 1px solid #000;
    color: #000;
    border-radius: 2px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 2px 8px;
    cursor: pointer;
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 6px;
    max-height: 340px;
    overflow-y: auto;
    padding-right: 4px;
}
.palette-grid::-webkit-scrollbar {
    width: 8px;
}
.palette-grid::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--r-sm);
}

.pillrow {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}
.pill {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 5px 10px;
    cursor: pointer;
    transition: all 0.12s;
}
.pill:hover {
    border-color: var(--border-strong);
    color: var(--text);
}
.pill.active {
    background: var(--grad-primary-btn);
    color: #000;
    border-color: var(--primary);
    font-weight: 700;
}

.index-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.cap-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.cap-label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.cap-label span {
    color: var(--text);
    font-weight: 700;
}
.cap-row input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 2px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}
.cap-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 2px;
    background: var(--primary);
    border: 1px solid var(--background);
    cursor: pointer;
}
.cap-row input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    background: var(--primary);
    border: 1px solid var(--background);
    cursor: pointer;
}
.cap-row input[type="range"]:disabled::-webkit-slider-thumb {
    background: var(--text-secondary);
}

.index-list {
    list-style: none;
    margin: 0;
    padding: 8px;
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    gap: 6px;
}
.index-list::-webkit-scrollbar {
    width: 8px;
}
.index-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--r-sm);
}
.index-list li {
    position: relative;
    aspect-ratio: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.12s, transform 0.1s;
}
.index-list li:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.index-list li.empty {
    grid-column: 1/-1;
    aspect-ratio: auto;
    cursor: default;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    padding: 16px 10px;
    text-align: center;
    background: transparent;
    border: none;
}
.index-list li.empty:hover {
    transform: none;
}
.index-thumb {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.index-thumb img {
    width: 34px;
    height: 34px;
}
.index-cat {
    display: none;
}
.index-path {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-lighter);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 10px;
    white-space: nowrap;
    padding: 4px 7px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s;
    z-index: 5;
    border-radius: 2px;
    max-width: none;
}
.index-list li:hover .index-path {
    opacity: 1;
}

.pitem {
    aspect-ratio: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: border-color 0.12s, transform 0.12s;
}
.pitem:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.pitem.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary) inset;
}
.pitem img {
    width: 34px;
    height: 34px;
}
.pitem .fallback {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-secondary);
}
.pitem .pt-tip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-lighter);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 10px;
    white-space: nowrap;
    padding: 4px 7px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s;
    z-index: 5;
    border-radius: 2px;
}
.pitem:hover .pt-tip {
    opacity: 1;
}

.custom-id-row {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}
.custom-id-row input {
    flex: 1;
}
.btn {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    border-radius: var(--r-sm);
    padding: 10px 16px;
    cursor: pointer;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text);
    transition: all 0.12s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover {
    border-color: var(--border-strong);
}
.btn.primary {
    background: var(--grad-primary-btn);
    color: #000;
    border-color: var(--primary);
}
.btn.primary:hover {
    box-shadow: var(--shadow-glow);
}
.btn.danger-outline {
    border-color: var(--danger);
    color: var(--danger);
}
.btn.danger-outline:hover {
    background: rgba(255, 59, 59, 0.1);
}


.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}
.form-field input,
.form-field select {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 10px 12px;
}
.form-field input:focus,
.form-field select:focus {
    outline: none;
    border-color: var(--primary);
}
.id-combo {
    display: flex;
    align-items: center;
    gap: 0;
}
.id-combo input:first-child {
    border-radius: var(--r-sm) 0 0 var(--r-sm);
    text-align: right;
}
.id-combo input:last-child {
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
    border-left: none;
}
.id-combo .colon {
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 10px 4px;
    font-family: var(--font-mono);
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
}
.chip button {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    padding: 0;
}
.add-tag-row {
    display: flex;
    gap: 8px;
}
.add-tag-row input {
    flex: 1;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.checkbox-row input {
    width: 16px;
    height: 16px;
    accent-color: #fff;
}


.json-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.code-block {
    background: var(--bg-lighter);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 20px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.6;
    color: #e6e6e6;
    white-space: pre;
    overflow-x: auto;
    max-height: 520px;
    overflow-y: auto;
}
.json-actions .flash {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text);
    align-self: center;
    opacity: 0;
    transition: opacity 0.15s;
}
.json-actions .flash.show {
    opacity: 1;
}

.footnote {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 10px;
}
.footnote code {
    color: var(--text);
}


.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}
.modal-box {
    position: relative;
    width: 100%;
    max-width: 380px;
    background: var(--grad-surface);
    border: 2px solid var(--border-strong);
    border-radius: var(--r-sm);
    padding: 26px 24px;
}
.modal-box .bl,
.modal-box .br,
.modal-box::before,
.modal-box::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border-color: var(--text);
    border-style: solid;
}
.modal-box::before {
    top: -2px;
    left: -2px;
    border-width: 2px 0 0 2px;
}
.modal-box::after {
    top: -2px;
    right: -2px;
    border-width: 2px 2px 0 0;
}
.modal-box .bl {
    bottom: -2px;
    left: -2px;
    border-width: 0 0 2px 2px;
}
.modal-box .br {
    bottom: -2px;
    right: -2px;
    border-width: 0 2px 2px 0;
}
.modal-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    margin: 0 0 4px;
}
.modal-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 18px;
}
.modal-box .form-field {
    margin-bottom: 14px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}
