/* Writing tools (writing-tools.js): the autocomplete list, the find & replace bar with its match
   highlights, and the "Omdøb karakter" dialog. Only wt- classes and #modal-rename-character;
   nothing here changes an existing rule. Colours come from the theme tokens in styles.css. */

/* ---------- Autocomplete list ---------- */

/* Like the INT./EXT. picker: a flat ruled box inside the scroll container, under the line */
.wt-suggest {
    position: absolute;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 180px;
    max-width: min(360px, calc(100% - 16px));
    box-sizing: border-box;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(30, 27, 22, .06);
}
.wt-suggest[hidden] {
    display: none;
}
.wt-suggest-item {
    display: flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 2px;
    color: var(--ink);
    font-family: var(--font-editor);
    font-size: 13px;
    letter-spacing: .02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.wt-suggest-typed {
    font-weight: 400;
}
.wt-suggest-item strong {
    font-weight: 700;
}
@media (hover: hover) {
    .wt-suggest-item:hover {
        background: var(--fill);
    }
}
.wt-suggest-item[aria-selected="true"],
.wt-suggest-item[aria-selected="true"]:hover {
    background: var(--ink);
    color: var(--on-ink);
}

/* ---------- Find & replace bar ---------- */

.wt-find {
    position: absolute;
    top: 8px;
    right: 16px;
    z-index: 20; /* over the pages and the zoom box, under the phone drawers */
    width: min(460px, calc(100% - 32px));
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(30, 27, 22, .06);
    color: var(--ink);
    font-family: var(--font-ui);
}
.wt-find[hidden],
.wt-find-row[hidden] {
    display: none;
}
.wt-find-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.wt-find-input {
    flex: 1;
    min-width: 0;
    height: 34px;
    box-sizing: border-box;
    padding: 0 10px;
    background: var(--surface);
    border: 1px solid var(--muted);
    border-radius: 4px;
    color: var(--ink);
    font-family: var(--font-editor);
    font-size: 14px;
    transition: border-color var(--transition-speed);
}
.wt-find-input::placeholder {
    color: var(--muted);
    opacity: 1;
}
.wt-find-input:focus {
    border-color: var(--ink);
}
.wt-find-count {
    flex: none;
    min-width: 64px;
    text-align: right;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.wt-find-count.none {
    color: var(--red);
}
.wt-find-btn,
.wt-find-text-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    min-width: 34px;
    box-sizing: border-box;
    padding: 0;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 15px;
    cursor: pointer;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}
.wt-find-text-btn {
    padding: 0 12px;
    border-color: var(--line-strong);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}
.wt-find-btn:hover:not(:disabled),
.wt-find-text-btn:hover {
    background: var(--fill);
    border-color: var(--ink);
}
.wt-find-btn:disabled {
    opacity: .4;
    cursor: default;
}
/* Text buttons, underlined like the modals' "Luk" */
.wt-find-close,
.wt-find-link {
    flex: none;
    min-height: 34px;
    padding: 0 6px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: .2em;
    cursor: pointer;
    white-space: nowrap;
}
.wt-find-close:hover,
.wt-find-link:hover {
    text-decoration-thickness: 2px;
}
.wt-find-options {
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 2px;
}
.wt-find-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
}
.wt-find-check input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--ink);
    cursor: pointer;
}

/* The matches, drawn by the CSS Custom Highlight API without touching the blocks. The pages are
   paper-white in both themes, so fixed colours read the same everywhere. */
::highlight(wt-find-all) {
    background-color: rgba(232, 184, 48, .32);
}
::highlight(wt-find-current) {
    background-color: rgba(232, 150, 24, .78);
    color: #1E1B16;
}

/* ---------- Rename dialog ---------- */

/* Above the phone drawers (z-index 1500), below the toasts (9999), as the PDF dialog */
#modal-rename-character.modal-backdrop {
    z-index: 1600;
    align-items: flex-start;
    padding-top: 8vh;
}
#modal-rename-character .wt-rename-dialog {
    width: min(480px, 96vw);
    max-width: 96vw;
}
#modal-rename-character .wt-rename-dialog:focus {
    outline: none;
}
#modal-rename-character [hidden] {
    display: none !important;
}
.wt-rename-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 44px;
    box-sizing: border-box;
    padding: 11px 4px;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.4;
    cursor: pointer;
}
.wt-rename-check input {
    flex: none;
    width: 18px;
    height: 18px;
    margin: 1px 0 0;
    accent-color: var(--ink);
    cursor: inherit;
}
.wt-rename-check-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.wt-rename-hint {
    font-size: 13px;
    color: var(--muted);
}
.modal-body p.wt-rename-preview {
    min-height: 1.5em;
    font-size: 13px;
    color: var(--ink);
}
.modal-body p.wt-rename-error {
    font-size: 13px;
    color: var(--red);
}

/* ---------- Phones and touch screens: 44 px targets ---------- */

@media screen and (max-width: 850px), (pointer: coarse) {
    .wt-suggest-item {
        min-height: 44px;
        font-size: 15px;
    }
    .wt-find-input {
        height: 44px;
        font-size: 16px; /* below 16 px iOS zooms the page on focus */
    }
    .wt-find-btn,
    .wt-find-text-btn,
    .wt-find-close,
    .wt-find-link,
    .wt-find-check {
        min-height: 44px;
        height: 44px;
    }
    .wt-find-btn {
        min-width: 44px;
    }
}
@media screen and (max-width: 850px) {
    .wt-find {
        top: 8px;
        left: 8px;
        right: 8px;
        width: auto;
    }
    .wt-replace-row {
        flex-wrap: wrap;
    }
    .wt-replace-row .wt-find-input {
        flex-basis: 100%;
    }
    .wt-replace-row .wt-find-text-btn {
        flex: 1;
    }
}
