:root {
    --bg-color: #0b1020;
    --bg-color-2: #111a33;
    --bg-color-3: #0f1324;

    --panel-bg-color: rgba(18, 24, 45, 0.72);
    --panel-bg-color-strong: rgba(18, 24, 45, 0.88);
    --control-bg-color: rgba(35, 44, 74, 0.78);

    --text-color: #e7ecff;
    --text-muted: #9ca7d8;
    --accent-color: #6ea8ff;
    --accent-color-2: #7c5cff;
    --accent-glow: rgba(110, 168, 255, 0.42);
    --accent-glow-2: rgba(124, 92, 255, 0.34);

    --border-color: rgba(155, 173, 255, 0.16);
    --border-color-strong: rgba(155, 173, 255, 0.26);

    --shadow-1: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 20px 60px rgba(0, 0, 0, 0.45);
    --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-color);
    overflow: hidden;
    background:
        radial-gradient(circle at top left, rgba(110, 168, 255, 0.22), transparent 30%),
        radial-gradient(circle at top right, rgba(124, 92, 255, 0.18), transparent 28%),
        radial-gradient(circle at bottom left, rgba(0, 255, 204, 0.10), transparent 24%),
        linear-gradient(135deg, var(--bg-color) 0%, var(--bg-color-2) 45%, var(--bg-color-3) 100%);
    background-attachment: fixed;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.01)),
        repeating-linear-gradient(180deg,
            rgba(255, 255, 255, 0.018) 0px,
            rgba(255, 255, 255, 0.018) 1px,
            transparent 1px,
            transparent 3px);
    mix-blend-mode: overlay;
    opacity: 0.5;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh; /* Dynamic viewport height */
    width: 100vw;
    position: relative;
    isolation: isolate;
}

.menu-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
    background: linear-gradient(180deg,
            rgba(24, 31, 58, 0.82),
            rgba(16, 21, 39, 0.68));
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    box-shadow: var(--shadow-1), var(--shadow-inset);
    flex-wrap: wrap;
}

.menu-item {
    position: relative;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
    border: 1px solid transparent;
    border-radius: 999px;
    transition:
        transform 0.18s ease,
        background-color 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        color 0.18s ease;
    user-select: none;
}



.menu-item:hover {
    background: linear-gradient(135deg, rgba(110, 168, 255, 0.18), rgba(124, 92, 255, 0.14));
    border-color: var(--border-color-strong);
    box-shadow:
        0 0 0 1px rgba(110, 168, 255, 0.16) inset,
        0 8px 24px rgba(0, 0, 0, 0.28),
        0 0 24px var(--accent-glow);
    transform: translateY(-1px);
}

.menu-item:active {
    transform: translateY(0);
}

.menu-popup {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: linear-gradient(180deg,
            rgba(24, 30, 58, 0.92),
            rgba(15, 20, 36, 0.92));
    border: 1px solid var(--border-color-strong);
    min-width: 220px;
    border-radius: 14px;
    box-shadow:
        0 16px 40px rgba(0, 0, 0, 0.45),
        0 0 32px rgba(110, 168, 255, 0.12);
    backdrop-filter: blur(22px) saturate(170%);
    -webkit-backdrop-filter: blur(22px) saturate(170%);
    overflow: hidden;
}

.menu-item:hover .menu-popup {
    display: block;
}

.menu-popup>div {
    padding: 10px 14px;
    color: var(--text-color);
    transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.menu-popup>div:hover {
    background: linear-gradient(90deg, rgba(110, 168, 255, 0.18), rgba(124, 92, 255, 0.14));
    color: #ffffff;
    transform: translateX(2px);
}

.main-content {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    gap: 12px;
    padding: 12px;
}

.image-area-container {
    flex-grow: 6;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 18px;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background:
        radial-gradient(circle at top, rgba(110, 168, 255, 0.14), transparent 35%),
        linear-gradient(180deg, rgba(14, 18, 34, 0.72), rgba(8, 10, 20, 0.58));
    border: 1px solid var(--border-color);
    box-shadow:
        var(--shadow-2),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(16px) saturate(150%);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    position: relative;
    min-height: 0;
}

.image-area-container::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 0%, rgba(110, 168, 255, 0.14), transparent 28%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 30%);
    opacity: 0.9;
}

.aspect-ratio-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 1;
}

