/* Design tokens — enesaydogan.com ile birebir. */
:root {
    --bg: #fbfbfa;
    --surface: #ffffff;
    --ink: #16181c;
    --muted: #6b7079;
    --faint: #9aa0a8;
    --line: #e6e5e1;
    --line-soft: #efeeeb;
    --accent: #1f5fd8;
    --live: #12a150;
    --shadow: 0 1px 2px rgba(20, 22, 26, .04), 0 8px 24px -14px rgba(20, 22, 26, .18);
    --radius: 14px;
}

:root[data-theme="dark"] {
    --bg: #0e0f11;
    --surface: #151719;
    --ink: #eceef1;
    --muted: #9098a2;
    --faint: #6a7078;
    --line: #26292e;
    --line-soft: #1e2125;
    --accent: #7aa2f7;
    --live: #3ecf7f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px -16px rgba(0, 0, 0, .7);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e0f11;
        --surface: #151719;
        --ink: #eceef1;
        --muted: #9098a2;
        --faint: #6a7078;
        --line: #26292e;
        --line-soft: #1e2125;
        --accent: #7aa2f7;
        --live: #3ecf7f;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px -16px rgba(0, 0, 0, .7);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-width: 320px;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv05", "ss01";
    transition: background .25s ease, color .25s ease;
    overflow: hidden;
    height: 100vh;
    height: 100svh;
}

a {
    color: inherit;
    text-decoration: none;
}

::selection {
    background: var(--accent);
    color: #fff;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 11.5px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--faint);
}

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

/* ── top bar ─────────────────────────────────── */
.top-bar {
    flex-shrink: 0;
    height: 60px;
    padding: 0 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
    z-index: 20;
}

.logo-text {
    font-weight: 600;
    letter-spacing: -.02em;
    font-size: 15px;
}

.logo-text span {
    color: var(--faint);
    font-weight: 400;
}

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

/* ── language switcher ───────────────────────── */
.lang-switcher {
    display: flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.lang-btn {
    background: transparent;
    border: none;
    color: var(--faint);
    padding: 0 8px;
    height: 24px;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    letter-spacing: .04em;
    cursor: pointer;
    transition: color .15s, background .15s;
}

.lang-btn:hover {
    color: var(--ink);
}

.lang-btn.active {
    background: color-mix(in srgb, var(--ink) 6%, transparent);
    color: var(--ink);
}

/* ── theme toggle ────────────────────────────── */
.theme {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.theme:hover {
    color: var(--ink);
    border-color: var(--muted);
}

.theme svg {
    width: 15px;
    height: 15px;
}

.theme .moon {
    display: none;
}

:root[data-theme="dark"] .theme .sun {
    display: none;
}

:root[data-theme="dark"] .theme .moon {
    display: block;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme .sun {
        display: none;
    }

    :root:not([data-theme="light"]) .theme .moon {
        display: block;
    }
}

/* ── buttons ─────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 34px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s, transform .15s;
}

.btn:hover {
    color: var(--ink);
    border-color: var(--muted);
    transform: translateY(-1px);
}

.btn svg {
    width: 14px;
    height: 14px;
    opacity: .75;
    flex-shrink: 0;
}

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-accent:hover {
    background: color-mix(in srgb, var(--accent) 88%, var(--ink));
    border-color: color-mix(in srgb, var(--accent) 88%, var(--ink));
    color: #fff;
}

.btn-accent svg {
    opacity: .9;
}

.btn:disabled,
.btn.is-disabled {
    opacity: .45;
    cursor: not-allowed;
}

.btn:disabled:hover,
.btn.is-disabled:hover {
    transform: none;
    background: var(--surface);
    border-color: var(--line);
    color: var(--muted);
}

.btn-accent:disabled:hover,
.btn-accent.is-disabled:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ── layout ──────────────────────────────────── */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 16px;
    gap: 16px;
}

/* ── sidebar ─────────────────────────────────── */
.sidebar {
    width: 340px;
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: height .25s ease;
}

.mobile-handle {
    display: none;
}

.control-tabs {
    display: flex;
    gap: 2px;
    padding: 0 12px;
    border-bottom: 1px solid var(--line-soft);
}

.tab-btn {
    position: relative;
    flex: 1;
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 13px 0 12px;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    letter-spacing: -.012em;
    cursor: pointer;
    transition: color .15s;
}

.tab-btn::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1.5px;
    background: transparent;
    transition: background .18s ease;
}

.tab-btn:hover {
    color: var(--ink);
}

.tab-btn.active {
    color: var(--ink);
}

.tab-btn.active::after {
    background: var(--accent);
}

.tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn .3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* ── sections & controls ─────────────────────── */
.sidebar-section {
    margin-bottom: 26px;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.sidebar-section h4 {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 11.5px;
    font-weight: 400;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--faint);
    margin-bottom: 14px;
}

.control-group {
    margin-bottom: 18px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 9px;
}

.label-row label {
    font-size: 13.5px;
    font-weight: 500;
    letter-spacing: -.012em;
    color: var(--ink);
}

.label-row .val {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px;
    color: var(--faint);
}

/* ── range input ─────────────────────────────── */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 3px;
    border-radius: 999px;
    background: var(--line);
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(20, 22, 26, .25);
    cursor: pointer;
    transition: transform .15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.12);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(20, 22, 26, .25);
    cursor: pointer;
}

input[type="range"]::-moz-range-track {
    height: 3px;
    border-radius: 999px;
    background: var(--line);
}

/* ── filter grid ─────────────────────────────── */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.filter-btn {
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 7px 7px 6px;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    transition: border-color .2s ease, box-shadow .25s ease, transform .2s ease;
}

