/* ── OVERRIDE ROOT BODY FOR FULL-HEIGHT APP ─────────────── */
body {
    overflow: hidden;
    height: 100vh;
}

/* ── MAIN LAYOUT ─────────────────────────────────────────── */
.craft-main {
    /* Clean sans game font, à la Infinite Craft — independent of the site serif. */
    --craft-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    font-family: var(--craft-font);
}

/* ── TOOLBAR ─────────────────────────────────────────────── */
.craft-toolbar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.5rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.craft-title {
    font-family: var(--craft-font);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.01em;
    margin-right: auto;
}
.craft-stat {
    font-size: 0.82rem;
    background: var(--surface-2);
    color: var(--muted);
    padding: 0.2rem 0.75rem;
    border-radius: 20px;
    border: 1px solid var(--border);
}
.craft-stat strong {
    color: var(--accent);
    font-weight: 700;
}
.craft-reset-btn {
    font-family: var(--craft-font);
    font-size: 0.74rem;
    font-weight: 500;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.3rem 0.9rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.craft-reset-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--surface);
}

/* ── GAME LAYOUT: CANVAS (left) + INVENTORY (right) ──────── */
.craft-app {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ── INVENTORY (RIGHT SIDEBAR, Infinite-Craft style) ─────── */
.craft-inventory {
    width: 340px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.craft-inv-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.85rem 1rem 0.7rem;
    flex-shrink: 0;
}
.craft-inv-title {
    font-family: var(--craft-font);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}
.craft-inv-count {
    font-family: var(--craft-font);
    font-size: 1.05rem;
    font-weight: 400;
    color: var(--muted);
}
.craft-inv-empty {
    padding: 0.6rem 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
    font-style: italic;
}

/* Dense, horizontally-wrapping chips. */
.craft-inv-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.85rem 0.85rem;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.4rem;
}
.craft-inv-list::-webkit-scrollbar { width: 6px; }
.craft-inv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

.craft-inv-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    cursor: grab;
    transition: background 0.1s, border-color 0.1s, transform 0.05s;
    font-size: 0.85rem;
    font-family: var(--craft-font);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    user-select: none;
    touch-action: none;
    white-space: nowrap;
}
.craft-inv-item:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
}
.craft-inv-item:active {
    cursor: grabbing;
    transform: scale(0.97);
}
.craft-inv-item .emoji {
    font-size: 1rem;
    flex-shrink: 0;
}
.craft-inv-item .name {
    white-space: nowrap;
}

/* ── INVENTORY FOOTER (search) ───────────────────────────── */
.craft-inv-footer {
    flex-shrink: 0;
    padding: 0.6rem 0.85rem 0.85rem;
    border-top: 1px solid var(--border);
}
.craft-search {
    width: 100%;
    padding: 0.5rem 0.7rem;
    font-size: 0.85rem;
    font-family: var(--craft-font);
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
}
.craft-search:focus {
    border-color: var(--accent);
}

/* ── CANVAS (full-bleed, Infinite-Craft style) ───────────── */
.craft-workbench {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
}
.craft-drop-zone {
    position: relative;
    flex: 1;
    background: var(--surface);
    min-height: 160px;
    overflow: hidden;
    touch-action: none;
}
.craft-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* ── RECIPE BOOK BUTTON (top-right of canvas) ────────────── */
.craft-recipes-btn {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    z-index: 6;
    font-family: var(--craft-font);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    transition: border-color var(--transition), background var(--transition);
}
.craft-recipes-btn:hover {
    border-color: var(--border-strong);
    background: var(--surface);
}

/* ── RECIPE BOOK MODAL ───────────────────────────────────── */
.craft-modal {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
}
.craft-modal[hidden] { display: none; }
.craft-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
}
.craft-modal-box {
    position: relative;
    width: min(700px, 92vw);
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.35);
    overflow: hidden;
    font-family: var(--craft-font);
}
.craft-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.craft-modal-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.craft-modal-close {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.25rem;
}
.craft-modal-close:hover { color: var(--text); }
.craft-modal-body {
    display: flex;
    min-height: 0;
    flex: 1;
}
.craft-recipe-left {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    min-height: 0;
}
.craft-recipe-left .craft-search { margin: 0.6rem; }
.craft-recipe-items {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.4rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.craft-recipe-items .craft-inv-item { white-space: normal; }
.craft-inv-item.r-active {
    background: var(--accent-bg);
    border-color: var(--accent);
}
.craft-recipe-detail {
    flex: 1;
    overflow-y: auto;
    padding: 0.9rem 1.1rem;
    min-width: 0;
}
.r-detail-head {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.6rem;
}
.r-detail-emoji { font-size: 1.8rem; line-height: 1; }
.r-detail-name { font-weight: 700; font-size: 1rem; color: var(--text); }
.r-detail-def { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; line-height: 1.4; }
.r-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 0.8rem 0 0.4rem;
}
.r-count { color: var(--accent); }
.r-empty { font-size: 0.8rem; color: var(--muted); font-style: italic; }
.r-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.3rem;
    padding: 0.25rem 0;
}
.r-op { color: var(--muted); font-weight: 600; padding: 0 0.1rem; }
.r-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-family: var(--craft-font);
    font-size: 0.8rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
}
.r-chip:hover { border-color: var(--accent); }
.r-chip .emoji { font-size: 0.95rem; }

