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

:root {
    --gradient-top: #aee4e9;
    --gradient-bottom: #f7d794;
    --text: #8d623e;
    --muted: #9a7a61;
    --button: #d9a066;
    --button-text: #fffef8;
    --input-shadow: 0 4px 14px rgba(120, 90, 60, 0.12);
    --btn-shadow: 0 5px 14px rgba(150, 95, 45, 0.22);
    --font: "Nunito", system-ui, -apple-system, sans-serif;
    --bento-shadow: 0 10px 28px rgba(100, 75, 50, 0.18);
}

html {
    height: 100%;
}

body {
    min-height: 100%;
    min-height: 100dvh;
    font-family: var(--font);
    color: var(--text);
    background-image: linear-gradient(180deg, var(--gradient-top) 0%, var(--gradient-bottom) 100%);
    background-color: var(--gradient-top);
    background-attachment: scroll;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

.page {
    width: min(100%, 470px);
    margin: 0 auto;
    padding:
        max(1.1rem, env(safe-area-inset-top))
        max(0rem, env(safe-area-inset-right))
        max(1.35rem, env(safe-area-inset-bottom))
        max(0rem, env(safe-area-inset-left));
}

.main {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.bento-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 0.25rem;
}

/* Note panel (z-index:3) overlaps the bento via negative margin; label/textarea
   use pointer-events:auto and sit above the bento, stealing food taps. Class is
   toggled in JS when the box opens so food hit targets win. */
.bento-wrap.bento-taps-on-top {
    position: relative;
    z-index: 2;
}

.bento-stage {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    border-radius: 0;
    overflow: hidden;
    box-shadow: none;
    isolation: isolate;
}

.bento-home {
    position: relative;
    z-index: 0;
    display: block;
    width: 100%;
    touch-action: manipulation;
    /* Noodle overlay + tap zone — smaller, lower on rice (tweak to match art) */
    --noodle-slot-left: 38%;
    --noodle-slot-top: 39%;
    --noodle-slot-width: 19%;
    --noodle-slot-height: 12%;
    --katsu-slot-left: 65%;
    --katsu-slot-top: 40%;
    --katsu-slot-width: 26%;
    --katsu-slot-height: 16%;
    --poke-slot-left: 32%;
    --poke-slot-top: 50%;
    --poke-slot-width: 20%;
    --poke-slot-height: 14%;
    --musubi-slot-left: 59%;
    --musubi-slot-top: 50%;
    --musubi-slot-width: 22%;
    --musubi-slot-height: 16%;
}

/* Parent none; children become targets when open. Layer above overlay imgs + old hit buttons. */
.bento-tap-layer {
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
}

/* Invisible tap zones on the base art (no overlay images) */
.food-hit {
    position: absolute;
    z-index: 22;
    margin: 0;
    padding: 0;
    border: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, -50%);
    background: transparent;
}

.bento-stage.is-open .food-hit {
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
}

.food-hit:focus,
.food-hit:focus-visible {
    outline: none;
}

/* % of bento-home — same rectangle as .noodle-bento-overlay */
.food-hit--noodle {
    left: var(--noodle-slot-left);
    top: var(--noodle-slot-top);
    width: var(--noodle-slot-width);
    height: var(--noodle-slot-height);
}

.food-hit--katsu {
    left: var(--katsu-slot-left);
    top: var(--katsu-slot-top);
    width: var(--katsu-slot-width);
    height: var(--katsu-slot-height);
}

.food-hit--poke {
    left: var(--poke-slot-left);
    top: var(--poke-slot-top);
    width: var(--poke-slot-width);
    height: var(--poke-slot-height);
}

.food-hit--musubi {
    left: var(--musubi-slot-left);
    top: var(--musubi-slot-top);
    width: var(--musubi-slot-width);
    height: var(--musubi-slot-height);
}

.bento-hero-img {
    display: block;
    width: 100%;
    height: auto;
    image-rendering: auto;
    vertical-align: top;
    pointer-events: none;
    user-select: none;
    -webkit-backface-visibility: hidden;
}

.bento-cover {
    position: absolute;
    left: 50%;
    top: 45.8%;
    z-index: 2;
    display: block;
    width: 236px;
    height: 213px;
    border: none;
    padding: 0;
    margin: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transform: translate(-50%, -50%);
    transition: transform 0.5s cubic-bezier(0.33, 1, 0.68, 1);
    will-change: transform;
}

.bento-cover.is-off {
    transform: translate(-50%, -50%) translate3d(150%, 0, 0);
    pointer-events: none;
}

.bento-cover-img {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: auto;
    pointer-events: none;
    user-select: none;
    -webkit-backface-visibility: hidden;
}

