/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Prevent text selection globally */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent callout on iOS long press */
    -webkit-touch-callout: none;
}

/* Prevent dragging and selection of images */
img {
    -webkit-user-drag: none;
    user-drag: none;
}

/* Disable text selection on main game screens */
#gameScreen, #gameScreen *, #clickToStartScreen, #clickToStartScreen *, #titleScreen, #titleScreen * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Re-enable text selection for interactive controls */
.volume-control, .volume-control *, .volume-slider, input[type="range"] {
    -webkit-user-select: auto !important;
    user-select: auto !important;
    -webkit-touch-callout: auto !important;
}


body {
    font-family: 'Hiragino Sans', 'Noto Sans JP', sans-serif;
    overflow: hidden;
    background: transparent !important;
    color: #4a4a4a;
}

/* Screen Management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.hidden {
    display: none !important;
}

/* Click to Start Screen */
/* =====================================================
   Click To Start Screen (Title Screen UI)
   ===================================================== */
#clickToStartScreen {
    background: linear-gradient(135deg, #ffeef8 0%, #e8f4fd 50%, #f0f8ff 100%);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

#clickToStartScreen::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(255, 182, 193, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(173, 216, 230, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(221, 160, 221, 0.2) 0%, transparent 50%);
    animation: float 20s ease-in-out infinite;
}

.click-to-start-container {
    background: rgba(255, 255, 255, 0.9);
    padding: 4rem;
    border-radius: 30px;
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255, 182, 193, 0.4);
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
    z-index: 10;
    position: relative;
    transition: transform 0.3s ease;
}

.click-to-start-container:hover {
    transform: scale(1.02);
}

.click-instruction {
    font-size: 1.5rem;
    color: #666;
    margin-top: 1rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Title Screen */
#titleScreen {
    background: transparent !important;
    position: relative;
    overflow: hidden;
}

/* === Title Background Image === */
#titleBgImg {
    position: absolute;
    left: 0; top: 0;
    width: 100vw;
    height: 100vh;
    object-fit: contain;
    object-position: center center;
    z-index: 0;
    pointer-events: none;
    user-select: none;
    display: none;
}

/* === Animated Background Canvas (Title Screen) === */
#titleBgCanvas {
    position: absolute;
    left: 0; top: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    user-select: none;
    background: transparent;
}

#titleScreen > .title-container {
    background: none !important;
    box-shadow: none !important;
    border: none !important;
    backdrop-filter: none !important;
    /* displayは元に戻す */
    display: block !important;
    position: relative;
    z-index: 1;
}

#titleScreen::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(255, 182, 193, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(173, 216, 230, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(221, 160, 221, 0.2) 0%, transparent 50%);
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    33% { transform: translateY(-20px) rotate(120deg); }
    66% { transform: translateY(10px) rotate(240deg); }
}

.title-container {
    background: transparent;
    padding: 3rem;
    backdrop-filter: blur(10px);
    text-align: center;
    z-index: 10;
    position: relative;
}

.game-title {
    font-size: 3.5rem;
    color: #fff;
    margin-bottom: 2rem;
    /* 黒いアウトラインを付与 */
    text-shadow:
        3px 3px 0 #222,
        -3px 3px 0 #222,
        3px -3px 0 #222,
        -3px -3px 0 #222,
        0px 3px 0 #222,
        3px 0px 0 #222,
        0px -3px 0 #222,
        -3px 0px 0 #222;
}

.main-button {
    background: linear-gradient(45deg, #ff69b4, #87ceeb);
    border: none;
    color: white;
    font-size: 1.2rem;
    padding: 1rem 2.5rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 1rem 0;
    box-shadow: 0 10px 20px rgba(255, 105, 180, 0.3);
    font-weight: bold;
}

.main-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 30px rgba(255, 105, 180, 0.4);
}

.player-name-input {
    margin-top: 1.5rem;
}

