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

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #ffdfdf 0%, #f8fce2 100%);
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    min-height: 100svh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

:root {
    --menu-page-pad-x: 10px;
    --menu-page-pad-y: 10px;
    --menu-page-gap: 10px;
    --menu-page-pad-bottom: 10px;
    --menu-speech-pad-y: 18px;
    --menu-speech-pad-x: 32px;
    --menu-speech-max-width: 650px;
    --menu-speech-font-size: 20px;
    --menu-grid-width: min(980px, 100%);
    --menu-grid-height: calc(135px * 3 + 56px);
    --menu-column-width: 200px;
    --menu-column-gap: clamp(140px, 22vw, 340px);
    --menu-row-gap: 18px;
    --menu-subcategory-gap: 18px;
    --menu-button-width: 200px;
    --menu-button-height: 135px;
    --menu-button-inner-gap: 10px;
    --menu-button-pad-y: 8px;
    --menu-button-pad-x: 8px;
    --menu-button-radius: 20px;
    --menu-icon-size: 48px;
    --menu-sub-icon-size: 42px;
    --menu-text-size: 18px;
    --menu-character-max-width: 330px;
    --menu-character-max-height: 330px;
    --menu-mic-size: 75px;
    --menu-mic-icon-size: 38px;
}

body.drag-scroll-active {
    cursor: grabbing;
    user-select: none;
}

.container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: var(--menu-page-pad-y) var(--menu-page-pad-x);
    gap: var(--menu-page-gap);
}

body.subcategory-mode .language-selector {
    display: none;
}

/* Language Selector */
.language-selector {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
}

.language-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.language-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.language-btn .icon {
    width: 24px;
    height: 24px;
}

.language-btn .arrow {
    font-size: 20px;
    transition: transform 0.3s ease;
}

.language-selector.active .arrow {
    transform: rotate(90deg);
}

.language-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    min-width: 150px;
}

.language-selector.active .language-dropdown {
    display: block;
}

.language-option {
    display: block;
    width: 100%;
    padding: 12px 20px;
    background: white;
    border: none;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease;
}

.language-option:hover {
    background: #f5f5f5;
}

.tourism-map-link {
    display: none;
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
    align-items: center;
    gap: 10px;
    padding: 12px 22px;
    background: rgba(255, 255, 255, 0.92);
    border: 2px solid rgba(255, 249, 230, 0.95);
    border-radius: 999px;
    color: #ef8f8f;
    text-decoration: none;
    box-shadow: 0 10px 24px rgba(122, 88, 58, 0.16);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.tourism-map-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 28px rgba(122, 88, 58, 0.2);
    background: rgba(255, 255, 255, 0.98);
}

.tourism-map-link-arrow {
    font-size: 20px;
    line-height: 1;
    color: #f18f8f;
}

.tourism-map-link-label {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
}

/* Speech Bubble */
.speech-bubble {
    --speech-bubble-arrow-fill: rgba(250, 245, 237, 0.95);
    --speech-bubble-mouth-width: 40px;
    --speech-bubble-mouth-height: 24px;
    --speech-bubble-bg: linear-gradient(135deg, rgba(255, 249, 230, 0.94) 0%, rgba(255, 255, 255, 0.96) 100%);
    background: var(--speech-bubble-bg);
    border: 3px solid #ff9999;
    border-radius: 20px;
    padding: var(--menu-speech-pad-y) var(--menu-speech-pad-x);
    margin: 0 auto;
    max-width: var(--menu-speech-max-width);
    position: relative;
    box-shadow: 0 6px 16px rgba(255, 153, 153, 0.3);
    flex-shrink: 0;
    z-index: 30;
    isolation: isolate;
}

.speech-bubble::after {
    content: none;
}

.speech-bubble::before {
    content: none;
}

.speech-bubble-mouth {
    position: absolute;
    left: 50%;
    bottom: calc(var(--speech-bubble-mouth-height) * -1);
    transform: translateX(-50%);
    width: var(--speech-bubble-mouth-width);
    height: var(--speech-bubble-mouth-height);
    overflow: visible;
    z-index: 1;
}

