:root {
    --z-input: 1;
    --z-falling-keys: 10;
    --z-dropdown: 100;
    --z-cursor: 1000;

    --bg: #fff;
    --fg: #444;
    --surface: #fff;
    --border: #999;
    --border-faint: #eee;
    --accent: #4a90e2;
    --sweep: #5ea8ff;
    --blood: #9e1414;
    --leaf: #1f7a37;
    --pressed: #f0e6d2;
    --suggest-hover: #eef;
    --link: #06c;
    --page-bg-img: url(/images/bg-day.svg);
    --eye-w: 60%;
    --eye-h: 52%;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #141414;
    --fg: #cfcfcf;
    --surface: #1f1f1f;
    --border: #555;
    --border-faint: #2a2a2a;
    --accent: #6aa9e9;
    --sweep: color-mix(in srgb, var(--accent) 72%, transparent);
    --blood: #d63a30;
    --leaf: #36a85f;
    --pressed: #3a3220;
    --suggest-hover: #2a2f3d;
    --link: #8ab4f8;
    --page-bg-img: url(/images/bg-night.svg);
    color-scheme: dark;
}

html {
    background-color: var(--bg);
    background-image: var(--page-bg-img);
    background-attachment: scroll;
    background-repeat: repeat;
    background-size: 100% auto;
}

body {
    margin: 40px auto;
    max-width: 680px;
    line-height: 1.7;
    font-size: clamp(18px, 0.5vw + 17px, 21px);
    color: var(--fg);
    background: transparent;
    padding: 0 10px;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    letter-spacing: 0.04em;
    font-feature-settings: "case" on;
    text-rendering: optimizeLegibility;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 80px);
}

main { flex: 1; }
main p { text-align: justify; }
footer { margin-top: 3em; }
header, footer { position: relative; z-index: 901; }

h1, h2, h3 {
    line-height: 1.2
}

a { color: var(--link); }

button { cursor: pointer; }

img {
    display: block;
    margin: 0 auto;
    max-width: 100%;
}

.left {
    float: left;
    margin: 0 1em 0.5em 0;
    max-width: 220px;
}

h2 { clear: both; }

header form input[name=q] {
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-right: none;
}
header form button[type=submit] {
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-left: none;
}
#header-suggest {
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-top: none;
}
#header-suggest a { color: var(--fg); }
#header-suggest small { color: var(--fg); opacity: 0.7; }

header form:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
header form input:focus, header form button:focus { outline: none; }
header form:focus-within input[name=q],
header form:focus-within #runic-toggle,
header form:focus-within #theme-toggle,
header form:focus-within button[type=submit] { border-color: var(--accent); }
header form:focus-within #header-suggest { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

#runic-toggle, #theme-toggle {
    font: inherit;
    padding: 4px 8px;
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-left: none;
    cursor: pointer;
    min-width: 36px;
}
#runic-toggle[aria-pressed="true"] { background: var(--pressed); }

.fall-wrap { position: relative; flex: 1; min-width: 0; display: flex; }
.fall-wrap input { position: relative; z-index: var(--z-input); }
.key-fall__layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: var(--z-falling-keys); }
.key-fall__glyph {
    position: absolute;
    font-size: 1rem;
    font-weight: 500;
    will-change: transform, opacity;
    animation-name: key-fall-arrive;
    animation-timing-function: cubic-bezier(.2,.9,.2,1);
    animation-fill-mode: forwards;
    text-shadow: 0 0 6px currentColor, 0 0 12px color-mix(in srgb, currentColor 40%, transparent);
}
@keyframes key-fall-arrive {
    0%   { transform: translate(var(--driftX,0), var(--fromY,-120px)) rotate(var(--rot,0deg)) scale(1.15); opacity: 0; }
    40%  { opacity: 1; }
    85%  { transform: translate(var(--driftX,0), 3px) rotate(0deg) scale(.98); }
    100% { transform: translate(0,0) rotate(0deg) scale(1); opacity: 1; filter: brightness(1.25); }
}

main p, main h1, main h2, main h3 {
    background-image:
        radial-gradient(circle at 45px 24px,   var(--blood) 0 24px, transparent 24px),
        radial-gradient(circle at 130px 62px,  var(--blood) 0 28px, transparent 28px),
        radial-gradient(circle at 70px 102px,  var(--blood) 0 22px, transparent 22px),
        repeating-linear-gradient(
            0deg,
            var(--fg) 0, var(--fg) 3px,
            color-mix(in srgb, var(--accent) 60%, var(--fg)) 3px,
            color-mix(in srgb, var(--accent) 60%, var(--fg)) 4px
        );
    background-size:
        320px 136px, 380px 204px, 300px 170px,
        auto;
    background-repeat:
        repeat, repeat, repeat,
        repeat;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    filter:
        drop-shadow(0 1px 0 rgba(255, 255, 255, 0.45))
        drop-shadow(0 -1px 1px rgba(0, 0, 0, 0.30));
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 900;
    pointer-events: none;
    background: radial-gradient(ellipse var(--eye-w) var(--eye-h) at 50% 45%,
        transparent 0%,
        transparent 18%,
        rgba(0, 0, 0, 0.8) 52%,
        rgba(0, 0, 0, 1) 76%);
}

@media (max-width: 1200px) { :root { --eye-w: 70%;  --eye-h: 52%; } }
@media (max-width: 1024px) { :root { --eye-w: 82%;  --eye-h: 53%; } }
@media (max-width: 820px)  { :root { --eye-w: 100%; --eye-h: 52%; } }
@media (max-width: 600px)  { :root { --eye-w: 135%; --eye-h: 48%; } }
@media (max-width: 420px)  { :root { --eye-w: 165%; --eye-h: 46%; } }