#main-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    background:
        linear-gradient(180deg, rgba(6, 8, 14, 0.98), rgba(11, 15, 28, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    box-shadow:
        0 0 0 1px rgba(110, 168, 255, 0.08) inset,
        0 12px 40px rgba(0, 0, 0, 0.55),
        0 0 32px rgba(110, 168, 255, 0.16),
        0 0 60px rgba(124, 92, 255, 0.08);
}

.panel-container {
    flex-grow: 4;
    max-width: 450px;
    min-width: 350px;
    background:
        linear-gradient(180deg, rgba(18, 24, 45, 0.88), rgba(11, 14, 28, 0.78));
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow:
        var(--shadow-2),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    overflow: hidden;
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.tab-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.tab-header {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px;
    background:
        linear-gradient(180deg, rgba(13, 17, 32, 0.92), rgba(18, 24, 45, 0.75));
    border-bottom: 1px solid var(--border-color);
}

.tab-button {
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: 999px;
    background:
        linear-gradient(180deg, rgba(52, 61, 94, 0.18), rgba(31, 39, 64, 0.18));
    color: var(--text-color);
    cursor: pointer;
    font-size: 14px;
    transition:
        transform 0.18s ease,
        background-color 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        color 0.18s ease;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.tab-button:hover {
    background:
        linear-gradient(135deg, rgba(110, 168, 255, 0.16), rgba(124, 92, 255, 0.14));
    border-color: rgba(110, 168, 255, 0.28);
    box-shadow:
        0 0 0 1px rgba(110, 168, 255, 0.08) inset,
        0 8px 22px rgba(0, 0, 0, 0.22),
        0 0 20px rgba(110, 168, 255, 0.14);
    transform: translateY(-1px);
}

.tab-button.active {
    color: #ffffff;
    border-color: rgba(110, 168, 255, 0.42);
    background:
        linear-gradient(135deg, rgba(110, 168, 255, 0.24), rgba(124, 92, 255, 0.22));
    box-shadow:
        0 0 0 1px rgba(110, 168, 255, 0.15) inset,
        0 0 22px rgba(110, 168, 255, 0.18),
        0 0 32px rgba(124, 92, 255, 0.12);
}

.tab-content {
    flex-grow: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(110, 168, 255, 0.5) transparent;
}

.tab-content::-webkit-scrollbar {
    width: 10px;
}

.tab-content::-webkit-scrollbar-track {
    background: transparent;
}

.tab-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(110, 168, 255, 0.55), rgba(124, 92, 255, 0.42));
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.tab-pane {
    display: none;
    padding: 16px;
}

.tab-pane.active {
    display: block;
}

.scroll-container {
    width: 100%;
}

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

.vbox label {
    font-size: 14px;
    color: var(--text-muted);
    letter-spacing: 0.01em;
}

.vbox input[type="range"] {
    width: 100%;
    margin-top: -5px;
    accent-color: var(--accent-color);
    filter: drop-shadow(0 0 8px rgba(110, 168, 255, 0.18));
}

.vbox input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(110, 168, 255, 0.3), rgba(124, 92, 255, 0.24));
}

.vbox input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    margin-top: -7px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: radial-gradient(circle at 30% 30%, #ffffff, var(--accent-color));
    box-shadow:
        0 0 0 4px rgba(110, 168, 255, 0.12),
        0 0 18px rgba(110, 168, 255, 0.3);
}

.vbox input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(110, 168, 255, 0.3), rgba(124, 92, 255, 0.24));
}

.vbox input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: radial-gradient(circle at 30% 30%, #ffffff, var(--accent-color));
    box-shadow:
        0 0 0 4px rgba(110, 168, 255, 0.12),
        0 0 18px rgba(110, 168, 255, 0.3);
}

.vbox button {
    padding: 10px 12px;
    border: 1px solid rgba(110, 168, 255, 0.18);
    border-radius: 12px;
    background:
        linear-gradient(180deg, rgba(39, 49, 82, 0.88), rgba(25, 33, 58, 0.88));
    color: var(--text-color);
    cursor: pointer;
    margin-top: 10px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 10px 24px rgba(0, 0, 0, 0.25);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        border-color 0.18s ease,
        background 0.18s ease;
}

.vbox button:hover {
    background:
        linear-gradient(135deg, rgba(110, 168, 255, 0.22), rgba(124, 92, 255, 0.18));
    border-color: rgba(110, 168, 255, 0.36);
    box-shadow:
        0 12px 28px rgba(0, 0, 0, 0.32),
        0 0 18px rgba(110, 168, 255, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.vbox button:active {
    transform: translateY(0);
}

.tone-curve-editor {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    background:
        radial-gradient(circle at center, rgba(110, 168, 255, 0.08), transparent 60%),
        linear-gradient(180deg, rgba(7, 10, 18, 0.98), rgba(12, 16, 30, 0.98));
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(110, 168, 255, 0.18);
    border-radius: 16px;
    overflow: hidden;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 10px 28px rgba(0, 0, 0, 0.3),
        0 0 24px rgba(110, 168, 255, 0.1);
    touch-action: none;
}

.tone-curve-editor::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.06), transparent 20%, transparent 80%, rgba(255, 255, 255, 0.04)),
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 18%, transparent 82%, rgba(255, 255, 255, 0.03));
    opacity: 0.6;
}

