/* --- ベース設定・でじらぼトーン＆マナー --- */
:root {
    --brand-blue: #4A90E2;
    --brand-dark: #2a3744;
    --text-color: #333;
    --bg-light: #fff9f0;
    --gold: #f1c40f;
    --silver: #bdc3c7;
    --bronze: #cd7f32;
    --danger: #e74c3c;
    --success: #2ecc71;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    margin: 0;
    padding: 0;
}

body {
    width: 100vw;
    height: 100dvh;
    display: flex;
    font-family: 'M PLUS Rounded 1c', sans-serif;
    overflow: hidden;
    background-color: #000;
}

.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

#app-container {
    position: relative;
    width: 100vw;
    height: 100dvh;
    background-color: var(--bg-light);
    overflow: hidden;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
}

.bg-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* --- 1. スタート画面 --- */
.start-panel {
    position: relative;
    z-index: 5;
    margin: auto;
    width: 85%;
    max-width: 550px;
    background: rgba(255, 255, 255, 0.95);
    border: 5px solid var(--brand-blue);
    border-radius: 24px;
    padding: 3vh 30px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    text-align: center;
    max-height: 95dvh;
    overflow-y: auto;
}

.app-title {
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    color: var(--brand-dark);
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 2vh;
}
.sub-title {
    font-size: clamp(1.1rem, 2.5vw, 1.6rem);
    color: var(--brand-blue);
}

.setting-group {
    margin-bottom: 1.5vh;
    text-align: left;
}
.setting-label {
    display: block;
    font-size: 1rem;
    font-weight: bold;
    color: var(--brand-dark);
    margin-bottom: 6px;
}
.btn-group {
    display: flex;
    gap: 10px;
    width: 100%;
}
.choice-btn {
    flex: 1;
    padding: 8px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    background: #fff;
    border: 3px solid #ccc;
    border-radius: 12px;
    color: #666;
    cursor: pointer;
    box-shadow: 0 4px 0 #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.05s;
}
.choice-btn.selected {
    background: var(--brand-blue);
    border-color: #2a5d96;
    color: #fff;
    box-shadow: 0 4px 0 #1b4370;
}
.choice-btn:active {
    transform: translateY(4px);
    box-shadow: none !important;
}

.speed-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.ui-btn {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    font-weight: 800;
    padding: 10px 30px;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 50px;
    box-shadow: 0 6px 0 #239a51;
    cursor: pointer;
    margin-top: 1vh;
}
.ui-btn:active {
    transform: translateY(6px);
    box-shadow: none;
}

/* --- 2. ゲームプレイ画面 --- */
#play-area {
    width: 70%; height: 100%; position: relative; z-index: 2; display: flex; flex-direction: column;
}

#ui-area {
    width: 30%; height: 100%; background-color: var(--brand-dark); border-left: 5px solid #111;
    position: relative; z-index: 10; display: flex; flex-direction: column; padding: 3vh 20px; align-items: center; box-shadow: -5px 0 15px rgba(0,0,0,0.3);
}

.game-header {
    height: 8vh; width: 100%; display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; background: rgba(255,255,255,0.85); border-bottom: 3px solid #ccc;
}
.header-item { font-size: clamp(1.2rem, 3vw, 1.6rem); font-weight: bold; color: var(--brand-dark); }

#timer-container { width: 45%; height: 16px; background-color: #e0e0e0; border: 2px solid var(--brand-dark); border-radius: 10px; overflow: hidden; }
#timer-bar { height: 100%; width: 100%; background-color: var(--danger); transform-origin: left; }

#hint-card {
    position: absolute; top: 10vh; left: 20px; width: 12vh; height: 12vh; background: white;
    border: 4px solid var(--brand-blue); border-radius: 16px; box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: flex; align-items: center; justify-content: center; z-index: 5;
}
#hint-img { width: 85%; height: 85%; object-fit: contain; }

#canvas-wrapper {
    flex: 1; position: relative; margin: 2vh auto; width: 90%; max-width: 550px; aspect-ratio: 1 / 1;
    background: rgba(255,255,255,0.9); border: 6px dashed #aaa; border-radius: 24px; box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
}
#paint-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; touch-action: none; border-radius: 18px; }
#guide-letter {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0.18; z-index: 2; pointer-events: none;
}

.action-btn {
    width: 100%; height: 10vh; font-family: inherit; font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 800;
    color: white; background-color: #ff7675; border: none; border-radius: 20px; box-shadow: 0 8px 0 #c0392b; cursor: pointer; margin-bottom: 3vh;
}
.action-btn:active { transform: translateY(8px); box-shadow: none; }

