/* Word Checker. Plain CSS, no web fonts, no inline styles (strict CSP).
 * Which parts show is driven entirely by attributes on <main>:
 *   data-view    = input | result
 *   data-list    = loading | ready | failed      (word list state)
 *   data-pending = (present while a submitted word waits for the list)
 *   data-verdict = yes | no                      (result view only)
 */

:root {
    color-scheme: light dark;
    --bg: #f1f5f9;
    --card: #ffffff;
    --card-edge: #f3f4f6;
    --shadow: 0 20px 25px -5px rgb(15 23 42 / 0.10), 0 8px 10px -6px rgb(15 23 42 / 0.10);
    --text: #111827;
    --muted: #6b7280;
    --brand: #4f46e5;
    --brand-press: #4338ca;
    --on-brand: #ffffff;
    --brand-sub: #e0e7ff;
    --field: #ffffff;
    --field-edge: #e5e7eb;
    --placeholder: #9ca3af;
    --yes: #15803d;
    --yes-disc: #16a34a;
    --no: #dc2626;
    --no-disc: #dc2626;
    --done: #111827;
    --done-press: #000000;
    --on-done: #ffffff;
    --ek-bg: #ffedd5;
    --ek-text: #9a3412;
    --g-bg: #eef2ff;
    --g-text: #4338ca;
    --warn-bg: #fff7ed;
    --warn-edge: #ffedd5;
    --warn-text: #c2410c;
    --focus: #6366f1;
    --brand-text: #4338ca;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1120;
        --card: #1e293b;
        --card-edge: transparent;
        --shadow: 0 20px 25px -5px rgb(0 0 0 / 0.45);
        --text: #f1f5f9;
        --muted: #94a3b8;
        --brand: #4f46e5;
        --brand-press: #4338ca;
        --brand-sub: #e0e7ff;
        --field: #0f172a;
        --field-edge: #475569;
        --placeholder: #64748b;
        --yes: #4ade80;
        --yes-disc: #16a34a;
        --no: #f87171;
        --no-disc: #dc2626;
        --done: #334155;
        --done-press: #475569;
        --on-done: #ffffff;
        --ek-bg: rgb(251 146 60 / 0.16);
        --ek-text: #fdba74;
        --g-bg: rgb(129 140 248 / 0.18);
        --g-text: #c7d2fe;
        --warn-bg: rgb(251 146 60 / 0.10);
        --warn-edge: rgb(251 146 60 / 0.30);
        --warn-text: #fdba74;
        --focus: #818cf8;
        --brand-text: #a5b4fc;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right))
             env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}

p { margin: 0; }

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

/* Top-anchored, not vertically centred: the header stays put when the card
 * changes height, and the input sits above where a phone keyboard opens. */
.app {
    max-width: 28rem;
    margin: 0 auto;
    /* padding, not margin: a margin collapses through body and adds to
     * min-height:100dvh, so the page scrolls (design critic #1). */
    padding: clamp(16px, 10vh, 112px) 0 24px;
}

.card {
    background: var(--card);
    border: 1px solid var(--card-edge);
    border-radius: 24px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.head {
    background: var(--brand);
    color: var(--on-brand);
    text-align: center;
    padding: 24px;
}
.head h1 {
    margin: 0;
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}
.head p {
    color: var(--brand-sub);
    font-size: 0.875rem;
    line-height: 1.25rem;
}

.body { padding: 24px; }

/* ---------------------------------------------------------------- input */
.row { display: flex; }
.check { margin-left: 8px; }   /* margin, not flex gap: gap needs iOS 14.5 */

#word {
    flex: 1;
    min-width: 0;
    height: 56px;
    padding: 0 16px;
    font: inherit;
    font-size: 1.125rem;           /* >= 16px, or iOS zooms on focus */
    color: var(--text);
    background: var(--field);
    border: 2px solid var(--field-edge);
    border-radius: 12px;
    transition: border-color 0.15s;
}
#word::placeholder { color: var(--placeholder); }
#word:focus { outline: none; border-color: var(--focus); }
#word:focus-visible { box-shadow: 0 0 0 3px rgb(99 102 241 / 0.25); }

.check {
    flex: none;
    width: 104px;                  /* fixed: text and spinner swap without shifting */
    height: 56px;
    display: inline-grid;
    place-items: center;
    font: inherit;
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--on-brand);
    background: var(--brand);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.15s;
}
.check > * { grid-area: 1 / 1; }
.check:active { transform: scale(0.95); }

.spinner {
    visibility: hidden;
    width: 24px;
    height: 24px;
    border: 3px solid rgb(255 255 255 / 0.35);
    border-left-color: #ffffff;    /* the visible arc (the original's was flattened) */
    border-radius: 50%;
}
/* Animated only while shown, so a hidden spinner costs nothing all session. */
.app[data-pending] .spinner { visibility: visible; animation: spin 0.8s linear infinite; }
.app[data-pending] .check-text { visibility: hidden; }
.app[data-pending] .check { background: var(--brand-press); }

