:root {
    --bg: #f4f7fc;
    --surface: #ffffff;
    --ink: #1f2530;
    --muted: #5d6678;
    --stroke: #d8e0ec;
    --accent: #2563eb;
    --accent-soft: #e9f0ff;
    --focus-bg: #edf2fb;
    --input-bg: #ffffff;
    --badge-bg: #fff5d8;
    --badge-ink: #7c5500;
    --badge-stroke: #f0c36f;
    --success-bg: #e8f6ee;
    --success-ink: #186c43;
    --success-stroke: #9ed1b5;
    --error-bg: #fdecec;
    --error-ink: #8f1f1f;
    --error-stroke: #de7d7d;
    --editor-bg: #ffffff;
    --editor-fg: #1f2530;
    --editor-caret: #2563eb;
    --editor-selection: #d7e5ff;
    --editor-gutter-bg: #ffffff;
    --editor-gutter-fg: #7a8395;
    --editor-gutter-border: #e6ebf3;
    --syntax-keyword: #a626a4;
    --syntax-operator: #383a42;
    --syntax-string: #50a14f;
    --syntax-number: #986801;
    --syntax-comment: #a0a1a7;
    --syntax-function: #4078f2;
    --syntax-type: #c18401;
    --syntax-variable: #383a42;
    --syntax-meta: #52606d;
    --source-accent: #2563eb;
    --target-accent: #0f766e;
    --footer-ink: #6f7684;
    --panel-shadow: 0 0.5rem 1.5rem rgba(21, 35, 60, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f131a;
        --surface: #171d27;
        --ink: #e8eaed;
        --muted: #aeb5c2;
        --stroke: #2b3443;
        --accent: #8ab4f8;
        --accent-soft: #1e2f4d;
        --focus-bg: #243146;
        --input-bg: #1a212d;
        --badge-bg: #382d18;
        --badge-ink: #ffd385;
        --badge-stroke: #6c5221;
        --success-bg: #1f3429;
        --success-ink: #9fdfbc;
        --success-stroke: #3f7152;
        --error-bg: #3a1f23;
        --error-ink: #ffb3b7;
        --error-stroke: #7a3a42;
        --editor-bg: #121822;
        --editor-fg: #e8eaed;
        --editor-caret: #8ab4f8;
        --editor-selection: #2f4666;
        --editor-gutter-bg: #121822;
        --editor-gutter-fg: #9ba5b5;
        --editor-gutter-border: #2a3342;
        --syntax-keyword: #c678dd;
        --syntax-operator: #abb2bf;
        --syntax-string: #98c379;
        --syntax-number: #d19a66;
        --syntax-comment: #6b7280;
        --syntax-function: #61afef;
        --syntax-type: #e5c07b;
        --syntax-variable: #abb2bf;
        --syntax-meta: #56b6c2;
        --source-accent: #7eaaf5;
        --target-accent: #5ec8bd;
        --footer-ink: #8f96a6;
        --panel-shadow: 0 0.625rem 1.5rem rgba(0, 0, 0, 0.25);
    }
}

* {
    box-sizing: border-box;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

html,
body {
    margin: 0;
    min-height: 100%;
    overflow-x: clip;
    background: var(--bg);
    color: var(--ink);
    font-family: "Google Sans", "Inter", "Segoe UI", sans-serif;
}

body {
    min-height: 100dvh;
    padding:
        max(1rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
    background: var(--bg);
}

.container {
    width: 100%;
    min-width: 0;
    max-width: 82.5rem;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(20rem, 1fr) auto minmax(20rem, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0.875rem;
    align-items: stretch;
    height: calc(100dvh - (max(1rem, env(safe-area-inset-top)) + max(1rem, env(safe-area-inset-bottom))));
    min-height: 0;
}

.panel {
    min-width: 0;
    min-height: 0;
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: 0.75rem;
    box-shadow: var(--panel-shadow);
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 0;
    overflow: hidden;
}

.target-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
}

.lang-control {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 3.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--stroke);
}

.lang-control .lang-selector {
    flex: 1;
}

.lang-selector {
    position: relative;
}

.lang-selector select {
    width: 100%;
    appearance: none;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--ink);
    font-size: 0.97rem;
    font-weight: 500;
    line-height: 1.2;
    padding: 0.625rem 1.875rem 0.625rem 0.5rem;
    outline: none;
}

