* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --sky:        #B8E0F7;
    --sky-deep:   #8FCAE8;
    --grass:      #C5DFA8;
    --cream:      #FFF8E7;
    --cream-dark: #F5EDDA;
    --yellow:     #F5C842;
    --yellow-deep:#E8A820;
    --orange:     #F4A534;
    --brown:      #6B3F1A;
    --brown-mid:  #A0673A;
    --brown-light:#C8956A;
    --shadow:     rgba(107, 63, 26, 0.18);
    --font:       'M PLUS Rounded 1c', 'Hiragino Maru Gothic Pro', 'Kosugi Maru', sans-serif;
}

body {
    background: linear-gradient(180deg, var(--sky) 0%, var(--grass) 100%);
    background-attachment: fixed;
    color: var(--brown);
    font-family: var(--font);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

.screen {
    display: none;
    width: 480px;
    max-width: 100vw;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
.screen.active { display: flex; }

/* ---- ワールドマップ ---- */
#map-screen {
    justify-content: flex-start;
    padding: 24px 20px;
    overflow-y: auto;
    max-height: 100vh;
    gap: 12px;
}

#map-header { text-align: center; }
#map-header h2 {
    font-size: 20px;
    font-weight: 800;
    color: var(--brown);
    text-shadow: 0 2px 0 rgba(255,255,255,0.6);
}
#map-subtitle { font-size: 13px; color: var(--brown-light); margin-top: 4px; }

#stage-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stage-card {
    width: 100%;
    padding: 14px 18px;
    border-radius: 20px;
    border: 3px solid rgba(255,255,255,0.7);
    background: var(--cream);
    box-shadow: 0 4px 12px var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
    color: var(--brown);
    font-family: var(--font);
    transition: transform 0.15s, box-shadow 0.15s;
}
.stage-card:active { transform: scale(0.97); box-shadow: 0 2px 6px var(--shadow); }

.stage-card.cleared {
    border-color: var(--yellow);
    background: linear-gradient(135deg, #FFF8E7, #FFF3C4);
}
.stage-card.locked { opacity: 0.5; cursor: default; }

.stage-icon      { font-size: 32px; line-height: 1; flex-shrink: 0; }
.stage-info      { flex: 1; }
.stage-subtitle  { font-size: 11px; color: var(--brown-light); margin-bottom: 2px; }
.stage-name      { font-size: 17px; font-weight: 700; color: var(--brown); }
.stage-song      { font-size: 12px; color: var(--brown-light); margin-top: 2px; }
.stage-rank      {
    font-size: 30px;
    font-weight: 800;
    color: var(--yellow-deep);
    text-shadow: 0 2px 0 rgba(255,255,255,0.6);
    min-width: 36px;
    text-align: center;
}
.stage-lock { font-size: 24px; flex-shrink: 0; }

/* リザルトボタン */
#share-buttons { display: flex; gap: 10px; }
#share-x {
    background: #2c2c2c;
    color: white;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 30px;
    box-shadow: none;
    border: none;
    font-family: var(--font);
}
#share-line {
    background: #06C755;
    color: white;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 30px;
    box-shadow: none;
    border: none;
    font-family: var(--font);
}
#result-buttons { display: flex; gap: 12px; }
#result-buttons button { padding: 12px 24px; font-size: 16px; }
#map-btn {
    background: var(--cream-dark);
    color: var(--brown);
    border: 2px solid var(--brown-light);
    box-shadow: 0 3px 0 var(--brown-light);
}

/* ---- タイトル ---- */
#title-screen {
    text-align: center;
    padding: 40px 20px;
    background: rgba(255,248,231,0.85);
    border-radius: 28px;
    margin: 20px;
    box-shadow: 0 8px 24px var(--shadow);
    border: 3px solid rgba(255,255,255,0.8);
}

h1 {
    font-size: 26px;
    font-weight: 800;
    color: var(--brown);
    text-shadow: 0 2px 0 rgba(255,255,255,0.7);
    margin-bottom: 4px;
    letter-spacing: 1px;
}
.subtitle { color: var(--brown-mid); font-size: 14px; }
.hint     { color: var(--brown-light); font-size: 12px; margin-top: 12px; }

button {
    background: var(--yellow);
    color: var(--brown);
    border: none;
    padding: 14px 40px;
    font-size: 17px;
    font-weight: 800;
    font-family: var(--font);
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--yellow-deep), 0 6px 16px rgba(232,168,32,0.3);
    transition: transform 0.1s, box-shadow 0.1s;
    letter-spacing: 1px;
}
button:hover  { transform: translateY(-2px); box-shadow: 0 6px 0 var(--yellow-deep), 0 8px 20px rgba(232,168,32,0.35); }
button:active { transform: translateY(2px);  box-shadow: 0 2px 0 var(--yellow-deep); }

/* ---- ローディング ---- */
#loading-screen {
    gap: 16px;
    text-align: center;
    padding: 40px;
    background: rgba(255,248,231,0.9);
    border-radius: 28px;
    margin: 20px;
    box-shadow: 0 8px 24px var(--shadow);
    border: 3px solid rgba(255,255,255,0.8);
}
#loading-icon        { font-size: 56px; line-height: 1; }
#loading-stage-name  { font-size: 22px; font-weight: 800; color: var(--brown); }
#loading-bar-wrap {
    width: 280px;
    height: 14px;
    background: rgba(107,63,26,0.12);
    border-radius: 7px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.5);
    margin-top: 4px;
}
#loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--yellow), var(--orange));
    border-radius: 6px;
    transition: width 0.15s ease-out;
}
#loading-text { font-size: 13px; color: var(--brown-mid); }

