/* KEYTOOL — the key converter panel.

   Palette roles only: a literal colour here cannot follow the white theme. And as everywhere else on
   the site, --active is paired with --page, never with --active-text: those two are the same green in
   the dark theme, which renders as invisible text. */

.brain-container.has-keytool {
    position: relative;
}

.keytool-view {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding: 0.9rem 1rem 2rem;
    background: var(--page);
    border: 2px solid var(--rule);
    color: var(--ink);
    overflow-y: auto;
    overscroll-behavior: contain;
    font-family: 'Courier New', monospace;
    font-size: 0.86rem;
    line-height: 1.5;
    text-align: left;
}

.keytool-view[hidden],
.keytool-view [hidden] {
    display: none !important;
}

.keytool-view__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 0.6rem;
}

.keytool-view__title {
    font-size: 1.05rem;
    letter-spacing: 0.16em;
    color: var(--accent-text);
}

.keytool-view__sub {
    color: var(--muted);
    font-size: 0.78rem;
}

.keytool-view__close {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--cube-edge);
    border-radius: 0;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem 0.55rem;
    cursor: pointer;
}

.keytool-view__close:hover,
.keytool-view__close:focus-visible {
    background: var(--active);
    color: var(--page);
    outline: none;
}

.keytool-warn {
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--accent);
    border-left-width: 3px;
    color: var(--muted);
    font-size: 0.78rem;
}

.keytool-warn strong {
    color: var(--accent-text);
}

.keytool-input {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.keytool-input__label {
    color: var(--accent-text);
    font-size: 0.74rem;
    letter-spacing: 0.06em;
}

.keytool-input__field {
    width: 100%;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--cube-edge);
    border-radius: 0;
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    padding: 0.45rem 0.5rem;
    overflow-wrap: anywhere;
}

.keytool-input__field:focus-visible {
    outline: 1px solid var(--accent);
    outline-offset: 1px;
}

.keytool-hint {
    min-height: 1.1rem;
    color: var(--muted);
    font-size: 0.76rem;
}

.keytool-hint[data-tone='secret'] {
    color: var(--accent-text);
}

.keytool-hint[data-tone='bad'] {
    color: var(--ink);
    border-left: 2px solid var(--accent);
    padding-left: 0.5rem;
}

.keytool-rows {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.keytool-row {
    display: grid;
    grid-template-columns: minmax(7rem, 12rem) 1fr auto;
    gap: 0.5rem;
    align-items: start;
    padding: 0.45rem 0.55rem;
    background: var(--surface);
    border: 1px solid var(--cube-edge);
}

/* a secret row is marked, so a screenshot of the page shows what not to share */
.keytool-row[data-secret='true'] {
    border-left: 3px solid var(--accent);
}

.keytool-row__label {
    color: var(--accent-text);
    font-size: 0.74rem;
}

.keytool-row__value {
    color: var(--ink);
    font-size: 0.76rem;
    overflow-wrap: anywhere;
    word-break: break-all;
    user-select: all;
}

.keytool-row__actions {
    display: flex;
    gap: 0.3rem;
}

.keytool-row__copy,
.keytool-row__reveal,
.keytool-clear,
.keytool-reveal-all {
    background: none;
    color: var(--muted);
    border: 1px solid var(--cube-edge);
    border-radius: 0;
    font-family: inherit;
    font-size: 0.72rem;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    white-space: nowrap;
}

.keytool-row__copy:hover,
.keytool-row__copy:focus-visible,
.keytool-row__reveal:hover,
.keytool-row__reveal:focus-visible,
.keytool-clear:hover,
.keytool-clear:focus-visible,
.keytool-reveal-all:hover,
.keytool-reveal-all:focus-visible {
    background: var(--active);
    color: var(--page);
    outline: none;
}

.keytool-row__reveal {
    color: var(--accent-text);
}

.keytool-error {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--accent);
    color: var(--ink);
    font-size: 0.78rem;
}

.keytool-note {
    color: var(--muted);
    font-size: 0.74rem;
    padding: 0.15rem 0;
}

.keytool-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.keytool-build {
    border-top: 1px solid var(--rule);
    padding-top: 0.6rem;
}

.keytool-build__title {
    color: var(--accent-text);
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    margin-bottom: 0.3rem;
}

.keytool-build__text {
    margin: 0;
    color: var(--muted);
    font-size: 0.76rem;
}

@media (max-width: 34rem) {
    .keytool-view {
        font-size: 0.82rem;
        padding: 0.7rem 0.6rem 1.6rem;
    }

    .keytool-row {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }

    .keytool-row__actions {
        justify-content: flex-start;
    }
}

/* ── the builder ─────────────────────────────────────────────────────────────────────────────── */

.keytool-build__kinds {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin: 0.35rem 0;
}

.keytool-kind {
    background: var(--surface);
    color: var(--muted);
    border: 1px solid var(--cube-edge);
    border-radius: 0;
    font-family: inherit;
    font-size: 0.74rem;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
}

/* green marks what is chosen, as everywhere else on this site */
.keytool-kind.is-active {
    background: var(--active);
    color: var(--page);
    border-color: var(--active);
}

.keytool-kind:hover,
.keytool-kind:focus-visible {
    background: var(--active);
    color: var(--page);
    outline: none;
}

.keytool-build__fields {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin: 0.5rem 0;
}

.keytool-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.keytool-field__label {
    color: var(--accent-text);
    font-size: 0.72rem;
    letter-spacing: 0.05em;
}

.keytool-field__input {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--cube-edge);
    border-radius: 0;
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    padding: 0.35rem 0.45rem;
    width: 100%;
    resize: vertical;
}

.keytool-field__input:focus-visible {
    outline: 1px solid var(--accent);
    outline-offset: 1px;
}

.keytool-build__out {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.keytool-row__qr {
    background: none;
    color: var(--accent-text);
    border: 1px solid var(--cube-edge);
    border-radius: 0;
    font-family: inherit;
    font-size: 0.72rem;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    white-space: nowrap;
}

.keytool-row__qr:hover,
.keytool-row__qr:focus-visible {
    background: var(--active);
    color: var(--page);
    outline: none;
}

/* ── the code itself ──────────────────────────────────────────────────────────────────────────────
   The canvas knows its own size from its backing store; it is never given a CSS width, because
   scaling a module grid by a non-integer factor is what makes a code unreadable. max-width lets it
   fit a narrow screen only if the module budget ever overflows, which the drawing code avoids. */

.keytool-qr {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--cube-edge);
    grid-column: 1 / -1;
}

.keytool-qr__canvas {
    max-width: 100%;
    height: auto;
    background: var(--page);
}

.keytool-qr__caption {
    color: var(--muted);
    font-size: 0.72rem;
}

.keytool-qr__close {
    background: none;
    color: var(--muted);
    border: 1px solid var(--cube-edge);
    font-family: inherit;
    font-size: 0.72rem;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
}

.keytool-qr__close:hover,
.keytool-qr__close:focus-visible {
    background: var(--active);
    color: var(--page);
    outline: none;
}

/* ── making a new key ─────────────────────────────────────────────────────────────────────────────── */

.keytool-make__go {
    margin: 0.4rem 0;
    background: var(--accent);
    color: var(--accent-ink);
    border: 1px solid var(--accent);
    border-radius: 0;
    font-family: inherit;
    font-size: 0.82rem;
    padding: 0.5rem 0.8rem;
    cursor: pointer;
}

.keytool-make__go:hover,
.keytool-make__go:focus-visible {
    background: var(--active);
    color: var(--page);
    border-color: var(--active);
    outline: none;
}