.lang-selector select:focus {
    background: var(--focus-bg);
}

.lang-selector select:focus-visible,
.custom-lang-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.lang-selector .icon {
    pointer-events: none;
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    color: var(--muted);
    display: inline-grid;
    place-items: center;
    line-height: 0;
}

.lang-selector .icon svg {
    width: 0.875rem;
    height: 0.875rem;
}

.custom-lang-input {
    border: 1px solid var(--stroke);
    border-radius: 0.5rem;
    background: var(--input-bg);
    color: var(--ink);
    font-size: 0.9rem;
    padding: 0.5rem 0.625rem;
    min-width: 11.875rem;
    outline: none;
}

.custom-lang-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.custom-lang-input[hidden] {
    display: none;
}

.highlight-badge {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    border: 1px solid var(--badge-stroke);
    border-radius: 999px;
    background: var(--badge-bg);
    color: var(--badge-ink);
    font-size: 0.73rem;
    font-weight: 600;
    line-height: 1;
    padding: 0.375rem 0.5625rem;
}

.highlight-badge[hidden] {
    display: none;
}

.translating-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    white-space: normal;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.25;
}

.translating-indicator[hidden] {
    display: none;
}

.spinner {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 999px;
    border: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
    border-top-color: var(--accent);
    animation: spin 700ms linear infinite;
}

.editor {
    min-width: 0;
    min-height: 0;
    height: 100%;
    background: var(--editor-bg);
    overflow: hidden;
}

.editor-wrap {
    display: grid;
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
}

.copy-icon-btn {
    position: absolute;
    top: 0.625rem;
    right: 0.625rem;
    z-index: 20;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--stroke);
    border-radius: 0.5rem;
    background: var(--input-bg);
    color: var(--muted);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.copy-icon-btn svg {
    width: 1rem;
    height: 1rem;
}

.copy-icon-btn .check-icon {
    display: none;
}

.copy-icon-btn.copied .copy-icon {
    display: none;
}

.copy-icon-btn.copied .check-icon {
    display: block;
}

.copy-icon-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--stroke);
}

.copy-icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.copy-icon-btn.copied {
    background: var(--success-bg);
    color: var(--success-ink);
    border-color: var(--success-stroke);
}

.editor.loading {
    opacity: 0.7;
}

.feedback-message {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    max-width: none;
    margin: 0;
    border: 1px solid var(--stroke);
    border-radius: 0.625rem;
    background: var(--surface);
    color: var(--ink);
    font-size: 0.86rem;
    font-weight: 500;
    line-height: 1.35;
    padding: 0.625rem 0.75rem;
    overflow-wrap: anywhere;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transform: translateY(-0.25rem);
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
    transition:
        max-height 260ms cubic-bezier(0.2, 0.7, 0.2, 1),
        opacity 180ms ease,
        transform 220ms ease,
        margin 260ms cubic-bezier(0.2, 0.7, 0.2, 1),
        padding 260ms cubic-bezier(0.2, 0.7, 0.2, 1),
        border-width 220ms ease;
    will-change: max-height, opacity, transform;
}

.feedback-message.is-visible {
    max-height: 6rem;
    opacity: 1;
    transform: translateY(0);
    margin: 0.5rem 0 0;
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
    border-width: 1px;
}

.feedback-message.info {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--stroke));
    background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
}

.feedback-message.success {
    border-color: var(--success-stroke);
    background: var(--success-bg);
    color: var(--success-ink);
}