.tone-curve-editor canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#metadata-tree {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    white-space: pre;
    color: #dce3ff;
    line-height: 1.55;
    text-shadow: 0 0 10px rgba(110, 168, 255, 0.08);
}

.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at center, rgba(110, 168, 255, 0.12), rgba(0, 0, 0, 0.72)),
        rgba(0, 0, 0, 0.58);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.dialog-box {
    background:
        linear-gradient(180deg, rgba(22, 28, 50, 0.94), rgba(13, 17, 32, 0.94));
    padding: 22px;
    border-radius: 18px;
    min-width: 300px;
    max-width: 90vw;
    border: 1px solid rgba(110, 168, 255, 0.22);
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.55),
        0 0 30px rgba(110, 168, 255, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.dialog-header {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 15px;
    color: #f4f7ff;
    text-shadow: 0 0 18px rgba(110, 168, 255, 0.14);
}

.dialog-content {
    margin-bottom: 20px;
    color: var(--text-color);
}

.dialog-content select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(110, 168, 255, 0.2);
    background:
        linear-gradient(180deg, rgba(34, 42, 70, 0.92), rgba(21, 28, 48, 0.92));
    color: var(--text-color);
    outline: none;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 8px 20px rgba(0, 0, 0, 0.24);
}

.dialog-content select:focus {
    border-color: rgba(110, 168, 255, 0.4);
    box-shadow:
        0 0 0 3px rgba(110, 168, 255, 0.14),
        0 8px 20px rgba(0, 0, 0, 0.24);
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.dialog-footer button {
    padding: 9px 16px;
    border: 1px solid rgba(110, 168, 255, 0.18);
    border-radius: 12px;
    background:
        linear-gradient(180deg, rgba(39, 49, 82, 0.9), rgba(25, 33, 58, 0.9));
    color: var(--text-color);
    cursor: pointer;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 8px 22px rgba(0, 0, 0, 0.25);
    transition:
        transform 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        background 0.18s ease;
}

.dialog-footer button:hover {
    background:
        linear-gradient(135deg, rgba(110, 168, 255, 0.24), rgba(124, 92, 255, 0.18));
    border-color: rgba(110, 168, 255, 0.34);
    box-shadow:
        0 12px 28px rgba(0, 0, 0, 0.32),
        0 0 18px rgba(110, 168, 255, 0.16);
    transform: translateY(-1px);
}

.dialog-footer button:active {
    transform: translateY(0);
}

.dialog-content .settings-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 15px 10px;
    align-items: center;
}

.dialog-content .settings-grid h3 {
    grid-column: 1 / -1;
    margin: 10px 0 0;
    color: var(--accent-color);
    border-bottom: 1px solid var(--border-color-strong);
    padding-bottom: 5px;
}

.dialog-content .settings-grid label {
    justify-self: start;
}

.dialog-content .slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dialog-content .slider-container input[type="range"] {
    flex-grow: 1;
}

.dialog-content .slider-value-input {
    width: 70px;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border-color-strong);
    background-color: var(--control-bg-color);
    color: var(--text-color);
    text-align: center;
}

.dialog-content .slider-value-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 8px var(--accent-glow);
}

.dialog-footer button#settings-dialog-save {
    background: linear-gradient(135deg, rgba(110, 168, 255, 0.24), rgba(124, 92, 255, 0.22));
    border-color: rgba(110, 168, 255, 0.42);
    color: #ffffff;
}


button:focus-visible,
.menu-item:focus-visible,
.tab-button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 2px solid rgba(110, 168, 255, 0.8);
    outline-offset: 2px;
}

/* --- Responsive Design --- */

@media (max-width: 820px) and (orientation: portrait) {
    .main-content {
        display: flex;
        flex-direction: column; /* ←これ復活させる */
        flex-grow: 1;
        overflow: hidden;
        gap: 12px;
        padding: 12px;
        min-height: 0;
    }

    .image-area-container {
        flex: 1 1 0;
        min-height: 0;
    }

    .panel-container {
        flex: 0 0 auto;
    }

    .tab-container {
        flex: 1;
        min-height: 0;
    }

    .tab-content {
        overflow: hidden;
    }
}

/* スマートフォン(横向き) */
@media (max-height: 500px) and (orientation: landscape) {
    .main-content {
        gap: 8px;
        padding: 8px;
    }
    .panel-container {
        min-width: 300px;
    }
    .tab-header {
        padding: 8px;
        gap: 4px;
    }
    .tab-button {
        padding: 8px 10px;
        font-size: 12px;
    }
}
