@font-face {
    font-family: 'KazakhLocal';
    src: url('converter/kazakh.ttf') format('truetype');
    font-display: swap;
}

:root {
    color-scheme: light;
    --bg: #f6f1e9;
    --card: #ffffff;
    --card-soft: rgba(255, 255, 255, 0.88);
    --text: #172026;
    --muted: #68717d;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --primary-soft: rgba(15, 118, 110, 0.12);
    --orange-soft: rgba(245, 158, 11, 0.16);
    --blue-soft: rgba(14, 165, 233, 0.14);
    --border: rgba(23, 32, 38, 0.12);
    --shadow: 0 22px 60px rgba(35, 28, 18, 0.12);
    --radius-lg: 28px;
    --radius-md: 18px;
}

* {
    box-sizing: border-box;
}

html {
    direction: ltr;
    overflow-x: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    color: var(--text);
    background:
        radial-gradient(circle at 0 0, rgba(15, 118, 110, 0.18), transparent 34rem),
        var(--bg);
    font-family: KazakhLocal, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
    border-radius: var(--radius-md);
    padding: 13px 18px;
    color: #ffffff;
    background: var(--primary);
    cursor: pointer;
    transition: background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

button:hover {
    background: var(--primary-dark);
    box-shadow: 0 12px 26px rgba(15, 118, 110, 0.22);
    transform: translateY(-1px);
}

button.secondary {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

button.ghost {
    color: var(--muted);
    background: rgba(104, 113, 125, 0.12);
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    outline: none;
    color: var(--text);
    background: var(--card);
}

textarea {
    flex: 1;
    min-height: clamp(320px, 42vh, 560px);
    padding: clamp(14px, 1.5vw, 22px);
    border-radius: 22px;
    resize: vertical;
    font-size: clamp(1.05rem, 1.15vw, 1.28rem);
    line-height: 1.8;
    unicode-bidi: plaintext;
    white-space: pre-wrap;
}

textarea:focus,
input:focus {
    border-color: rgba(15, 118, 110, 0.48);
    box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

textarea::selection {
    color: #0f172a;
    background: rgba(45, 212, 191, 0.38);
}

#inputText.input-rtl,
#outputText.output-rtl {
    direction: rtl;
    text-align: justify;
    text-align-last: right;
}

#inputText.input-ltr,
#outputText.output-ltr {
    direction: ltr;
    text-align: justify;
    text-align-last: left;
}

.app-shell {
    width: min(1440px, calc(100% - 48px));
    margin: 0 auto;
    padding: clamp(20px, 3vw, 42px) 0 clamp(28px, 4vw, 64px);
}

.topbar {
    display: flex;
    align-items: center;
    margin-bottom: 34px;
}

.language-switcher {
    display: flex;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card-soft);
    box-shadow: var(--shadow);
}

.language-button {
    padding: 10px 15px;
    color: var(--muted);
    background: transparent;
    border-radius: 999px;
    box-shadow: none;
}

.language-button:hover {
    color: var(--primary-dark);
    background: var(--primary-soft);
    box-shadow: none;
}

.language-button.active {
    color: #ffffff;
    background: var(--primary);
}

.hero {
    margin-bottom: 30px;
}

.eyebrow {
    margin: 0 0 14px;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
    margin-top: 0;
}

h1 {
    max-width: 980px;
    margin-bottom: 18px;
    font-size: clamp(2.3rem, 5.4vw, 5.6rem);
    line-height: 1.05;
    letter-spacing: -0.055em;
}

.subtitle {
    max-width: 760px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 1.08rem;
    line-height: 1.8;
}

.arabic-ui .hero,
.arabic-ui .settings-panel,
.arabic-ui .feedback-panel,
.arabic-ui .notes {
    direction: rtl;
    text-align: right;
}

.arabic-ui .topbar,
.arabic-ui .language-switcher,
.arabic-ui .converter-grid,
.arabic-ui .actions,
.arabic-ui .panel {
    direction: ltr;
}

.arabic-ui .keyboard-bar {
    direction: rtl;
}

.toolbar,
.settings-panel,
.panel,
.feedback-panel,
.notes {
    border: 1px solid var(--border);
    background: var(--card-soft);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
    margin-bottom: 18px;
    border-radius: 999px;
}

.mode-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    padding: 12px 16px;
    border-radius: 999px;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}

.mode-option input,
.setting-option input {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--primary);
}

.mode-option.active {
    color: #ffffff;
    background: var(--primary);
}

.settings-panel {
    margin-bottom: 18px;
    padding: 14px;
    border-radius: 24px;
}

.settings-content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
}

