.otp-tool {
    --otp-panel: #f7f8fa;
    --otp-panel-strong: #ffffff;
    --otp-border: #d8dde5;
    --otp-border-strong: #c5ccd7;
    --otp-text: #172238;
    --otp-muted: #687385;
    --otp-blue-soft: #dce9f8;
    --otp-blue-border: #b7c9e0;
    --otp-blue: #2563eb;
    --otp-hover: #f2f6fb;
    --otp-hover-border: #a9bbd1;
    --otp-danger-soft: #f5e7e7;
    --otp-danger-border: #e6cccc;
    --otp-success-soft: #edf8ef;
    --otp-success-border: #c9e1ce;
    --otp-warning-soft: #fff6e6;
    --otp-warning-border: #ead6ad;
    color: var(--otp-text);
    font-family: "Inter", var(--font-sans);
}

.otp-tool,
.otp-tool * {
    box-sizing: border-box;
}

.otp-tool :where(button, input, textarea) {
    /* Keep this reset low-specificity so component typography can override it. */
    font: inherit;
}

.otp-tool button,
.otp-tool input[type="checkbox"] {
    -webkit-tap-highlight-color: transparent;
}

.otp-tool button:focus-visible,
.otp-tool input:focus-visible,
.otp-tool textarea:focus-visible,
.otp-tool summary:focus-visible,
.otp-table-scroll:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.24);
    outline-offset: 2px;
}

.otp-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.otp-mode {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 0 0 320px;
    gap: 4px;
    padding: 5px;
    border: 1px solid var(--otp-border);
    border-radius: 999px;
    background: #f0f2f5;
}

