:root {
    color-scheme: dark;
    --bg: #121212;
    --panel: #1f1f1f;
    --panel-border: #2f2f2f;
    --text: #f5f5f5;
    --muted: #bdbdbd;
    --accent: #7c4dff;
    --accent-strong: #6a3dff;
    --success: #4caf50;
    --warn: #ffb300;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
}

.toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: block;
    flex-direction: column;
    gap: 12px;
    padding: 16px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--panel-border);
    flex: 0 0 auto;
}

.toolbar h3 {
    margin: 0 0 6px;
}

.toolbar-subtitle {
    font-size: 0.9rem;
    color: var(--muted);
    margin: 0;
    font-style: italic;
}

.status {
    margin: 0;
    color: var(--success);
    font-weight: 600;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.map-select {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.95rem;
}

.map-select-stack {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.map-select-note {
    font-size: 0.75rem;
    color: #9fa4ad;
    line-height: 1.25;
}

.crop-enhance-toggle {
    margin-right: auto;
}

.map-select input[type="checkbox"] {
    accent-color: var(--accent);
}

.map-select select {
    background: #2b2b2b;
    color: var(--text);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 6px 10px;
}

.map-switcher {
    display: flex;
    background: #2b2b2b;
    border-radius: 6px;
    padding: 3px;
    border: 1px solid var(--panel-border);
    gap: 2px;
    align-items: center;
}

.actions button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #3a3a3a;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s ease;
}

.actions .map-switcher button {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.actions .map-switcher button:hover:not(:disabled) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.actions .map-switcher button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.actions .map-switcher button.active {
    background: var(--accent);
    color: white;
    font-weight: 500;
}

.issue-report-link {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: rgba(31, 31, 31, 0.95);
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: background 0.2s ease;
}

.issue-report-link svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex: 0 0 auto;
}

.issue-report-link:hover {
    background: #2a2a2a;
}

.issue-report-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.actions button:hover:not(:disabled) {
    background: #4a4a4a;
}

.actions button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.actions .primary {
    background: var(--accent);
}

.actions .primary:hover:not(:disabled) {
    background: var(--accent-strong);
}

.hint {
    color: var(--muted);
    font-size: 0.9rem;
}

.content {
    padding: 12px 15px 15px;
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.preview-modal-container {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    position: relative; /* Context for absolute positioning of close button */
    padding-top: 40px; /* Make space for close button */
    overflow: hidden; /* Prevent body scroll, use internal scroll */
}

/* Close button on top-right */
.top-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    transition: color 0.2s;
    padding: 0;
}

.top-close-btn:hover {
    color: var(--text);
}

.top-close-btn:disabled {
    cursor: not-allowed;
    opacity: 0.3;
}

.preview-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.preview-header h3 {
    margin: 0;
}

.preview-controls {
    padding-right: 28px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.preview-controls button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #3a3a3a;
    color: var(--text);
    cursor: pointer;
}

.preview-controls button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.preview-canvas-wrap {
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 10px;
    background: #0f0f0f;
    overflow: auto;
    flex: 1;
    min-height: 100px; /* Ensure at least some canvas visible */
}

.preview-canvas-wrap canvas {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

.drop-zone {
    position: relative;
    border: 2px dashed var(--panel-border);
    border-radius: 10px;
    padding: 0;
    background: #0f0f0f;
    min-height: 0;
    overflow: hidden;
    height: 100%;
    flex: 1;
}

.drop-zone.is-dragging {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(124, 77, 255, 0.4);
}

.drop-zone canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    margin: 0 auto;
    cursor: grab;
}

.drop-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.6);
    font-size: 1.2rem;
    color: var(--text);
    border-radius: 10px;
    pointer-events: none;
    z-index: 5;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s ease-in-out infinite;
}

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

.loading-overlay {
    background: rgba(18, 18, 18, 0.85); /* Darker opaque background for loading */
    pointer-events: auto; /* Block interactions */
}

.hidden {
    display: none;
}

.offscreen {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    left: -9999px;
    top: -9999px;
}

.crop-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    z-index: 100;
}

.crop-container {
    background: var(--panel);
    padding: 20px;
    border-radius: 12px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    border: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
}

.crop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.crop-container h3 {
    margin: 0;
}

.crop-title-group {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.crop-canvas {
    display: block;
    border: 2px solid var(--panel-border);
    max-width: 100%;
    max-height: 70vh;
    cursor: crosshair;
}

.crop-status {
    margin: 6px 0 0;
    color: var(--warn);
}

.crop-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.crop-controls button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #3a3a3a;
    color: var(--text);
    cursor: pointer;
}

.crop-controls .confirm {
    background: var(--success);
}

.confirm-container {
    max-width: 400px;
    width: 90vw;
}

.confirm-content {
    margin: 10px 0 20px;
    line-height: 1.5;
    color: var(--muted);
}

.crop-wrapper-outer {
    display: block;
    border: 2px solid var(--panel-border);
    width: 100%;
    height: 60vh;
    overflow: hidden;
    margin-bottom: 20px;
    background: #000;
}

.crop-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

#cropImage {
    display: block;
    max-width: 100%;
}

#cropEditCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

.crop-edit-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 0;
}

.crop-edit-toolbar button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #3a3a3a;
    color: var(--text);
    cursor: pointer;
}

.crop-edit-toolbar button.active {
    background: var(--accent);
}

