:root {
    --scotoma-workspace-height: calc(100vh - 49px);
    --scotoma-size: 500px;
}

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

html {
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
}

body.site-page.experimental-page.scotoma-page {
    width: 100%;
    max-width: none !important;
    min-height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--tbi-bg, #f1f2ed) !important;
    color: var(--tbi-ink, #20231c) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", Roboto, sans-serif;
}

@supports (min-height: 100dvh) {
    body.site-page.experimental-page.scotoma-page { min-height: 100dvh !important; }
}

body.scotoma-page > .tbi-sitebar {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    order: 0;
    width: 100% !important;
    margin: 0 !important;
    flex: 0 0 auto;
    border: 0 !important;
    border-bottom: 1px solid rgba(207, 210, 199, .9) !important;
    border-radius: 0 !important;
    background: rgba(241, 242, 237, .94) !important;
    box-shadow: none !important;
}

body.scotoma-page > .tbi-sitebar .tbi-sitebar-inner {
    width: min(1180px, calc(100% - 28px)) !important;
    min-height: 48px !important;
    padding: 0 !important;
}

body.scotoma-page > .tbi-sitebar .tbi-sitebar-meta span { display: inline; }

body.scotoma-page > .google-auto-placed {
    order: 2;
    flex: 0 0 auto !important;
}

.scotoma-shell {
    position: relative;
    order: 1;
    width: 100%;
    max-width: none !important;
    height: var(--scotoma-workspace-height);
    min-height: 0;
    margin: 0;
    padding: 0;
    display: flex;
    flex: 0 0 var(--scotoma-workspace-height);
    overflow: hidden;
    isolation: isolate;
    background: #e7e9e3;
}

.scotoma-stage {
    position: relative;
    z-index: 1;
    width: auto;
    min-width: 0;
    min-height: 0;
    margin: 0;
    display: block;
    flex: 1;
    overflow: hidden;
    background:
        linear-gradient(rgba(32, 35, 28, .035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(32, 35, 28, .035) 1px, transparent 1px),
        radial-gradient(circle at 50% 48%, rgba(255, 255, 255, .8), rgba(255, 255, 255, 0) 56%),
        #e7e9e3;
    background-size: 28px 28px, 28px 28px, auto, auto;
}

.scotoma-visual {
    position: absolute;
    inset: 0;
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    pointer-events: none;
}

.scotoma-frame {
    position: relative;
    width: var(--scotoma-size);
    height: var(--scotoma-size);
    max-width: calc(100% - 32px);
    max-height: calc(100% - 32px);
    border: 1px solid rgba(32, 35, 28, .26);
    border-radius: 50%;
    background: rgba(239, 240, 236, .74);
    box-shadow: 0 22px 60px rgba(32, 35, 28, .13), inset 0 0 42px rgba(255, 255, 255, .8);
}

.scotoma-frame::before,
.scotoma-frame::after {
    content: "";
    position: absolute;
    z-index: 4;
    border-radius: 50%;
    pointer-events: none;
}

.scotoma-frame::before {
    inset: 7%;
    border: 1px solid rgba(32, 35, 28, .1);
}

.scotoma-frame::after {
    inset: 48.8%;
    background: #23251d;
    box-shadow: 0 0 0 5px rgba(255, 255, 255, .42);
}

.scotoma-circle {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 50%;
    animation: scotoma-rotate 20s linear infinite;
    will-change: transform;
}

.scotoma-segment {
    position: absolute;
    inset: 0;
    overflow: hidden;
    transform-origin: center;
}

.scotoma-segment-content {
    position: absolute;
    inset: 0;
    clip-path: polygon(50% 50%, 50% 0%, 100% 0%);
}

.scotoma-crescent-container {
    position: absolute;
    width: 0;
    height: 0;
    animation: scotoma-orbit var(--orbit-duration) linear infinite var(--orbit-direction);
    left: 50%;
    top: 50%;
    transform-origin: 0 0;
    will-change: transform;
}

.scotoma-crescent {
    position: absolute;
    left: var(--orbit-radius);
    top: calc(var(--crescent-size) * -.5);
    width: var(--crescent-size);
    height: var(--crescent-size);
    border-radius: 50%;
    background: radial-gradient(
        circle at 70% 48%,
        transparent 0 35%,
        var(--crescent-tone) 38% 61%,
        transparent 64%
    );
    opacity: var(--crescent-opacity);
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .18));
    animation: scotoma-self-rotate var(--self-rotation-duration) linear infinite var(--self-rotation-direction);
    transform-origin: center;
    will-change: transform;
}

.scotoma-toolbar {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

body.site-page.scotoma-page .scotoma-toolbar button,
body.site-page.scotoma-page .info-toggle {
    min-height: 44px;
    margin: 0;
    padding: 8px 12px !important;
    border: 1px solid rgba(255, 255, 255, .28) !important;
    border-radius: 999px !important;
    background: rgba(35, 37, 29, .9) !important;
    color: #fff !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .15) !important;
    font-size: .75rem;
    font-weight: 800;
    line-height: 1.2;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
}

body.site-page.scotoma-page #regenerate-motion {
    border-color: rgba(32, 35, 28, .18) !important;
    background: rgba(255, 255, 255, .86) !important;
    color: #23251d !important;
}

