/* ---------------------------------------------------------
   Stas Lebedev — Isometric noodle shop home page
   Without WebGL (or before it boots) this is a plain, readable page.
   With WebGL, html.webgl turns it into the 3D shop with overlay UI.
--------------------------------------------------------- */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-serif: 'Cormorant Garamond', Georgia, serif;
    --font-jp: 'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif;

    --bg-1: #f7efe1;
    --bg-2: #e8d9c0;
    --ink: #1f1a15;
    --ink-2: #594f45;
    --muted: #8a7d6e;
    --card: #fffaf1;
    --card-edge: #e4d4ba;
    --accent: #b8322a;
    --accent-ink: #fff7ef;
    --indigo: #24305e;
    --shadow: 0 18px 40px -18px rgba(70, 45, 20, 0.38), 0 2px 6px rgba(70, 45, 20, 0.08);
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg-1: #232542;
    --bg-2: #0d0e19;
    --ink: #f4ede2;
    --ink-2: #cbc1b3;
    --muted: #918aa3;
    --card: #181a2b;
    --card-edge: #2e3049;
    --accent: #e0574a;
    --accent-ink: #1b0c0a;
    --indigo: #8e9ce0;
    --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--ink);
    line-height: 1.6;
    background-color: var(--bg-2);
    background-image: radial-gradient(120% 90% at 50% 38%, var(--bg-1) 0%, var(--bg-2) 72%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.6s ease, color 0.6s ease;
}

/* A few stars once the lanterns are lit */
:root[data-theme="dark"] body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.55;
    background-image:
        radial-gradient(1px 1px at 12% 18%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 28% 8%, #fff 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 44% 22%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 63% 12%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 78% 26%, #fff 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 88% 9%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 6% 42%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 94% 48%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 53% 4%, #fff 50%, transparent 51%);
}

a {
    color: inherit;
}

.jp {
    font-family: var(--font-jp);
    font-weight: 700;
}

::selection {
    background: var(--ink);
    color: var(--bg-1);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.skip-link {
    position: absolute;
    top: -48px;
    left: 0;
    z-index: 30;
    padding: 8px 16px;
    background: var(--ink);
    color: var(--bg-1);
}

.skip-link:focus {
    top: 0;
}

/* ---------- Loader ---------- */
.loader {
    display: none;
}

.is-loading .loader {
    display: grid;
    place-items: center;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: var(--bg-2);
    color: var(--ink-2);
    font-family: var(--font-serif);
    font-size: 1.35rem;
}

/* Don't animate the switch from the plain layout to the 3D layout */
.is-loading *,
.is-loading *::before {
    transition: none !important;
}

.loader .dots {
    display: inline-block;
    animation: blink 1.2s steps(2) infinite;
}

/* ---------- Scene ---------- */
#scene {
    display: none;
}

.webgl body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.webgl #scene {
    display: block;
    position: fixed;
    inset: 0;
}

.webgl #scene canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Brand ---------- */
.brand {
    max-width: 680px;
    margin: 0 auto;
    padding: 4rem 1.5rem 2rem;
}

.webgl .brand {
    position: fixed;
    top: 2rem;
    left: 2rem;
    z-index: 5;
    max-width: 340px;
    margin: 0;
    padding: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.seal {
    display: inline-grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    margin-bottom: 0.9rem;
    border-radius: 4px;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 1.15rem;
    line-height: 1;
    transform: rotate(-4deg);
}

.brand h1 {
    font-family: var(--font-serif);
    font-size: 2.75rem;
    font-weight: 400;
    line-height: 1.05;
    letter-spacing: -0.02em;
}

.brand .role {
    margin-top: 0.6rem;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}

.brand .hint {
    display: none;
}

.webgl .brand .hint {
    display: block;
    margin-top: 1rem;
    max-width: 260px;
    font-size: 0.85rem;
    color: var(--ink-2);
}

/* ---------- Theme toggle (same moon/sun morph as the about page) ---------- */
.theme-toggle {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 12;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--card-edge);
    border-radius: 50%;
    background: var(--card);
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.6s ease;
}

