:root {
    --primary-color: #1976d2;
    --primary-hover: #1565c0;
    --primary-light: #e3f2fd;
    --primary-active: #0d47a1;
    --bg-color: #f4f6f8;
    --card-bg: #ffffff;
    --text-color: #333333;
    --text-muted: #666666;
    --border-color: #e0e0e0;
    --radius: 12px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    --transition: all 0.2s ease;
}

* {
    box-sizing: border-box;
    font-feature-settings: "palt";
    -webkit-font-feature-settings: "palt";
}

body, button, input, select, textarea {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    font-feature-settings: "palt";
    -webkit-font-feature-settings: "palt";
    margin: 0;
    padding: 0;
}

body {
    padding: 15px 10px 40px 10px;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

/* Header & Meta */
.header-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5px;
    margin-bottom: 12px;
}

.version-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.version-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
    font-weight: bold;
    background: #e9ecef;
    padding: 2px 8px;
    border-radius: 4px;
}

.changelog-link {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: underline;
    transition: var(--transition);
}

.changelog-link:hover {
    color: var(--primary-color);
}

.credit-link {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.credit-link strong {
    color: #444;
    text-decoration: underline;
}

.credit-link:hover {
    text-decoration: underline;
    color: var(--primary-color);
}

h1.main-title {
    font-size: 1.5rem;
    margin: 0;
    padding: 0 5px;
    line-height: 1.3;
    color: var(--primary-color);
    font-weight: 900;
}

.main-title .sub-title {
    font-size: 0.75em;
    color: #555;
    font-weight: 700;
}

.eng-title {
    font-size: 0.65rem;
    color: #a0a0a0;
    text-transform: uppercase;
    padding: 0 5px;
    margin-top: 4px;
    margin-bottom: 20px;
    letter-spacing: 0.8px;
    font-weight: 700;
}

/* Card layout */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.card-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 15px;
    color: #222;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 2px solid #ccc;
    padding-bottom: 8px;
}

.card-title svg {
    width: 20px;
    height: 20px;
    fill: var(--primary-color);
}

/* Dropzone for Image Upload */
.dropzone {
    border: 2px dashed #ccc;
    border-radius: 10px;
    padding: 25px 15px;
    text-align: center;
    background: #fafafa;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.dropzone-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 10px auto;
    fill: var(--primary-color);
}

.dropzone-text {
    font-weight: 700;
    font-size: 0.95rem;
    color: #444;
    margin-bottom: 4px;
}

.dropzone-subtext {
    font-size: 0.75rem;
    color: #888;
}

.file-input {
    display: none;
}

.dropzone-privacy-note {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
    margin: 10px 0 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.dropzone-privacy-note .privacy-icon {
    flex-shrink: 0;
    color: var(--primary-color);
}

.dropzone-controls {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 700;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: #f0f4f8;
    color: #333333;
    border: 1px solid #d0d7de;
}

.btn-secondary:hover {
    background-color: #e1e8f0;
    color: #111111;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
}

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

/* Custom Dropdown for Aspect Ratio Selector (Matched with uma-hyper-recovery) */
.aspect-ratio-selector {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* Aspect Ratio Header & Orientation Toggle */
.ratio-header-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.ratio-header-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: #475569;
}

.orientation-toggle-container {
    display: inline-flex;
    background: #e2e8f0;
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}

.orient-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #64748b;
    cursor: pointer;
    transition: var(--transition);
}

.orient-btn:hover {
    color: #1e293b;
}

.orient-btn.active {
    background: #ffffff;
    color: var(--primary-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.custom-dropdown {
    position: relative;
    display: inline-block;
    width: 100%;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: var(--card-bg);
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #334155;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.dropdown-trigger:hover {
    border-color: var(--primary-color);
    background: #f8fafc;
}

.dropdown-trigger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.2);
}

.dropdown-selected-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
}

.dropdown-selected-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-align: left;
}

.dropdown-chevron {
    transition: transform 0.2s ease;
    color: #64748b;
    flex-shrink: 0;
}

.custom-dropdown.open .dropdown-chevron {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 200;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 6px 0;
    display: none;
    flex-direction: column;
    max-height: 280px;
    overflow-y: auto;
}

.custom-dropdown.open .dropdown-menu {
    display: flex;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    width: 100%;
    border: none;
    background: transparent;
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.dropdown-item:hover {
    background: #f1f5f9;
    color: var(--primary-color);
}

.dropdown-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 700;
}

.dropdown-item svg {
    flex-shrink: 0;
    color: currentColor;
}

.custom-ratio-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.custom-ratio-group input[type="number"] {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
    text-align: center;
}

/* Mode Selection Cards */
.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

@media (max-width: 580px) {
    .mode-selector {
        grid-template-columns: 1fr;
    }
}