.speech-bubble-mouth-outer {
    fill: #ff9999;
}

.speech-bubble-mouth-inner {
    fill: var(--speech-bubble-arrow-fill);
}

.speech-bubble p {
    font-size: var(--menu-speech-font-size);
    text-align: center;
    color: #333;
    line-height: 1.5;
    white-space: pre-line;
    margin: 0;
    font-weight: 600;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 50px;
    min-height: 0;
    position: relative;
}

/* Button Grid Container with Scrolling */
.button-grid-container {
    position: relative;
    width: var(--menu-grid-width);
    height: var(--menu-grid-height);
    max-height: var(--menu-grid-height);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 1;
    z-index: 1;
}

.back-btn.subcategory-back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 25px;
    background: white;
    color: #333;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.back-btn.subcategory-back-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.back-btn.subcategory-back-btn.hidden {
    display: none;
}

.back-btn.subcategory-back-btn .icon {
    width: 24px;
    height: 24px;
}

.button-grid-scroll {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(2, var(--menu-column-width));
    column-gap: var(--menu-column-gap);
    justify-content: center;
    align-items: start;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 12px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.button-grid-scroll::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Scroll arrows */
.scroll-arrow {
    --arrow-transform: none;
    position: absolute;
    background: linear-gradient(145deg, #ff8a8a 0%, #ff5b5b 100%);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(210, 35, 35, 0.45);
    transform: var(--arrow-transform);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    z-index: 20;
    animation: pulse-arrow 1.8s ease-in-out infinite;
}

.scroll-arrow:hover {
    transform: var(--arrow-transform) scale(1.08);
    box-shadow: 0 12px 26px rgba(210, 35, 35, 0.55);
    filter: saturate(1.1);
}

.scroll-arrow.hidden {
    display: none;
}

.scroll-arrow-up {
    top: -28px;
    left: 50%;
    --arrow-transform: translateX(-50%);
}

.scroll-arrow-down {
    bottom: -28px;
    left: 50%;
    --arrow-transform: translateX(-50%);
}

.scroll-arrow svg {
    width: 32px;
    height: 32px;
    fill: #fff;
}

/* Character */
.character {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    z-index: 5;
}

.fixed-character {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.character-image {
    max-width: var(--menu-character-max-width);
    max-height: var(--menu-character-max-height);
    width: auto;
    height: auto;
    animation: float 3s ease-in-out infinite;
}

/* Floating animation */
@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-20px);
    }
}

.character-placeholder {
    font-size: 180px;
    line-height: 1;
}

@keyframes pulse-arrow {
    0%, 100% {
        box-shadow: 0 8px 20px rgba(210, 35, 35, 0.45);
    }
    50% {
        box-shadow: 0 10px 26px rgba(210, 35, 35, 0.62);
    }
}

.button-column {
    display: flex;
    flex-direction: column;
    gap: var(--menu-row-gap);
    width: var(--menu-column-width);
}

.category-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--menu-button-inner-gap);
    width: var(--menu-button-width);
    min-width: var(--menu-button-width);
    height: var(--menu-button-height);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: var(--menu-button-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: var(--menu-button-pad-y) var(--menu-button-pad-x);
}

.category-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    background: white;
}

.btn-icon {
    width: var(--menu-icon-size);
    height: var(--menu-icon-size);
}

.subcategory-btn .btn-icon {
    width: var(--menu-sub-icon-size);
    height: var(--menu-sub-icon-size);
    display: block;
}

.btn-text {
    font-size: var(--menu-text-size);
    font-weight: 600;
    color: #333;
    text-align: center;
    line-height: 1.3;
    word-break: keep-all;
    overflow-wrap: break-word;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Microphone Button */
.mic-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--menu-mic-size);
    height: var(--menu-mic-size);
    background: rgba(85, 85, 85, 0.88);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    margin: 0 auto;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    position: relative;
    z-index: 40;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.mic-btn:hover {
    transform: scale(1.1);
    background: #444;
}

