/* ============================================================
   English → Luganda · Korean · Japanese
   SCS 1104 · Discrete Mathematics
   ============================================================ */


/* ============================================================
   RESET
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}


/* ============================================================
   TOKENS — the whole design system lives here
   ============================================================ */
:root {
    /* Neutrals — warm greys */
    --ink-0: #faf9f7;
    --ink-1: #f2f0ec;
    --ink-2: #e5e2dc;
    --ink-3: #a8a29a;
    --ink-4: #57534e;
    --ink-5: #1c1917;

    /* One accent */
    --accent:      #c2410c;
    --accent-soft: #fff1e9;

    /* Semantic */
    --danger: #b91c1c;

    /* Type */
    --font: "Inter", -apple-system, BlinkMacSystemFont,
            "Segoe UI", system-ui, sans-serif;
    --mono: "JetBrains Mono", "SF Mono", "Fira Code",
            Consolas, "Liberation Mono", monospace;

    --text-sm: 0.8125rem;
    --text-md: 1rem;
    --text-lg: 1.375rem;

    /* Spacing — 8px grid */
    --s-1: 0.5rem;
    --s-2: 1rem;
    --s-3: 1.5rem;
    --s-4: 3rem;

    /* Radii */
    --r-sm: 8px;
    --r-lg: 16px;

    /* One shadow */
    --shadow: 0 1px 2px  rgba(28, 25, 23, 0.06),
              0 4px 12px rgba(28, 25, 23, 0.04);

    color-scheme: light;
}


/* ============================================================
   DARK MODE
   ============================================================ */
[data-theme="dark"] {
    --ink-0: #0c0a09;
    --ink-1: #1c1917;
    --ink-2: #292524;
    --ink-3: #78716c;
    --ink-4: #a8a29a;
    --ink-5: #fafaf9;

    --accent:      #fb923c;
    --accent-soft: #2a1a0f;

    --danger: #f87171;

    color-scheme: dark;
}


/* ============================================================
   BASE
   ============================================================ */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    font-size: var(--text-md);
    line-height: 1.6;
    color: var(--ink-5);
    background: var(--ink-0);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.25s ease, color 0.25s ease;
}

.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;
}


/* ============================================================
   LAYOUT
   ============================================================ */
.app {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: var(--s-4) var(--s-3) var(--s-3);
    flex: 1;
}


/* ============================================================
   BRAND LINE
   ============================================================ */
.brand {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--ink-3);
    letter-spacing: 0.02em;
    margin-bottom: var(--s-3);
}

.brand-arrow {
    margin: 0 0.25em;
    color: var(--ink-2);
}


/* ============================================================
   LANGUAGE SELECTOR
   ============================================================ */
.languages {
    display: flex;
    gap: var(--s-1);
    margin-bottom: var(--s-3);
}

.lang {
    padding: 0.3rem 0.8rem;
    font: 500 var(--text-sm) / 1 var(--font);
    color: var(--ink-4);
    background: transparent;
    border: 1px solid var(--ink-2);
    border-radius: 999px;
    cursor: pointer;
    transition: color 0.15s ease,
                background-color 0.15s ease,
                border-color 0.15s ease;
}

.lang:hover:not(.active) {
    border-color: var(--ink-3);
    color: var(--ink-5);
}

.lang.active {
    color: var(--ink-0);
    background: var(--ink-5);
    border-color: var(--ink-5);
}

.lang:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}


/* ============================================================
   INPUT WRAPPER
   ============================================================ */
.input-wrap {
    position: relative;
}


/* ============================================================
   INPUT
   ============================================================ */
.input {
    width: 100%;
    min-height: 120px;
    padding: var(--s-2) 0;
    font: 400 var(--text-md) / 1.6 var(--font);
    color: var(--ink-5);
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--ink-2);
    border-radius: 0;
    resize: none;
    overflow: hidden;
    transition: border-color 0.15s ease;
}

.input:focus {
    outline: none;
    border-bottom-color: var(--accent);
}

.input::placeholder {
    color: transparent;
}


/* ============================================================
   GHOST PLACEHOLDER
   ============================================================ */
.ghost {
    position: absolute;
    top: var(--s-2);
    left: 0;
    right: 0;
    font: 400 var(--text-md) / 1.6 var(--font);
    color: var(--ink-3);
    pointer-events: none;
    user-select: none;
    white-space: pre-wrap;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.ghost:empty::before {
    content: "Type something in English…";
}

.input:focus + .ghost,
.input:not(:placeholder-shown) + .ghost {
    opacity: 0;
}

.ghost-cursor {
    display: inline-block;
    width: 1px;
    height: 1.1em;
    margin-left: 1px;
    background: currentColor;
    vertical-align: text-bottom;
    animation: blink 1.1s steps(2, start) infinite;
}

@keyframes blink {
    to { visibility: hidden; }
}


/* ============================================================
   EXAMPLES
   ============================================================ */
.examples {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1);
    margin-top: var(--s-2);
}

