@font-face {
    font-family: '8BIT WONDER';
    src: url('fonts/8bit-wonder.ttf') format('truetype');
    font-display: swap;
}

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

body {
    margin: 0;
    overflow: hidden;
    /* the pixel font is for headings and buttons; paragraphs need a clean font */
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

canvas {
    display: block;
}

#views {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    width: max-content;
    max-width: calc(100% - 32px);
}

/* ---- pixel buttons: the top menu and the view buttons ----
   Drawn like Crossy Road's in-game buttons, in design pixels of --u (4px):
   a light band along the top, a dark band along the bottom, a white outline
   on the sides and bottom, and stepped corners. Only CSS, no images. */

.px-btn {
    --u: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 40px;
    margin: 0;
    padding: var(--u) 16px;
    border: 0;
    color: #fff;
    font: 13px/1 '8BIT WONDER', sans-serif;
    text-transform: uppercase;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    /* a 1px outline and a 2px drop in the dark colour keep white text readable on the light colours */
    text-shadow:
        1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink),
        1px 1px 0 var(--ink), -1px 1px 0 var(--ink), 1px -1px 0 var(--ink), -1px -1px 0 var(--ink),
        0 2px 0 var(--ink), 1px 2px 0 var(--ink), -1px 2px 0 var(--ink), 0 3px 0 var(--ink);
    /* layers, first on top: corner pixels, top band, bottom band, body.
       No background-color, so the two top corner pixels stay see-through */
    background:
        linear-gradient(var(--hl) 0 0) left 0 top var(--u) / var(--u) var(--u) no-repeat,
        linear-gradient(var(--hl) 0 0) right 0 top var(--u) / var(--u) var(--u) no-repeat,
        linear-gradient(var(--sh) 0 0) left 0 bottom var(--u) / var(--u) var(--u) no-repeat,
        linear-gradient(var(--sh) 0 0) right 0 bottom var(--u) / var(--u) var(--u) no-repeat,
        linear-gradient(#fff 0 0) left 0 bottom 0 / var(--u) var(--u) no-repeat,
        linear-gradient(#fff 0 0) right 0 bottom 0 / var(--u) var(--u) no-repeat,
        linear-gradient(var(--hl) 0 0) center top / calc(100% - 2 * var(--u)) var(--u) no-repeat,
        linear-gradient(var(--sh) 0 0) center bottom / 100% var(--u) no-repeat,
        linear-gradient(var(--body) 0 0) center / 100% calc(100% - 2 * var(--u)) no-repeat;
    /* the white outline: the side lines start two pixels down (stepped top corners)
       and the bottom line stops at the sides (notched bottom corners) */
    box-shadow:
        calc(-2 * var(--u)) var(--u) 0 calc(-1 * var(--u)) #fff,
        calc(2 * var(--u)) var(--u) 0 calc(-1 * var(--u)) #fff,
        0 var(--u) 0 0 #fff;
    /* a hard dark shadow lifts the button off the scene */
    filter: drop-shadow(0 var(--u) 0 rgba(0, 0, 0, 0.35));
    transition: transform 0.08s ease-out, filter 0.08s ease-out;
}

/* colours, for buttons and page banners: --hl top band, --body, --sh bottom band, --ink text outline */
.gold   { --body: #ecbd54; --hl: #fbe79e; --sh: #b25534; --ink: #b25534; } /* chicken */
.blue   { --body: #75c3f3; --hl: #b6e8fe; --sh: #2e5bd8; --ink: #2e5bd8; } /* shoyu */
.orange { --body: #f2a346; --hl: #fad593; --sh: #ae452a; --ink: #ae452a; } /* miso */
.pink   { --body: #eb6c77; --hl: #f8b0b3; --sh: #a8324e; --ink: #a8324e; } /* spicy miso */
.teal   { --body: #4fb8b0; --hl: #a2e3da; --sh: #23727f; --ink: #23727f; } /* the stall's roof */
.red    { --body: #e5483d; --hl: #f8948a; --sh: #a42a24; --ink: #a42a24; } /* the close button */
.green  { --body: #7cc46a; --hl: #c3eaa5; --sh: #367a3c; --ink: #367a3c; } /* the izakaya's menu: skills */
.indigo { --body: #5b6ad0; --hl: #a5aef2; --sh: #2f3a94; --ink: #2f3a94; } /* the taishō's chat */

/* the view you're on turns gold, like the Play button */
#views .px-btn[aria-pressed="true"] {
    --body: #ecbd54;
    --hl: #fbe79e;
    --sh: #b25534;
    --ink: #b25534;
}

.px-btn svg {
    display: block;
    flex: none;
    filter: drop-shadow(0 2px 0 var(--ink));
}

/* only where there's a mouse, so the lift doesn't stick after a tap on phones */
@media (hover: hover) {
    .px-btn:hover {
        transform: translateY(-2px);
        filter: drop-shadow(0 calc(var(--u) + 2px) 0 rgba(0, 0, 0, 0.35)) brightness(1.06);
    }
}

/* pressed, and the page that's open: sink one pixel, lose the bottom band and the shadow */
.px-btn:active,
#views .px-btn:active,
.px-btn[aria-current="page"] {
    transform: translateY(var(--u));
    --sh: var(--body);
    filter: none;
}

.px-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 8px;
}

/* smaller buttons inside the page panel */
.px-btn.small {
    height: 32px;
    padding: var(--u) 12px;
    font-size: 11px;
    gap: 8px;
}

.px-btn.wide {
    width: 220px;
    justify-content: flex-start;
}

/* ---- page panel ---- */

#panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    width: 40%;
    min-width: 360px;
    overflow-y: auto;
    padding: 0;
    /* paper, like a ramen shop menu */
    background: #fbf3e3;
    /* a white pixel edge and a hard shadow against the scene */
    box-shadow: -4px 0 0 #fff, -8px 0 0 rgba(0, 0, 0, 0.3);
    color: #4a3b2c;
    line-height: 1.6;
    transform: translateX(100%);
    visibility: hidden;
    /* hide only after the slide-out finishes */
    transition: transform 0.4s ease, visibility 0s linear 0.4s;
}

#panel.open {
    transform: none;
    visibility: visible;
    transition: transform 0.4s ease;
}

/* the close button floats over the banner and stays put while the page scrolls */
#panel-close {
    position: sticky;
    top: 30px;
    z-index: 2;
    display: flex;
    width: 44px;
    padding: var(--u) 0;
    /* the negative bottom margin lets the banner start at the very top, under the button */
    margin: 30px 32px -70px auto;
}

/* white focus rings don't show on paper */
#panel .px-btn:focus-visible {
    outline-color: #2b2118;
}

/* the page's banner, in its bowl's colour (the section's class sets the colours) */
#panel .banner {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 34px 96px 28px 40px;
    background: linear-gradient(var(--sh) 0 0) center bottom / 100% 6px no-repeat, var(--body);
}

#panel h2 {
    font: 30px/1 '8BIT WONDER', sans-serif;
    color: #fff;
    text-transform: uppercase;
    /* the buttons' text outline at double size */
    text-shadow:
        2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink),
        2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink),
        0 4px 0 var(--ink), 2px 4px 0 var(--ink), -2px 4px 0 var(--ink), 0 6px 0 var(--ink);
}