.control-icon,
.info-toggle-icon {
    display: inline-block;
    min-width: 1em;
    margin-right: 6px;
    font-size: .95rem;
    line-height: 1;
    text-align: center;
}

.scotoma-status {
    position: absolute;
    top: max(65px, calc(env(safe-area-inset-top) + 60px));
    left: max(14px, env(safe-area-inset-left));
    z-index: 30;
    margin: 0;
    padding: 6px 9px;
    border: 1px solid rgba(207, 210, 199, .75);
    border-radius: 7px;
    background: rgba(255, 255, 255, .78);
    color: #62665d !important;
    font: 700 .6875rem/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.scotoma-hud {
    position: absolute;
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    z-index: 20;
    margin: 0;
    color: #686c63;
    font: 800 .625rem/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: .08em;
    pointer-events: none;
}

body.site-page.scotoma-page .info-toggle {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    z-index: 70;
}

.scotoma-note {
    position: relative;
    left: auto;
    bottom: auto;
    z-index: 40;
    width: clamp(350px, 29vw, 410px);
    min-width: 330px;
    min-height: 0;
    margin: 0;
    padding: 24px 20px;
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    overflow: auto;
    border: 0;
    border-left: 1px solid var(--tbi-line, #cfd2c7);
    border-radius: 0;
    background: var(--tbi-paper, #fff);
    color: var(--tbi-ink, #20231c);
    box-shadow: none;
    backdrop-filter: none;
}

.note-kicker {
    display: block;
    margin-bottom: 7px;
    color: #74786d;
    font: 800 .65rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: .09em;
}

body.site-page.scotoma-page .scotoma-note h1 {
    margin: 0 0 12px !important;
    color: var(--tbi-ink, #20231c) !important;
    font-size: clamp(1.7rem, 3.2vw, 2.5rem) !important;
    line-height: 1.08;
    letter-spacing: -.04em;
}

body.site-page.scotoma-page .scotoma-note p {
    margin: 0;
    color: var(--tbi-body, #55584f) !important;
    font-size: .875rem;
    line-height: 1.7;
}

.study-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.study-meta span {
    min-height: 54px;
    padding: 9px;
    display: flex;
    align-items: end;
    border: 1px solid var(--tbi-line-soft, #e4e6df);
    border-radius: 8px;
    background: var(--tbi-bg, #f1f2ed);
    color: #676b62;
    font: 800 .625rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: .06em;
}

body.info-closed .scotoma-note { display: none; }

body.motion-paused .scotoma-circle,
body.motion-paused .scotoma-crescent-container,
body.motion-paused .scotoma-crescent,
body.page-hidden .scotoma-circle,
body.page-hidden .scotoma-crescent-container,
body.page-hidden .scotoma-crescent {
    animation-play-state: paused !important;
}

body.site-page.scotoma-page :focus-visible {
    outline: 3px solid rgba(180, 119, 0, .34) !important;
    outline-offset: 2px;
}

@keyframes scotoma-rotate { to { transform: rotate(360deg); } }
@keyframes scotoma-orbit { to { transform: rotate(360deg); } }
@keyframes scotoma-self-rotate { to { transform: rotate(360deg); } }

@media (max-width: 820px),
       (max-width: 1024px) and (max-height: 600px) and (orientation: landscape) {
    .scotoma-shell { display: block; }
    .scotoma-stage { width: 100%; height: 100%; }
    .scotoma-note {
        position: absolute;
        inset: auto max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        z-index: 80;
        width: auto;
        min-width: 0;
        max-height: min(48%, 430px);
        padding: 17px;
        display: none;
        justify-content: flex-start;
        gap: 12px;
        border: 1px solid var(--tbi-line, #cfd2c7);
        border-radius: 12px;
        box-shadow: 0 18px 48px rgba(0, 0, 0, .24);
    }
    body.info-open .scotoma-note { display: flex; }
    body.site-page.scotoma-page .scotoma-note h1 { font-size: clamp(1.35rem, 6vw, 1.8rem) !important; }
    body.site-page.scotoma-page .scotoma-note p { font-size: .8rem; line-height: 1.55; }
    .study-meta { display: none; }
}

@media (max-width: 480px) {
    .control-label,
    .info-toggle-label { display: none; }
    body.site-page.scotoma-page .scotoma-toolbar button,
    body.site-page.scotoma-page .info-toggle {
        width: 44px;
        min-width: 44px;
        padding: 0 !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 50% !important;
    }
    .control-icon,
    .info-toggle-icon { margin: 0; }
    .scotoma-status { top: max(65px, calc(env(safe-area-inset-top) + 60px)); }
}

@media (max-height: 620px) and (orientation: landscape) {
    .scotoma-note { max-height: calc(100% - 16px); }
    .scotoma-hud { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    body.scotoma-page:not(.motion-enabled) .scotoma-circle,
    body.scotoma-page:not(.motion-enabled) .scotoma-crescent-container,
    body.scotoma-page:not(.motion-enabled) .scotoma-crescent {
        animation-play-state: paused !important;
    }
}