/* One reserved line under the input, so status text never shifts the card. */
.hint {
    min-height: 1.25rem;
    margin-top: 10px;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--muted);
    text-align: center;
}
.hint-loading { display: none; color: var(--brand-text); font-weight: 600; }
.app[data-pending] .hint-ready { display: none; }
.app[data-pending] .hint-loading { display: inline; }

.warn {
    display: none;
    margin-top: 12px;
    padding: 16px;
    background: var(--warn-bg);
    border: 1px solid var(--warn-edge);
    border-radius: 12px;
    color: var(--warn-text);
    font-size: 0.9375rem;
    text-align: center;
}
.app[data-list="failed"] .warn { display: block; }
.app[data-list="failed"] .hint { display: none; }
.retry {
    display: block;
    width: 100%;
    min-height: 48px;
    margin-top: 12px;
    font: inherit;
    font-weight: 700;
    color: inherit;
    background: none;
    border: 2px solid currentColor;
    border-radius: 12px;
    cursor: pointer;
}

/* --------------------------------------------------------------- result */
.result { display: none; }
.app[data-view="result"] .ask { display: none; }
.app[data-view="result"] .result {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-top: 8px;
}
.result:focus { outline: none; }

.disc {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #ffffff;
}
.disc svg { width: 56px; height: 56px; grid-area: 1 / 1; }
.app[data-verdict="yes"] .disc { background: var(--yes-disc); animation: pulse-green 0.8s ease-out; }
.app[data-verdict="no"]  .disc { background: var(--no-disc);  animation: shake-red 0.5s ease-in-out; }
.app[data-verdict="yes"] .icon-no,
.app[data-verdict="no"]  .icon-yes { display: none; }

.verdict {
    margin-top: 20px;
    font-size: 4.5rem;
    line-height: 1;
    font-weight: 900;
    letter-spacing: -0.03em;
    text-transform: uppercase;
}
.app[data-verdict="yes"] .verdict { color: var(--yes); }
.app[data-verdict="no"]  .verdict { color: var(--no); }

.checked {
    margin-top: 12px;
    max-width: 100%;
    font-size: 1.375rem;
    line-height: 1.75rem;
    font-weight: 700;
    word-break: break-word;        /* fallback before iOS 15.4 */
    overflow-wrap: anywhere;
}
.sub {
    margin-top: 2px;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--muted);
}

.links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin: 19px -5px 0;           /* pill margins, not gap (iOS 14.5) */
}
.pill {
    display: inline-flex;
    align-items: center;
    margin: 5px;
    min-height: 48px;
    padding: 0 16px;
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 700;
    text-decoration: none;
    transition: filter 0.15s;
}
.pill svg { width: 15px; height: 15px; flex: none; margin-left: 6px; }
.pill .emoji { margin-right: 6px; }
.pill-ek { background: var(--ek-bg); color: var(--ek-text); }
.pill-google { background: var(--g-bg); color: var(--g-text); }

.done {
    width: 100%;
    min-height: 64px;
    margin-top: 24px;
    font: inherit;
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--on-done);
    background: var(--done);
    border: 0;
    border-radius: 16px;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.15);
    cursor: pointer;
    transition: transform 0.1s, background-color 0.15s;
}
.done:active { transform: scale(0.98); }

.check:focus-visible, .retry:focus-visible, .pill:focus-visible, .done:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

@keyframes pulse-green {
    0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgb(34 197 94 / 0.7); }
    70%  { transform: scale(1.05); box-shadow: 0 0 0 12px rgb(34 197 94 / 0); }
    100% { transform: scale(1); }
}
@keyframes shake-red {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}
@keyframes nudge {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}
.shake { animation: nudge 0.35s ease-in-out; }
@keyframes spin { to { transform: rotate(360deg); } }
/* The reduced-motion stand-in for the nudge: a colour flash, no movement. */
@keyframes flash { 0%, 60% { border-color: var(--no); } }

@media (prefers-reduced-motion: reduce) {
    .disc { animation: none !important; }
    .shake { animation: flash 0.6s; }
    .app[data-pending] .spinner { animation-duration: 2.4s; }
    .check:active, .done:active { transform: none; }
    .check, .done, .pill, #word { transition: none; }
}

/* Long words step down a size so a closing quote never wraps alone. */
.checked[data-long] { font-size: 1.0625rem; line-height: 1.5rem; }

/* Hover only where there is a real pointer; on touch, :hover sticks after a tap. */
@media (hover: hover) {
    .check:hover { background: var(--brand-press); }
    .pill:hover { filter: brightness(0.96); }
    .done:hover { background: var(--done-press); }
}