.theme-toggle:hover {
    border-color: var(--ink);
}

.toggle-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--ink);
    transition: all 0.4s var(--ease);
}

:root[data-theme="dark"] .toggle-icon {
    width: 18px;
    height: 18px;
    background-color: transparent;
    box-shadow: inset -5px -5px 0 0 var(--ink);
    transform: rotate(-15deg);
}

/* ---------- Ticket menu ---------- */
.tickets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-width: 680px;
    margin: 0 auto;
    padding: 0 1.5rem 1rem;
}

.ticket-home {
    display: none !important;
}

.webgl .ticket-home {
    display: flex !important;
}

.webgl .tickets {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 6;
    flex-wrap: nowrap;
    max-width: none;
    margin: 0;
    padding: 0;
    transform: translateX(-50%);
    transition: opacity 0.3s ease;
}

.ticket {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.85rem 0.5rem 0.55rem;
    border: 1px solid var(--card-edge);
    border-radius: 6px;
    background: var(--card);
    box-shadow: var(--shadow);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.2s var(--ease), border-color 0.2s ease, background-color 0.6s ease;
}

.ticket:hover {
    transform: translateY(-2px);
    border-color: var(--ink-2);
}

.ticket .num {
    display: grid;
    place-items: center;
    width: 1.7rem;
    height: 1.7rem;
    flex: none;
    border-radius: 50%;
    border: 1px solid var(--accent);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 600;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.ticket .txt {
    display: flex;
    flex-direction: column;
    padding-left: 0.6rem;
    border-left: 1px dashed var(--card-edge);
    line-height: 1.2;
}

.ticket .txt .jp {
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--muted);
}

.ticket[aria-current="page"] {
    border-color: var(--accent);
}

.ticket[aria-current="page"] .num {
    background: var(--accent);
    color: var(--accent-ink);
}

/* ---------- Hotspots (projected from 3D each frame) ---------- */
.hotspots {
    display: none;
}

.webgl .hotspots {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    transition: opacity 0.35s ease, visibility 0s;
}

.webgl:not([data-station="overview"]) .hotspots {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0s 0.2s;
}

.hotspot {
    position: absolute;
    top: 0;
    left: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    pointer-events: auto;
    will-change: transform;
}

.hotspot .dot {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    transform: translate(-50%, -50%);
    animation: pulse 2.6s ease-out infinite;
}

.hotspot .label {
    position: absolute;
    top: 0;
    left: 20px;
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--card-edge);
    border-radius: 4px;
    background: var(--card);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    transform: translate(-4px, -50%);
    transition: opacity 0.2s ease, transform 0.2s var(--ease);
    pointer-events: none;
}

.hotspot:hover .label,
.hotspot:focus-visible .label,
.hotspot.is-hovered .label {
    opacity: 1;
    transform: translate(0, -50%);
}

/* ---------- Pointer tooltip ---------- */
.tooltip {
    display: none;
}

.webgl .tooltip {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    background: var(--ink);
    color: var(--bg-1);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.webgl .tooltip.show {
    opacity: 1;
}

/* ---------- Panel ---------- */
.panel {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
}

.panel-close,
.panel-nav {
    display: none;
}

.panel article {
    padding: 2.5rem 0;
    border-top: 1px solid var(--card-edge);
}

/* While a station is open on desktop, the tickets shrink to numbers and sit
   centred in the space left of the panel; the brand drops its hint. */
@media (min-width: 721px) {
    .webgl:not([data-station="overview"]) .tickets {
        left: calc((100vw - 400px - 1.5rem) / 2);
    }

    .webgl:not([data-station="overview"]) .brand .hint,
    .webgl:not([data-station="overview"]) .brand .role {
        opacity: 0;
    }
}

@media (min-width: 721px) and (max-width: 1279px) {
    .webgl:not([data-station="overview"]) .ticket .txt {
        display: none;
    }

    .webgl:not([data-station="overview"]) .ticket {
        padding: 0.4rem;
    }
}

.brand .hint,
.brand .role {
    transition: opacity 0.3s ease;
}

.webgl .panel {
    position: fixed;
    top: 5rem;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 3rem));
    margin: 0;
    padding: 0;
    border: 1px solid var(--card-edge);
    border-radius: 10px;
    background: var(--card);
    box-shadow: var(--shadow);
    transform: translateX(calc(100% + 2rem));
    opacity: 0;
    visibility: hidden;
    transition: transform 0.55s var(--ease), opacity 0.3s ease, visibility 0s 0.55s, background-color 0.6s ease;
}