.mode-card {
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px;
    cursor: pointer;
    transition: var(--transition);
    background: #ffffff;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.mode-card:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.mode-card.active {
    border-color: var(--primary-color);
    background: #f0f7ff;
}

.mode-card .mode-radio {
    margin-top: 3px;
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
}

.mode-info h4 {
    margin: 0 0 4px 0;
    font-size: 0.9rem;
    color: #1e293b;
}

.mode-info p {
    margin: 0;
    font-size: 0.75rem;
    color: #64748b;
    line-height: 1.4;
}

/* Editor Workspace (65svh Max Height) */
.editor-workspace {
    position: relative;
    max-height: 65svh;
    background: #0f172a;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
    touch-action: none;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
}

.workspace-canvas-container {
    position: relative;
    display: inline-block;
    width: fit-content;
    height: fit-content;
    max-height: 65svh;
    line-height: 0;
    margin: auto;
    flex-shrink: 0;
}

#editorCanvas {
    display: block;
    max-width: 100%;
    max-height: 65svh;
    width: auto;
    height: auto;
}

#handlesOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

/* Centered Loupe Widget with Integrated Direction Arrow Buttons */
.loupe-widget {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 165px;
    height: 165px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 100;
    transition: top 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), left 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.loupe {
    position: relative;
    width: 110px;
    height: 110px;
    box-sizing: content-box;
    border-radius: 50%;
    border: 3px solid #ffffff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), inset 0 0 10px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    background: #0f172a;
    pointer-events: auto;
}

.loupe-canvas {
    width: 110px;
    height: 110px;
    display: block;
}

/* Direction Arrow Nudge Buttons Floating Around Loupe */
.loupe-nudge-btn {
    position: absolute;
    width: 32px;
    height: 32px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    transition: var(--transition);
    z-index: 101;
    padding: 0;
}

.loupe-nudge-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    transform: scale(1.1);
}

.loupe-nudge-btn:active {
    transform: scale(0.95);
    background: var(--primary-color);
}

.loupe-nudge-btn:active svg {
    stroke: #ffffff;
}

.loupe-nudge-btn svg {
    width: 18px;
    height: 18px;
    stroke: #1e293b;
}

.loupe-nudge-btn.up { top: -2px; left: 50%; transform: translateX(-50%); }
.loupe-nudge-btn.down { bottom: -2px; left: 50%; transform: translateX(-50%); }
.loupe-nudge-btn.left { left: -2px; top: 50%; transform: translateY(-50%); }
.loupe-nudge-btn.right { right: -2px; top: 50%; transform: translateY(-50%); }

.loupe-nudge-btn.up:hover { transform: translateX(-50%) scale(1.1); }
.loupe-nudge-btn.down:hover { transform: translateX(-50%) scale(1.1); }
.loupe-nudge-btn.left:hover { transform: translateY(-50%) scale(1.1); }
.loupe-nudge-btn.right:hover { transform: translateY(-50%) scale(1.1); }

.loupe-step-toggle {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: #1e293b;
    color: #ffffff;
    border: 2px solid var(--primary-color);
    border-radius: 14px;
    padding: 5px 11px;
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
    transition: var(--transition);
    z-index: 102;
    line-height: 1;
}

.loupe-step-toggle:hover {
    background: var(--primary-color);
    transform: scale(1.08);
}



/* Result Section & Preview Containment */
.result-container {
    margin-top: 15px;
    text-align: center;
}

.result-canvas-wrapper {
    width: 100%;
    max-width: 100%;
    max-height: 60vh;
    max-height: 60svh;
    background: transparent;
    border-radius: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    border: none;
    overflow: hidden;
}

#previewCanvas {
    max-width: 100%;
    max-height: 55vh;
    max-height: 55svh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.result-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 15px;
}

/* Toast (Matched with uma-hyper-recovery) */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30, 30, 30, 0.9);
    color: #ffffff;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: bold;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 10000;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

.toast svg {
    width: 18px;
    height: 18px;
    stroke: #4ade80;
}

/* Modal Dialog */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 15px;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #ffffff;
    border-radius: 14px;
    max-width: 760px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.25s ease;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 14px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: var(--transition);
}

.modal-close-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    text-align: center;
    background: #f1f5f9;
}

.modal-canvas-wrapper {
    max-width: 100%;
    max-height: 55vh;
    overflow: auto;
    background: transparent;
    border-radius: 0;
    padding: 0;
    display: inline-block;
    box-shadow: none;
    border: none;
}

#modalResultCanvas, #modalResultImg {
    max-width: 100%;
    max-height: 50vh;
    height: auto;
    display: block;
    margin: 0 auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    background: #ffffff;
}

/* Loading Overlay for Modal */
.modal-loading {
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    font-weight: bold;
    color: var(--primary-color);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid var(--primary-light);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