.otp-mode-button {
    min-height: 44px;
    padding: 9px 18px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #687385;
    cursor: pointer;
    font-size: 0.94rem;
    font-weight: 750;
    transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.otp-mode-button.is-active {
    background: var(--otp-blue-soft);
    box-shadow: inset 0 0 0 1px var(--otp-blue-border);
    color: var(--otp-text);
}

.otp-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.otp-button,
.otp-small-button,
.otp-copy-button,
.otp-stepper button {
    appearance: none;
    border: 1px solid var(--otp-border);
    background: #ffffff;
    color: #3f4a5d;
    cursor: pointer;
    font-weight: 700;
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.otp-button:hover:not(:disabled),
.otp-small-button:hover:not(:disabled),
.otp-copy-button:hover:not(:disabled),
.otp-stepper button:hover:not(:disabled) {
    border-color: var(--otp-hover-border);
    background: var(--otp-hover);
}

.otp-button {
    min-height: 42px;
    padding: 10px 15px;
    border-radius: 11px;
    white-space: nowrap;
    font-size: 0.87rem;
}

.otp-button-danger {
    border-color: var(--otp-danger-border);
    background: var(--otp-danger-soft);
    color: #76484d;
}

.otp-button-danger:hover:not(:disabled) {
    border-color: #d4aeb4;
    background: #f0dede;
}

.otp-layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    align-items: start;
    gap: 18px;
    min-width: 0;
}

.otp-settings {
    position: sticky;
    top: 76px;
    min-width: 0;
}

.otp-settings-summary {
    display: none;
}

.otp-settings-body,
.otp-workspace {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.otp-panel,
.otp-io {
    min-width: 0;
    border: 1px solid var(--otp-border);
    border-radius: 15px;
    background: var(--otp-panel);
}

.otp-panel {
    padding: 15px;
}

.otp-panel-title {
    margin: 0 0 12px;
    color: #4e5a6e;
    font-size: 0.81rem;
    font-weight: 800;
    letter-spacing: 0.035em;
    line-height: 1.25;
    text-transform: uppercase;
}

.otp-field {
    display: grid;
    gap: 7px;
}

.otp-field-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: #39455a;
    font-size: 0.86rem;
    font-weight: 750;
}

.otp-field-count {
    flex: 0 0 auto;
    color: var(--otp-muted);
    font-size: 0.78rem;
}

.otp-text-input {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    border: 1px solid var(--otp-border-strong);
    border-radius: 10px;
    background: var(--otp-panel-strong);
    color: #243047;
    padding: 11px 13px;
    font-size: 0.9rem;
}

.otp-key-input,
.otp-io textarea,
.otp-calculations td {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.otp-key-input {
    font-weight: 700;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.otp-key-explainer {
    margin-top: 10px;
    padding: 11px;
    border: 1px solid var(--otp-border);
    border-radius: 10px;
    background: var(--otp-panel-strong);
}

.otp-key-explainer p {
    margin: 0;
    color: var(--otp-muted);
    font-size: 0.77rem;
    line-height: 1.5;
}

.otp-key-explainer strong {
    color: var(--otp-text);
    font-weight: 800;
}

.otp-key-example {
    display: grid;
    gap: 3px;
    margin: 9px 0;
    padding: 9px 0;
    border-top: 1px solid var(--otp-border);
    border-bottom: 1px solid var(--otp-border);
}

.otp-key-example div {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: baseline;
    gap: 9px;
}

.otp-key-example dt,
.otp-key-example dd {
    margin: 0;
}

.otp-key-example dt {
    color: var(--otp-muted);
    font-size: 0.72rem;
    font-weight: 750;
    line-height: 1.4;
}

.otp-key-example code {
    display: inline-block;
    color: var(--otp-text);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1.4;
}

.otp-key-security {
    color: #536178 !important;
}

.otp-help {
    margin: 9px 0 0;
    color: var(--otp-muted);
    font-size: 0.78rem;
    line-height: 1.5;
}

.otp-key-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.otp-small-button {
    min-height: 40px;
    padding: 9px 10px;
    border-radius: 9px;
    font-size: 0.79rem;
}

.otp-small-button-primary {
    grid-column: 1 / -1;
    border-color: var(--otp-blue-border);
    background: var(--otp-blue-soft);
    color: #233b63;
}

.otp-button:disabled,
.otp-small-button:disabled,
.otp-copy-button:disabled,
.otp-stepper button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
    transform: none;
}

.otp-validation {
    margin-top: 12px;
    padding: 10px 11px;
    border: 1px solid var(--otp-warning-border);
    border-radius: 10px;
    background: var(--otp-warning-soft);
    color: #74591f;
    font-size: 0.8rem;
    font-weight: 650;
    line-height: 1.45;
}

.otp-validation.is-good {
    border-color: var(--otp-success-border);
    background: var(--otp-success-soft);
    color: #246134;
}

.otp-validation.is-bad {
    border-color: var(--otp-danger-border);
    background: var(--otp-danger-soft);
    color: #78464b;
}

.otp-options {
    display: grid;
    gap: 13px;
}

.otp-option,
.otp-option label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #3f4a5d;
    cursor: pointer;
    font-size: 0.87rem;
    font-weight: 550;
}

.otp-option-with-control {
    justify-content: space-between;
    gap: 12px;
}

.otp-option input[type="checkbox"] {
    width: 19px;
    height: 19px;
    flex: 0 0 auto;
    margin: 0;
    accent-color: var(--otp-blue);
}

.otp-option.is-disabled {
    opacity: 0.48;
}

.otp-stepper {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.otp-stepper button {
    display: grid;
    width: 34px;
    height: 34px;
    padding: 0;
    place-items: center;
    border-radius: 8px;
    font-size: 1rem;
}

.otp-stepper strong {
    min-width: 20px;
    color: #28354d;
    text-align: center;
    font-size: 0.87rem;
}

.otp-group-help {
    padding-top: 10px;
    border-top: 1px solid var(--otp-border);
}

.otp-io-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    min-width: 0;
}

.otp-io {
    display: flex;
    flex-direction: column;
    gap: 11px;
    padding: 15px;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.otp-io:focus-within {
    border-color: var(--otp-blue-border);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.otp-io-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.otp-io-heading h2 {
    margin: 0;
    color: var(--otp-text);
    font-size: 1.02rem;
    font-weight: 800;
    letter-spacing: -0.015em;
}

.otp-copy-button {
    min-height: 32px;
    padding: 6px 13px;
    border-radius: 999px;
    color: #626d7e;
    font-size: 0.77rem;
}

.otp-copy-button.is-done {
    border-color: var(--otp-success-border);
    background: var(--otp-success-soft);
    color: #246134;
}

.otp-copy-button.is-error {
    border-color: var(--otp-warning-border);
    background: var(--otp-warning-soft);
    color: #74591f;
}

.otp-io textarea {
    width: 100%;
    min-width: 0;
    min-height: 215px;
    flex: 1 1 auto;
    resize: vertical;
    border: 1px solid var(--otp-border-strong);
    border-radius: 11px;
    background: var(--otp-panel-strong);
    color: #253149;
    padding: 13px;
    font-size: 0.94rem;
    line-height: 1.55;
}

.otp-io-output textarea {
    background: #fcfcfd;
}

.otp-io textarea::placeholder,
.otp-text-input::placeholder {
    color: #8b94a2;
}

.otp-io-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding-top: 10px;
    border-top: 1px solid var(--otp-border);
    color: #677286;
    font-size: 0.77rem;
    font-weight: 650;
}

.otp-io-footer strong {
    color: #28354d;
    font-weight: 800;
}

.otp-calculations {
    overflow: hidden;
    background: var(--otp-panel-strong);
}

.otp-empty {
    padding: 17px;
    border: 1px dashed var(--otp-border-strong);
    border-radius: 10px;
    color: var(--otp-muted);
    text-align: center;
    font-size: 0.84rem;
    line-height: 1.5;
}

.otp-table-scroll {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--otp-border);
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
}

.otp-calculations table {
    width: 100%;
    min-width: 710px;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.otp-calculations th,
.otp-calculations td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--otp-border);
    color: #29364e;
    text-align: center;
    white-space: nowrap;
}

