.wrap.tools {
    padding: 10px 20px 28px;
}

.panel.tool {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, .01));
    box-shadow: var(--shadow);
}

.tool-head {
    padding: 14px;
    border-bottom: 1px solid var(--border);
}

.tool-title {
    margin: 0 0 6px;
    font-size: 16px;
}

.tool-msg {
    margin: 0;
    color: var(--muted);
}

.tool-body {
    padding: 14px;
    display: grid;
    gap: 16px;
}

.row {
    display: grid;
    gap: var(--gap);
    align-items: start;
}

.row.cols-2 {
    grid-template-columns: 1fr 1fr;
}

@media (max-width: 980px) {
    .row.cols-2 {
        grid-template-columns: 1fr;
    }
}

.field {
    display: grid;
    gap: 6px;
}

.seg {
    display: inline-flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.cb {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.cb input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

select,
input[type="text"],
input[type="number"],
textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    font-size: 14px;
}

/* Test area */
.test-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #0f1420;
    padding: 14px;
    min-height: 220px;
    position: relative;
    overflow: hidden;
}

/* scrolling container */
.viewport {
    height: 220px;
    overflow: auto;
    /* scroll, not translateY */
    position: relative;
    /* caret is positioned to this */
}

/* wrapped, normal flow text */
.words {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text);
    user-select: none;

    white-space: normal;
    /* allow wrap at spaces */
    word-break: keep-all;
    /* do not break inside words */
    overflow-wrap: normal;
    /* normal wrapping, no mid-word breaks */
}

/* keep each word as a unit so it wraps cleanly between words */
.word {
    display: inline-block;
    padding: 0 6px;
    border-radius: 6px;
    vertical-align: baseline;
}

.word.active {
    background: rgba(255, 255, 255, .04);
}

.ch {
    opacity: .95;
}

.ch.correct {
    color: #a7f3d0;
}

.ch.incorrect {
    color: #fca5a5;
}

.ch.current {
    border-bottom: 2px solid var(--accent-light);
}

/* caret sits over text in the same scrolling container */
.caret {
    position: absolute;
    /* relative to .viewport */
    width: 2px;
    background: var(--accent-light);
    height: 1.2em;
    transform: translateY(3px);
    animation: blink 1s step-end infinite;
    pointer-events: none;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

.typing-input {
    position: absolute;
    left: -9999px;
    top: 0;
    width: 0;
    height: 0;
    opacity: 0;
}

/* Stats */
.stats {
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    gap: 10px;
}

@media (max-width: 1100px) {
    .stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 640px) {
    .stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

.stat {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--panel);
}

.stat h4 {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: .3px;
    text-transform: uppercase;
}

.stat .val {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 18px;
}

.results {
    display: grid;
    gap: 10px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.best-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Heatmap */
.heatmap {
    display: grid;
    grid-template-columns: repeat(13, 1fr);
    gap: 6px;
}

.hm-cell {
    border: 1px solid var(--border);
    background: var(--panel);
    border-radius: 8px;
    padding: 6px;
    text-align: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
}

.hm-cell .k {
    display: block;
    color: var(--muted);
}

.hm-cell .v {
    display: block;
    font-size: 14px;
}

.hm-0 {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .04);
}

.hm-1 {
    background: rgba(252, 165, 165, .12);
}

.hm-2 {
    background: rgba(252, 165, 165, .18);
}

.hm-3 {
    background: rgba(252, 165, 165, .24);
}

.hm-4 {
    background: rgba(252, 165, 165, .30);
}

.hm-5 {
    background: rgba(252, 165, 165, .36);
}

/* Dropzone for passage */
.dropzone {
    position: relative;
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, .02);
    text-align: center;
    color: var(--muted);
    transition: border-color .2s, background .2s, box-shadow .2s;
    cursor: pointer;
}

.dropzone.dragover {
    border-color: var(--accent);
    background: radial-gradient(600px 300px at 50% 0%, rgba(101, 78, 163, .12), transparent 60%);
    box-shadow: inset 0 0 0 1px var(--accent-weak);
}

.hidden-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    border: 0;
}

.hint {
    color: var(--muted);
    font-size: 12px;
}