:root {
    --bg-color: #1a162b;
    --ui-text: #fef9c3;
    --ui-bg: rgba(30, 27, 46, 0.88);
    --accent: #f59e0b;
    --accent-hover: #d97706;
    --secondary: #38bdf8;
    --danger: #f43f5e;
    --font-family: 'Hiragino Maru Gothic ProN', 'Yu Gothic Round', 'Meiryo', sans-serif;
}

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

body, html {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    overflow: hidden;
    touch-action: none;
    font-family: var(--font-family);
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* イベントスライド演出用のレイヤー（画像とテキストを分離して被りを完全排除） */
#event-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #0c0919;
    z-index: 2000;
    display: none;
    flex-direction: column;
    color: white;
    opacity: 1;
    transition: opacity 0.4s ease;
}

#event-image-area {
    flex: 1;
    width: 100%;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #0c0919;
    padding: 12px 14px 6px 14px;
}

#event-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center center;
    opacity: 0;
    transition: opacity 0.35s ease;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.7));
    border-radius: 12px;
}

#event-text-container {
    width: 100%;
    min-height: 125px;
    max-height: 38vh;
    flex-shrink: 0;
    padding: 16px 20px calc(18px + env(safe-area-inset-bottom)) 20px;
    background: linear-gradient(180deg, #18132e 0%, #0d0a1a 100%);
    border-top: 2px solid rgba(254, 240, 138, 0.45);
    text-align: center;
    z-index: 2;
    pointer-events: none;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#event-text {
    font-size: 16px;
    line-height: 1.75;
    font-weight: bold;
    color: #fffbeb;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.9);
    margin: 0;
}

#event-skip-btn {
    position: absolute;
    top: env(safe-area-inset-top, 20px);
    right: 18px;
    background: rgba(30, 27, 46, 0.6);
    border: 1px solid rgba(254, 240, 138, 0.5);
    color: #fef08a;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    z-index: 3;
    pointer-events: auto;
    cursor: pointer;
    backdrop-filter: blur(4px);
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* 上部ステータスバー */
.status-box {
    position: absolute;
    top: 14px;
    left: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: auto;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--ui-bg);
    border: 2px solid rgba(254, 240, 138, 0.3);
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 15px;
    font-weight: bold;
    color: #fffbeb;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
}

#level-display {
    font-size: 18px;
    color: #fef08a;
    border-color: rgba(254, 240, 138, 0.6);
}

#stamp-display {
    color: #fde047;
}

#radar-display {
    color: #38bdf8;
    display: none;
}

#power-display {
    color: #4ade80;
    display: none;
}

#map-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    background: var(--ui-bg);
    color: #fef08a;
    border: 2px solid rgba(254, 240, 138, 0.4);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
}

#map-btn:active {
    background: rgba(55, 48, 89, 0.95);
    transform: scale(0.96);
}

/* D-Pad 操作パネル：絵本クレヨン・木彫り調の温かいボタン */
#dpad-container {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    width: 216px;
    height: 216px;
    pointer-events: auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 10px;
}

.dpad-btn {
    background: linear-gradient(145deg, rgba(62, 53, 94, 0.8), rgba(36, 30, 58, 0.88));
    border: 2.5px solid rgba(254, 240, 138, 0.45);
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fef08a;
    font-size: 26px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.38), inset 0 2px 4px rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    transition: transform 0.1s, background 0.1s;
    user-select: none;
    -webkit-user-select: none;
}

.dpad-btn:active, .dpad-btn.active {
    background: linear-gradient(145deg, #f59e0b, #d97706);
    border-color: #fef08a;
    color: #1c1917;
    transform: scale(0.92);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

#btn-up { grid-column: 2; grid-row: 1; }
#btn-left { grid-column: 1; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; }
#btn-down { grid-column: 2; grid-row: 3; }

/* 共通モーダル */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 8, 20, 0.82);
    display: none;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 100;
    backdrop-filter: blur(6px);
}

.modal-content {
    background: linear-gradient(135deg, #282142 0%, #1e1833 100%);
    border: 2px solid rgba(254, 240, 138, 0.4);
    border-radius: 20px;
    padding: 24px 20px;
    text-align: center;
    color: #fffbeb;
    max-width: 90%;
    min-width: 310px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
}

.modal h2 {
    margin-bottom: 14px;
    font-size: 22px;
    color: #fef08a;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.modal p {
    margin-bottom: 20px;
    line-height: 1.6;
    color: #e2e8f0;
    font-size: 15px;
}

.modal button {
    display: block;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #fffbeb;
    border: none;
    padding: 13px 20px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
    font-family: inherit;
}

.modal button:active {
    transform: scale(0.97);
}

.modal button.danger {
    background: linear-gradient(135deg, #f43f5e 0%, #be123c 100%);
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.3);
}

.modal button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

#msg-btn {
    position: relative;
    overflow: hidden;
    margin-top: 10px;
}

#msg-btn-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background-color: rgba(255, 255, 255, 0.25);
    z-index: 1;
}

#msg-btn-text {
    position: relative;
    z-index: 2;
}

/* なぞなぞ専用モーダル */
#riddle-options-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.riddle-opt-btn {
    background: rgba(49, 44, 79, 0.85);
    border: 2px solid rgba(254, 240, 138, 0.35);
    color: #fffbeb;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: inherit;
}

.riddle-opt-btn:active {
    background: rgba(245, 158, 11, 0.5);
    border-color: #fde047;
    transform: scale(0.98);
}

.riddle-opt-badge {
    background: #f59e0b;
    color: #1e1b2e;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
}

/* 地図モーダル */
#map-wrapper {
    margin-bottom: 14px;
    border: 2px solid rgba(254, 240, 138, 0.3);
    border-radius: 12px;
    overflow: hidden;
    background-color: #0d0a18;
}

#modal-map-canvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 42vh;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #cbd5e1;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.color-box {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* 揺れアニメーション */
@keyframes shake {
    0% { transform: translate(2px, 1px) rotate(0deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

.shake-screen {
    animation: shake 0.4s cubic-bezier(.36, .07, .19, .97) both;
}
