/* App document shell */
html {
    /* background-color: #f9f9f9; */
    transition: none;
}

/* App page primitive */
page {
    display: block;
    min-height: 100%;
}

/* Target-specific backgrounds */
html[app-target="index"] {
    background-color: #09070a;
}

html[app-target="panel"],
html[app-target="lesson"] {
    /* background-color: #f9f9f9; */
}

/* App root states */
[app-root] {
    opacity: 1;
    display: block;
    transition: opacity 0.1s linear;
    will-change: opacity;
    backface-visibility: hidden;
}

/* Preload body hiding */
html[app-preload] body {
    opacity: 0;
}

/* Preload target backgrounds */
html[app-preload][app-target="index"] {
    background: #09070a;
}

html[app-preload][app-target="panel"] {
    background: #f9f9f9;
}

html[app-preload][app-target="lesson"] {
    background: #f9f9f9;
}

/* App transition states */
[app-root][app-leaving] {
    opacity: 0;
    transition-duration: 0.08s;
    transition-timing-function: linear;
}

[app-root][app-hidden] {
    display: none;
    visibility: hidden;
    pointer-events: none;
}

/* App enter state */
[app-root][app-enter] {
    opacity: 0;
}

/* App visible state */
[app-root][app-enter][app-visible] {
    opacity: 1;
}

/* Overlay target backgrounds */
appoverlay[app][target="index"] {
    background: #09070a;
}

appoverlay[app][target="index"] loader[app] {
    border-color: rgba(255, 255, 255, 0.28);
    border-top-color: #fcfcfc;
    box-shadow: 0 0 0.8rem rgba(255, 255, 255, 0.16);
}

appoverlay[app][target="panel"] {
    background: #f9f9f9;
}

appoverlay[app][target="lesson"] {
    background: #f9f9f9;
}

/* App overlay */
appoverlay[app] {
    position: fixed;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    z-index: 10030;
    transition: opacity 0.16s ease-out;
    will-change: opacity;
}

/* Handoff overlay state */
appoverlay[app][handoff] {
    opacity: 0;
    pointer-events: auto;
}

appoverlay[app][handoff][loading] {
    opacity: 1;
}

/* App loader */
loader[app] {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 3rem;
    height: 3rem;
    transform: translate(-50%, -50%) scale(0.92);
    opacity: 0;
    z-index: 10031;
    pointer-events: none;
    border-radius: 50%;
    border: 0.18rem solid rgba(0, 0, 0, 0.16);
    border-top-color: var(--main-color, #050509);
    background: transparent;
    box-shadow: 0 0 0.8rem rgba(0, 0, 0, 0.12);
    transition: opacity 0.16s ease, transform 0.16s ease;
    animation: app-loader-spin 0.75s linear infinite;
}

/* Visible loader state */
appoverlay[app][loading] loader[app] {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Loader animation */
@keyframes app-loader-spin {
    from {
        transform: translate(-50%, -50%) rotate(0deg) scale(1);
    }

    to {
        transform: translate(-50%, -50%) rotate(360deg) scale(1);
    }
}

/* SPA debug log */
debuglog[spa] {
    position: fixed;
    right: 0.5rem;
    bottom: 0.5rem;
    width: 32rem;
    max-width: calc(100vw - 1rem);
    z-index: 10050;
    display: flex;
    flex-direction: column;
    border-radius: 0.6rem;
    border: 0.06rem solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.82);
    color: #f3f3f3;
    box-shadow: 0 0 1rem rgba(0, 0, 0, 0.4);
    font-size: 0.7rem;
}

debuglog[spa] > header {
    display: block;
    padding: 0.4rem 0.55rem;
    font-weight: 700;
    letter-spacing: 0.04rem;
    cursor: pointer;
    user-select: none;
    border-bottom: 0.06rem solid rgba(255, 255, 255, 0.2);
}

debuglog[spa] tools {
    display: none;
    gap: 0.35rem;
    padding: 0.35rem 0.45rem;
    border-bottom: 0.06rem solid rgba(255, 255, 255, 0.12);
}

debuglog[spa][open] tools {
    display: flex;
}

debuglog[spa] tools > button {
    border: 0.06rem solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.08);
    color: #f3f3f3;
    border-radius: 0.3rem;
    padding: 0.2rem 0.45rem;
    cursor: pointer;
    font-size: 0.68rem;
}

debuglog[spa] tools > button:hover {
    background: rgba(255, 255, 255, 0.16);
}

debuglog[spa] logs {
    display: none;
    max-height: 11rem;
    overflow: auto;
    padding: 0.35rem 0.45rem;
}

debuglog[spa][open] logs {
    display: block;
}

debuglog[spa] line {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2rem;
}

debuglog[spa] line[error] {
    color: #ff7f7f;
    text-shadow: 0 0 0.2rem rgba(255, 38, 38, 0.35);
}

debuglog[spa][detached] {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    max-width: none;
    border-radius: 0;
    border: none;
    box-shadow: none;
}

debuglog[spa][detached] > header {
    cursor: default;
}

debuglog[spa][detached] tools {
    display: flex;
}

debuglog[spa][detached] logs,
debuglog[spa][detached] pane,
debuglog[spa][detached] panes {
    max-height: 70vh;
}

uitest[panel-trash] {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    width: 22rem;
    max-height: 16rem;
    overflow: hidden;
    border: 0.08rem solid rgba(0, 0, 0, 0.2);
    background: #fff;
    border-radius: 0.6rem;
    box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.18);
    z-index: 10060;
    font-family: inherit;
}

uitest[panel-trash] > header {
    display: block;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 0.06rem solid rgba(0, 0, 0, 0.12);
}

uitest[panel-trash] > list {
    display: block;
    max-height: 12rem;
    overflow: auto;
    padding: 0.6rem 0.8rem;
}

uitest[panel-trash] line {
    display: block;
    padding: 0.35rem 0.4rem;
    margin-bottom: 0.3rem;
    border-radius: 0.4rem;
    background: #f6f6f6;
    font-size: 0.82rem;
}

uitest[panel-trash] line[state="running"] {
    background: #fff7e6;
    border: 0.06rem solid #ffd08a;
}

uitest[panel-trash] line[state="pass"] {
    background: #ecfdf3;
    border: 0.06rem solid #a8e6c1;
}

uitest[panel-trash] line[state="fail"] {
    background: #fff1f1;
    border: 0.06rem solid #ffb4b4;
}

[ui-test-highlight][ui-test-pass] {
    outline: 0.18rem solid #16a34a;
    outline-offset: 0.1rem;
}

[ui-test-highlight][ui-test-fail] {
    outline: 0.18rem solid #ef4444;
    outline-offset: 0.1rem;
}
