:root {
    color-scheme: dark;
    --bg: #0d1117;
    --panel: #161b22;
    --panel-2: #1c2128;
    --border: #30363d;
    --text: #e6edf3;
    --muted: #8b949e;
    --green: #3fb950;
    --red: #f85149;
    --accent: #58a6ff;
    --orange: #d29922;
    --purple: #bc8cff;
    --radius: 10px;
    --mono: "JetBrains Mono", "Fira Code", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(50rem 24rem at 50% -8rem, rgba(63, 185, 80, 0.09), transparent),
        var(--bg);
    color: var(--text);
    font-family: var(--mono);
    line-height: 1.5;
}

main {
    max-width: 640px;
    margin: 0 auto;
    padding: 32px 16px 48px;
}

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

/* ---------- Header ---------- */
.top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

h1 {
    margin: 0;
    font-size: 2rem;
    line-height: 1.2;
    color: var(--green);
    letter-spacing: 2px;
}
h1::before { content: "> "; color: var(--muted); }
h1::after {
    content: "_";
    animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.streak {
    padding: 4px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.85rem;
    white-space: nowrap;
}

#countdown {
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
#countdown:empty { display: none; }

/* ---------- Progress ---------- */
.progress {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}
.progress:empty { display: none; }

.pip {
    flex: 1;
    height: 6px;
    border-radius: 999px;
    background: var(--border);
    transition: background 0.2s;
}
.pip.ok { background: var(--green); }
.pip.fail { background: var(--red); }
.pip.current { background: var(--accent); }

/* ---------- Code window ---------- */
.window {
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(1, 4, 9, 0.45);
}
.window.glow { animation: glow 0.6s ease-out; }
@keyframes glow {
    from { box-shadow: 0 0 0 0 rgba(63, 185, 80, 0.6); }
    to { box-shadow: 0 0 0 16px rgba(63, 185, 80, 0); }
}

.window-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
}

.dots { display: flex; gap: 6px; }
.dots i {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.dots i:nth-child(1) { background: #ff5f56; }
.dots i:nth-child(2) { background: #ffbd2e; }
.dots i:nth-child(3) { background: #27c93f; }

.filename {
    flex: 1;
    color: var(--muted);
    font-size: 0.8rem;
}

.badge {
    padding: 2px 10px;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 0.7rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.d-easy { color: var(--green); }
.d-medium { color: var(--accent); }
.d-hard { color: var(--orange); }
.d-expert { color: var(--red); }
.d-quirk { color: var(--purple); }

#code {
    margin: 0;
    padding: 16px 16px 16px 0;
    overflow-x: auto;
    font-size: 0.95rem;
    line-height: 1.6;
    tab-size: 2;
}
#code:empty { display: none; }
#code code {
    display: block;
    min-width: max-content;
    counter-reset: line;
    font-family: inherit;
}

.line {
    display: block;
    min-height: 1.6em;
    padding-left: 16px;
    white-space: pre;
}
.line::before {
    content: counter(line);
    counter-increment: line;
    display: inline-block;
    width: 2ch;
    margin-right: 16px;
    color: var(--muted);
    opacity: 0.6;
    text-align: right;
    user-select: none;
}

.tok-keyword { color: #ff7b72; }
.tok-string { color: #a5d6ff; }
.tok-number { color: #79c0ff; }
.tok-comment { color: var(--muted); font-style: italic; }
.tok-fn { color: #d2a8ff; }
.tok-builtin { color: #ffa657; }

/* ---------- Info and input ---------- */
.info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0 8px;
    color: var(--muted);
    font-size: 0.85rem;
}
.info:empty { display: none; }

.tries { display: flex; gap: 6px; }
.tries i {
    display: block;
    width: 10px;
    height: 10px;
    border: 1.5px solid var(--muted);
    border-radius: 50%;
}
.tries i.used {
    background: var(--red);
    border-color: var(--red);
}

#guess {
    width: 100%;
    padding: 12px 14px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    font-size: 1rem; /* 16px: voorkomt inzoomen op iPhone */
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
#guess::placeholder { color: var(--muted); }
#guess:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.2);
}
#guess:disabled { opacity: 0.5; }
#guess.shake {
    border-color: var(--red);
    animation: shake 0.35s;
}
@keyframes shake {
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* ---------- Result ---------- */
#result {
    margin: 16px 0;
    white-space: pre-line;
    overflow-wrap: anywhere;
}
#result:empty { display: none; }

#result.correct,
#result.wrong,
#result.final {
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius);
}
#result.correct { border-left-color: var(--green); }
#result.wrong { border-left-color: var(--red); }
#result.final {
    border-left-color: var(--accent);
    font-size: 1.1rem;
}
#result.correct strong { color: var(--green); }
#result.wrong strong { color: var(--red); }

#wrongguesses {
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
}
#wrongguesses:empty { display: none; }
#wrongguesses li {
    color: var(--red);
    font-size: 0.9rem;
    text-decoration: line-through;
}
#wrongguesses li::before {
    content: "✗ ";
    display: inline-block;
    margin-right: 4px;
    text-decoration: none;
}

/* ---------- Buttons ---------- */
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

button {
    padding: 10px 20px;
    background: var(--green);
    color: var(--bg);
    border: none;
    border-radius: var(--radius);
    font: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: filter 0.15s, transform 0.05s;
}
button:hover { filter: brightness(1.15); }
button:active { transform: translateY(1px); }
#share { background: var(--accent); }

button:focus-visible,
summary:focus-visible,
#code:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- How to play ---------- */
.howto {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.85rem;
}
.howto summary {
    color: var(--text);
    cursor: pointer;
}
.howto ul {
    margin: 8px 0 0;
    padding-left: 1.2rem;
}
.howto code { color: var(--accent); }

/* ---------- Responsive & motion ---------- */
@media (max-width: 480px) {
    main { padding-top: 20px; }
    h1 { font-size: 1.5rem; }
    #code { font-size: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}

@media (min-width: 1400px) {
    main { max-width: 800px; }
    html { font-size: 125%; }
}