.player-name-input label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: #666;
}

.player-name-input input {
    padding: 0.8rem;
    border: 2px solid rgba(255, 182, 193, 0.3);
    border-radius: 20px;
    font-size: 1rem;
    width: 200px;
    text-align: center;
    background: rgba(255, 255, 255, 0.7);
}

/* Game Screen */
#gameScreen {
    position: relative;
    background: transparent !important;
}

/* =====================================================
   Game Screen Background & Heroine Container
   ===================================================== */
.background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: bottom center;
    background-repeat: no-repeat;
    transform-origin: bottom center;
    transition: all 1s ease;
}

.heroine-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    z-index: 5;
    overflow: hidden;
}

.heroine-image {
    max-height: 95vh;
    max-width: 100vw;
    width: auto;
    height: auto;
    object-fit: contain;
    transform-origin: bottom center;
    transition: all 0.5s ease;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.1));
}

/* Fluid Canvas */
.fluid-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 5; /* Lowered to not interfere with letterbox bars */
    pointer-events: none;
}

/* Letterbox Effect */
.letterbox-bar {
    display: none !important;
}

.letterbox-top {
    top: 0;
}

.letterbox-bottom {
    bottom: 0;
}

/* Heroine Image Container and Image */
.heroine-container {
    position: fixed;
    left: 50%;
    bottom: var(--letterbox-bar-height, 120px);
    top: auto;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    width: 100vw;
    height: calc(100vh - var(--letterbox-bar-height, 120px));
    display: flex;
    align-items: flex-end;
    justify-content: center;
    /* レターボックス上端を基準に画像下端を揃える */
}

.heroine-image {
    max-width: 100vw;
    max-height: calc(100vh - var(--letterbox-bar-height, 120px));
    width: auto;
    height: auto;
    object-fit: contain;
    display: none;
    flex-shrink: 0;
}

/* 縦長画面（ポートレート）の場合は横にフィット */
@media (orientation: portrait) {
    .heroine-image {
        width: 100vw;
        height: auto;
        max-height: calc(100vh - var(--letterbox-bar-height, 120px));
    }
}

/* 横長画面（ランドスケープ）の場合は縦にフィット */
@media (orientation: landscape) {
    .heroine-image {
        height: calc(100vh - var(--letterbox-bar-height, 120px));
        width: auto;
        max-width: 100vw;
    }
}

/* レスポンシブテキスト調整 */
/* 小さな画面（スマートフォン縦向き） */
@media (max-width: 480px) and (orientation: portrait) {
    .message-content {
        font-size: clamp(0.75rem, 4vw, 1rem);
        line-height: 1.5;
    }
    
    .speaker-name {
        font-size: clamp(0.8rem, 4vw, 1.1rem);
    }
    
    .message-window.narration-window {
        font-size: clamp(0.9rem, 4vw, 1.1rem);
    }
    
    .message-window.narration-window .message-content {
        font-size: clamp(0.9rem, 4vw, 1.1rem);
    }
}

/* 横向きスマートフォン・小さなタブレット */
@media (max-height: 500px) and (orientation: landscape) {
    .message-window {
        height: clamp(80px, 12vh, 120px);
    }
    
    .message-content {
        font-size: clamp(0.7rem, 2vh, 1rem);
        min-height: clamp(30px, 6vh, 60px);
    }
    
    .speaker-name {
        font-size: clamp(0.8rem, 2.5vh, 1rem);
        margin: clamp(3px, 0.8vh, 8px) 0 clamp(1px, 0.2vh, 2px) 0;
    }
}

/* 大きな画面での最適化 */
@media (min-width: 1200px) {
    .message-content {
        font-size: clamp(1rem, 1.5vw, 1.4rem);
        max-width: 80%;
        margin: 0 auto;
    }
    
    .message-window.narration-window .message-content {
        font-size: clamp(1.1rem, 1.8vw, 1.5rem);
        max-width: 70%;
    }
}

