:root {
    --ink: #edf1ff;
    --muted: #8d91ab;
    --muted-strong: #b7b9ca;
    --canvas: #12131f;
    --panel: #1a1b2a;
    --panel-strong: #222337;
    --line: rgba(235, 239, 255, 0.1);
    --line-strong: rgba(235, 239, 255, 0.18);
    --violet: #8c7cff;
    --cyan: #62e2ec;
    --coral: #ff927f;
    --yellow: #f8d66d;
    --shadow: 0 20px 60px rgba(5, 6, 17, 0.38);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;
    --card-font-scale: 1;
    --card-icon-size: 20px;
    --preview-size: 120px;
    color-scheme: dark;
    font-family: "Manrope", "Noto Sans JP", system-ui, sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 78% -12%, rgba(113, 98, 255, 0.23), transparent 34rem),
        radial-gradient(circle at -8% 48%, rgba(59, 204, 219, 0.08), transparent 28rem),
        var(--canvas);
}

body.modal-open {
    overflow: hidden;
}

button, input {
    font: inherit;
}

button, summary {
    cursor: pointer;
}

button, a, input, summary {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 3px;
}

button {
    color: var(--ink);
}

a {
    color: var(--muted-strong);
    text-underline-offset: 4px;
}

a:hover {
    color: var(--cyan);
}

.app-shell {
    width: min(1720px, calc(100% - 56px));
    margin: 0 auto;
    padding: 20px 0 32px;
}

.topbar, .header-actions, .brand, .sidebar-header, .map-toolbar, .site-footer {
    display: flex;
    align-items: center;
}

.topbar {
    min-height: 54px;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    flex-shrink: 0;
    gap: 11px;
    color: var(--ink);
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 31px;
    height: 31px;
    border: 1px solid rgba(98, 226, 236, 0.6);
    border-radius: 9px;
    color: var(--cyan);
    font: 500 23px/1 "DM Mono", monospace;
    transform: rotate(-6deg);
}

.brand-name {
    font: 700 15px/1 "Space Grotesk", system-ui, sans-serif;
    letter-spacing: -0.02em;
}

.brand-name span {
    color: var(--cyan);
}

.header-actions {
    gap: 10px;
}

.source-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--panel);
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
}

.source-link:hover {
    border-color: var(--cyan);
    background: #222337;
    color: var(--cyan);
}

.view-link {
    font-size: 11px;
    padding: 10px 0;
    white-space: nowrap;
    text-decoration-color: var(--line-strong);
}

.sidebar-imports {
    margin-top: 20px;
}

.sidebar-imports .primary-button {
    width: 100%;
    justify-content: space-between;
    color: var(--canvas);
}

.sidebar-imports p {
    margin: 10px 0 20px;
    color: var(--muted-strong);
    font-size: 10px;
    line-height: 1.6;
}

.primary-button, .secondary-button, .direction-buttons button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted-strong);
    font-size: 12px;
    font-weight: 700;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.primary-button {
    color: white;
    border-color: var(--violet);
    background: var(--violet);
    box-shadow: 0 8px 22px rgba(140, 124, 255, 0.22);
}

.primary-button:hover {
    background: #a298ff;
    border-color: #a298ff;
}

.secondary-button:hover, .direction-buttons button:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: rgba(255, 255, 255, 0.04);
}

.workspace {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 18px;
    align-items: stretch;
    margin-top: 20px;
}

.sidebar, .map-panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: rgba(25, 26, 42, 0.86);
    box-shadow: var(--shadow);
}

.sidebar {
    position: sticky;
    top: 20px;
    overflow: hidden;
}

.sidebar-header {
    justify-content: space-between;
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--line);
}

.sidebar-header h2 {
    margin: 0;
    font: 600 18px/1.1 "Space Grotesk", system-ui, sans-serif;
    letter-spacing: -0.03em;
}

.sidebar-content {
    padding: 20px;
}

.section-label {
    margin: 0 0 11px;
    color: var(--cyan);
    font: 500 11px/1.2 "DM Mono", monospace;
}

.scene-buttons {
    display: grid;
    gap: 8px;
}

.scene-buttons button {
    position: relative;
    padding: 11px 13px;
    border: 1px solid transparent;
    border-radius: 11px;
    text-align: left;
    color: var(--muted-strong);
    background: rgba(11, 12, 23, 0.28);
    transition: background 160ms ease, border-color 160ms ease;
}

.scene-buttons button:hover {
    border-color: var(--line-strong);
    color: var(--ink);
}