/* Noodles: left compartment only */
.noodle-btn {
    position: absolute;
    left: 2%;
    top: 29%;
    width: 46%;
    height: 20%;
    transform: none;
    border-radius: 18px;
    border: none;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    touch-action: manipulation;
    pointer-events: none;
    z-index: 3;
    min-width: 0;
    min-height: 0;
}

.musubi-btn {
    position: absolute;
    left: 48%;
    top: 64%;
    width: 50%;
    height: 30%;
    border: none;
    background: transparent;
    pointer-events: none;
    z-index: 0;
}

.musubi-btn:focus-visible,
.musubi-btn:focus,
.musubi-btn:active {
    outline: none;
    box-shadow: none;
    border: none;
}

@media (prefers-reduced-motion: reduce) {
    .bento-cover {
        transition-duration: 0.01ms;
    }
}

.noodle-btn:focus-visible {
    outline: none;
    box-shadow: none;
    border: none;
}

.noodle-btn:focus,
.noodle-btn:active {
    outline: none;
    box-shadow: none;
    border: none;
}

.memory-panel {
    margin-top: -11.4rem;
    position: relative;
    z-index: 30;
    width: 86%;
    margin-left: auto;
    margin-right: auto;
    /* Let taps reach the bento in overlapped areas; keep form controls interactive */
    pointer-events: none;
}

.memory-panel .label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    text-align: center;
    pointer-events: auto;
}

.memory-input {
    width: 100%;
    min-height: 72px;
    padding: 0.65rem 0.85rem;
    border-radius: 14px;
    border: 1px solid rgba(200, 170, 130, 0.35);
    background: #fff;
    color: #5a3d2a;
    resize: none;
    font: inherit;
    font-size: 0.9rem;
    box-shadow: var(--input-shadow);
    pointer-events: auto;
}

.memory-input:focus {
    outline: 2px solid rgba(201, 150, 90, 0.45);
    border-color: rgba(201, 150, 90, 0.55);
}

.actions {
    text-align: center;
    margin-top: -0.55rem;
    position: relative;
    z-index: 30;
}

.btn {
    border: none;
    border-radius: 14px;
    padding: 0.52rem 1rem;
    min-width: 122px;
    min-height: 34px;
    font: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    color: var(--button-text);
    background: var(--button);
    cursor: pointer;
    box-shadow: var(--btn-shadow);
    touch-action: manipulation;
}

.btn-primary:hover {
    filter: brightness(1.03);
}

.btn-block {
    width: 100%;
    min-width: unset;
    margin-top: 0.85rem;
}

.persona-output {
    margin-top: 0.35rem;
}

.persona-heading {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 0.45rem;
    text-align: center;
}

.persona-card {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(180, 140, 100, 0.28);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: 0 4px 16px rgba(100, 75, 50, 0.08);
}

.persona-card .persona-type-word {
    font-size: clamp(1.6rem, 5.5vw, 2.1rem);
    font-weight: 800;
    letter-spacing: 0.1em;
    text-align: center;
    color: #6b442a;
    margin-bottom: 0.3rem;
    line-height: 1.15;
}

.persona-card .persona-type-hint {
    text-align: center;
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.8rem;
}

.persona-card .persona-title {
    margin-bottom: 0.5rem;
    color: var(--text);
    font-weight: 700;
}

.persona-card .persona-body p + p {
    margin-top: 0.5rem;
}

.persona-card .persona-rep-wrap {
    margin: 0.25rem auto 0.9rem;
    text-align: center;
}

.persona-card .persona-rep-image {
    display: block;
    width: min(180px, 62%);
    height: auto;
    margin: 0 auto;
    object-fit: contain;
    border-radius: 12px;
}

.persona-card .persona-rep-label {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: #7b4b2a;
}

.persona-card .persona-detail-list {
    margin-top: 0.7rem;
    margin-left: 1rem;
    color: #6b442a;
    font-size: 0.9rem;
}

.persona-card .persona-detail-list li + li {
    margin-top: 0.35rem;
}

/* Don’t use transform to center <dialog> — it fights showModal()’s top layer in
   WebKit/Blink and the modal can open invisibly or off-screen. */
.food-dialog {
    position: fixed;
    inset: 0;
    width: min(400px, calc(100vw - 1.25rem));
    max-width: calc(100vw - 1.25rem);
    max-height: min(92dvh, 640px);
    height: fit-content;
    margin: auto;
    border: none;
    padding: 0;
    background: transparent;
    overflow: hidden;
}

.food-dialog::backdrop {
    background: rgba(60, 42, 28, 0.45);
}

.dialog-inner {
    position: relative;
    border-radius: 24px;
    padding: 1.1rem 1rem 1.15rem;
    color: #5a3d2a;
    background: #fff8ef;
    border: none;
    box-shadow: none;
    max-height: none;
    overflow: hidden;
}

