:root {
    color: #1f1717;
    background: #f7edf6;
    font-family: "KyoboHandwriting2019", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

@font-face {
    font-family: "KyoboHandwriting2019";
    src: url("https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_20-04@1.0/KyoboHand.woff") format("woff");
    font-weight: normal;
    font-display: swap;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}

body {
    display: flex;
    justify-content: center;
    min-height: 100svh;
    min-height: 100dvh;
    background: #f3e5f1;
}

button,
input {
    font: inherit;
}

[hidden] {
    display: none !important;
}

.app-shell {
    width: 100%;
    height: 100svh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.phone-stage {
    position: relative;
    width: min(100vw, 45.7628svh, 560px);
    width: min(100vw, 45.7628dvh, 560px);
    aspect-ratio: 1080 / 2360;
    height: auto;
    max-height: 100%;
    background: #f6e9f6;
    overflow: hidden;
}

#stageCanvas {
    display: block;
    width: 100%;
    height: auto;
}

.stage-controls {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.control-button {
    min-width: 98px;
    min-height: 72px;
    border: 0;
    border-radius: 999px;
    background: #fff7fd;
    color: #1b1115;
    display: grid;
    place-items: center;
    padding: 14px 20px;
    font-size: clamp(18px, 5vw, 26px);
    line-height: 1.2;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
}

.control-button:focus,
.control-button:focus-visible,
.primary-button:focus,
.primary-button:focus-visible,
.icon-button:focus,
.icon-button:focus-visible {
    outline: none;
}

.control-button:active,
.primary-button:active,
.icon-button:active {
    transform: translateY(2px);
    box-shadow: none;
}

.save-button {
    position: absolute;
    top: max(24px, env(safe-area-inset-top));
    right: 28px;
}

.photo-button {
    position: absolute;
    left: 50%;
    top: 49%;
    transform: translate(-50%, -50%);
    width: 104px;
    height: 104px;
    min-width: 104px;
    min-height: 104px;
    padding: 0;
    background: transparent;
}

.photo-button:active {
    transform: translate(-50%, calc(-50% + 2px));
}

.photo-button-text {
    display: block;
    font-family: "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    font-size: 70px;
    font-weight: 300;
    line-height: 0.9;
    transform: translateY(-4px);
}

.photo-button.has-photo {
    top: auto;
    left: 22px;
    bottom: max(28px, env(safe-area-inset-bottom));
    transform: none;
    width: 112px;
    height: 64px;
    min-width: 112px;
    min-height: 64px;
    padding: 10px 14px;
    background: #fff7fd;
    font-size: clamp(16px, 4vw, 21px);
    word-break: keep-all;
}

.photo-button.has-photo.is-reset-ready {
    height: 76px;
    min-height: 76px;
    gap: 2px;
}

.photo-button.has-photo:active {
    transform: translateY(2px);
}

.photo-button.has-photo .photo-button-text {
    font-family: inherit;
    font-size: inherit;
    line-height: 1.2;
    transform: none;
}

.photo-button-subtext {
    display: block;
    font-size: 0.68em;
    line-height: 1;
}

.dish-button {
    position: absolute;
    right: 22px;
    bottom: max(28px, env(safe-area-inset-bottom));
    width: 138px;
    min-width: 138px;
    min-height: 64px;
    padding: 10px 18px;
    font-size: clamp(18px, 4.8vw, 25px);
    word-break: keep-all;
}

.photo-button.has-photo + .dish-button {
    left: auto;
}

#photoInput {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 18px;
    background: rgba(40, 31, 38, 0.36);
    z-index: 10;
}

.modal.is-open {
    display: flex;
}

.modal-panel {
    width: min(100%, 520px);
    max-height: min(78svh, 720px);
    background: #fff9fe;
    border: 1px solid rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 20px 12px;
}

.modal-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.modal-header h1 span {
    font-size: 0.72em;
    font-weight: 400;
}

.icon-button {
    width: 38px;
    height: 38px;
    border: 0;
    background: #fff;
    font-size: 18px;
    cursor: pointer;
}

.dish-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 8px 20px 18px;
    overflow: auto;
}

.dish-option {
    min-height: 86px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    cursor: pointer;
}

.dish-option input {
    width: 18px;
    height: 18px;
    accent-color: #d4476a;
}

.dish-thumb {
    width: 48px;
    height: 48px;
    object-fit: contain;
    flex: 0 0 auto;
}

.dish-thumb.is-fallback {
    border-radius: 50%;
    background: #ffd7a6;
    border: 2px solid #f0a65f;
}

.dish-name {
    min-width: 0;
    font-size: 16px;
    line-height: 1.25;
    word-break: keep-all;
}

.dish-name-small {
    font-size: 14px;
}

.modal-actions {
    padding: 0 20px 20px;
}

.primary-button {
    width: 100%;
    min-height: 54px;
    border: 0;
    background: #202020;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

@media (min-width: 561px) {
    .app-shell {
        padding: 0;
        align-items: center;
    }

    .phone-stage {
        box-shadow: 0 20px 60px rgba(48, 31, 42, 0.2);
    }

    #stageCanvas {
        aspect-ratio: 1080 / 2360;
    }
}