.example {
    padding: 0.25rem 0.625rem;
    font: 400 var(--text-sm) / 1 var(--font);
    color: var(--ink-4);
    background: var(--ink-1);
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background-color 0.15s ease,
                color 0.15s ease;
}

.example:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.example:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}


/* ============================================================
   ACTIONS
   ============================================================ */
.actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--s-3);
}

.btn-translate {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font: 600 var(--text-md) / 1 var(--font);
    color: var(--ink-0);
    background: var(--ink-5);
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background-color 0.15s ease,
                transform 0.08s ease,
                opacity 0.15s ease;
}

.btn-translate:hover {
    background: var(--accent);
}

.btn-translate:active {
    transform: translateY(1px);
}

.btn-translate:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.btn-translate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-translate:disabled:hover {
    background: var(--ink-5);
}


/* ============================================================
   RESULTS
   ============================================================ */
.results {
    margin-top: var(--s-4);
    padding-top: var(--s-3);
    border-top: 1px solid var(--ink-2);
    animation: rise 0.25s ease-out;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.output-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--s-1);
}

.output-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.output {
    font: 400 var(--text-lg) / 1.5 var(--font);
    color: var(--ink-5);
    letter-spacing: -0.01em;
    white-space: pre-wrap;
    word-break: break-word;
}

.output.error {
    font-size: var(--text-md);
    color: var(--danger);
}


/* ============================================================
   COPY BUTTON
   ============================================================ */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    font: 400 var(--text-sm) / 1 var(--font);
    color: var(--ink-3);
    background: transparent;
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: color 0.15s ease,
                background-color 0.15s ease;
}

.copy-btn:hover {
    color: var(--ink-5);
    background: var(--ink-1);
}

.copy-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.copy-btn.copied {
    color: var(--accent);
}


/* ============================================================
   SOURCE VIEWER
   ============================================================ */
.source {
    margin-top: var(--s-4);
    padding-top: var(--s-3);
    border-top: 1px solid var(--ink-2);
}

.source summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: var(--s-1) 0;
    font-size: var(--text-sm);
    color: var(--ink-3);
    cursor: pointer;
    user-select: none;
    list-style: none;
    transition: color 0.15s ease;
}

.source summary::-webkit-details-marker {
    display: none;
}

.source summary::before {
    content: "›";
    display: inline-block;
    font-size: 1.1em;
    color: var(--ink-3);
    transform: rotate(0deg);
    transition: transform 0.2s ease;
}

.source[open] summary::before {
    transform: rotate(90deg);
}

.source summary:hover {
    color: var(--ink-5);
}

.source-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1);
    margin: var(--s-2) 0 var(--s-1);
}

.source-tab {
    padding: 0.3rem 0.75rem;
    font: 400 var(--text-sm) / 1 var(--mono);
    color: var(--ink-4);
    background: var(--ink-1);
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: color 0.15s ease,
                background-color 0.15s ease;
}

.source-tab:hover {
    color: var(--ink-5);
}

.source-tab.active {
    color: var(--accent);
    background: var(--accent-soft);
}

.source-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.source-panel {
    margin: 0;
    padding: var(--s-2);
    font: 400 0.78rem / 1.55 var(--mono);
    color: var(--ink-5);
    background: var(--ink-1);
    border-radius: var(--r-sm);
    overflow: auto;
    max-height: 400px;
    white-space: pre;
    tab-size: 4;
}

.source-panel em {
    color: var(--ink-3);
    font-style: italic;
}

.source-panel::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.source-panel::-webkit-scrollbar-track {
    background: transparent;
}

.source-panel::-webkit-scrollbar-thumb {
    background: var(--ink-2);
    border-radius: 5px;
}

.source-panel::-webkit-scrollbar-thumb:hover {
    background: var(--ink-3);
}


/* ============================================================
   SYNTAX HIGHLIGHTING — Prism token colors
   Warm palette that matches the app's neutrals + accent.
   Light-mode colors first; dark-mode overrides below.
   ============================================================ */

/* Comments — muted, italic */
.source-panel .token.comment,
.source-panel .token.prolog,
.source-panel .token.doctype,
.source-panel .token.cdata {
    color: var(--ink-3);
    font-style: italic;
}

/* Punctuation — slightly muted */
.source-panel .token.punctuation {
    color: var(--ink-4);
}

/* Keywords — const, let, function, if, return, async, etc. */
.source-panel .token.keyword,
.source-panel .token.control,
.source-panel .token.directive {
    color: #c2410c;
    font-weight: 600;
}

/* Strings — "hello", 'world', `template` */
.source-panel .token.string,
.source-panel .token.attr-value,
.source-panel .token.char {
    color: #15803d;
}

/* Numbers — 42, 3.14, 0xFF */
.source-panel .token.number,
.source-panel .token.boolean,
.source-panel .token.constant {
    color: #7c3aed;
}

/* Functions — setupUI(), translateText(), fetch() */
.source-panel .token.function,
.source-panel .token.method {
    color: #1d4ed8;
}