.noodle-dialog {
    background: url("assets/pop_up_1.png") center/cover no-repeat;
    min-height: min(88dvh, 560px);
}

.dialog-inner.musubi-picker {
    min-height: min(92dvh, 720px);
}

.dialog-inner.food-picker-tall {
    min-height: min(88dvh, 640px);
}

/* Full-card popups: katsu, poke, musubi; noodles use Frame 91 PNG + hit zones */
.dialog-inner.noodle-dialog.katsu-popup-sheet,
.dialog-inner.noodle-dialog.poke-popup-sheet,
.dialog-inner.noodle-dialog.musubi-popup-sheet {
    padding-top: 2.75rem;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
    padding-bottom: 0.35rem;
    background-color: #fde5c5;
    background-repeat: no-repeat;
    background-position: center bottom;
    background-size: contain;
    background-position: center center;
    min-height: min(86dvh, 620px);
    height: min(86dvh, 620px);
    overflow: hidden;
    border: none;
    box-shadow: none;
    border-radius: 22px;
}

/* Frame 91 asset fills the modal; tune hit zones on .noodle-frame91-wrap */
.dialog-inner.noodle-dialog.noodle-frame91-popup {
    padding: 2.85rem 0.55rem 0.7rem;
    background: #fde5c5;
    background-image: none;
    border: none;
    border-radius: 22px;
    outline: none;
    box-shadow: none;
    min-height: min(86dvh, 620px);
    height: min(86dvh, 620px);
    overflow: hidden;
}

.dialog-inner.noodle-dialog.noodle-frame91-popup .dialog-close {
    top: 0.8rem;
    right: 0.8rem;
    z-index: 10;
    min-width: 38px;
    min-height: 38px;
    padding: 0;
    font-size: 1.35rem;
    line-height: 1;
    border-radius: 9px;
    background: #fffefb;
    border: 2px solid rgba(92, 98, 168, 0.95);
    color: #5c3f28;
    box-shadow: 0 2px 8px rgba(45, 55, 110, 0.15);
}

.noodle-frame91-wrap {
    position: relative;
    width: 100%;
    margin-top: 0.15rem;
    line-height: 0;
    isolation: isolate;
    /* Large, non-overlapping row hit zones for reliable taps */
    --hit-opt1-top: 32%;
    --hit-opt1-height: 22%;
    --hit-opt2-top: 56%;
    --hit-opt2-height: 22%;
}

.noodle-frame91-img {
    display: block;
    position: relative;
    z-index: 1;
    width: 100%;
    height: auto;
    border-radius: 14px;
    pointer-events: none;
    user-select: none;
}

.noodle-frame-hit {
    position: absolute;
    margin: 0;
    padding: 0;
    border: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
}

.noodle-frame-hit:focus,
.noodle-frame-hit:focus-visible {
    outline: none;
}

/* Row 1 on top in stacking order (see script append order); higher z-index if edges overlap */
.noodle-frame-hit--opt1 {
    left: 5%;
    width: 90%;
    top: var(--hit-opt1-top);
    height: var(--hit-opt1-height);
    z-index: 3;
}

.noodle-frame-hit--opt2 {
    left: 5%;
    width: 90%;
    top: var(--hit-opt2-top);
    height: var(--hit-opt2-height);
    z-index: 2;
}

.dialog-inner.noodle-dialog.katsu-popup-sheet {
    background-image: url("assets/popup-katsu.png?v=3");
    border: none;
    box-shadow: none;
    border-radius: 22px;
}

.dialog-inner.noodle-dialog.poke-popup-sheet {
    background-image: url("assets/popup-poke.png?v=3");
}

.dialog-inner.noodle-dialog.musubi-popup-sheet {
    background-image: url("assets/popup-musubi.png?v=2");
}

.dialog-inner.katsu-popup-sheet .katsu-value-grid {
    position: absolute;
    left: 4%;
    right: 4%;
    top: 16%;
    bottom: 8%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 0.35rem;
    margin-top: 0;
    padding: 0;
    min-height: 0;
}

.dialog-inner.musubi-popup-sheet .musubi-value-grid {
    position: absolute;
    left: 4%;
    right: 4%;
    top: 13%;
    bottom: 6%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 0.35rem;
    margin-top: 0;
    padding: 0;
    min-height: 0;
}

.dialog-inner.katsu-popup-sheet .katsu-option-btn--overlay,
.dialog-inner.musubi-popup-sheet .musubi-option-btn--overlay {
    opacity: 0;
    background: transparent;
    min-height: 0;
    border-radius: 14px;
    border: none;
    box-shadow: none;
    outline: none;
}