.filter-btn:hover {
    border-color: color-mix(in srgb, var(--muted) 45%, var(--line));
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.filter-btn.active {
    border-color: var(--accent);
}

.filter-preview {
    width: 100%;
    aspect-ratio: 4/3;
    border-radius: 6px;
    margin-bottom: 7px;
    /* Photo-like base: warm-dominant with a cool shadow region, mirroring the
       tonal balance of a real photo. The presets rely on this — `.cold`'s
       hue-rotate(180deg) only reads cool against a warm source. */
    background-image:
        radial-gradient(85% 70% at 24% 16%, rgba(255, 231, 194, .92) 0%, rgba(255, 231, 194, 0) 60%),
        radial-gradient(70% 55% at 88% 8%, rgba(163, 180, 194, .42) 0%, rgba(163, 180, 194, 0) 72%),
        linear-gradient(168deg, #dfb184 0%, #c98a5e 34%, #9a6a4f 62%, #55524f 84%, #33363b 100%);
    background-size: cover;
    background-position: center;
}

.filter-btn span {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: -.01em;
}

.filter-btn.active span {
    color: var(--ink);
}

/* ── icon buttons ────────────────────────────── */
.button-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.btn-icon {
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-family: inherit;
    font-size: 15px;
    cursor: pointer;
    transition: color .15s, border-color .15s, transform .15s;
}

.btn-icon:hover {
    color: var(--ink);
    border-color: var(--muted);
    transform: translateY(-1px);
}

/* ── crop controls ───────────────────────────── */
.ratio-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.ratio-btn {
    background: color-mix(in srgb, var(--ink) 5%, transparent);
    border: 1px solid transparent;
    color: var(--muted);
    padding: 5px 0;
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    cursor: pointer;
    transition: color .15s, background .15s, border-color .15s;
}

.ratio-btn:hover {
    color: var(--ink);
}

.ratio-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.manual-ratio {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
    color: var(--faint);
}

.manual-ratio input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 6px;
    border-radius: 8px;
    text-align: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.manual-ratio input:focus-visible {
    border-color: var(--accent);
}

/* ── canvas area ─────────────────────────────── */
.canvas-area {
    flex: 1;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--line-soft);
    position: relative;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow);
    transition: transform .2s;
}

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

.drop-zone {
    text-align: center;
    padding: 48px;
    pointer-events: none;
}

.drop-zone svg {
    width: 34px;
    height: 34px;
    color: var(--faint);
    margin-bottom: 18px;
}

.drop-zone h2 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -.025em;
    line-height: 1.3;
    margin-bottom: 8px;
}

.drop-zone p {
    color: var(--muted);
    font-size: 15.5px;
}

.drop-zone .drop-error {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    color: var(--ink);
    font-weight: 500;
    max-width: 34ch;
    margin-inline: auto;
}

/* ── scrollbar ───────────────────────────────── */
.tab-content::-webkit-scrollbar,
.canvas-area::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

.tab-content::-webkit-scrollbar-thumb,
.canvas-area::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 999px;
}

.tab-content::-webkit-scrollbar-thumb:hover,
.canvas-area::-webkit-scrollbar-thumb:hover {
    background: var(--faint);
}

/* ── motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ── responsive ──────────────────────────────── */
@media (max-width: 1024px) {
    .sidebar {
        width: 300px;
    }
}

@media (max-width: 760px) {
    .top-bar {
        padding: 0 16px;
        gap: 12px;
    }

    .top-actions {
        gap: 8px;
    }

    .main-content {
        flex-direction: column;
        padding: 0;
        gap: 0;
    }

    .canvas-area {
        height: 100%;
        border: none;
        border-radius: 0;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: min(45vh, 360px);
        z-index: 1000;
        border-radius: var(--radius) var(--radius) 0 0;
        border-bottom: none;
        box-shadow: 0 -1px 2px rgba(20, 22, 26, .04), 0 -12px 32px -16px rgba(20, 22, 26, .3);
    }

    .mobile-handle {
        display: block;
        width: 100%;
        height: 28px;
        border: none;
        background: transparent;
        cursor: pointer;
        position: relative;
        flex-shrink: 0;
    }

    .mobile-handle::before {
        content: '';
        position: absolute;
        top: 11px;
        left: 50%;
        width: 36px;
        height: 3px;
        background: var(--line);
        border-radius: 999px;
        transform: translateX(-50%);
    }

    .tab-content {
        padding: 18px 16px;
    }

    .sidebar.collapsed {
        height: 52px;
    }

    .sidebar.collapsed .control-tabs,
    .sidebar.collapsed .tab-content {
        opacity: 0;
        pointer-events: none;
    }
}

@media (max-width: 480px) {
    /* Dar ekranda Open/Save ikona iner. Etiket font-size:0 ile gizlenir:
       metin düğümü DOM'da kaldığı için i18n ve ekran okuyucular çalışmaya devam eder. */
    .top-actions .btn {
        font-size: 0;
        gap: 0;
        width: 34px;
        padding: 0;
    }
}

/* ── helpers ─────────────────────────────────── */
.mt-4 {
    margin-top: 26px;
}

.w-100 {
    width: 100%;
}

.mb-2 {
    margin-bottom: 8px;
}

/* ── filter preview modifiers ────────────────── */
.gray {
    filter: grayscale(1);
}

.sepia {
    filter: sepia(0.8);
}

.vintage {
    filter: sepia(0.5) contrast(1.2);
}

.dramatic {
    filter: contrast(1.5) brightness(0.8);
}

.noir {
    filter: grayscale(1) contrast(1.8);
}

.cold {
    filter: hue-rotate(180deg) saturate(0.8);
}

.warm {
    filter: sepia(0.3) saturate(1.5);
}

.retro {
    filter: sepia(0.2) hue-rotate(-20deg) contrast(1.1);
}

.vivid {
    filter: saturate(2);
}