.mic-icon {
    width: var(--menu-mic-icon-size);
    height: var(--menu-mic-icon-size);
}

@media (orientation: portrait) {
    :root {
        --menu-page-pad-x: clamp(12px, 3vw, 15px);
        --menu-page-pad-y: clamp(12px, 2vh, 15px);
        --menu-page-gap: clamp(12px, 2vh, 16px);
        --menu-page-pad-bottom: clamp(12px, 2vh, 16px);
        --menu-speech-pad-y: clamp(14px, 2.2vh, 24px);
        --menu-speech-pad-x: clamp(28px, 7vw, 56px);
        --menu-speech-max-width: min(90vw, 880px);
        --menu-speech-font-size: clamp(14.5px, 2.7vw, 27px);
        --menu-grid-width: min(100%, 760px);
        --menu-grid-height: min(76dvh, clamp(520px, calc(100dvh - 200px), 1120px));
        --menu-row-gap: clamp(10px, 1.8vh, 18px);
        --menu-subcategory-gap: clamp(10px, 2vh, 26px);
        --menu-button-height: clamp(50px, calc((var(--menu-grid-height) - (var(--menu-row-gap) * 7) - 28px) / 8), 132px);
        --menu-button-width: min(100%, clamp(300px, 78vw, 700px));
        --menu-column-width: var(--menu-button-width);
        --menu-column-gap: 0px;
        --menu-button-inner-gap: clamp(10px, 2vw, 16px);
        --menu-button-pad-y: clamp(8px, 1.5vh, 14px);
        --menu-button-pad-x: clamp(12px, 3vw, 18px);
        --menu-button-radius: 18px;
        --menu-icon-size: clamp(34px, 6.4vw, 56px);
        --menu-sub-icon-size: clamp(32px, 5.4vw, 46px);
        --menu-text-size: clamp(17px, 3vw, 26px);
        --menu-character-max-width: clamp(150px, 30vw, 360px);
        --menu-character-max-height: clamp(150px, 30vw, 360px);
        --menu-mic-size: clamp(68px, 10vw, 88px);
        --menu-mic-icon-size: clamp(34px, 5vw, 42px);
    }

    .tourism-map-link {
        display: inline-flex;
        top: 20px;
        right: 20px;
        gap: 8px;
        padding: 10px 16px;
    }

    .tourism-map-link-arrow {
        font-size: 16px;
    }

    .tourism-map-link-label {
        font-size: 14px;
    }

    .container {
        padding: 15px;
    }

    .speech-bubble {
        margin-top: clamp(28px, 6vh, 54px);
        margin-bottom: clamp(28px, 3.4vh, 44px);
    }

    .speech-bubble p {
        font-size: var(--menu-speech-font-size);
    }

    .speech-bubble {
        --speech-bubble-mouth-width: 28px;
        --speech-bubble-mouth-height: 16px;
    }

    .main-content {
        flex-direction: column;
        align-items: center;
        gap: 14px;
    }

    .button-grid-container {
        width: 100%;
        max-width: min(100%, clamp(360px, 70vw, 760px));
        height: var(--menu-grid-height);
        position: relative;
    }

    .back-btn.subcategory-back-btn {
        top: 15px;
        left: 15px;
        padding: 10px 16px;
        font-size: 14px;
    }

    .back-btn.subcategory-back-btn .icon {
        width: 20px;
        height: 20px;
    }

    .button-grid-scroll {
        grid-template-columns: 1fr;
        column-gap: 0;
        row-gap: var(--menu-row-gap);
        align-content: start;
        justify-content: stretch;
        overflow-x: hidden;
        overflow-y: auto;
        max-width: 100%;
        padding: 10px 6px;
    }
    
    .button-column {
        flex-direction: column;
        gap: var(--menu-row-gap);
        width: 100%;
        min-width: 0;
    }

    .scroll-arrow {
        width: 52px;
        height: 52px;
    }

    .character-image {
        max-width: var(--menu-character-max-width);
        max-height: var(--menu-character-max-height);
    }

    .fixed-character {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .character-placeholder {
        font-size: 120px;
    }

    .scroll-arrow-left,
    .scroll-arrow-right {
        display: none !important;
    }

    .category-btn {
        width: 100%;
        min-width: 0;
        height: var(--menu-button-height);
        flex-direction: row;
        gap: var(--menu-button-inner-gap);
        padding: var(--menu-button-pad-y) var(--menu-button-pad-x);
        flex: 0 0 auto;
    }

    .btn-icon {
        width: var(--menu-icon-size);
        height: var(--menu-icon-size);
        flex-shrink: 0;
    }

    .btn-text {
        font-size: var(--menu-text-size);
        flex: 1;
        text-align: left;
    }

    .mic-btn {
        width: var(--menu-mic-size);
        height: var(--menu-mic-size);
        margin-top: 10px;
    }

    .mic-icon {
        width: var(--menu-mic-icon-size);
        height: var(--menu-mic-icon-size);
    }

    .language-btn {
        padding: 8px 14px;
        font-size: 14px;
    }

    .language-btn .icon {
        width: 20px;
        height: 20px;
    }
}

@media (orientation: landscape) {
    :root {
        --menu-page-pad-x: clamp(4px, 0.8vw, 6px);
        --menu-page-pad-y: clamp(4px, 0.8vh, 6px);
        --menu-page-gap: clamp(4px, 0.8vh, 6px);
        --menu-page-pad-bottom: clamp(4px, 0.8vh, 6px);
        --menu-speech-pad-y: clamp(12px, 1.8vh, 22px);
        --menu-speech-pad-x: clamp(24px, 3vw, 44px);
        --menu-speech-max-width: min(82vw, 920px);
        --menu-speech-font-size: clamp(18px, 2.6vh, 28px);
        --menu-grid-width: min(1380px, 99.8%);
        --menu-grid-height: clamp(220px, calc(100dvh - 160px), 840px);
        --menu-row-gap: clamp(8px, 1.8vh, 18px);
        --menu-subcategory-gap: clamp(18px, 2.4vh, 28px);
        --menu-button-height: clamp(90px, calc((var(--menu-grid-height) - (var(--menu-row-gap) * 3) - 12px) / 4), 190px);
        --menu-grid-inline-pad: clamp(16px, 6vw, 120px);
        --menu-center-reserve-width: clamp(180px, 24vw, 320px);
        --menu-button-width: clamp(170px, calc((100vw - (var(--menu-page-pad-x) * 2) - (var(--menu-grid-inline-pad) * 2) - var(--menu-center-reserve-width)) / 2), 380px);
        --menu-column-width: var(--menu-button-width);
        --menu-column-gap: clamp(16px, 8vw, 160px);
        --menu-button-inner-gap: clamp(8px, 1vw, 12px);
        --menu-button-pad-y: clamp(10px, 1.4vh, 14px);
        --menu-button-pad-x: clamp(12px, 1.6vw, 16px);
        --menu-button-radius: clamp(14px, 1.6vw, 18px);
        --menu-icon-size: clamp(40px, 4.6vw, 56px);
        --menu-sub-icon-size: clamp(34px, 4vw, 46px);
        --menu-text-size: clamp(17px, 2.15vw, 24px);
        --menu-character-max-width: clamp(120px, 24vw, 340px);
        --menu-character-max-height: clamp(120px, 24vw, 340px);
        --menu-mic-size: clamp(68px, 7vw, 92px);
        --menu-mic-icon-size: clamp(34px, 3.6vw, 44px);
    }

    .container {
        padding-bottom: calc(var(--menu-page-pad-bottom) + env(safe-area-inset-bottom));
    }

    .main-content {
        gap: clamp(8px, 2.2vw, 24px);
    }

    .button-grid-scroll {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding-left: var(--menu-grid-inline-pad);
        padding-right: var(--menu-grid-inline-pad);
    }

    .button-column {
        flex: 0 0 var(--menu-column-width);
        justify-content: flex-start;
    }

    body.subcategory-mode .button-column {
        justify-content: center;
        gap: var(--menu-subcategory-gap);
    }
}