#panel .ja {
    margin-top: 14px;
    font: 17px/1.2 'DotGothic16', system-ui, sans-serif;
    color: #fff;
    text-shadow:
        1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink),
        1px 1px 0 var(--ink), -1px 1px 0 var(--ink), 1px -1px 0 var(--ink), -1px -1px 0 var(--ink),
        0 2px 0 var(--ink);
}

#panel .content {
    display: flex;
    flex-direction: column;
    gap: 26px;
    padding: 30px 40px 40px;
}

/* cards: paper with a light top edge, a darker bottom edge and stepped corners */
#panel article,
#panel .card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 18px 20px;
    background:
        linear-gradient(#fff 0 0) center top / calc(100% - 8px) 4px no-repeat,
        linear-gradient(#fff 0 0) left 0 top 4px / 4px 4px no-repeat,
        linear-gradient(#fff 0 0) right 0 top 4px / 4px 4px no-repeat,
        linear-gradient(#e2d2b4 0 0) center bottom / calc(100% - 8px) 4px no-repeat,
        linear-gradient(#e2d2b4 0 0) left 0 bottom 4px / 4px 4px no-repeat,
        linear-gradient(#e2d2b4 0 0) right 0 bottom 4px / 4px 4px no-repeat,
        linear-gradient(#fffaf1 0 0) center / 100% calc(100% - 8px) no-repeat;
}

#panel h3 {
    margin-top: 4px;
    font: 15px/1.2 '8BIT WONDER', sans-serif;
    color: #2b2118;
    text-transform: uppercase;
}

#panel article p,
#panel .card p {
    font-size: 15px;
    line-height: 1.55;
}

/* plain text links, if you add any */
#panel a:not(.px-btn) {
    color: #b25534;
}

#panel a:not(.px-btn):focus-visible {
    outline: 3px solid #2b2118;
    outline-offset: 2px;
}

/* a project screenshot across the top of its card */
#panel .shot {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

/* small pixel tags: what a project used, or the dates of a job */
#panel .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
}

#panel .tags li,
#panel .dates {
    padding: 7px 8px 6px;
    font: 10px/1 '8BIT WONDER', sans-serif;
    color: #5a4630;
    text-transform: uppercase;
    white-space: nowrap;
    background: #f0e2c6;
    box-shadow: inset 0 -3px 0 #dccaa7;
}