.setting-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.dictionary-stats,
.match-list,
.priority-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.dictionary-stats span,
.match-chip,
.priority-list span {
    padding: 8px 12px;
    border-radius: 999px;
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.match-panel {
    flex-basis: 100%;
}

.match-panel h3,
.match-group h4 {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 0.96rem;
}

.match-groups {
    display: grid;
    gap: 12px;
}

.match-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.match-chip.person {
    color: #7c2d12;
    background: var(--orange-soft);
}

.match-chip.place {
    color: #075985;
    background: var(--blue-soft);
}

.match-remove {
    width: 22px;
    height: 22px;
    padding: 0;
    color: inherit;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 999px;
    line-height: 1;
}

.match-remove:hover {
    background: #ffffff;
    box-shadow: none;
    transform: none;
}

.converter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(98px, 0.16fr) minmax(0, 1fr);
    gap: clamp(14px, 1.6vw, 24px);
    align-items: stretch;
}

.panel {
    display: flex;
    flex-direction: column;
    min-height: clamp(460px, 52vh, 700px);
    padding: clamp(14px, 1.6vw, 22px);
    border-radius: 30px;
}

.panel-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    margin-bottom: 14px;
}

.panel-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.18rem;
}

.panel-header span {
    color: var(--muted);
    font-size: 0.94rem;
}

.panel-header span.over-limit {
    color: #9f1239;
    font-weight: 700;
}

.keyboard-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    min-width: 0;
}

.keyboard-option {
    width: auto;
    min-width: 0;
    padding: 5px 8px;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font-size: 0.78rem;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: none !important;
    transform: none !important;
    border: 1px solid var(--border);
}

.keyboard-option:hover {
    color: var(--primary-dark);
    background: var(--primary-soft);
    box-shadow: none !important;
    transform: none !important;
}

.keyboard-option.active {
    color: #ffffff;
    background: var(--primary);
    border-color: var(--primary);
}

.actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
}

.copy-button {
    align-self: flex-end;
    margin-top: 14px;
}

.feedback-panel {
    margin-top: 18px;
    padding: 14px;
    border-radius: 26px;
}

.feedback-toggle {
    width: auto;
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.feedback-toggle.active {
    color: #ffffff;
    background: var(--primary);
}

.feedback-content {
    margin-top: 16px;
}

.feedback-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.feedback-header h2 {
    margin-bottom: 8px;
    font-size: 1.15rem;
}

.feedback-header p,
.feedback-header span {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.feedback-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.feedback-form label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--muted);
    font-size: 0.95rem;
}

.feedback-form input,
.feedback-form select,
.feedback-form textarea {
    min-height: auto;
    padding: 12px 14px;
    border-radius: 16px;
    font-size: 1rem;
    line-height: 1.5;
    unicode-bidi: plaintext;
}

.feedback-form select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%2368717d' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 34px;
}

.feedback-note {
    grid-column: span 2;
}

.feedback-note textarea {
    height: 52px;
    resize: vertical;
}

.feedback-form button {
    align-self: end;
    min-height: 48px;
}

.captcha-row {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.captcha-img {
    flex: 0 0 auto;
    width: 160px;
    height: 60px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f0f5f4;
    object-fit: contain;
    cursor: pointer;
}

#captchaInput {
    flex: 1;
    width: auto;
    min-width: 80px;
    max-width: 130px;
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 1rem;
    text-align: center;
    letter-spacing: 0.12em;
}

.captcha-refresh {
    flex: 0 0 auto;
    min-width: 38px;
    height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 0.92rem;
    line-height: 38px;
    white-space: nowrap;
}

.captcha-refresh:hover {
    background: var(--primary);
    color: #ffffff;
    transform: none;
    box-shadow: none;
}

.arabic-ui .feedback-form input,
.arabic-ui .feedback-form select,
.arabic-ui .feedback-form textarea {
    direction: rtl;
    text-align: right;
}

.selection-popover {
    position: fixed;
    z-index: 30;
    width: min(360px, calc(100vw - 24px));
    padding: 14px;
    border: 1px solid rgba(15, 118, 110, 0.2);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 20px 50px rgba(31, 41, 51, 0.22);
    transform: translate(-50%, -100%);
}

.selection-popover.rtl-text {
    direction: rtl;
    text-align: right;
}

.selection-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    color: var(--muted);
    background: rgba(104, 113, 125, 0.12);
    border-radius: 999px;
    line-height: 1;
}

.selection-popover.rtl-text .selection-close {
    right: auto;
    left: 8px;
}

.selection-row {
    display: grid;
    gap: 6px;
    padding-right: 28px;
}

.selection-popover.rtl-text .selection-row {
    padding-right: 0;
    padding-left: 28px;
}

.selection-row span {
    color: var(--muted);
    font-size: 0.88rem;
}

.selection-row strong {
    max-height: 4.5em;
    overflow: auto;
    font-weight: 600;
    line-height: 1.5;
}

.selection-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.selection-actions button {
    flex: 1;
    padding: 9px 12px;
    border-radius: 14px;
}

.selection-actions button:first-child {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: min(420px, calc(100% - 32px));
    padding: 14px 18px;
    border: 1px solid rgba(15, 118, 110, 0.2);
    border-radius: 18px;
    color: var(--primary-dark);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 20px 50px rgba(31, 41, 51, 0.18);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 16px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-action {
    width: auto;
    min-height: auto;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.86rem;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0);
}