/* Message Windows */
/* --- Message window overlays letterbox bar by z-index --- */
:root {
    --letterbox-bar-height: 120px;
}

/* --- Fixed height message-window to prevent layout shifts over letterbox --- */
.message-window {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    min-width: 0;
    border-radius: 0;
    padding: 0 30px 10px 30px; /* Fixed padding values */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 2px solid rgba(255, 182, 193, 0.3);
    border-right: none;
    border-left: none;
    border-bottom: none;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.10);
    z-index: 20; /* Always above letterbox bars (z-index: 12) */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 120px; /* Fixed height - same as letterbox bar height */
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: auto;
    margin-bottom: 0;
    transition: none;
}
/* --- End fixed height message-window --- */
/* --- End: message window overlays letterbox bar by z-index --- */



.message-window.player,
.message-window.heroine {
    background: transparent !important;
    backdrop-filter: blur(10px);
}

.speaker-name, .message-content {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
}

/* --- Fixed font-size for message-content and speaker-name to prevent shifting over letterbox --- */
.speaker-name {
    width: 100%;
    text-align: center;
    font-weight: bold;
    margin: 8px 0 2px 0;
    font-size: 1.2rem; /* Fixed size for stable layout */
    color: #666;
    position: relative;
    top: 6px;
}

.message-content {
    width: 80%;
    margin: 0 auto;
    text-align: left;
    /* Responsive font-size: scales with viewport width, clamped */
    font-size: clamp(1rem, 4vw, 1.5rem);
    line-height: 1.6;
    min-height: 48px;
    position: relative;
    color: #fff;
    text-shadow:
        2px 2px 0 #222,
        -2px 2px 0 #222,
        2px -2px 0 #222,
        -2px -2px 0 #222,
        0px 2px 0 #222,
        2px 0px 0 #222,
        0px -2px 0 #222,
        -2px 0px 0 #222;
    /* Allow text wrapping */
    white-space: normal;
    box-sizing: border-box;
    /* テキストが収まるよう自動調整 */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}
/* --- End fixed font-size for message-content and speaker-name --- */


.player-window .message-content,
.heroine-window .message-content {
    text-align: center;
    justify-content: center;
    align-items: center;
    display: flex;
    flex-direction: column;
}




/* === Protagonist Message Window Overrides === */
.message-window.player-window {
    background: transparent !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
    border: none !important;
}

/* === Heroine Message Window Overrides === */
.message-window.heroine-window {
    background: transparent !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
    border: none !important;
}

/* Narration window style */
/* === Narration Message Window (centered) === */
.message-window.narration-window {
    /* Center window on screen */
    position: fixed;
    top: 50%;
    left: 0;
    right: 0;
    bottom: auto;
    transform: translateY(-50%);
    width: 100vw;
    max-width: none;
    padding: clamp(15px, 3vh, 25px) clamp(20px, 4vw, 40px);
    /* Slight full-element transparency */
    opacity: 0.9;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background: rgba(40, 40, 40, 0.85);
    color: #fff;
    border: none;
    text-align: center;
    font-size: clamp(1rem, 2.5vw, 1.3rem);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
    transition: opacity 0.5s ease;
}

.message-window.narration-window.hidden {
    opacity: 0;
    pointer-events: none;
}



.message-window.narration-window .message-content {
    text-align: center;
    width: 100%;
    color: #fff;
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0,0,0,0.25);
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: clamp(1rem, 2.5vw, 2.0rem);
    line-height: clamp(1.4, 1.6, 1.8);
    white-space: nowrap;
    box-sizing: border-box;
    /* テキストが収まるよう自動調整 */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.speaker-name {
    font-weight: bold;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: #666;
}

.heroine-window .speaker-name {
    color: #ff69b4;
}

.player-window .speaker-name {
    color: #4169e1;
}