#panel .links {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 4px;
}

/* contact: one button per line */
#panel .links.stack {
    flex-direction: column;
    align-items: flex-start;
    gap: 22px;
}

/* experience: the job title with its dates on the right */
#panel .entry-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* about: the photo next to the text */
#panel .about {
    flex-direction: row;
    align-items: flex-start;
    gap: 18px;
}

#panel figure {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

#panel figure img {
    display: block;
    width: 120px;
    height: 120px;
    object-fit: cover;
    /* a white pixel frame with a shade underneath */
    box-shadow: 0 0 0 4px #fff, 0 8px 0 0 #e2d2b4;
}

/* skills: the izakaya's menu, each skill and its dish on one dotted line */
#panel h3 span {
    margin-left: 8px;
    font: 15px/1 'DotGothic16', system-ui, sans-serif;
    color: #8a6e4b;
    text-transform: none;
}

#panel .menu {
    display: flex;
    flex-direction: column;
    gap: 14px;
    list-style: none;
}

#panel .menu-line {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

#panel .skill {
    font: 12px/1.2 '8BIT WONDER', 'DotGothic16', sans-serif;
    color: #2b2118;
    text-transform: uppercase;
    white-space: nowrap;
}

#panel .skill[lang="ja"] {
    font: 15px/1.2 'DotGothic16', system-ui, sans-serif;
}

#panel .dots {
    flex: 1;
    min-width: 16px;
    border-bottom: 2px dotted #d8c6a3;
    transform: translateY(-3px);
}

#panel .dish {
    font: 15px/1 'DotGothic16', system-ui, sans-serif;
    color: #367a3c;
    white-space: nowrap;
}

#panel .menu p:not(.menu-line) {
    margin-top: 3px;
    font-size: 14px;
    line-height: 1.45;
    color: #5a4630;
}

#panel figcaption {
    font: 10px/1 '8BIT WONDER', sans-serif;
    color: #5a4630;
    text-transform: uppercase;
}

/* phones: a sheet that slides up from the bottom */
@media (max-width: 700px) {
    #panel {
        top: auto;
        left: 0;
        width: 100%;
        min-width: 0;
        max-height: 70vh;
        box-shadow: 0 -4px 0 #fff, 0 -8px 0 rgba(0, 0, 0, 0.3);
        transform: translateY(100%);
    }

    #panel-close {
        top: 20px;
        margin: 20px 22px -60px auto;
    }

    #panel .banner {
        padding: 22px 80px 20px 20px;
    }

    #panel h2 {
        font-size: 24px;
    }

    #panel .ja {
        margin-top: 12px;
        font-size: 15px;
    }

    #panel .content {
        gap: 22px;
        padding: 22px 20px 32px;
    }
}

/* while a page is open, centre the view buttons in the space left of the panel */
@media (min-width: 701px) {
    #views {
        transition: left 0.4s ease;
    }

    body:has(#panel.open) #views {
        left: calc((100% - max(40%, 360px)) / 2);
        max-width: calc(100% - max(40%, 360px) - 32px);
    }
}

/* ---- loading screen ---- */

#loader {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: #060a14;
    color: #e8ecf4;
    transition: opacity 0.6s ease, visibility 0s linear 0.6s;
}