.toast.error {
    color: #9f1239;
    border-color: rgba(159, 18, 57, 0.2);
}

.arabic-ui .toast {
    direction: rtl;
}

.notes {
    margin-top: 18px;
    padding: 20px;
    border-radius: 26px;
}

.notes h2 {
    margin-bottom: 12px;
    font-size: 1.05rem;
}

@media (min-width: 1600px) {
    .app-shell {
        width: min(1560px, calc(100% - 72px));
    }

    .converter-grid {
        grid-template-columns: minmax(0, 1fr) 112px minmax(0, 1fr);
    }
}

@media (max-width: 1100px) {
    .app-shell {
        width: min(100% - 32px, 1040px);
    }

    .toolbar {
        grid-template-columns: 1fr;
        border-radius: 28px;
    }

    .converter-grid {
        grid-template-columns: 1fr;
    }

    .actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        order: 2;
    }

    .result-panel {
        order: 3;
    }
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100% - 24px, 680px);
        padding: 18px 0 28px;
    }

    .topbar {
        margin-bottom: 22px;
    }

    .language-switcher {
        width: 100%;
        justify-content: space-between;
        border-radius: 22px;
    }

    .language-button {
        flex: 1;
        padding: 10px 8px;
    }

    .hero {
        margin-bottom: 18px;
    }

    .eyebrow {
        margin-bottom: 8px;
        font-size: 0.82rem;
        letter-spacing: 0.08em;
    }

    h1 {
        font-size: clamp(2rem, 11vw, 3.2rem);
        letter-spacing: -0.045em;
    }

    .subtitle {
        font-size: 1rem;
        line-height: 1.7;
    }

    .toolbar {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 5px;
        padding: 6px;
        border-radius: 18px;
    }

    .mode-option {
        justify-content: center;
        min-width: 0;
        padding: 8px 6px;
        font-size: 0.76rem;
        gap: 4px;
        white-space: nowrap;
        overflow: hidden;
    }

    .mode-option input,
    .setting-option input {
        width: 14px;
        height: 14px;
    }

    .converter-grid {
        gap: 12px;
    }

    .panel {
        min-height: auto;
        padding: 12px;
        border-radius: 22px;
    }

    .keyboard-option {
        padding: 5px 6px;
        font-size: 0.68rem;
    }

    textarea {
        min-height: 260px;
        border-radius: 18px;
        font-size: 16px;
        line-height: 1.75;
    }

    .actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .actions button {
        min-width: 0;
        padding: 11px 8px;
        font-size: 0.84rem;
        white-space: nowrap;
    }

    .selection-actions {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    button {
        width: 100%;
        padding: 13px 16px;
        border-radius: 16px;
    }

    .copy-button {
        align-self: stretch;
    }

    .settings-panel,
    .feedback-panel,
    .notes {
        margin-top: 12px;
        padding: 14px;
        border-radius: 22px;
    }

    .feedback-header {
        flex-direction: column;
        gap: 8px;
    }

    .feedback-form {
        grid-template-columns: 1fr;
    }

    .feedback-note {
        grid-column: auto;
    }

    .feedback-note textarea {
        height: 90px;
    }

    .captcha-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .captcha-img {
        width: 140px;
        height: 52px;
    }

    #captchaInput {
        flex: 1 1 auto;
        min-width: 80px;
        max-width: none;
    }

    .captcha-refresh {
        flex: 0 0 auto;
        min-width: 36px;
        height: 36px;
        padding: 0 12px;
        font-size: 0.85rem;
        line-height: 36px;
    }

    .priority-list span {
        flex: 1 1 calc(50% - 8px);
        text-align: center;
    }
}

@media (max-width: 420px) {
    .app-shell {
        width: min(100% - 16px, 420px);
    }

    .language-switcher {
        gap: 6px;
        padding: 6px;
    }

    .language-button {
        font-size: 0.92rem;
    }

    .toolbar {
        padding: 5px;
        gap: 5px;
    }

    .mode-option {
        padding: 7px 4px;
        font-size: 0.68rem;
        gap: 3px;
    }

    .actions button {
        padding: 10px 6px;
        font-size: 0.76rem;
    }

    .settings-panel,
    .feedback-panel {
        padding: 12px;
    }

    .feedback-header p {
        font-size: 0.85rem;
    }

    .feedback-form label {
        font-size: 0.85rem;
    }

    .feedback-form input,
    .feedback-form select,
    .feedback-form textarea {
        font-size: 16px;
        padding: 10px 12px;
    }

    .captcha-img {
        width: 120px;
        height: 48px;
    }

    #captchaInput {
        min-width: 60px;
        font-size: 16px;
        padding: 10px 12px;
    }

    .captcha-refresh {
        min-width: 32px;
        height: 32px;
        padding: 0 10px;
        font-size: 0.82rem;
        line-height: 32px;
    }

    textarea {
        min-height: 220px;
        padding: 12px;
    }

    .actions {
        gap: 6px;
    }

    .priority-list span {
        flex-basis: 100%;
    }

    .selection-popover {
        width: calc(100vw - 16px);
    }
}