.message-content {
    font-size: clamp(0.8rem, 2.2vw, 1.2rem);
    line-height: clamp(1.4, 1.6, 1.8);
    min-height: clamp(40px, 8vh, 80px);
    position: relative;
    color: #fff;
    text-shadow:
        2px 2px 0 #222,
        -2px 2px 0 #222,
        2px -2px 0 #222,
        -2px -2px 0 #222,
        0px 2px 0 #222,
        2px 0px 0 #222,
        0px -2px 0 #222,
        -2px 0px 0 #222;
    /* テキストが収まるよう自動調整 */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.next-icon {
    position: fixed;
    bottom: 0;
    right: 0;
    color: #ff69b4;
    font-size: 1.2rem;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* Typing Game */
.typing-game {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: transparent;
    border-radius: 20px;
    padding: 2rem;
    min-width: 500px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 182, 193, 0.3);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    z-index: 15;
    /* IME無効化 */
    ime-mode: disabled;
    -webkit-ime-mode: disabled;
    -ms-ime-mode: disabled;
}

/* タイピングゲーム中のIME無効化を強化 */
.typing-game-active {
    ime-mode: disabled !important;
    -webkit-ime-mode: disabled !important;
    -ms-ime-mode: disabled !important;
}

.typing-game-active * {
    ime-mode: disabled !important;
    -webkit-ime-mode: disabled !important;
    -ms-ime-mode: disabled !important;
}

.typing-container h3 {
    color: #666;
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.sample {
    #background: linear-gradient(45deg, #ffe4e1, #e6f3ff);
    padding: 1rem;
    border-radius: 15px;
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
    min-height: 60px;
    display: flex;
    align-items: center;
    border: 2px solid rgba(255, 182, 193, 0.2);
    font-weight: bold;
}

.typing-input {
    width: 100%;
    padding: 1rem;
    font-size: 1.2rem;
    border: 2px solid rgba(255, 182, 193, 0.3);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.8);
    margin-bottom: 1rem;
}

.typing-input:focus {
    outline: none;
    border-color: #ff69b4;
    box-shadow: 0 0 20px rgba(255, 105, 180, 0.3);
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: rgba(255, 182, 193, 0.2);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(45deg, #ff69b4, #87ceeb);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 10px;
}

.typing-feedback {
    font-size: 1rem;
    text-align: center;
    min-height: 30px;
    font-weight: bold;
}

.typing-feedback.error {
    color: #ff6b6b;
}

.typing-feedback.success {
    color: #51cf66;
}

/* Speech Bubble for Mistakes */
/* =====================================================
   Speech Bubble (Typing Mistake Feedback)
   ===================================================== */
.speech-bubble {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    pointer-events: none;
}

.speech-bubble.hidden {
    display: none;
}

.bubble-content {
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid #ff6b8b;
    border-radius: 25px;
    padding: 15px 25px;
    position: relative;
    box-shadow: 0 8px 25px rgba(255, 107, 139, 0.4);
    backdrop-filter: blur(10px);
    animation: bubblePop 0.8s ease;
}

.bubble-content::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 15px solid #ff6b8b;
}

.bubble-content::before {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 12px solid rgba(255, 255, 255, 0.95);
}

#bubbleText {
    font-size: 1.8rem;
    font-weight: bold;
    color: #ff1493;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

@keyframes bubblePop {
    0% {
        transform: scale(0) rotate(-10deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotate(5deg);
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Volume Control UI */
/* =====================================================
   Volume Control UI
   ===================================================== */
.volume-control {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    font-family: inherit;
}

.volume-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 15px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 182, 193, 0.3);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    min-width: 200px;
}

.volume-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-weight: bold;
    color: #666;
}

.volume-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s ease;
}

.volume-toggle:hover {
    background: rgba(255, 182, 193, 0.2);
}

.volume-sliders {
    animation: slideDown 0.3s ease;
}

