:root {
    --primary: #0099ff;
    --accent: #ff0099;
    --bg-grad-start: #87CEEB;
    --bg-grad-end: #f0f8ff;
    --font-main: 'M PLUS Rounded 1c', sans-serif;
}

* { box-sizing: border-box; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

body {
    margin: 0; padding: 0; overflow: hidden;
    background: linear-gradient(to bottom, var(--bg-grad-start), var(--bg-grad-end));
    font-family: var(--font-main);
    color: #333;
}

.game-wrapper {
    position: relative; width: 100vw; height: 100vh; overflow: hidden;
}

canvas { display: block; width: 100%; height: 100%; }

/* --- 水滴エフェクト --- */
#water-drops-container {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 50; /* UIの下、キャンバスの上 */
    overflow: hidden;
}

.water-drop {
    position: absolute;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.1));
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2), inset 2px 2px 5px rgba(255, 255, 255, 0.5);
    opacity: 0;
    transform: scale(0);
    animation: dropSplash 0.5s forwards ease-out;
}

/* 液体っぽく形を歪ませる */
.water-drop:nth-child(2n) { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }
.water-drop:nth-child(3n) { border-radius: 40% 60% 70% 30% / 40% 70% 30% 60%; }

@keyframes dropSplash {
    0% { transform: scale(0); opacity: 0.8; margin-top: -50px; }
    60% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0.9; margin-top: 0; }
}

.ui-layer {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    display: flex; flex-direction: column; justify-content: space-between;
}