.otp-calculations th {
    background: #f3f5f8;
    color: #586478;
    font-family: "Inter", var(--font-sans);
    font-size: 0.71rem;
    font-weight: 800;
    letter-spacing: 0.035em;
    text-transform: uppercase;
}

.otp-calculations tr:last-child td {
    border-bottom: 0;
}

.otp-calculations td:nth-child(6) {
    color: #285b9f;
    font-weight: 800;
}

.otp-table-note {
    margin: 9px 0 0;
    color: var(--otp-muted);
    font-size: 0.75rem;
}

.otp-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.otp-chips > span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 9px;
    border: 1px solid var(--otp-border);
    border-radius: 999px;
    background: var(--otp-panel-strong);
    color: #5c687a;
    font-size: 0.75rem;
    font-weight: 650;
}

.otp-chips strong {
    color: #28354d;
    font-weight: 800;
}

.otp-notice {
    margin-top: 12px;
    padding: 11px 13px;
    border: 1px solid var(--otp-warning-border);
    border-radius: 10px;
    background: var(--otp-warning-soft);
    color: #6f5723;
    font-size: 0.79rem;
    line-height: 1.5;
}

.otp-tool [hidden] {
    display: none !important;
}

html[data-theme="dark"] .otp-tool {
    --otp-panel: #1c222b;
    --otp-panel-strong: #171c23;
    --otp-border: #333c49;
    --otp-border-strong: #465263;
    --otp-text: #f2f5fb;
    --otp-muted: #a8b2c0;
    --otp-blue-soft: #243752;
    --otp-blue-border: #58779f;
    --otp-blue: #75a7ef;
    --otp-hover: #29323f;
    --otp-hover-border: #647185;
    --otp-danger-soft: #39262b;
    --otp-danger-border: #76505a;
    --otp-success-soft: #1d3126;
    --otp-success-border: #3f6b4d;
    --otp-warning-soft: #352e20;
    --otp-warning-border: #6b5a33;
}

html[data-theme="dark"] .otp-mode {
    background: #171c23;
}

html[data-theme="dark"] .otp-mode-button {
    color: #aeb7c5;
}

html[data-theme="dark"] .otp-mode-button.is-active {
    color: #f2f5fb;
}

html[data-theme="dark"] .otp-button,
html[data-theme="dark"] .otp-small-button,
html[data-theme="dark"] .otp-copy-button,
html[data-theme="dark"] .otp-stepper button {
    background: #202731;
    color: #d8dee8;
}