.feedback-message.warning {
    border-color: var(--badge-stroke);
    background: var(--badge-bg);
    color: var(--badge-ink);
}

.feedback-message.error {
    border-color: var(--error-stroke);
    background: var(--error-bg);
    color: var(--error-ink);
}

.site-footer {
    grid-column: 1 / -1;
    color: var(--footer-ink);
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    padding: 0.25rem 0.125rem 0;
    overflow-wrap: anywhere;
}

.site-footer a {
    color: inherit;
    text-decoration-thickness: 1px;
    text-underline-offset: 1.5px;
}

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

.translate-arrow {
    align-self: start;
    position: sticky;
    top: calc(50dvh - 1.375rem);
    border: 1px solid var(--stroke);
    border-radius: 62.4375rem;
    background: var(--surface);
    color: var(--ink);
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.25rem;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease;
}

.translate-label {
    display: none;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.translate-icon {
    width: 1.1rem;
    height: 1.1rem;
    flex: 0 0 auto;
}

.translate-arrow:hover {
    border-color: var(--stroke);
    background: var(--accent-soft);
}

.translate-arrow:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.translate-arrow:focus-visible,
.copy-icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.cm-editor {
    min-width: 0;
    height: 100%;
    font-size: 0.94rem;
    font-family: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

.cm-scroller {
    width: 100%;
    box-sizing: border-box;
    padding: 0;
    overflow: auto;
    overscroll-behavior: contain;
}

.cm-content {
    min-width: 0;
    width: auto;
    padding: 0.875rem;
}

.cm-gutters {
    padding-top: 0;
}

.cm-gutterElement {
    line-height: inherit;
}

.cm-focused {
    outline: none;
}

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

@media (max-width: 1040px) {
    body {
        padding:
            max(0.625rem, env(safe-area-inset-top)) max(0.625rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.625rem, env(safe-area-inset-left));
    }

    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: 0.625rem;
        height: auto;
    }

    .feedback-message {
        order: -1;
    }

    .site-footer {
        text-align: left;
        font-size: 0.76rem;
        padding-top: 0.125rem;
    }

    .translate-arrow {
        position: static;
        justify-self: stretch;
        width: 100%;
        height: 2.75rem;
        border-radius: 0.625rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .translate-label {
        display: inline;
    }

    .editor {
        height: clamp(260px, 44vh, 460px);
    }

    .target-toolbar {
        grid-template-columns: 1fr;
    }

    .copy-icon-btn {
        top: 0.5rem;
        right: 0.5rem;
        width: 2.75rem;
        height: 2.75rem;
    }

    .lang-control {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .lang-selector select,
    .custom-lang-input {
        font-size: 16px;
    }

    .lang-control .lang-selector {
        flex: 1 1 auto;
        min-width: 0;
    }

    .highlight-badge {
        order: 2;
    }

    .translating-indicator {
        order: 4;
        flex: 1 1 100%;
    }

    .custom-lang-input {
        order: 3;
        flex: 1 1 100%;
        min-width: 0;
        width: 100%;
    }
}

@media (max-width: 380px) {
    .lang-control {
        padding: 0.375rem 0.5rem;
        gap: 0.375rem;
    }

    .translate-arrow {
        height: 2.625rem;
    }

    .feedback-message {
        font-size: 0.82rem;
        padding: 0.5rem 0.625rem;
    }

    .site-footer {
        font-size: 0.74rem;
    }

    .feedback-message.is-visible {
        max-height: 7rem;
    }
}

@media (min-width: 1041px) and (max-width: 1260px) {
    .container {
        grid-template-columns: minmax(17.5rem, 1fr) auto minmax(17.5rem, 1fr);
        gap: 0.625rem;
    }

    .lang-control {
        min-height: 3.25rem;
        padding: 0.375rem 0.625rem;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .spinner {
        animation: none;
    }

    .feedback-message {
        transition: none;
        transform: none;
    }
}