:root {
    --ye-surface: #ffffff;
    --ye-surface-2: #f9fafb;
    --ye-border: #e5e7eb;
    --ye-border-strong: #d1d5db;
    --ye-text: #1f2937;
    --ye-text-soft: #374151;
    --ye-muted: #6b7280;
    --ye-accent: #2563eb;
    --ye-accent-ink: #1d4ed8;
    --ye-accent-soft: #dbeafe;
    --ye-danger: #dc2626;
    --ye-danger-soft: #fef2f2;
    --ye-radius: 9px;
    --ye-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .1);
    --ye-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.ye {
    border: 1px solid var(--ye-border-strong);
    border-radius: var(--ye-radius);
    background: var(--ye-surface);
    color: var(--ye-text);
    font-family: var(--ye-font);
    font-size: 14px;
    display: flex;
    flex-direction: column;
}

.ye *,
.ye *::before,
.ye *::after {
    box-sizing: border-box;
}

/* Toolbar */

.ye-toolbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1px;
    padding: 6px;
    background: var(--ye-surface-2);
    border-bottom: 1px solid var(--ye-border);
    border-radius: var(--ye-radius) var(--ye-radius) 0 0;
}

.ye-toolbar__sep {
    width: 1px;
    align-self: stretch;
    margin: 3px 4px;
    background: var(--ye-border);
}

.ye-toolbar__btn {
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--ye-text-soft);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: .15s;
}

.ye-toolbar__btn:hover {
    background: var(--ye-surface);
    border-color: var(--ye-border-strong);
    color: var(--ye-text);
}

.ye-toolbar__btn.is-active {
    background: var(--ye-accent-soft);
    border-color: var(--ye-accent-soft);
    color: var(--ye-accent-ink);
}

.ye-toolbar__btn:disabled,
.ye-toolbar__btn.is-disabled {
    opacity: .4;
    cursor: default;
    pointer-events: none;
}

.ye-toolbar__btn--bold {
    font-weight: 800;
}

.ye-toolbar__btn--italic {
    font-style: italic;
}

.ye-toolbar__btn--underline:not(:has(*)) {
    text-decoration: underline;
}

.ye-toolbar__btn--strike:not(:has(*)) {
    text-decoration: line-through;
}

.ye-toolbar__btn--wide {
    min-width: 118px;
    padding: 0 10px;
    gap: 6px;
    justify-content: space-between;
}

.ye-toolbar__btn--fore {
    border-bottom: 3px solid var(--ye-accent);
    font-weight: 800;
}

.ye-toolbar__btn--back {
    background: #fef08a;
    color: #713f12;
    font-weight: 800;
}

/* Icons */

.ye-caret {
    font-size: 10px;
    opacity: .6;
}

.ye-ico {
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

svg.ye-ico {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    font-size: 0;
}

/* Menu */

.ye-menu {
    position: relative;
    display: inline-flex;
}

.ye-menu__pop {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 9999;
    min-width: 160px;
    padding: 5px;
    background: var(--ye-surface);
    border: 1px solid var(--ye-border);
    border-radius: var(--ye-radius);
    box-shadow: var(--ye-shadow);
    opacity: 0;
    transform: translateY(-6px) scale(.985);
    transition: opacity .14s ease, transform .14s ease;
    pointer-events: none;
}

.ye-menu__pop.is-open {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.ye-menu>.ye-menu__pop {
    display: none;
}

.ye-menu__item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ye-text);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
}

.ye-menu__item:hover {
    background: var(--ye-surface-2);
}

.ye-menu__item--h1 {
    font-size: 1.35em;
    font-weight: 700;
}

.ye-menu__item--h2 {
    font-size: 1.18em;
    font-weight: 700;
}

.ye-menu__item--h3 {
    font-size: 1.06em;
    font-weight: 700;
}

.ye-menu__item--h4 {
    font-weight: 700;
}

/* Colors */

.ye-menu__pop--colors {
    display: grid;
    grid-template-columns: repeat(6, 22px);
    gap: 5px;
    min-width: 0;
}

.ye-swatch {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, .12);
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    color: var(--ye-muted);
}

.ye-swatch:hover {
    outline: 2px solid var(--ye-accent);
    outline-offset: 1px;
}

