html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    color: #1f1f1f;
    background: #ffffff;
    -webkit-user-select: none;
    user-select: none;
}

button,
input {
    font: inherit;
}

.craft-game,
.craft-game * {
    -webkit-user-drag: none;
    -webkit-user-select: none;
    user-select: none;
}

.search-box,
.target-input {
    -webkit-user-select: text;
    user-select: text;
}

.app-shell,
.craft-game {
    width: 100vw;
    height: 100vh;
}

.craft-game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 6px var(--sidebar-width, 310px);
    background: #ffffff;
}

.craft-canvas {
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(#f7f7f7 1px, transparent 1px),
        linear-gradient(90deg, #f7f7f7 1px, transparent 1px),
        #ffffff;
    background-size: 36px 36px;
}

.game-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgb(255 255 255 / 20%);
    pointer-events: auto;
}

.brand {
    position: absolute;
    top: 18px;
    left: 22px;
    z-index: 1;
    font-size: 24px;
    font-weight: 700;
    color: #161616;
    letter-spacing: 0;
}

.target-chip {
    position: absolute;
    top: 55px;
    left: 22px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: min(360px, calc(100vw - 390px));
    min-height: 30px;
    padding: 5px 9px;
    border: 1px solid #d8d8d8;
    border-radius: 5px;
    background: #ffffff;
    box-shadow: 0 1px 4px rgb(0 0 0 / 8%);
    font-size: 14px;
}

.target-chip span {
    color: #777777;
}

.target-chip strong {
    min-width: 0;
    overflow: hidden;
    color: #202020;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toast-message {
    position: absolute;
    top: 92px;
    left: 22px;
    z-index: 4;
    max-width: min(520px, calc(100vw - 360px));
    padding: 8px 11px;
    border: 1px solid #dedede;
    border-radius: 5px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
    color: #333333;
    font-size: 14px;
}

.merge-wait-dialog {
    position: absolute;
    z-index: 6;
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    width: min(330px, calc(100vw - 390px));
    min-height: 58px;
    padding: 14px 16px;
    border: 1px solid #d8d8d8;
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgb(0 0 0 / 14%);
    color: #2d2d2d;
    font-size: 14px;
    line-height: 1.35;
    pointer-events: none;
}

.merge-wait-dialog.is-hidden {
    visibility: hidden;
    opacity: 0;
}

.merge-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #cfcfcf;
    border-top-color: #4f4f4f;
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

.craft-token {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    max-width: 230px;
    padding: 6px 10px;
    border: 1px solid #d8d8d8;
    border-radius: 5px;
    background: #f5f5f5;
    color: #262626;
    box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
    cursor: grab;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    touch-action: none;
}

.craft-token:active {
    cursor: grabbing;
}

.craft-token span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
}

.canvas-token {
    position: absolute;
    z-index: 2;
}

.canvas-token.is-dragging {
    box-shadow: 0 8px 20px rgb(0 0 0 / 18%);
    transform: translateY(-1px);
}

.canvas-token.is-merge-target {
    border-color: #4f8cff;
    background: #eef5ff;
    box-shadow: 0 0 0 3px rgb(79 140 255 / 18%), 0 3px 10px rgb(0 0 0 / 12%);
}

.canvas-token.is-merge-target::before {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 16px;
    height: 16px;
    border: 2px solid #ffffff;
    border-radius: 999px;
    background: #4f8cff;
    box-shadow: 0 1px 5px rgb(0 0 0 / 20%);
    content: "";
}

.canvas-token.is-loading {
    opacity: 0.66;
}

.canvas-token.is-loading::after {
    content: "";
    width: 8px;
    height: 8px;
    border: 2px solid #a5a5a5;
    border-top-color: transparent;
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

.inventory {
    display: flex;
    height: 100%;
    min-height: 0;
    min-width: 0;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid #d8d8d8;
    background: #f8f8f8;
}

.sidebar-resizer {
    width: 6px;
    background: #f8f8f8;
    border-left: 1px solid #d8d8d8;
    cursor: col-resize;
    touch-action: none;
}

.sidebar-resizer:hover,
.sidebar-resizer:active {
    background: #e6e6e6;
}

.inventory-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 14px;
    border-bottom: 1px solid #e4e4e4;
}

.items-count {
    min-width: 0;
    font-size: 20px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
}

.icon-button {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    color: #6b6b6b;
    cursor: pointer;
}

.restart-button {
    font-size: 20px;
}

.icon-button:hover {
    background: #ececec;
    color: #1f1f1f;
}

.search-box {
    height: 34px;
    margin: 12px 12px 8px;
    padding: 0 10px;
    border: 1px solid #d6d6d6;
    border-radius: 5px;
    background: #ffffff;
    outline: none;
}

.search-box:focus {
    border-color: #8c8c8c;
}

.sort-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 48px;
    padding: 8px 12px;
    border-top: 1px solid #e0e0e0;
    background: #f8f8f8;
    color: #6a6a6a;
    font-size: 13px;
}

.sort-toggle {
    display: flex;
    flex-shrink: 0;
    gap: 7px;
}

.toolbar-button {
    height: 26px;
    padding: 0 9px;
    border: 1px solid #d6d6d6;
    border-radius: 4px;
    background: #ffffff;
    color: #565656;
    cursor: pointer;
}

.toolbar-button.active {
    background: #e9e9e9;
    color: #202020;
}