/* ---- ゲーム ---- */
#game-screen { position: relative; }

#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}
#score {
    font-size: 24px;
    font-weight: 800;
    color: var(--brown);
    text-shadow: 0 2px 0 rgba(255,255,255,0.6);
}
#combo { font-size: 16px; font-weight: 700; color: var(--brown); text-align: center; flex: 1; }

#quit-btn {
    background: rgba(255,255,255,0.6);
    color: var(--brown-mid);
    border: 2px solid rgba(107,63,26,0.2);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 14px;
    padding: 0;
    box-shadow: 0 2px 6px var(--shadow);
    flex-shrink: 0;
    pointer-events: auto;
    font-family: var(--font);
}
#quit-btn:active { background: rgba(244,165,52,0.4); }

#game-canvas {
    display: block;
    max-width: 100vw;
    max-height: 65vh;
    touch-action: none;
    border-radius: 0;
}

#hp-bar {
    width: 440px;
    max-width: 92vw;
    height: 10px;
    background: rgba(107,63,26,0.1);
    border-radius: 5px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.5);
}
#hp-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #7EC850, #A8E070);
    border-radius: 4px;
    transition: width 0.1s, background 0.3s;
}

/* レーンボタン */
#lane-buttons { display: flex; gap: 10px; }
.lane-btn {
    width: min(90px, 22vw);
    height: 52px;
    font-size: 17px;
    font-weight: 800;
    font-family: var(--font);
    background: rgba(255,248,231,0.85);
    color: var(--brown-mid);
    border: 3px solid rgba(255,255,255,0.8);
    border-radius: 16px;
    padding: 0;
    box-shadow: 0 4px 0 rgba(107,63,26,0.15), 0 4px 10px var(--shadow);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
.lane-btn:active,
.lane-btn.pressed {
    background: var(--yellow);
    color: var(--brown);
    border-color: var(--yellow-deep);
    box-shadow: 0 2px 0 var(--yellow-deep);
    transform: translateY(2px);
}

/* ---- ストーリー ---- */
#story-screen,
#story-screen * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
#story-screen {
    position: relative;
    width: 480px;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
    cursor: pointer;
}
#story-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, var(--sky) 0%, var(--sky-deep) 40%, var(--grass) 100%);
    z-index: 0;
}
#story-chars {
    position: absolute;
    bottom: 160px;
    left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 10px;
    z-index: 1;
}
#story-char-left,
#story-char-right {
    height: min(260px, 38vh);
    max-width: 45%;
    object-fit: contain;
    transition: opacity 0.3s, transform 0.3s;
    filter: drop-shadow(0 6px 12px rgba(107,63,26,0.2));
}
#story-char-left  { transform-origin: bottom left; }
#story-char-right { transform-origin: bottom right; }

#story-dialog {
    position: relative;
    z-index: 2;
    background: rgba(255, 248, 231, 0.96);
    border-top: 3px solid rgba(255,255,255,0.8);
    border-radius: 24px 24px 0 0;
    padding: 16px 22px 22px;
    min-height: 155px;
    box-shadow: 0 -4px 20px var(--shadow);
}
#story-speaker {
    font-size: 14px;
    font-weight: 800;
    color: var(--brown-mid);
    margin-bottom: 8px;
    letter-spacing: 1px;
    background: var(--yellow);
    display: inline-block;
    padding: 2px 12px;
    border-radius: 20px;
    box-shadow: 0 2px 0 var(--yellow-deep);
}
#story-text {
    font-size: 16px;
    line-height: 1.75;
    color: var(--brown);
    min-height: 60px;
    font-weight: 700;
}
#story-next {
    position: absolute;
    bottom: 16px;
    right: 20px;
    background: transparent;
    color: var(--brown-light);
    border: none;
    font-size: 20px;
    padding: 4px 8px;
    box-shadow: none;
    animation: blink 1s infinite;
    font-family: var(--font);
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

/* ---- リザルト ---- */
#result-screen {
    text-align: center;
    padding: 32px 24px;
    background: rgba(255,248,231,0.92);
    border-radius: 28px;
    margin: 20px;
    box-shadow: 0 8px 24px var(--shadow);
    border: 3px solid rgba(255,255,255,0.8);
}
#result-screen h2 {
    font-size: 18px;
    font-weight: 800;
    color: var(--brown-light);
    letter-spacing: 6px;
}
#result-rank {
    font-size: 96px;
    font-weight: 800;
    color: var(--yellow-deep);
    text-shadow: 0 4px 0 rgba(232,168,32,0.3), 0 0 30px rgba(245,200,66,0.4);
    line-height: 1.1;
}
#result-score { font-size: 28px; font-weight: 700; color: var(--brown); }
#result-stats {
    color: var(--brown-mid);
    font-size: 14px;
    line-height: 1;
    width: 220px;
    background: var(--cream-dark);
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.7);
}
#result-stats div {
    padding: 8px 20px;
    border-bottom: 1px solid rgba(107,63,26,0.08);
    display: flex;
    justify-content: space-between;
    font-weight: 700;
}
#result-stats div:last-child { border-bottom: none; }