.crop-edit-toolbar button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.brush-size-control {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.brush-size-control input[type="range"] {
    width: 180px;
}


.instructions {
    position: fixed;
    top: auto;
    bottom: 20px;
    right: 20px;
    width: calc(100% - 40px);
    max-width: 400px;
    background: rgba(31, 31, 31, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: width 0.3s ease, transform 0.3s ease;
    overflow: hidden;
}

.instructions.collapsed {
    width: auto;
    min-width: 120px;
}

.instructions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    user-select: none;
    font-weight: 500;
    gap: 8px;
}

.instructions-header:hover {
    background: rgba(255, 255, 255, 0.08);
}

.instructions-header .icon {
    font-size: 1.1rem;
}

.instructions-header .toggle-icon {
    font-size: 0.8rem;
    color: var(--muted);
    transition: transform 0.3s ease;
}

.instructions.collapsed .toggle-icon {
    transform: rotate(90deg);
}

.instructions-content {
    padding: 12px;
    border-top: 1px solid var(--panel-border);
    max-height: 400px;
    overflow-y: auto;
}

.instructions ol {
    margin: 0;
    padding-left: 20px;
    line-height: 1.6;
    color: var(--muted);
    font-size: 0.9rem;
}

.instructions li + li {
    margin-top: 8px;
}

.update-log {
    margin-top: 20px;
    padding-top: 5px;
    border-top: 1px solid var(--panel-border);
}

.log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 8px; /* Slightly more padding */
    margin: -8px; /* Negative margin to expand clickable area */
    margin-bottom: 5px;
    border-radius: 4px;
}

.log-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.log-content {
    margin-top: 10px;
    padding-left: 5px;
}

.log-loading {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.log-error {
    margin: 0;
    color: #ff8a80;
    font-size: 0.9rem;
}


.log-header h4 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 500;
}

.toggle-icon {
    font-size: 0.8rem;
    color: var(--muted);
}

.log-content ul {
    margin: 0;
    padding-left: 0;
    list-style: none;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.log-content > ul > li {
    margin-bottom: 12px;
    position: relative;
    padding-left: 10px;
}

/* Version Header */
.update-log .version {
    display: inline-block;
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    background: var(--accent);
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
}

/* Sub-list items */
.log-content ul ul {
    list-style: disc;
    padding-left: 20px;
    margin-top: 4px;
}

.log-content ul ul li {
    margin-bottom: 4px;
    padding-left: 0;
}

.crop-hint {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
}


/* Overwrite toolbar display for 2-column layout */
/* Since instructions are moved out, we can simplify toolbar */
.toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-main {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.toolbar-main > div {
    align-items: center;
    gap: 12px;
}

.toolbar-header h3 {
    white-space: nowrap;
}

.status-row {
    width: 100%;
    margin-top: 4px;
}

.status {
    margin: 0;
    color: var(--success);
    font-weight: 600;
}

@media (max-width: 600px) {
    .issue-report-link {
        top: 12px;
        right: 12px;
        padding: 7px 10px;
        font-size: 0.85rem;
    }
}

/* Export UI */
.export-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    background: #1f1f1f;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    margin-top: 15px;
}

.export-options-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    flex: 1; /* Allow it to grow */
}

/* Base styles for buttons in export bar */
.export-bar button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #3a3a3a;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
}

/* Specific styles for format switcher buttons to override general buttons */
.format-switcher {
    display: flex;
    background: #2b2b2b;
    border-radius: 6px;
    padding: 2px;
    border: 1px solid var(--panel-border);
}

.format-switcher button {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    margin: 0 !important;
}

.format-switcher button.active {
    background: var(--accent);
    color: white;
    font-weight: 500;
}

.quality-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(43, 43, 43, 0.6);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
}

.quality-slider .label {
    font-size: 0.85rem;
    color: var(--muted);
    min-width: 60px;
}

.quality-slider input[type="range"] {
    width: 80px;
    height: 4px;
    accent-color: var(--accent);
}

.format-hint {
    font-size: 0.8rem;
    color: var(--muted);
    margin-left: 10px;
    align-self: center;
}

.hint-text {
    display: inline-block;
}

@media(max-width: 600px) {
    .export-options-group {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }
    .format-hint {
        margin-left: 0;
        margin-top: 5px;
    }
}

.right-group {
    display: flex;
    align-items: center;
    margin-left: auto;
    gap: 15px;
}

.main-actions {
    display: flex;
    gap: 10px;
}

/* Ensure buttons in main-actions look right */
.main-actions button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #3a3a3a;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
}

.main-actions .confirm {
    background: var(--success);
}

.export-ui {
    background: #252525;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

.export-status {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.export-status .status-text {
    color: var(--text);
    font-weight: 500;
}

.export-status .progress-track {
    background: rgba(0, 0, 0, 0.4);
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    width: 100%;
}

.export-status .progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s ease;
}

.export-status .progress-text {
    align-self: flex-end;
    font-size: 0.85rem;
    color: var(--muted);
}

.export-result {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    background: #1f1f1f;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
}

.result-file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 500;
}

.result-file-info .badge {
    background: var(--accent);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
}

.result-file-info .format-badge {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--panel-border);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.result-file-info .dim-info {
    color: var(--muted);
    font-size: 0.85rem;
    margin-left: 5px;
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.action-buttons button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #3a3a3a;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s;
}

.action-buttons button:hover {
    background: #4a4a4a;
}

.result-actions .confirm {
    background: var(--success);
    color: #fff;
}