.inventory-list {
    display: flex;
    align-content: flex-start;
    align-items: flex-start;
    flex: 1;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 12px 14px;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.inventory-token {
    max-width: 132px;
    touch-action: none;
}

.inventory-drag-preview {
    position: fixed;
    z-index: 40;
    max-width: 230px;
    pointer-events: none;
    box-shadow: 0 10px 22px rgb(0 0 0 / 18%);
    opacity: 0.96;
    transform: translateY(-1px);
}

.confirm-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 31;
    width: min(320px, 90vw);
    transform: translate(-50%, -50%);
    padding: 18px;
    border: 1px solid #d4d4d4;
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 12px 32px rgb(0 0 0 / 14%);
    text-align: center;
}

.restart-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 31;
    width: min(540px, 94vw);
    transform: translate(-50%, -50%);
    padding: 26px;
    border: 1px solid #dcdcdc;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 18px 52px rgb(0 0 0 / 18%), 0 1px 2px rgb(0 0 0 / 8%);
    text-align: center;
}

.target-complete-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 31;
    width: min(480px, 92vw);
    transform: translate(-50%, -50%);
    padding: 28px 26px 24px;
    border: 1px solid #d7d7d7;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 18px 54px rgb(0 0 0 / 18%), 0 1px 2px rgb(0 0 0 / 8%);
    text-align: center;
}

.target-complete-icon {
    display: inline-grid;
    width: 48px;
    height: 48px;
    margin-bottom: 13px;
    place-items: center;
    border: 1px solid #d7e4ff;
    border-radius: 999px;
    background: #eef5ff;
    color: #1d5bbf;
    font-size: 24px;
    line-height: 1;
}

.target-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 20px;
}

.target-stats div {
    display: grid;
    gap: 4px;
    min-height: 74px;
    align-content: center;
    padding: 12px 10px;
    border: 1px solid #e4e4e4;
    border-radius: 6px;
    background: #fafafa;
}

.target-stats span {
    color: #202020;
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}

.target-stats strong {
    color: #6a6a6a;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
}

.target-complete-actions {
    margin-top: 20px;
}

.dialog-title {
    color: #202020;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: 0;
}

.confirm-copy {
    margin: 9px auto 0;
    max-width: 390px;
    color: #666666;
    font-size: 13px;
    line-height: 1.45;
}

.mode-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 22px;
    padding: 5px;
    border: 1px solid #eeeeee;
    border-radius: 8px;
    background: #f7f7f7;
}

.mode-button {
    display: flex;
    min-height: 82px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #333333;
    cursor: pointer;
    line-height: 1.2;
    transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.mode-button:hover {
    background: #ffffff;
}

.mode-button.active {
    border-color: #c9d9ff;
    background: #ffffff;
    box-shadow: 0 1px 4px rgb(0 0 0 / 8%);
    color: #163b77;
    font-weight: 700;
}

.mode-icon {
    display: inline-grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border: 1px solid #dddddd;
    border-radius: 999px;
    background: #ffffff;
    color: #3a3a3a;
    font-size: 20px;
    line-height: 1;
}

.mode-button.active .mode-icon {
    border-color: #b8cffd;
    background: #eef5ff;
    color: #17498f;
}

.target-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    margin-top: 14px;
    padding: 8px 8px 8px 12px;
    border: 1px solid #dfdfdf;
    border-radius: 5px;
    background: #fafafa;
}

.target-preview-text {
    display: grid;
    min-width: 0;
    justify-items: start;
    gap: 2px;
}

.target-preview-text span {
    color: #777777;
    font-size: 13px;
}

.target-preview-text strong {
    max-width: 100%;
    overflow: hidden;
    color: #202020;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.target-reroll-button {
    display: inline-grid;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid #d4d4d4;
    border-radius: 5px;
    background: #ffffff;
    color: #333333;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.target-reroll-button:hover {
    border-color: #b8b8b8;
    background: #f6f6f6;
}

.target-input {
    width: 100%;
    height: 36px;
    margin-top: 14px;
    padding: 0 10px;
    border: 1px solid #d4d4d4;
    border-radius: 5px;
    outline: none;
}

.target-input:focus {
    border-color: #8c8c8c;
}

.confirm-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 14px;
}

.confirm-actions.compact {
    margin-top: 9px;
}

.confirm-actions button {
    min-width: 64px;
    height: 32px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    background: #f5f5f5;
    cursor: pointer;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 1000;
    padding: 10px 14px;
    border-radius: 5px;
    background: #fff0c2;
    box-shadow: 0 2px 12px rgb(0 0 0 / 18%);
}

#blazor-error-ui .dismiss {
    margin-left: 12px;
    cursor: pointer;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 760px) {
    .craft-game {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) 42vh;
    }

    .sidebar-resizer {
        display: none;
    }

    .inventory {
        border-top: 1px solid #d8d8d8;
        border-left: 0;
    }

    .brand {
        display: none;
    }

    .target-chip {
        top: 18px;
        max-width: calc(100vw - 44px);
    }

    .toast-message {
        top: 58px;
    }

    .toast-message {
        max-width: calc(100vw - 44px);
    }

    .merge-wait-dialog {
        width: min(320px, calc(100vw - 36px));
    }

    .restart-dialog {
        padding: 20px;
    }

    .target-complete-dialog {
        padding: 22px 18px 20px;
    }

    .target-stats {
        grid-template-columns: 1fr;
    }

    .mode-picker {
        grid-template-columns: 1fr;
    }

    .mode-button {
        min-height: 58px;
        flex-direction: row;
    }
}