.volume-sliders.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slider-group {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.slider-group label {
    font-weight: bold;
    min-width: 40px;
    color: #666;
    font-size: 0.9rem;
}

.volume-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(90deg, #ffb6c1, #87ceeb);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ff69b4;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(255, 105, 180, 0.4);
    transition: transform 0.2s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.volume-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ff69b4;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(255, 105, 180, 0.4);
}

.volume-value {
    font-size: 0.8rem;
    color: #888;
    min-width: 35px;
    text-align: right;
}

/* Font size adjustments */
.speaker-name {
    font-size: 1.65rem;
}

.message-content {
    font-size: 2rem;
}

/* Responsive Design */
/* =====================================================
   Responsive Design (<= 768px)
   ===================================================== */
@media (max-width: 768px) {
    .game-title {
        font-size: 2.5rem;
    }
    
    .message-window {
        max-width: 90%;
        font-size: 0.9rem;
    }
    
    .typing-game {
        min-width: 90%;
        padding: 1.5rem;
    }
    
    .sample, .typing-input {
        font-size: 1rem;
    }
}

/* Loading Animation */
/* =====================================================
   Loading Animation
   ===================================================== */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
}

.loading::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 105, 180, 0.3);
    border-top: 4px solid #ff69b4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =====================================================
   モバイル対応: ひらがなボタンUI
   ===================================================== */
.hiragana-buttons-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25; /* メッセージウィンドウより高く */
    
    /* コンテナスタイル */
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 15px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 182, 193, 0.4);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    
    /* グリッドレイアウト - 動的列数対応 */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
    gap: 8px;
    max-width: 95vw;
    width: auto;
    justify-content: center;
    
    /* スクロール可能 */
    max-height: 40vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.hiragana-button {
    /* ボタンサイズとタッチ領域 */
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    
    /* スタイル */
    background: linear-gradient(135deg, #ff69b4, #87ceeb);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    
    /* インタラクション */
    transition: all 0.15s ease;
    box-shadow: 0 3px 10px rgba(255, 105, 180, 0.3);
    
    /* タッチサポート */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
}

.hiragana-button:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 5px 15px rgba(255, 105, 180, 0.4);
    background: linear-gradient(135deg, #ff1493, #4169e1);
}

.hiragana-button:active {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 2px 8px rgba(255, 105, 180, 0.6);
}

/* バックスペースボタンの特別スタイル */
.hiragana-button.backspace-button {
    background: linear-gradient(135deg, #ff6b6b, #ffa500);
    font-size: 1.4rem;
    grid-column: span 2; /* 2マス分の幅 */
}

.hiragana-button.backspace-button:hover {
    background: linear-gradient(135deg, #ff5555, #ff8c00);
}

/* 確定ボタンの特別スタイル */
.hiragana-button.confirm-button {
    background: linear-gradient(135deg, #32cd32, #00ff7f);
    font-size: 1.1rem;
    grid-column: span 2; /* 2マス分の幅 */
    font-weight: bold;
}

.hiragana-button.confirm-button:hover {
    background: linear-gradient(135deg, #228b22, #00fa54);
    transform: translateY(-3px) scale(1.08);
}

/* モバイルサイズ調整 */
@media (max-width: 768px) {
    .hiragana-buttons-container {
        bottom: 10px;
        padding: 10px;
        grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
        gap: 6px;
        max-width: 98vw;
        max-height: 35vh;
    }
    
    .hiragana-button {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        font-size: 1rem;
        border-radius: 10px;
    }
    
    .hiragana-button.backspace-button {
        font-size: 1.2rem;
    }
}

/* 超小型モバイル対応 */
@media (max-width: 480px) {
    .hiragana-buttons-container {
        grid-template-columns: repeat(auto-fit, minmax(36px, 1fr));
        gap: 4px;
        padding: 8px;
        max-width: 99vw;
    }
    
    .hiragana-button {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        font-size: 0.9rem;
    }
}