html[data-theme="dark"] .otp-button:hover:not(:disabled),
html[data-theme="dark"] .otp-small-button:hover:not(:disabled),
html[data-theme="dark"] .otp-copy-button:hover:not(:disabled),
html[data-theme="dark"] .otp-stepper button:hover:not(:disabled) {
    background: var(--otp-hover);
}

html[data-theme="dark"] .otp-button-danger {
    background: var(--otp-danger-soft);
    color: #f0b8c2;
}

html[data-theme="dark"] .otp-button-danger:hover:not(:disabled) {
    border-color: #94646f;
    background: #472d34;
}

html[data-theme="dark"] .otp-small-button-primary {
    background: var(--otp-blue-soft);
    color: #c9ddfb;
}

html[data-theme="dark"] .otp-key-security {
    color: #b8c3d2 !important;
}

html[data-theme="dark"] .otp-panel-title,
html[data-theme="dark"] .otp-field-label,
html[data-theme="dark"] .otp-option,
html[data-theme="dark"] .otp-option label {
    color: #cbd3df;
}

html[data-theme="dark"] .otp-text-input,
html[data-theme="dark"] .otp-io textarea {
    background: #141920;
    color: #eef2f7;
}

html[data-theme="dark"] .otp-io-output textarea {
    background: #161b22;
}

html[data-theme="dark"] .otp-stepper strong,
html[data-theme="dark"] .otp-io-footer strong,
html[data-theme="dark"] .otp-chips strong {
    color: #eef2f7;
}

html[data-theme="dark"] .otp-calculations th {
    background: #202731;
    color: #bdc6d3;
}

html[data-theme="dark"] .otp-calculations td {
    color: #dce2eb;
}

html[data-theme="dark"] .otp-calculations td:nth-child(6) {
    color: #9fc5ff;
}

html[data-theme="dark"] .otp-validation.is-good {
    color: #aee1bb;
}

html[data-theme="dark"] .otp-validation.is-bad {
    color: #f1b5bd;
}

html[data-theme="dark"] .otp-validation,
html[data-theme="dark"] .otp-notice {
    color: #e7cf94;
}

@media (max-width: 1023px) {
    .otp-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .otp-settings {
        position: static;
    }

    .otp-settings-summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: 48px;
        padding: 11px 14px;
        border: 1px solid var(--otp-border);
        border-radius: 12px;
        background: var(--otp-panel);
        color: #3f4a5d;
        cursor: pointer;
        font-size: 0.9rem;
        font-weight: 800;
        list-style: none;
    }

    .otp-settings-summary::-webkit-details-marker {
        display: none;
    }

    .otp-settings-summary::after {
        content: "+";
        color: var(--otp-blue);
        font-size: 1.1rem;
        font-weight: 800;
    }

    .otp-settings[open] .otp-settings-summary::after {
        content: "−";
    }

    .otp-settings-hint {
        margin-left: auto;
        color: var(--otp-muted);
        font-size: 0.76rem;
        font-weight: 650;
    }

    .otp-settings[open] .otp-settings-body {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-top: 12px;
    }

    html[data-theme="dark"] .otp-settings-summary {
        color: #e1e7ef;
    }
}

@media (max-width: 760px) {
    .otp-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 11px;
    }

    .otp-mode {
        width: 100%;
        flex-basis: auto;
    }

    .otp-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .otp-button {
        width: 100%;
        padding-inline: 8px;
        white-space: normal;
    }

    .otp-settings[open] .otp-settings-body,
    .otp-io-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .otp-io textarea {
        min-height: 175px;
    }

    .otp-panel,
    .otp-io {
        padding: 13px;
    }
}

@media (max-width: 380px) {
    .otp-actions {
        grid-template-columns: minmax(0, 1fr);
    }

    .otp-field-label {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .otp-key-actions {
        grid-template-columns: minmax(0, 1fr);
    }

    .otp-small-button-primary {
        grid-column: auto;
    }

    .otp-option-with-control {
        align-items: flex-start;
        flex-direction: column;
    }

    .otp-stepper {
        align-self: flex-end;
    }
}

@media (prefers-reduced-motion: reduce) {
    .otp-tool *,
    .otp-tool *::before,
    .otp-tool *::after {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}