.meter-box {
    flex: 1; width: 100%; background: rgba(0, 0, 0, 0.2); border-radius: 20px; padding: 2vh 15px; display: flex; flex-direction: column; align-items: center;
}
.meter-label { color: #fff; font-size: 1rem; font-weight: bold; margin-bottom: 1.5vh; }
.vertical-meter-container { position: relative; width: 50px; flex: 1; background: #1e272e; border: 3px solid #fff; border-radius: 25px; overflow: hidden; box-shadow: inset 0 0 10px rgba(0,0,0,0.5); }
#meter-gauge { position: absolute; bottom: 0; left: 0; width: 100%; height: 0%; background: linear-gradient(0deg, #e74c3c 0%, #f1c40f 75%, #2ecc71 100%); transition: height 0.5s ease; }
.indicator-line { position: absolute; left: 0; width: 100%; border-top: 2px dashed rgba(255,255,255,0.6); pointer-events: none; z-index: 3; }
.indicator-line span { position: absolute; left: 60px; white-space: nowrap; color: #fff; font-size: 0.9rem; transform: translateY(-50%); font-weight: bold; text-shadow: 1px 1px 2px #000; }
.gold-line { bottom: 90%; border-top-color: var(--gold); }
.gold-line span { color: var(--gold); }
.silver-line { bottom: 80%; border-top-color: var(--silver); }
.silver-line span { color: var(--silver); }
.bronze-line { bottom: 50%; border-top-color: #cd7f32; }
#secret-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #2c3e50; color: #fff; font-size: 2.5rem; font-weight: 800; display: flex; align-items: center; justify-content: center; z-index: 15; }
#meter-value { color: #fff; font-size: 1.6rem; font-weight: 800; margin-top: 1vh; }

#effect-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 100; display: flex; align-items: center; justify-content: center; transition: opacity 0.3s ease; }
.cut-in-box { background: white; padding: 30px 50px; border-radius: 24px; border: 5px solid var(--brand-blue); text-align: center; animation: popScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.cut-in-title { font-size: 3rem; font-weight: 800; margin-bottom: 10px; }
.cut-in-score { font-size: 4rem; font-weight: 800; color: #ff7675; }

@keyframes popScale { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-12px); } 50% { transform: translateX(12px); } 75% { transform: translateX(-12px); } }
.shake { animation: shake 0.4s ease; }

/* --- 3. リザルト画面（iPad見切れ対策＆メダル修正） --- */
.result-card {
    position: relative;
    z-index: 5;
    margin: auto;
    width: 90%;
    max-width: 600px;
    background: white;
    border: 6px solid var(--brand-blue);
    border-radius: 24px;
    padding: 3vh 30px;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    max-height: 90dvh; /* GIGA端末用オーバーフロー対策 */
    overflow-y: auto;
}

.result-title {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    color: var(--brand-dark);
    font-weight: 800;
}

.medal-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 1vh 0;
}

#medal-emoji {
    font-size: clamp(4rem, 10vh, 5.5rem);
    animation: pulse 1.5s infinite;
    line-height: 1.1;
}

#medal-text {
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    font-weight: 800;
    color: var(--brand-dark);
    font-family: 'M PLUS Rounded 1c', sans-serif;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.score-details {
    background: #fcf6ed;
    border-radius: 16px;
    padding: 1.5vh 20px;
    margin-bottom: 2vh;
    text-align: left;
}
.score-line { font-size: clamp(1rem, 2.5vw, 1.2rem); font-weight: bold; color: #555; margin: 6px 0; display: flex; justify-content: space-between; }
.score-highlight { color: var(--brand-dark); font-size: clamp(1.2rem, 3vw, 1.4rem); }
.result-hr { border: none; border-top: 2px dashed #ccc; margin: 8px 0; }
.score-total { font-size: clamp(1.2rem, 3vw, 1.5rem); font-weight: 800; color: var(--brand-dark); display: flex; justify-content: space-between; align-items: center; }
.score-total-highlight { color: var(--danger); font-size: clamp(1.8rem, 4vw, 2.2rem); }
.result-buttons { display: flex; gap: 15px; justify-content: center; }

/* === ジェムナビボタン === */
.gem-navi-wrapper {
    position: fixed; bottom: 20px; right: 20px; z-index: 9999;
    display: flex; align-items: stretch; background: #fff;
    border-radius: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    border: 3px solid #78C2C4; overflow: hidden; transition: box-shadow 0.2s;
}
.gem-navi-handle {
    padding: 0 15px; background: #E6E9ED; color: #AAB2BD;
    cursor: grab; font-size: 1.2rem; user-select: none; touch-action: none;
    display: flex; align-items: center; justify-content: center;
}
.gem-navi-handle:active { cursor: grabbing; background: #CCD1D9; }
.gem-navi-btn {
    background: linear-gradient(135deg, #A0CECB, #78C2C4);
    color: #fff !important; text-decoration: none; padding: 10px 20px;
    font-weight: bold; font-family: "M PLUS Rounded 1c", sans-serif;
    display: flex; align-items: center; gap: 5px; font-size: 1rem; white-space: nowrap;
}
.gem-navi-btn:hover { opacity: 0.9; }
.gem-navi-icon {
    width: 24px !important; height: 24px !important; object-fit: cover !important;
    border-radius: 50% !important; flex-shrink: 0 !important;
    margin-right: 4px !important; display: inline-block !important;
}

@media (min-width: 768px) {
    .start-panel { padding: 4vh 40px; }
    .setting-label { font-size: 1.2rem; }
    .choice-btn { font-size: 1.1rem; padding: 12px; }
}