.ye-swatch--none {
    grid-column: span 6;
    width: 100%;
    background: var(--ye-surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ye-color-custom {
    grid-column: span 6;
    display: flex;
    gap: 5px;
    margin-top: 6px;
    padding-top: 7px;
    border-top: 1px solid var(--ye-border);
}

.ye-color-native {
    width: 28px;
    height: 28px;
    flex: none;
    padding: 0;
    border: 1px solid var(--ye-border-strong);
    border-radius: 5px;
    background: none;
    cursor: pointer;
}

.ye-color-native::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.ye-color-native::-webkit-color-swatch {
    border: 0;
    border-radius: 3px;
}

.ye-color-hex {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    border: 1px solid var(--ye-border-strong);
    border-radius: 5px;
    background: var(--ye-surface);
    color: var(--ye-text);
    font-family: inherit;
    font-size: 12.5px;
}

.ye-color-hex:focus {
    outline: none;
    border-color: var(--ye-accent);
}

/* Popups */

.ye-menu__pop--table {
    min-width: 0;
}

.y-context-menu.ye-ctxpop {
    padding: 6px;
}

/* Prompt */

.y-context-menu.ye-formpop {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 250px;
    padding: 10px;
}

.ye-formpop__input {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--ye-border-strong);
    border-radius: 7px;
    font-family: inherit;
    font-size: 13px;
    color: var(--ye-text);
    background: var(--ye-surface);
}

.ye-formpop__input:focus {
    outline: none;
    border-color: var(--ye-accent);
}

.ye-formpop__err {
    display: none;
    font-size: 12px;
    color: var(--ye-danger);
}

.ye-formpop__err.is-shown {
    display: block;
}

.ye-formpop__row {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.ye-formpop__btn {
    padding: 6px 12px;
    border: 1px solid var(--ye-border);
    border-radius: 6px;
    background: var(--ye-surface);
    font-family: inherit;
    font-size: 12.5px;
    color: var(--ye-text-soft);
    cursor: pointer;
}

.ye-formpop__btn:hover {
    border-color: var(--ye-accent);
    color: var(--ye-accent-ink);
}

.ye-formpop__btn--ok {
    background: var(--ye-accent);
    border-color: var(--ye-accent);
    color: #fff;
}

.ye-formpop__btn--ok:hover {
    color: #fff;
}

.ye-formpop__check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--ye-text-soft);
    cursor: pointer;
}

.ye-formpop__check input {
    margin: 0;
}

/* Find */

.y-context-menu.ye-findpop {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 320px;
    max-width: 92vw;
    padding: 10px;
}

.ye-findpop__row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ye-findpop__row .ye-formpop__input {
    flex: 1;
    min-width: 0;
}

.ye-findpop__count {
    font-size: 11.5px;
    color: var(--ye-muted);
    white-space: nowrap;
    min-width: 56px;
    text-align: right;
}

.ye-findpop__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex: none;
    border: 1px solid var(--ye-border);
    border-radius: 6px;
    background: var(--ye-surface);
    color: var(--ye-text-soft);
    cursor: pointer;
}

.ye-findpop__btn:hover {
    border-color: var(--ye-accent);
    color: var(--ye-accent-ink);
}

.ye-findpop__btn .ye-ico {
    font-size: 18px;
}

::highlight(ye-find) {
    background: var(--ye-accent-soft);
    color: var(--ye-accent-ink);
}

::highlight(ye-find-current) {
    background: var(--ye-accent);
    color: #fff;
}

/* Grid */

.ye-grid {
    display: grid;
    grid-template-columns: repeat(6, 18px);
    gap: 3px;
}

.ye-grid__cell {
    width: 18px;
    height: 18px;
    border: 1px solid var(--ye-border-strong);
    border-radius: 3px;
    cursor: pointer;
}

.ye-grid__cell.is-on {
    background: var(--ye-accent-soft);
    border-color: var(--ye-accent);
}

.ye-grid__label {
    margin-top: 7px;
    font-size: 12px;
    color: var(--ye-muted);
    text-align: center;
}

.ye-grid__opt {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--ye-text-soft);
    cursor: pointer;
}

/* Table ops */

.ye-tableops {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    min-width: 200px;
}

.ye-tableops button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 9px;
    border: 1px solid var(--ye-border);
    border-radius: 6px;
    background: var(--ye-surface);
    font-family: inherit;
    font-size: 12.5px;
    color: var(--ye-text-soft);
    cursor: pointer;
}