.scene-buttons button.active {
    border-color: rgba(140, 124, 255, 0.5);
    background: rgba(140, 124, 255, 0.14);
    color: var(--ink);
}

.scene-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
}

.scene-caption {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.4;
}

.scene-buttons button.active .scene-caption {
    color: #c3b4ff;
}

.scene-buttons button.super-rare {
    border-color: #ff927fa6;
    background: #ff927f1f;
    color: #ffe2d8;
    box-shadow: 0 0 10px #ff927f19;
    animation: rare-map-glow 3s ease-in-out infinite;
}

.scene-buttons button.super-rare .scene-caption {
    color: #ffbdaf;
}

.scene-buttons button.super-rare.active {
    border-color: #ffd4b5;
    background: #ff927f33;
}

@keyframes rare-map-glow {
    0%, 100% { box-shadow: 0 0 10px #ff927f19; }
    50% { box-shadow: 0 0 18px #ff927f4d, inset 0 0 12px #ff927f0d; }
}

.scene-buttons button.super-rare::after {
    position: absolute;
    top: 15px;
    right: 12px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--coral);
    box-shadow: 0 0 0 4px rgba(255, 146, 127, 0.1);
    content: "";
}

.display-mode-toggle {
    margin-top: 24px;
}

.map-legend {
    margin: 11px 0 0;
    color: var(--muted);
    font-size: 10px;
}

.map-legend span {
    margin-right: 5px;
    color: var(--coral);
    font-size: 8px;
}

.toggle-buttons {
    display: flex;
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: rgba(13, 14, 25, 0.56);
}

.mode-button {
    flex: 1;
    min-width: 0;
    padding: 10px 4px;
    border: 0;
    border-radius: 8px;
    color: var(--muted-strong);
    background: transparent;
    font-size: 11px;
    font-weight: 600;
}

.mode-button.active {
    color: #191926;
    background: #b18bff;
}

.beta-badge {
    margin-left: 2px;
    opacity: 0.7;
}

.filter-button {
    width: 100%;
    margin-top: 14px;
}

.filter-panel {
    display: none;
    margin-top: 10px;
}

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

.filter-options {
    display: grid;
    gap: 3px;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px;
    border-radius: 8px;
    color: var(--muted-strong);
    font-size: 11px;
}

.filter-option:has(input:checked) {
    background: rgba(140, 124, 255, 0.1);
    color: var(--ink);
}

.filter-option label, .item-checkbox label {
    cursor: pointer;
}

input[type="radio"], input[type="checkbox"] {
    flex: none;
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--violet);
    cursor: pointer;
}

.item-checkbox-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    max-height: 230px;
    margin-top: 8px;
    padding: 8px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(11, 12, 23, 0.28);
}