#loader.done {
    opacity: 0;
    visibility: hidden;
}

#loader p {
    /* Latin letters use 8BIT WONDER; Japanese falls through to DotGothic16 */
    font: 20px '8BIT WONDER', 'DotGothic16', sans-serif;
    text-align: center;
    padding: 0 16px;
}

/* a red ramen bowl with three wisps of steam */
#loader .bowl {
    position: relative;
    width: 96px;
    height: 48px;
    margin-top: 48px;
    border-radius: 0 0 48px 48px;
    background: #c43d2c;
    border-top: 6px solid #f2e3c6;
}

#loader .steam {
    position: absolute;
    bottom: 100%;
    width: 8px;
    height: 32px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    animation: steam 2s ease-in infinite;
}

#loader .steam:nth-child(1) { left: 24px; }
#loader .steam:nth-child(2) { left: 44px; animation-delay: 0.6s; }
#loader .steam:nth-child(3) { left: 64px; animation-delay: 1.2s; }

@keyframes steam {
    0%   { transform: translateY(8px) scaleX(1); opacity: 0; }
    40%  { opacity: 0.8; }
    100% { transform: translateY(-24px) scaleX(1.8); opacity: 0; }
}

#loader .bar {
    position: relative;
    width: 200px;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.15);
}

#loader .bar-fill {
    width: 0;
    height: 100%;
    background: #ffb27a;
    transition: width 0.2s ease;
}

/* no file size from the server: loop instead of showing progress */
#loader .bar.indeterminate .bar-fill {
    width: 40%;
    transition: none;
    animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
    from { transform: translateX(-100%); }
    to   { transform: translateX(250%); }
}

/* ---- plain menu ---- */

#pages {
    position: fixed;
    top: 20px;
    left: 24px;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    /* leave room for the sound button on the right */
    max-width: calc(100% - 108px);
}

/* phones: the menu goes two by two and the view buttons show only their icons */
@media (max-width: 700px) {
    #pages {
        top: 16px;
        left: 20px;
        right: 20px;
        max-width: none;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 16px;
        row-gap: 18px;
    }

    #pages .px-btn {
        font-size: 12px;
    }

    #views {
        gap: 14px;
    }

    #views .px-btn {
        width: 52px;
        padding: var(--u) 0;
    }

    /* hidden on screen, but still read out by screen readers */
    #views .label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* ---- sound on/off, top right ---- */

#sound {
    position: fixed;
    top: 20px;
    right: 24px;
    z-index: 1;
    width: 44px;
    padding: var(--u) 0;
}

/* a speaker with waves while the sound is on, crossed out while it's off */
#sound[aria-pressed="true"] .off,
#sound[aria-pressed="false"] .on {
    display: none;
}

/* wide screens: while a page is open, step left of the panel instead of hiding under it
   (narrower screens don't have room next to the menu, so there the panel covers it) */
@media (min-width: 1400px) {
    #sound {
        transition: right 0.4s ease, transform 0.08s ease-out, filter 0.08s ease-out;
    }

    body:has(#panel.open) #sound {
        right: calc(max(40%, 360px) + 24px);
    }
}

/* phones: at the end of the menu's third row, beside Skills */
@media (max-width: 700px) {
    #sound {
        top: 132px;
        right: 20px;
    }
}

/* ---- the taishō's chat (#taisho) ---- */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* the page fills the panel, so the question box sits at the bottom */
#panel section[data-page="taisho"]:not([hidden]) {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

#panel .chat {
    flex: 1;
    gap: 0;
    padding-bottom: 0;
}

#panel .chat-log {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding-bottom: 24px;
    list-style: none;
}

#panel .msg {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 92%;
}

#panel .msg p {
    padding: 12px 16px 14px;
    font-size: 15px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* the taishō: his face, and a paper card like the other pages */
#panel .msg.taisho::before {
    content: "";
    flex: none;
    width: 32px;
    height: 32px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Crect width='8' height='2' fill='%231e1a18'/%3E%3Crect y='2' width='8' height='1' fill='%23f4f1ea'/%3E%3Crect y='3' width='8' height='4' fill='%23e8b38a'/%3E%3Crect x='2' y='4' width='1' height='1' fill='%231e1a18'/%3E%3Crect x='5' y='4' width='1' height='1' fill='%231e1a18'/%3E%3Crect x='3' y='5' width='2' height='1' fill='%23a33a2c'/%3E%3Crect y='7' width='8' height='1' fill='%232f3a94'/%3E%3C/svg%3E") center / contain no-repeat;
    image-rendering: pixelated;
}