.ye-tableops button .ye-ico {
    font-size: 17px;
    flex: none;
}

.ye-tableops button:hover {
    border-color: var(--ye-accent);
    color: var(--ye-accent-ink);
}

.ye-tableops button.ye-tableops__danger {
    grid-column: span 2;
    color: var(--ye-danger);
    border-color: #fecaca;
    background: var(--ye-danger-soft);
}

.ye-tableops__sep {
    grid-column: 1 / -1;
    height: 1px;
    background: var(--ye-border);
    margin: 3px 0;
}

.ye-body {
    flex: 1;
    min-height: 0;
}

.ye-area {
    padding: 12px 16px;
    outline: none;
    line-height: 1.6;
    color: var(--ye-text);
    overflow-y: auto;
    max-height: 250px;
}

.ye-area:empty::before {
    content: attr(data-placeholder);
    color: var(--ye-muted);
}

.ye-area> :first-child {
    margin-top: 0;
}

.ye-area> :last-child {
    margin-bottom: 0;
}

.ye-area p {
    margin: 0 0 .7em;
}

.ye-area h1 {
    font-size: 1.6em;
    font-weight: 700;
    margin: .7em 0 .35em;
}

.ye-area h2 {
    font-size: 1.35em;
    font-weight: 700;
    margin: .7em 0 .35em;
}

.ye-area h3 {
    font-size: 1.15em;
    font-weight: 700;
    margin: .7em 0 .35em;
}

.ye-area h4 {
    font-size: 1.02em;
    font-weight: 700;
    margin: .7em 0 .35em;
}

.ye-area ul,
.ye-area ol {
    margin: 0 0 .7em;
    padding-left: 1.6em;
}

.ye-area li {
    margin: .15em 0;
}

.ye-area a {
    color: var(--ye-accent);
    text-decoration: underline;
}

.ye-area blockquote {
    margin: 0 0 .7em;
    padding: .3em .9em;
    border-left: 3px solid var(--ye-border-strong);
    color: var(--ye-text-soft);
}

.ye-area hr {
    border: 0;
    border-top: 2px solid var(--ye-border);
    margin: 1em 0;
}

.ye-area img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

.ye-area img.ye-img--sel {
    outline: 2px solid var(--ye-accent);
    outline-offset: 1px;
}

.ye-area img[style*="float: left"],
.ye-area img[style*="float:left"] {
    margin: .2em 1em .5em 0;
}

.ye-area img[style*="float: right"],
.ye-area img[style*="float:right"] {
    margin: .2em 0 .5em 1em;
}

.ye-img-handle {
    position: fixed;
    z-index: 9998;
    width: 12px;
    height: 12px;
    background: var(--ye-accent);
    border: 2px solid #fff;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    cursor: nwse-resize;
    display: none;
}

.ye-area iframe {
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    border: 0;
    border-radius: 8px;
}

.ye-area code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9em;
    background: var(--ye-surface-2);
    border: 1px solid var(--ye-border);
    border-radius: 5px;
    padding: .1em .35em;
}

.ye-area pre {
    background: var(--ye-surface-2);
    border: 1px solid var(--ye-border);
    border-radius: 7px;
    padding: 10px 12px;
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9em;
}

.ye-area pre code {
    background: none;
    border: 0;
    padding: 0;
}

.ye-area table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 .7em;
}

.ye-area th,
.ye-area td {
    border: 1px solid var(--ye-border-strong);
    padding: 6px 9px;
    min-width: 30px;
}

.ye-area th {
    background: var(--ye-surface-2);
    font-weight: 700;
}

.ye-area table.ye-table--no-grid th,
.ye-area table.ye-table--no-grid td {
    border-style: dashed;
    border-color: var(--ye-border);
}

.ye-area table.ye-table--no-grid th {
    background: none;
}

.ye-source-view {
    width: 100%;
    min-height: 160px;
    padding: 12px 16px;
    border: 0;
    outline: none;
    resize: vertical;
    background: var(--ye-surface);
    color: var(--ye-text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.5;
}

.ye-source-view:not([hidden]) {
    display: block;
}

.ye-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 12px;
    border-top: 1px solid var(--ye-border);
    background: var(--ye-surface-2);
    border-radius: 0 0 var(--ye-radius) var(--ye-radius);
}