@media (max-width: 560px) {
    .craft-modal-body { flex-direction: column; }
    .craft-recipe-left {
        width: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 38%;
    }
}

/* ── DEFINITION PANEL (persistent, below the canvas) ─────── */
.craft-def-panel {
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin: 0.75rem;
    padding: 0.7rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
}
.craft-def-emoji {
    font-size: 1.8rem;
    line-height: 1;
    flex-shrink: 0;
}
.craft-def-body {
    min-width: 0;
}
.craft-def-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent);
}
.craft-def-text {
    font-size: 0.82rem;
    color: var(--text);
    margin-top: 0.15rem;
    line-height: 1.45;
}
.craft-def-meta {
    font-family: var(--craft-font);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--muted);
    margin-top: 0.3rem;
}

/* ── PLACEHOLDER (empty canvas) ──────────────────────────── */
.craft-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
    pointer-events: none;
    line-height: 1.6;
}
.craft-big-emoji {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

/* ── CANVAS CARDS ────────────────────────────────────────── */
.craft-card {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.85rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: grab;
    font-size: 0.82rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.10);
    transition: box-shadow 0.15s, border-color 0.15s, opacity 0.15s;
    user-select: none;
    touch-action: none;
    white-space: nowrap;
    z-index: 1;
    min-width: 60px;
}
.craft-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.16);
    border-color: var(--border-strong);
    z-index: 3;
}
.craft-card.dragging {
    cursor: grabbing;
    opacity: 0.85;
    box-shadow: 0 6px 20px rgba(0,0,0,0.22);
    z-index: 5;
}
.craft-card.combine-target {
    border-color: var(--accent);
    background: var(--accent-bg);
    box-shadow: 0 0 0 2px var(--accent), 0 4px 16px rgba(0,0,0,0.16);
    z-index: 2;
}
.craft-ghost {
    pointer-events: none;
    position: fixed;
    opacity: 0.8;
    z-index: 9999;
    box-shadow: 0 8px 24px rgba(0,0,0,0.28);
}
.craft-card-emoji {
    font-size: 1.3rem;
    flex-shrink: 0;
    line-height: 1;
}
.craft-card-name {
    color: var(--text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.craft-card-del {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1;
    padding: 0 0 0 0.1rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, color 0.12s;
}
.craft-card:hover .craft-card-del {
    opacity: 1;
}
.craft-card-del:hover {
    color: var(--text);
}

/* ── COMBINE FEEDBACK ────────────────────────────────────── */
.craft-card.combined {
    animation: craftPop 0.3s ease;
}
.craft-card.first-discovery {
    animation: craftPop 0.3s ease;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent), 0 0 18px var(--accent);
}
.craft-card.no-reaction {
    animation: craftShake 0.4s ease;
}
.craft-card.decomposed {
    animation: craftReverse 0.4s ease;
}
@keyframes craftPop {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); }
}
@keyframes craftReverse {
    0%   { transform: scale(0.7) rotate(8deg); opacity: 0.2; }
    60%  { transform: scale(1.08) rotate(-4deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); }
}
@keyframes craftShake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-5px); }
    75%      { transform: translateX(5px); }
}

/* ── RESPONSIVE ───────────────────────────────────────────── */
@media (max-width: 720px) {
    /* Stack canvas above items instead of splitting the narrow width. */
    .craft-app {
        flex-direction: column;
    }
    .craft-inventory {
        width: auto;
        height: 34vh;
        min-height: 130px;
        max-height: 220px;
        border-left: none;
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }
    .craft-card {
        font-size: 0.72rem;
        padding: 0.35rem 0.65rem;
        gap: 0.35rem;
    }
    .craft-card-emoji {
        font-size: 1.05rem;
    }
    .craft-card-name {
        max-width: 80px;
    }
    .craft-toolbar {
        padding: 0.4rem 0.75rem;
        gap: 0.6rem;
        flex-wrap: wrap;
    }
    .craft-title {
        font-size: 1rem;
    }
    .craft-stat {
        font-size: 0.72rem;
        padding: 0.15rem 0.5rem;
    }

    /* Compact the definition panel so it doesn't dominate the canvas. */
    .craft-def-panel {
        margin: 0.5rem;
        padding: 0.5rem 0.7rem;
        gap: 0.5rem;
    }
    .craft-def-emoji {
        font-size: 1.4rem;
    }
    .craft-def-name {
        font-size: 0.85rem;
    }
    .craft-def-text {
        font-size: 0.76rem;
        line-height: 1.35;
    }
    .craft-def-meta {
        font-size: 0.64rem;
    }

    /* The tool overrides body height/overflow for the app shell — shrink
       the shared header/footer chrome here too so the canvas gets the room. */
    .site-header .header-inner {
        height: 44px;
    }
    .site-footer {
        padding: 0.5rem 1rem;
    }
    .footer-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.15rem;
    }
    .footer-note {
        font-size: 0.64rem;
    }
}

@media (max-width: 480px) {
    .craft-inventory {
        height: 30vh;
        min-height: 110px;
    }
    .craft-inv-item {
        font-size: 0.75rem;
        padding: 0.25rem 0.45rem;
    }
    .craft-inv-header {
        padding: 0.6rem 0.85rem 0.5rem;
    }
}