/* Noren-style slit band across the top of the panel */
.webgl .panel::before {
    content: '';
    flex: none;
    height: 12px;
    border-radius: 9px 9px 0 0;
    background: repeating-linear-gradient(90deg, var(--indigo) 0 calc(25% - 3px), transparent calc(25% - 3px) 25%);
    opacity: 0.9;
}

.webgl:not([data-station="overview"]) .panel {
    transform: none;
    opacity: 1;
    visibility: visible;
    transition: transform 0.55s var(--ease), opacity 0.3s ease, visibility 0s, background-color 0.6s ease;
}

.webgl .panel-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.75rem 1.75rem 1.5rem;
}

.webgl .panel article {
    display: none;
    padding: 0;
    border: 0;
}

.webgl .panel article[data-active] {
    display: block;
    animation: rise 0.5s var(--ease) both;
}

.webgl .panel-close {
    display: grid;
    place-items: center;
    position: absolute;
    top: 1.35rem;
    right: 0.9rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--ink-2);
    font-size: 1.35rem;
    line-height: 1;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.webgl .panel-close:hover {
    background: var(--card-edge);
    color: var(--ink);
}

.webgl .panel-nav {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    flex: none;
    padding: 0.75rem 1rem;
    border-top: 1px dashed var(--card-edge);
}

.panel-nav button {
    padding: 0.45rem 0.6rem;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--ink-2);
    font: 500 0.8rem var(--font-sans);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.panel-nav button:hover {
    background: var(--card-edge);
    color: var(--ink);
}

.panel-footer {
    padding-top: 2rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.webgl .panel-footer {
    display: none;
}

/* ---------- Article content ---------- */
.kicker {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}

.kicker .jp {
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

.panel h2 {
    margin-bottom: 1.25rem;
    font-family: var(--font-serif);
    font-size: 2.4rem;
    font-weight: 400;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.panel h2:focus {
    outline: none;
}

.panel h3 {
    margin-bottom: 0.35rem;
    font-size: 1rem;
    font-weight: 600;
}

.panel p {
    font-size: 0.94rem;
    color: var(--ink-2);
}

.panel .lead {
    font-size: 1.1rem;
    font-weight: 300;
    line-height: 1.65;
}

.more-link {
    display: inline-block;
    margin-top: 1.5rem;
    padding-bottom: 2px;
    border-bottom: 1px solid currentColor;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
}

.menu-list,
.timeline,
.contact-list {
    list-style: none;
}

.menu-list li {
    padding: 1rem 0;
    border-top: 1px dashed var(--card-edge);
}

.menu-list li:first-child {
    border-top: 0;
    padding-top: 0;
}

.timeline li {
    position: relative;
    padding: 0 0 1.75rem 1.25rem;
    border-left: 1px solid var(--card-edge);
}

.timeline li::before {
    content: '';
    position: absolute;
    top: 0.45rem;
    left: -4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
}

.timeline li:last-child {
    padding-bottom: 0;
}

.timeline .date {
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.contact-list a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 0;
    border-bottom: 1px solid var(--card-edge);
    font-weight: 500;
    text-decoration: none;
    transition: padding 0.2s ease, border-color 0.2s ease;
}

.contact-list a:hover {
    padding-inline: 0.4rem;
    border-color: var(--ink);
}

.contact-list .detail {
    color: var(--ink-2);
    font-size: 0.88rem;
}

/* ---------- Portfolio ---------- */
.portfolio-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    list-style: none;
}

.portfolio-list .card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.card .thumb {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    border: 1px solid var(--card-edge);
    border-radius: 6px;
    background: color-mix(in srgb, var(--card-edge) 55%, var(--card));
}

.card .thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s var(--ease);
}

.card .glyph {
    font-size: 1.4rem;
    color: var(--muted);
}

.card .badge {
    position: absolute;
    top: 0.4rem;
    left: 0.4rem;
    z-index: 1;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: var(--card);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-2);
}