.item-checkbox {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.item-checkbox label {
    display: flex;
}

.item-checkbox img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.controls details {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.controls summary {
    color: var(--muted-strong);
    font-size: 11px;
    font-weight: 600;
    user-select: none;
}

.controls details[open] summary {
    margin-bottom: 14px;
    color: var(--ink);
}

.calibration-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.calibration-fields label {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.5;
}

.calibration-fields label:first-child {
    grid-column: 1 / -1;
}

.calibration-fields input {
    width: 100%;
    min-width: 0;
    margin-top: 5px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(13, 14, 25, 0.56);
    color: var(--ink);
    font-size: 12px;
}

.action-buttons, .direction-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 10px;
}

.action-buttons button, .direction-buttons button {
    min-height: 36px;
    padding: 0 8px;
    font-size: 10px;
}

.log-container {
    height: 150px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(11, 12, 23, 0.28);
    overflow: hidden;
}

.log-scroll {
    height: 100%;
    padding: 10px;
    overflow-y: auto;
    font: 400 9px/1.6 "DM Mono", monospace;
    overflow-wrap: anywhere;
}

.log-entry {
    margin-bottom: 6px;
}

.timestamp {
    margin-right: 6px;
    color: var(--cyan);
}

.message {
    color: var(--muted-strong);
}

.map-panel {
    padding: 20px;
}

.map-toolbar {
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.map-toolbar h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.03em;
}

.map-toolbar p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

.data-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: 38%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 99px;
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-status::before {
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    content: "";
}

.data-status.is-loaded {
    color: var(--muted-strong);
    border-color: rgba(98, 226, 236, 0.25);
}

.data-status.is-loaded::before {
    background: var(--cyan);
}

.container {
    position: relative;
    width: 100%;
    max-width: 1920px;
    overflow: auto;
    border-radius: var(--radius-md);
    scrollbar-width: thin;
    scrollbar-color: #7467c5 #1b2030;
}

.image-container {
    position: relative;
    width: 100%;
    min-width: 1024px;
    border-radius: var(--radius-md);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

#image {
    display: block;
    width: 100%;
    height: auto;
}

.grid-canvas, .drag-overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.drag-overlay-canvas {
    z-index: 9999;
}

/* Overlay dimensions stay in display pixels so locations and dragging remain aligned. */
.item-list {
    --card-accent: #5cbac4;
    position: absolute;
    display: grid;
    gap: 3px;
    width: max-content;
    max-width: calc(100% - 16px);
    padding: 5px 7px 5px 6px;
    border: 1px solid #485366;
    border-left: 3px solid var(--card-accent);
    border-radius: 9px;
    background: #1b2030;
    box-shadow: 0 3px 8px rgba(5, 6, 17, 0.3);
    text-align: left;
    transform: translate3d(0, 0, 0);
    z-index: 1;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
    touch-action: none;
}

.item-list:hover {
    border-color: var(--card-accent);
}

.item-list.horizontal {
    display: flex;
    flex-wrap: wrap;
    column-gap: 7px;
}

.item-list.rare-card {
    --card-accent: #bd9bf7;
    border-color: #87749f;
    border-left-color: var(--card-accent);
    background: #302b43;
}

.item-list.super-rare-card {
    --card-accent: #ffa5b7;
    border-color: #a17083;
    border-left-color: var(--card-accent);
    background: #452d3c;
}

.reward-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.item-list img {
    display: block;
    flex: none;
    width: var(--card-icon-size);
    height: var(--card-icon-size);
    object-fit: contain;
    border-radius: 3px;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
}

.item-list .quantity {
    min-width: 1ch;
    color: #f4f5ff;
    font-size: clamp(11px, calc(12px * var(--card-font-scale)), 13px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    text-align: right;
    pointer-events: none;
}

.group-count {
    position: absolute;
    top: -8px;
    right: -5px;
    min-width: 27px;
    padding: 2px 5px;
    border: 1px solid #d8c8ff;
    border-radius: 6px;
    background: #c4a8ff;
    color: #211832;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

.item-preview {
    display: none;
    position: fixed;
    padding: 12px;
    border: 1px solid rgba(98, 226, 236, 0.4);
    border-radius: var(--radius-md);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
    z-index: 10000;
    pointer-events: none;
}

.item-preview.active {
    display: block;
}

.item-preview img {
    width: var(--preview-size);
    height: var(--preview-size);
    max-width: 70vw;
    max-height: 50vh;
    object-fit: contain;
}

.item-preview-name {
    margin-top: 8px;
    color: var(--ink);
    font-size: 12px;
    text-align: center;
}

.item-summary {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.item-summary h3 {
    margin: 0 0 14px;
    font: 600 14px/1.2 "Space Grotesk", system-ui, sans-serif;
    letter-spacing: -0.02em;
}

.item-summary-content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.item-summary-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 10px 7px 7px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(11, 12, 23, 0.28);
}

.item-summary-item img {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.item-summary-quantity {
    color: var(--cyan);
    font-size: 12px;
    font-weight: 700;
}

.item-summary-empty {
    padding: 12px 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

.site-footer {
    justify-content: space-between;
    gap: 18px;
    margin-top: 22px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.6;
}

.site-footer p {
    margin: 0;
}

.site-footer nav {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
}

.site-footer a {
    text-decoration: none;
}

.menu-toggle, .sidebar-close, .sidebar-overlay {
    display: none;
}

.icon-button {
    display: grid;
    place-items: center;
    flex: none;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    color: var(--muted-strong);
    font-size: 22px;
    line-height: 1;
}

.icon-button:hover {
    border-color: var(--line-strong);
    color: var(--ink);
}

.sidebar-close {
    display: none;
}

.drop-zone-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(5, 6, 17, 0.76);
    backdrop-filter: blur(6px);
    z-index: 20000;
}

.drop-zone-backdrop.hidden {
    display: none;
}

.drop-zone {
    position: relative;
    width: min(460px, 100%);
    padding: 44px 34px 30px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.drop-zone.drag-over {
    border-color: var(--cyan);
    background: #202735;
}

.drop-zone-close {
    position: absolute;
    top: 12px;
    right: 12px;
}

.drop-zone-content {
    text-align: center;
}

.drop-icon {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0 auto 20px;
    border: 1px dashed rgba(98, 226, 236, 0.45);
    border-radius: 14px;
    color: var(--cyan);
    font-size: 30px;
}

.drop-zone h2 {
    margin: 0 0 12px;
    font: 600 28px/1.1 "Space Grotesk", system-ui, sans-serif;
    letter-spacing: -0.04em;
}

.drop-hint {
    margin: 0 0 24px;
    color: var(--muted-strong);
    font-size: 13px;
    line-height: 1.7;
}

.import-note {
    margin: 18px 0 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.6;
}

#hiddenFileInput {
    display: none;
}

.data-loaded-indicator, .data-error-indicator {
    position: fixed;
    right: 22px;
    bottom: 22px;
    max-width: min(400px, calc(100% - 44px));
    padding: 12px 15px;
    border: 1px solid rgba(98, 226, 236, 0.35);
    border-radius: 11px;
    color: var(--ink);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
    font-size: 12px;
    overflow-wrap: anywhere;
    z-index: 21000;
}

.data-error-indicator {
    border-color: rgba(255, 146, 127, 0.55);
    color: #ffb9ab;
}

.sidebar, .item-checkbox-list, .log-scroll {
    scrollbar-width: thin;
    scrollbar-color: #7467c5 transparent;
}

@media (pointer: coarse) {
    .view-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
    }
}

@media (min-width: 1001px) {
    body:not(.render-mode) .workspace {
        height: max(560px, calc(100dvh - 164px));
    }

    body:not(.render-mode) .sidebar,
    body:not(.render-mode) .map-panel {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    body:not(.render-mode) .sidebar {
        position: relative;
        top: auto;
    }

    body:not(.render-mode) .sidebar-header,
    body:not(.render-mode) .map-toolbar {
        flex: none;
    }

    body:not(.render-mode) .sidebar-content {
        min-height: 0;
        overflow-y: auto;
    }

    body:not(.render-mode) .container {
        flex: 1;
        min-height: 0;
    }

    body:not(.render-mode) .item-summary {
        flex: none;
        max-height: 25%;
        overflow-y: auto;
    }
}

@media (max-width: 1000px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .menu-toggle {
        display: flex;
        width: 42px;
        padding: 0;
        font-size: 18px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(320px, calc(100% - 32px));
        height: 100dvh;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
        overflow-y: auto;
        background: var(--panel);
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform 180ms ease, visibility 180ms;
        z-index: 15000;
    }

    .sidebar.active {
        transform: translateX(0);
        visibility: visible;
    }

    .sidebar-header {
        position: sticky;
        top: 0;
        background: var(--panel);
        z-index: 1;
    }

    .sidebar-close {
        display: grid;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        display: block;
        background: rgba(5, 6, 17, 0.7);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 180ms ease, visibility 180ms;
        z-index: 14000;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

@media (max-width: 600px) {
    .app-shell {
        width: calc(100% - 28px);
        padding-top: 12px;
    }

    .topbar {
        gap: 10px;
        flex-wrap: wrap;
    }

    .brand {
        gap: 8px;
    }

    .header-actions {
        gap: 6px;
        margin-left: auto;
    }

    .source-link {
        padding: 0 10px;
        font-size: 11px;
    }

    .view-link {
        font-size: 10px;
    }

    .primary-button {
        padding: 0 11px;
        font-size: 11px;
    }

    .map-panel {
        padding: 14px;
        border-radius: 18px;
    }

    .map-toolbar {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 14px;
    }

    .map-toolbar h2 {
        font-size: 15px;
    }

    .map-toolbar p {
        font-size: 10px;
    }

    .data-status {
        max-width: 100%;
    }

    .image-container {
        border-radius: 10px;
    }

    .item-summary {
        margin-top: 16px;
        padding-top: 16px;
    }

    .item-summary-item {
        gap: 5px;
        padding: 5px 8px 5px 5px;
    }

    .item-summary-item img {
        width: 25px;
        height: 25px;
    }

    .site-footer {
        align-items: start;
        flex-direction: column;
        gap: 8px;
        margin-top: 18px;
    }

    .drop-zone {
        padding: 44px 24px 26px;
    }
}

/* Keep the HTTP renderer's map geometry independent of the interactive page layout. */
body.render-mode {
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
}

.render-mode .app-shell {
    width: 100%;
    max-width: none;
    padding: 0;
}

.render-mode .workspace {
    display: block;
    margin-top: 0;
}

.render-mode .topbar, .render-mode .sidebar,
.render-mode .sidebar-overlay, .render-mode .map-toolbar, .render-mode .item-summary,
.render-mode .site-footer, .render-mode .data-loaded-indicator, .render-mode .data-error-indicator {
    display: none;
}

.render-mode .map-panel {
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.render-mode .image-container {
    min-width: 0;
    border-radius: 16px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
        animation: none !important;
    }
}