.ye-brand {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ye-muted);
    text-decoration: none;
    letter-spacing: .01em;
    transition: color .15s;
}

.ye-brand:hover {
    color: var(--ye-accent);
}

.ye-count {
    font-size: 11.5px;
    color: var(--ye-muted);
}

.ye-count.is-near {
    color: var(--ye-accent);
}

.ye-count.is-limit {
    color: var(--ye-danger);
    font-weight: 600;
}

.ye-file-input {
    display: none;
}

.ye.ye--drop .ye-area {
    outline: 2px dashed var(--ye-accent);
    outline-offset: -5px;
    background: var(--ye-accent-soft);
}

.ye.ye--busy .ye-area {
    opacity: .6;
    pointer-events: none;
}

.ye.ye--busy .ye-count {
    color: var(--ye-accent);
}

.ye.ye--full {
    position: fixed;
    inset: 0;
    z-index: 1000;
    border-radius: 0;
    max-height: none;
}

.ye.ye--full .ye-area {
    max-height: none;
}

body.ye-lock {
    overflow: hidden;
}

.y-context-menu {
    position: fixed;
    min-width: 180px;
    padding: 4px;
    background: var(--y-win-bg, var(--ye-surface));
    border: 1px solid var(--y-win-divider, var(--ye-border));
    border-radius: var(--y-win-border-radius, var(--ye-radius));
    box-shadow: #0000001c 0 5px 20px;
    z-index: 10000;
    opacity: 1;
    transform: scale(1);
    transition: .12s ease;
}

.y-context-menu.is-hidden {
    opacity: 0;
    transform: scale(.98);
    pointer-events: none;
}

.y-dropdown__menu {
    min-width: 160px;
    padding: 4px;
    background: var(--y-win-bg, var(--ye-surface));
    border: 1px solid var(--y-win-divider, var(--ye-border));
    border-radius: var(--y-win-border-radius, var(--ye-radius));
    box-shadow: #0000001c 0 5px 20px;
}

.y-dropdown__item-wrapper {
    position: relative;
}

.y-dropdown__submenu {
    position: absolute;
    top: 0;
    left: 100%;
    z-index: 1;
    opacity: 1;
    transform: scale(1);
    transition: .15s ease;
}

.y-dropdown__submenu.is-hidden {
    opacity: 0;
    transform: scale(.96);
    pointer-events: none;
    visibility: hidden;
}

.y-dropdown__item {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: .1s;
    font-size: 14px;
    white-space: nowrap;
    color: var(--y-win-text, var(--ye-text));
}

.y-dropdown__item:hover {
    background: var(--y-win-action-bg, var(--ye-surface-2));
}

.y-dropdown__item--danger {
    color: var(--ye-danger);
}

.y-dropdown__item--danger:hover {
    background: var(--ye-danger-soft);
}

.y-dropdown__item-icon {
    display: flex;
    align-items: center;
    font-size: 18px;
    flex-shrink: 0;
}

.y-dropdown__item-label {
    flex: 1;
}

.y-dropdown__item-arrow {
    opacity: .4;
    font-size: 16px;
    line-height: 1;
}

.y-dropdown__separator {
    height: 1px;
    margin: 4px 0;
    background: var(--y-win-divider, var(--ye-border));
}

@media (prefers-color-scheme: dark) {
    .ye:not(.ye--light) {
        --ye-surface: #1e1f24;
        --ye-surface-2: #26272e;
        --ye-border: #34363f;
        --ye-border-strong: #434654;
        --ye-text: #e5e7eb;
        --ye-text-soft: #cbd0d8;
        --ye-muted: #9096a1;
        --ye-accent: #60a5fa;
        --ye-accent-ink: #93c5fd;
        --ye-accent-soft: #1e3a5f;
        --ye-danger: #f87171;
        --ye-danger-soft: #3a1e1e;
    }
}

.ye.ye--dark {
    --ye-surface: #1e1f24;
    --ye-surface-2: #26272e;
    --ye-border: #34363f;
    --ye-border-strong: #434654;
    --ye-text: #e5e7eb;
    --ye-text-soft: #cbd0d8;
    --ye-muted: #9096a1;
    --ye-accent: #60a5fa;
    --ye-accent-ink: #93c5fd;
    --ye-accent-soft: #1e3a5f;
    --ye-danger: #f87171;
    --ye-danger-soft: #3a1e1e;
}