.card[data-kind="video"] .thumb::after {
    content: '▶';
    position: absolute;
    display: grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    padding-left: 3px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.8rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.card:hover .thumb img {
    transform: scale(1.04);
}

.card:hover .title {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.card .meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.card .title {
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.3;
}

.card .desc {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 0.78rem;
    color: var(--ink-2);
    line-height: 1.4;
}

.card .year {
    font-size: 0.72rem;
    color: var(--muted);
}

.portfolio-empty {
    padding: 1.25rem;
    border: 1px dashed var(--card-edge);
    border-radius: 6px;
    text-align: center;
}

/* Viewer dialog */
.viewer {
    width: min(960px, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    margin: auto;
    padding: 0;
    overflow: auto;
    border: 1px solid var(--card-edge);
    border-radius: 10px;
    background: var(--card);
    color: var(--ink);
    box-shadow: var(--shadow);
}

.viewer::backdrop {
    background: rgba(12, 10, 8, 0.72);
    backdrop-filter: blur(4px);
}

.viewer-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1rem 0.9rem 1.25rem;
}

.viewer-head h2 {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 400;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.viewer-open {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink-2);
    white-space: nowrap;
}

.viewer-close {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--ink-2);
    font-size: 1.35rem;
    cursor: pointer;
}

.viewer-close:hover {
    background: var(--card-edge);
    color: var(--ink);
}

.viewer-media {
    display: grid;
    place-items: center;
    background: #000;
}

.viewer-media iframe,
.viewer-media video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 75vh;
    border: 0;
}

.viewer-media[data-kind="drive"] iframe {
    aspect-ratio: 4 / 3;
}

.viewer-media img {
    display: block;
    max-width: 100%;
    max-height: 75vh;
    object-fit: contain;
}

.viewer-desc {
    padding: 0.9rem 1.25rem 1.1rem;
    font-size: 0.9rem;
    color: var(--ink-2);
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
    .webgl .brand {
        top: 1.25rem;
        left: 1.25rem;
        right: 4.5rem;
    }

    .brand h1 {
        font-size: 2.1rem;
    }

    .seal {
        width: 1.8rem;
        height: 1.8rem;
        margin-bottom: 0.6rem;
        font-size: 1rem;
    }

    .webgl .brand .hint {
        margin-top: 0.6rem;
        font-size: 0.8rem;
    }

    .webgl:not([data-station="overview"]) .brand {
        opacity: 0;
    }

    .theme-toggle {
        top: 1.25rem;
        right: 1.25rem;
    }

    .webgl .tickets {
        left: 0;
        right: 0;
        bottom: max(0.9rem, env(safe-area-inset-bottom));
        padding: 0.5rem 1rem;
        overflow-x: auto;
        transform: none;
        scrollbar-width: none;
    }

    .webgl .tickets::-webkit-scrollbar {
        display: none;
    }

    .ticket .txt .jp {
        display: none;
    }

    .webgl:not([data-station="overview"]) .tickets {
        opacity: 0;
        pointer-events: none;
    }

    .webgl .panel {
        top: auto;
        left: 0.75rem;
        right: 0.75rem;
        bottom: max(0.75rem, env(safe-area-inset-bottom));
        width: auto;
        max-height: 56vh;
        max-height: 56dvh;
        transform: translateY(calc(100% + 2rem));
    }

    .webgl .panel-body {
        padding: 1.25rem 1.25rem 1rem;
    }

    .panel h2 {
        font-size: 2rem;
        margin-bottom: 0.9rem;
    }

    .webgl .panel-close {
        top: 1.1rem;
    }
}

/* ---------- Motion ---------- */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent);
    }

    70%,
    100% {
        box-shadow: 0 0 0 12px color-mix(in srgb, var(--accent) 0%, transparent);
    }
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes blink {
    50% {
        opacity: 0.2;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
