/* Dyslexia-friendly base styles:
   - Off-white background (reduces glare)
   - Generous line-height and letter-spacing
   - Sans-serif with good distinction between letters
   - Soft, non-aggressive highlight for errors
*/

:root {
    --bg: #fdfaf3;
    --panel-bg: #ffffff;
    --text: #2a2a2a;
    --muted: #6b6b6b;
    --accent: #2a6fa6;
    --accent-hover: #225d8c;
    --border: #d8d4cc;
    --highlight: #fff3b0;
    --highlight-border: #d4a40a;
    --success: #2e7d32;
    --error: #b71c1c;
    --radius: 10px;

    --topbar-h: 56px;
    --page-padding: 1.5rem;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Verdana", "Tahoma", "Trebuchet MS", system-ui, sans-serif;
    line-height: 1.6;
    letter-spacing: 0.02em;
    min-height: 100vh;
    height: 100%;
}

h1, h2, h3 { font-weight: 600; letter-spacing: 0.01em; }
.muted { color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.04);
}
.login-card h1 { margin: 0 0 0.25rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1.25rem; }
.login-card label { display: flex; flex-direction: column; font-size: 0.92rem; gap: 0.35rem; }
.login-card input {
    font: inherit;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(42,111,166,0.15);
}

button {
    font: inherit;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
}
button.secondary:hover { background: #f0ece2; }

.flash {
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.92rem;
    margin-top: 1rem;
}
.flash-error { background: #fdecea; color: var(--error); }
.flash-success { background: #eaf6ec; color: var(--success); }

/* ---------- App layout ---------- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--page-padding);
    height: var(--topbar-h);
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 1.1rem; }
.user-info { display: flex; align-items: center; gap: 1rem; font-size: 0.92rem; }
.link-btn {
    color: var(--accent);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
}
.link-btn:hover { background: #f0ece2; }

/* Main grid: two equal-height panels filling the remaining viewport */
.app-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    padding: var(--page-padding);
    max-width: 1400px;
    margin: 0 auto;
    height: calc(100vh - var(--topbar-h));
}
@media (max-width: 800px) {
    .app-main {
        grid-template-columns: 1fr;
        /* On mobile, allow page to scroll between two stacked panels */
        height: auto;
        min-height: calc(100vh - var(--topbar-h));
    }
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    min-height: 0; /* important: lets children with overflow actually scroll */
    position: relative;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.panel h3 { margin: 1rem 0 0.5rem; font-size: 0.95rem; color: var(--muted); }

/* Panel header row: title on the left, controls on the right */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}
.panel-header h2 { margin: 0; }

/* Icon button (used for copy-to-clipboard) */
.icon-btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    position: relative;
}
.icon-btn:hover:not(:disabled) {
    background: #f0ece2;
    color: var(--accent);
    border-color: var(--accent);
}
.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.icon-btn .icon {
    width: 18px;
    height: 18px;
    display: block;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
/* Check icon is hidden by default; shown when .copied is set */
.icon-btn .icon-check {
    position: absolute;
    opacity: 0;
    transform: scale(0.6);
}
.icon-btn.copied {
    color: var(--success);
    border-color: var(--success);
    background: #eaf6ec;
}
.icon-btn.copied .icon-copy {
    opacity: 0;
    transform: scale(0.6);
}
.icon-btn.copied .icon-check {
    opacity: 1;
    transform: scale(1);
}

/* Input textarea fills the input panel */
#input-text {
    flex: 1;
    min-height: 180px;
    width: 100%;
    font: inherit;
    line-height: 1.7;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    resize: vertical;
}
#input-text:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(42,111,166,0.15);
}

.actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.9rem;
    flex-wrap: wrap;
}
.status { color: var(--muted); font-size: 0.9rem; }
.status.error { color: var(--error); }