.height-panel {
    align-self: center; margin-top: 10px;
    background: rgba(0,0,0,0.7); color: #fff;
    padding: 8px 20px; border-radius: 20px; border: 2px solid #fff;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.height-panel .label { font-size: 0.8rem; color: #ccc; }
.height-panel .value { font-size: 2rem; font-weight: bold; color: #00ffff; text-shadow: 0 0 10px cyan; font-family: monospace; }

/* Scoreboard */
.scoreboard {
    position: absolute; top: 80px; width: 100%;
    display: flex; justify-content: center; align-items: center; gap: 30px;
}
.score-box {
    text-align: center; background: rgba(255,255,255,0.8);
    padding: 5px 15px; border-radius: 10px; border: 2px solid #999;
    min-width: 80px;
}
.score-box.p1 { border-color: var(--accent); color: var(--accent); }
.score-box.p2 { border-color: var(--primary); color: var(--primary); }
.score-label { display: block; font-size: 0.8rem; font-weight: bold; }
.score-num { display: block; font-size: 2rem; font-weight: 900; line-height: 1; }
.vs { font-weight: bold; font-style: italic; text-shadow: 1px 1px 0 #fff; color: #555; }

.turn-indicator {
    position: absolute; top: 150px; width: 100%;
    display: flex; justify-content: space-between; padding: 0 20px;
}
.badge {
    background: rgba(255,255,255,0.9); padding: 5px 15px; border-radius: 10px;
    font-weight: bold; opacity: 0.5; transform: scale(0.9); transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.badge.p1 { color: var(--accent); }
.badge.p2 { color: var(--primary); }
.badge.active { opacity: 1; transform: scale(1.1); box-shadow: 0 0 15px rgba(255,255,255,0.8); border: 2px solid currentColor; }

.controls {
    pointer-events: auto;
    width: 100%; padding-bottom: 30px;
    background: linear-gradient(to top, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0) 100%);
    display: flex; flex-direction: column; align-items: center; gap: 15px;
}

.btn-pour {
    width: 260px; height: 80px; border-radius: 40px;
    background: #fff; border: 4px solid #ddd;
    font-size: 1.8rem; font-weight: bold; color: #333;
    box-shadow: 0 8px 0 #ccc, 0 10px 20px rgba(0,0,0,0.2);
    cursor: pointer; transition: all 0.1s;
}
.btn-pour:active, .btn-pour.pressed { transform: translateY(6px); box-shadow: 0 2px 0 #ccc; background: #eee; }
.btn-pour:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-special {
    background: linear-gradient(45deg, #ff6600, #ffcc00); color: white;
    border: 2px solid white; padding: 8px 24px; border-radius: 20px;
    font-weight: bold; cursor: pointer; box-shadow: 0 4px 0 #cc4400;
}
.btn-special:active { transform: translateY(2px); box-shadow: 0 2px 0 #cc4400; }
.btn-special:disabled { background: #999; box-shadow: none; opacity: 0.6; cursor: not-allowed; }

.hint { font-size: 0.9rem; margin: 0; opacity: 0.8; font-weight: bold; text-shadow: 1px 1px 0 #fff; }

.overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.95); z-index: 100;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    pointer-events: auto; overflow: hidden;
}
.overlay.active { display: flex; }

/* Title Visuals */
.title-bg-visual {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 0; overflow: hidden; display: flex; justify-content: center; align-items: flex-end;
}
.cup-rim-bg {
    width: 130vw; height: 55vh;
    border: 15px solid rgba(255, 100, 0, 0.2); border-top: none;
    border-radius: 0 0 30% 30%; position: relative; bottom: -10%;
    background-color: rgba(0, 255, 255, 0.1); box-sizing: border-box;
}
.water-surface {
    position: absolute; top: -45px; left: -15px; width: calc(100% + 30px); height: 70px;
    background: rgba(0, 255, 255, 0.25); border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    animation: surfaceWobble 4s infinite ease-in-out; filter: blur(2px);
}
@keyframes surfaceWobble {
    0%, 100% { border-radius: 50% 50% 0 0 / 100% 100% 0 0; transform: translateY(0); }
    50% { border-radius: 40% 60% 0 0 / 80% 120% 0 0; transform: translateY(8px); }
}

.title-container { position: relative; z-index: 2; margin-bottom: 50px; text-align: center; }
.title {
    font-size: 3.5rem; color: var(--primary); transform: rotate(-3deg);
    text-shadow: 4px 4px 0 #fff, 6px 6px 0 rgba(0,0,0,0.1); margin-bottom: 0;
}
.title-anim {
    display: inline-block; color: var(--accent); font-size: 4.5rem;
    animation: bounceText 2s infinite cubic-bezier(0.280, 0.840, 0.420, 1);
}
@keyframes bounceText {
    0%, 100% { transform: scale(1, 1) translateY(0); }
    10% { transform: scale(1.1, 0.9) translateY(0); }
    30% { transform: scale(0.9, 1.1) translateY(-10px); }
    50% { transform: scale(1.05, 0.95) translateY(0); }
    57% { transform: scale(1, 1) translateY(-3px); }
    64% { transform: scale(1, 1) translateY(0); }
}
.subtitle { color: #666; margin-top: 10px; font-size: 1.2rem; background: rgba(255,255,255,0.8); padding: 5px 15px; border-radius: 20px; display: inline-block; }

.btn-menu {
    background: var(--primary); color: white; border: none; padding: 15px 40px;
    font-size: 1.2rem; border-radius: 30px; margin: 10px; cursor: pointer;
    font-weight: bold; position: relative; z-index: 2;
    box-shadow: 0 5px 0 #0066aa; transition: transform 0.1s;
}
.btn-menu:active { transform: translateY(4px); box-shadow: 0 1px 0 #0066aa; }
.btn-sub {
    background: #999; color: white; border: none; padding: 10px 20px;
    font-size: 1rem; border-radius: 20px; margin-top: 10px; cursor: pointer; position: relative; z-index: 2;
}
.menu-col { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 20px; }

/* Mind Game */
#screen-mindgame { background: rgba(0,0,0,0.95); color: white; }
.mindgame-content { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.alert { color: yellow; font-size: 3rem; text-shadow: 0 0 20px red; margin-bottom: 10px; animation: flash 0.5s infinite alternate; }
@keyframes flash { from { opacity: 1; } to { opacity: 0.5; } }
.big-msg { font-size: 2rem; margin-bottom: 30px; }

.rhythm-text {
    font-size: 5rem; font-weight: 900; color: #00ffff;
    text-shadow: 0 0 20px blue; height: 100px; margin-bottom: 20px; transition: all 0.1s;
}
.rhythm-text.beat { transform: scale(1.5); color: #fff; text-shadow: 0 0 40px #ff00ff; }
.rhythm-text.go { transform: scale(1.8); color: #ffff00; text-shadow: 0 0 50px orange; }

.rps-split-area { display: flex; justify-content: space-between; width: 90%; max-width: 800px; margin-top: 20px; }
.rps-panel {
    background: rgba(255,255,255,0.1); padding: 20px; border-radius: 20px; border: 2px solid #555;
    width: 45%; text-align: center; transition: all 0.2s;
}
.rps-panel.active-input { border-color: #ffff00; background: rgba(255,255,0,0.1); box-shadow: 0 0 20px rgba(255,255,0,0.3); }
.rps-name { font-size: 1.5rem; font-weight: bold; margin-bottom: 10px; color: #ccc; }
.status-ready { font-size: 1.5rem; color: #888; height: 40px; margin-bottom: 10px; }
.status-ready.ok { color: #00ff00; font-weight: bold; text-shadow: 0 0 10px #00ff00; }

.rps-btns { display: flex; gap: 10px; justify-content: center; }
.btn-hand {
    position: relative; font-size: 3rem; width: 80px; height: 80px; border-radius: 50%;
    border: 4px solid #555; background: #222; color: #555; cursor: not-allowed; transition: all 0.1s;
}
.btn-hand .key {
    position: absolute; left: -5px; bottom: -5px; font-size: 1rem; background: #fff; color: #000;
    width: 25px; height: 25px; border-radius: 50%; line-height: 25px; font-weight: bold; border: 2px solid #000;
}
.btn-hand.active { border-color: #fff; background: #444; color: #fff; cursor: pointer; }
.btn-hand.active:hover { background: #666; transform: scale(1.1); }
.btn-hand.active:active, .btn-hand.selected { background: #ffcc00; border-color: #fff; transform: scale(0.95); box-shadow: 0 0 20px #ffcc00; }
.btn-danger { background: red; color: white; border: 2px solid white; padding: 15px 40px; font-size: 1.5rem; border-radius: 40px; cursor: pointer; }

.rps-result-showdown { display: flex; justify-content: center; align-items: center; gap: 40px; margin-bottom: 20px; }
.show-hand { font-size: 6rem; background: #fff; border-radius: 50%; width: 140px; height: 140px; display: flex; justify-content: center; align-items: center; border: 5px solid #000; }
.show-vs { font-size: 3rem; font-style: italic; color: #ccc; }
.result-text { font-size: 4rem; color: gold; text-shadow: 0 0 20px orange; animation: pop-in 0.3s; }
@keyframes pop-in { 0% { transform: scale(0); } 100% { transform: scale(1); } }

/* Result Details */
#screen-result h2 { font-size: 3.5rem; color: var(--accent); text-shadow: 3px 3px 0 #fff; margin-bottom: 10px; }
.result-details { background: rgba(255,255,255,0.8); padding: 20px; border-radius: 15px; border: 2px solid #ccc; text-align: center; margin-bottom: 20px; width: 80%; max-width: 400px; }
.res-label { font-size: 0.9rem; color: #666; margin: 5px 0 0; }
.res-value-big { font-size: 2.5rem; font-weight: bold; color: #0099ff; margin: 0 0 10px; font-family: monospace; }
.res-value-rank { font-size: 2rem; font-weight: bold; color: #ff6600; margin: 0; }
.res-reason { color: #555; font-size: 1rem; margin-bottom: 20px; }

.total-score-display {
    background: rgba(0,0,0,0.8); color: #fff; padding: 10px 30px; border-radius: 30px; margin-bottom: 20px; border: 2px solid gold;
}
.ts-label { font-size: 0.8rem; display: block; text-align: center; color: #ccc; }
.ts-numbers { font-size: 2.5rem; font-weight: bold; }
.ts-val.p1 { color: var(--accent); }
.ts-val.p2 { color: var(--primary); }
.ts-hyphen { margin: 0 10px; color: #fff; }

/* Mobile Optimizations */
@media (max-width: 600px) {
    .title { font-size: 2.5rem; }
    .title-anim { font-size: 3rem; }
    .scoreboard { top: 60px; gap: 15px; }
    .score-box { min-width: 60px; padding: 2px 10px; }
    .score-num { font-size: 1.5rem; }
    .turn-indicator { top: 120px; }
    .rps-split-area { flex-direction: column-reverse; align-items: center; gap: 10px; margin-top: 10px; }
    .rps-panel { width: 95%; padding: 10px; }
    .rps-name { margin-bottom: 5px; font-size: 1.2rem; }
    .rps-btns { gap: 5px; }
    .btn-hand { width: 60px; height: 60px; font-size: 2rem; }
    .btn-hand .key { display: none; }
    .status-ready { height: 30px; font-size: 1.2rem; }
    .rhythm-text { font-size: 3.5rem; height: 70px; }
    .rps-result-showdown { gap: 10px; }
    .show-hand { width: 90px; height: 90px; font-size: 4rem; }
    .show-vs { font-size: 2rem; }
    .btn-pour { width: 200px; height: 70px; font-size: 1.5rem; }
}