#panel .msg.taisho p {
    background:
        linear-gradient(#fff 0 0) center top / calc(100% - 8px) 4px no-repeat,
        linear-gradient(#e2d2b4 0 0) center bottom / calc(100% - 8px) 4px no-repeat,
        linear-gradient(#fffaf1 0 0) center / 100% calc(100% - 8px) no-repeat;
}

/* the visitor: right-aligned, in the page's indigo */
#panel .msg.you {
    align-self: flex-end;
}

#panel .msg.you p {
    color: #fff;
    background: linear-gradient(var(--sh) 0 0) center bottom / 100% 4px no-repeat, var(--body);
}

/* waiting for an answer: three dots */
#panel .msg.typing p::after {
    content: "...";
    display: inline-block;
    width: 3ch;
    overflow: hidden;
    vertical-align: bottom;
    animation: typing 1.2s steps(4) infinite;
}

@keyframes typing {
    from { width: 0; }
    to { width: 4ch; }
}

#panel .msg.error p {
    color: #8a3324;
}

/* chips, question box and note stay at the bottom while the conversation scrolls */
#panel .chat-dock {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 0 -40px;
    padding: 16px 40px 22px;
    background: #fbf3e3;
    box-shadow: 0 -4px 0 #f1e4c8;
}

#panel .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

#panel .chat-form {
    display: flex;
    gap: 12px;
}

#panel .chat-form input {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    /* 16px stops phones zooming in on focus */
    font: 16px/1.3 system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: #2b2118;
    background: #fffaf1;
    border: 3px solid #e2d2b4;
    border-radius: 0;
}

#panel .chat-form input:focus {
    border-color: #2f3a94;
    outline: none;
}

#panel .chat-form .send {
    height: auto;
    padding: var(--u) 14px;
}

#panel .chat-form button:disabled,
#panel .chips button:disabled {
    opacity: 0.55;
    pointer-events: none;
}

#panel .chat-note {
    font-size: 12px;
    color: #7a6650;
}

@media (max-width: 700px) {
    #panel .chat-dock {
        margin: 0 -20px;
        padding: 12px 20px 16px;
    }

    #panel .chat-note {
        display: none;
    }
}

/* the taishō's speech bubble on the Taisho view: placed over his head by main.js */
#taisho-bubble {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 2;
    padding: 10px 14px;
    font: 15px/1.2 'DotGothic16', system-ui, sans-serif;
    color: #2b2118;
    background: #fffaf1;
    border: 3px solid #2f3a94;
    box-shadow: 0 4px 0 #2f3a94;
    cursor: pointer;
    white-space: nowrap;
    transform: translate(-50%, -100%);
    animation: bob 2.4s ease-in-out infinite;
}

/* the bubble's tail */
#taisho-bubble::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -14px;
    width: 12px;
    height: 10px;
    background: #2f3a94;
    clip-path: polygon(0 0, 100% 0, 0 100%);
}

#taisho-bubble:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 4px;
}

@keyframes bob {
    50% { margin-top: -5px; }
}

/* ---- no WebGL: show the pages as a normal scrolling page ---- */

body.plain {
    overflow: auto;
    background: #060a14;
}

body.plain #loader,
body.plain #views,
body.plain #pages,
body.plain #sound,
body.plain #panel-close,
body.plain #taisho-bubble {
    display: none;
}

body.plain #panel {
    position: static;
    width: auto;
    min-width: 0;
    max-width: 720px;
    max-height: none;
    margin: 0 auto;
    border: none;
    box-shadow: none;
    transform: none;
    visibility: visible;
    transition: none;
}

body.plain #panel section + section {
    margin-top: 48px;
}

/* ---- reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
    #panel,
    #panel.open,
    #loader,
    #views,
    #sound,
    .px-btn {
        transition-duration: 0.01s;
    }

    #loader .steam,
    #loader .bar.indeterminate .bar-fill,
    #taisho-bubble {
        animation: none;
    }

    #loader .steam {
        opacity: 0.5;
    }
}