.dialog-inner.katsu-popup-sheet .katsu-value-grid {
    z-index: 6;
}

.dialog-inner.katsu-popup-sheet .dialog-title,
.dialog-inner.katsu-popup-sheet .dialog-food-name {
    position: relative;
    z-index: 8;
    pointer-events: none;
}

.dialog-inner.poke-popup-sheet .poke-value-grid {
    position: absolute;
    left: 3%;
    right: 3%;
    top: 9%;
    bottom: 6%;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, 1fr);
    gap: 0.15rem;
    margin-top: 0;
    padding: 0;
    min-height: 0;
    z-index: 8;
}

.dialog-inner.poke-popup-sheet .poke-option-btn--overlay {
    opacity: 0;
    background: transparent;
    min-height: 0;
    border-radius: 12px;
    pointer-events: auto;
    border: none;
    box-shadow: none;
    outline: none;
}

.noodle-option-thumb {
    display: block;
    pointer-events: none;
    user-select: none;
}

/* On bento: show original PNG exactly as exported */
.noodle-bento-overlay {
    position: absolute;
    left: var(--noodle-slot-left);
    top: var(--noodle-slot-top);
    width: var(--noodle-slot-width);
    height: var(--noodle-slot-height);
    max-width: none;
    max-height: none;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    object-fit: contain;
    object-position: center center;
    z-index: 15;
    pointer-events: none;
}

.katsu-bento-overlay {
    position: absolute;
    left: var(--katsu-slot-left);
    top: var(--katsu-slot-top);
    width: var(--katsu-slot-width);
    height: var(--katsu-slot-height);
    max-width: none;
    max-height: none;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    object-fit: contain;
    object-position: center center;
    z-index: 14;
    pointer-events: none;
}

.poke-bento-overlay {
    position: absolute;
    left: var(--poke-slot-left);
    top: var(--poke-slot-top);
    width: var(--poke-slot-width);
    height: var(--poke-slot-height);
    max-width: none;
    max-height: none;
    transform: translate(-50%, -50%) rotate(-90deg);
    box-sizing: border-box;
    object-fit: contain;
    object-position: center center;
    z-index: 14;
    pointer-events: none;
}

.musubi-bento-overlay {
    position: absolute;
    left: var(--musubi-slot-left);
    top: var(--musubi-slot-top);
    width: var(--musubi-slot-width);
    height: var(--musubi-slot-height);
    max-width: none;
    max-height: none;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    object-fit: contain;
    object-position: center center;
    z-index: 14;
    pointer-events: none;
}

.dialog-close {
    position: absolute;
    top: 0.2rem;
    right: 0.5rem;
    z-index: 5;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    border-radius: 8px;
}

.dialog-title {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text);
    padding-right: 1.5rem;
}

.dialog-food-name {
    margin-top: 0.2rem;
    margin-bottom: 0.7rem;
    font-size: 0.9rem;
    color: #7a5a3e;
}

.value-grid {
    position: relative;
}

.noodle-value-grid {
    min-height: 0;
}

.musubi-value-grid {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(120px, 1fr) minmax(120px, 1fr);
    gap: 0.45rem;
    min-height: 280px;
    margin-top: 0.25rem;
    padding: 0 0.15rem;
}

.musubi-option-btn {
    display: block;
    width: 100%;
    min-height: 100px;
    padding: 0.25rem;
    border: none;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
}

.musubi-option-btn.is-selected,
.musubi-option-btn:focus-visible,
.musubi-option-btn:focus,
.musubi-option-btn:active {
    outline: none;
    box-shadow: none;
}

.katsu-value-grid {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(100px, 1fr) minmax(100px, 1fr);
    gap: 0.45rem;
    min-height: 260px;
    margin-top: 0.25rem;
    padding: 0 0.15rem;
}

.katsu-option-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 96px;
    padding: 0.35rem;
    border: none;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
}

.katsu-option-btn img {
    max-width: 100%;
    max-height: 88px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.katsu-option-btn.is-selected,
.katsu-option-btn:focus-visible,
.katsu-option-btn:focus,
.katsu-option-btn:active {
    outline: none;
    box-shadow: none;
}

.poke-value-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    min-height: 120px;
    margin-top: 0.25rem;
}

.poke-option-btn {
    display: block;
    width: 100%;
    padding: 0.75rem 0.85rem;
    border: none;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    text-align: left;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
}

.poke-option-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: #5a3d2a;
    line-height: 1.3;
}

.poke-option-btn.is-selected,
.poke-option-btn:focus-visible,
.poke-option-btn:focus,
.poke-option-btn:active {
    outline: none;
    box-shadow: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (min-width: 768px) {
    body {
        display: flex;
        justify-content: center;
    }

    .page {
        width: 400px;
    }
}