/* ---------- Corrected output (scrollable) ---------- */
.scrollable {
    overflow-y: auto;
    /* Custom scrollbar styling for nicer feel */
    scrollbar-width: thin;
    scrollbar-color: #c9c4b8 transparent;
}
.scrollable::-webkit-scrollbar { width: 8px; }
.scrollable::-webkit-scrollbar-thumb { background: #c9c4b8; border-radius: 4px; }
.scrollable::-webkit-scrollbar-track { background: transparent; }

.corrected {
    /* Roughly 55% of the panel height; rest is for error list */
    flex: 1 1 55%;
    min-height: 120px;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.corrected mark {
    background: var(--highlight);
    border-bottom: 2px solid var(--highlight-border);
    padding: 0 2px;
    border-radius: 3px;
    cursor: help;
    position: relative;
}
.corrected mark:hover { background: #ffe580; }

/* Cursor hint for highlighted words */
.corrected mark[data-tip] {
    cursor: help;
}

/* Portal-rendered tooltip — appended to <body> by app.js, positioned via JS.
   Lives outside any scrolling container so it never gets clipped. */
.tooltip {
    position: fixed;
    background: #222;
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: "Verdana", "Tahoma", "Trebuchet MS", system-ui, sans-serif;
    line-height: 1.4;
    letter-spacing: normal;
    max-width: 280px;
    width: max-content;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Arrow on the tooltip. Default: tooltip is below the word, so arrow points up.
   When .tooltip is given .above, the arrow flips to point down. */
.tooltip::after {
    content: "";
    position: absolute;
    left: var(--arrow-left, 50%);
    transform: translateX(-50%);
    border: 5px solid transparent;
}
.tooltip:not(.above)::after {
    bottom: 100%;
    border-bottom-color: #222;
}
.tooltip.above::after {
    top: 100%;
    border-top-color: #222;
}

.errors-heading { flex: 0 0 auto; }

/* ---------- Error list (scrollable) ---------- */
.error-list {
    flex: 1 1 45%;
    min-height: 80px;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.error-list:empty { display: none; }

.error-item {
    background: #fff8e6;
    border: 1px solid #f0deaa;
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    font-size: 0.92rem;
}
.error-item .swap { font-weight: 600; }
.error-item .original { text-decoration: line-through; color: #a14a1f; }
.error-item .arrow { margin: 0 0.4rem; color: var(--muted); }
.error-item .correction { color: var(--success); }
.error-item .explanation {
    margin-top: 0.3rem;
    color: var(--muted);
    font-style: italic;
}
.error-item .meta {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--muted);
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}
.error-item .meta .tag {
    display: inline-block;
    background: #efe9d8;
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
}

.no-errors {
    background: #eaf6ec;
    border: 1px solid #c3e0c8;
    color: var(--success);
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    font-weight: 600;
}

/* ---------- Spinner ---------- */
.spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(2px);
    border-radius: var(--radius);
    z-index: 20;
    opacity: 1;
    transition: opacity 0.18s ease;
}
.spinner.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner-ring {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid #ece6d6;
    border-top-color: var(--accent);
    border-right-color: var(--accent);
    animation: spinner-rotate 1.1s linear infinite;
}

.spinner-letter {
    position: relative;
    width: 78px;
    height: 78px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Georgia", "Times New Roman", serif;
    font-size: 3.2rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0;
    /* Flip animation each time the letter changes */
    animation: spinner-flip 0.4s ease;
    will-change: transform, opacity;
}
.spinner-letter.flipping {
    animation: spinner-flip 0.32s ease;
}

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

@keyframes spinner-flip {
    0%   { transform: rotateY(-90deg); opacity: 0; }
    50%  { opacity: 1; }
    100% { transform: rotateY(0);      opacity: 1; }
}

/* Reduced motion: simpler spinner */
@media (prefers-reduced-motion: reduce) {
    .spinner-ring { animation-duration: 2.4s; }
    .spinner-letter { animation: none; }
}