/* Properties — object keys, .length, .value */
.source-panel .token.property,
.source-panel .token.attr-name {
    color: #0369a1;
}

/* Class names, types, built-ins */
.source-panel .token.class-name,
.source-panel .token.builtin,
.source-panel .token.maybe-class-name {
    color: #b45309;
}

/* Operators — + - * / = === => */
.source-panel .token.operator,
.source-panel .token.entity,
.source-panel .token.url {
    color: var(--ink-4);
}

/* Regex literals, important values, variables */
.source-panel .token.regex,
.source-panel .token.important,
.source-panel .token.variable {
    color: #be185d;
}

/* CSS selectors and HTML tags */
.source-panel .token.selector,
.source-panel .token.tag {
    color: #c2410c;
    font-weight: 600;
}

/* Bold / italic emphasis */
.source-panel .token.bold,
.source-panel .token.important {
    font-weight: 600;
}

.source-panel .token.italic {
    font-style: italic;
}


/* ------------------------------------------------------------
   Token colors — dark mode overrides
   Same hue family, lighter and more saturated so they sit
   comfortably on the dark code background.
   ------------------------------------------------------------ */
[data-theme="dark"] .source-panel .token.keyword,
[data-theme="dark"] .source-panel .token.control,
[data-theme="dark"] .source-panel .token.directive {
    color: #fb923c;
}

[data-theme="dark"] .source-panel .token.string,
[data-theme="dark"] .source-panel .token.attr-value,
[data-theme="dark"] .source-panel .token.char {
    color: #86efac;
}

[data-theme="dark"] .source-panel .token.number,
[data-theme="dark"] .source-panel .token.boolean,
[data-theme="dark"] .source-panel .token.constant {
    color: #c4b5fd;
}

[data-theme="dark"] .source-panel .token.function,
[data-theme="dark"] .source-panel .token.method {
    color: #93c5fd;
}

[data-theme="dark"] .source-panel .token.property,
[data-theme="dark"] .source-panel .token.attr-name {
    color: #7dd3fc;
}

[data-theme="dark"] .source-panel .token.class-name,
[data-theme="dark"] .source-panel .token.builtin,
[data-theme="dark"] .source-panel .token.maybe-class-name {
    color: #fcd34d;
}

[data-theme="dark"] .source-panel .token.regex,
[data-theme="dark"] .source-panel .token.important,
[data-theme="dark"] .source-panel .token.variable {
    color: #f9a8d4;
}

[data-theme="dark"] .source-panel .token.selector,
[data-theme="dark"] .source-panel .token.tag {
    color: #fb923c;
}


/* ============================================================
   FOOTER
   ============================================================ */
.footer {
    padding: var(--s-3);
    text-align: center;
    font-size: var(--text-sm);
    color: var(--ink-3);
}

.footer a {
    color: var(--ink-4);
    text-decoration: none;
    border-bottom: 1px solid var(--ink-2);
    padding-bottom: 1px;
    transition: color 0.15s ease,
                border-color 0.15s ease;
}

.footer a:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}


/* ============================================================
   THEME TOGGLE
   ============================================================ */
.theme-toggle {
    position: fixed;
    top: var(--s-3);
    right: var(--s-3);
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: transparent;
    border: none;
    border-radius: var(--r-sm);
    color: var(--ink-4);
    cursor: pointer;
    z-index: 10;
    transition: background-color 0.15s ease,
                color 0.15s ease;
}

.theme-toggle:hover {
    background: var(--ink-1);
    color: var(--ink-5);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-toggle svg {
    position: absolute;
    transition: opacity 0.25s ease,
                transform 0.25s ease;
}

[data-theme="light"] .icon-moon {
    opacity: 0;
    transform: rotate(-45deg) scale(0.6);
}
[data-theme="light"] .icon-sun {
    opacity: 1;
    transform: rotate(0) scale(1);
}

[data-theme="dark"] .icon-sun {
    opacity: 0;
    transform: rotate(45deg) scale(0.6);
}
[data-theme="dark"] .icon-moon {
    opacity: 1;
    transform: rotate(0) scale(1);
}


/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
    .app {
        padding: var(--s-3) var(--s-2) var(--s-2);
    }

    .brand {
        margin-bottom: var(--s-2);
        padding-right: 2.5rem;
    }

    .languages {
        flex-wrap: wrap;
        margin-bottom: var(--s-2);
    }

    .lang {
        flex: 0 1 auto;
    }

    .btn-translate {
        width: 100%;
        justify-content: center;
    }

    .output-head {
        align-items: flex-start;
        gap: var(--s-1);
    }

    .source-panel {
        font-size: 0.72rem;
        padding: var(--s-2);
    }

    .footer {
        padding-inline: var(--s-2);
    }

    .theme-toggle {
        top: var(--s-2);
        right: var(--s-2);
    }
}


/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .ghost-cursor {
        animation: none;
        opacity: 0.6;
    }
}