:root {
    --primary: #ffc107;
    --primary-dark: #ffa000;
    --bg-dark: #1a1a1a;
    --panel-bg: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-color: #f5f5f5;
    --hp-color: #4caf50;
    --hp-warn: #ff9800;
    --hp-crit: #f44336;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* ダブルタップズームを無効化し、ピンチズームなどは許可する設定 */
    touch-action: manipulation; 
}

body {
    background: var(--bg-dark);
    color: var(--text-color);
    font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none; /* iOS Safari用 */
    -webkit-tap-highlight-color: transparent; /* タップ時の青い枠を消す */
}

/* HUD Styles */
.hud {
    display: flex;
    gap: 30px;
    margin-bottom: 20px;
    background: var(--panel-bg);
    padding: 15px 30px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
}

.coin-display {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--primary);
    font-size: 1.1rem;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255,193,7,0.3);
}

.coin-icon {
    font-size: 1.2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
}

/* HP Gauge */
.gauge-container {
    width: 120px;
    height: 8px;
    background: rgba(0,0,0,0.3);
    border-radius: 4px;
    overflow: hidden;
}

.stage-num {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
}

.gauge-fill {
    height: 100%;
    background: var(--hp-color);
    transition: width 0.3s ease, background 0.3s ease;
}

/* Progress Ring */
.progress-ring-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

#progressRing {
    fill: none;
    stroke: var(--primary);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 113.1; /* 2 * PI * 18 */
    stroke-dashoffset: 113.1;
    transition: stroke-dashoffset 0.5s ease;
    transform: rotate(-90deg);
    transform-origin: center;
}

.ring-bg {
    fill: none;
    stroke: rgba(255,255,255,0.1);
    stroke-width: 3;
}

#percentText {
    position: absolute;
    font-size: 0.8rem;
    font-weight: bold;
}

/* Canvas Layout */
.canvas-wrapper {
    position: relative;
}

.canvas-container {
    position: relative;
    width: 320px;
    height: 320px;
    border: 8px solid #333;
    border-radius: 4px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    background: #000;
}

.canvas-container.shake {
    animation: shake 0.1s ease-in-out infinite;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    touch-action: none;
}

/* Milestone Effect */
.milestone-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, transparent 70%);
    opacity: 0;
    z-index: 10;
}

.milestone-flash {
    animation: flash 1s ease-out forwards;
}

/* Controls */
.controls {
    margin-top: 30px;
    display: flex;
    gap: 15px;
}

button {
    padding: 12px 24px;
    background: var(--panel-bg);
    color: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
}

button:hover {
    background: rgba(255,255,255,0.1);
    transform: translateY(-2px);
}

button.active {
    background: var(--primary);
    color: #000;
    font-weight: bold;
    border-color: var(--primary);
    box-shadow: 0 4px 15px rgba(255, 193, 7, 0.4);
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.result-card {
    position: relative;
    background: #2a2a2a;
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    animation: slideUp 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.gem-name {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 5px;
    text-shadow: 0 0 10px rgba(255,255,255,0.2);
}

.rank-badge {
    position: absolute;
    top: -20px;
    right: -20px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    font-weight: 900;
    background: #444;
    border: 4px solid var(--bg-dark);
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    transform: rotate(15deg);
}

.rank-s { background: linear-gradient(135deg, #ffd700, #ff8c00); color: #000; }
.rank-a { background: linear-gradient(135deg, #e0e0e0, #9e9e9e); color: #000; }
.rank-b { background: linear-gradient(135deg, #cd7f32, #8d6e63); color: #000; }
.rank-c { background: #607d8b; color: #fff; }
.rank-d { background: #333; color: #999; }

.result-stats {
    display: flex;
    justify-content: space-around;
    margin: 25px 0;
    background: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 12px;
}

/* Shop Layout */
.shop-card {
    background: #2a2a2a;
    padding: 30px;
    border-radius: 20px;
    max-width: 450px;
    width: 90%;
    border: 1px solid var(--border-color);
}

.shop-items {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
}

.shop-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,255,255,0.05);
    padding: 15px 20px;
    border-radius: 12px;
}

.item-info {
    display: flex;
    flex-direction: column;
}

.item-name {
    font-weight: bold;
}

.item-level {
    font-size: 0.8rem;
    opacity: 0.6;
}

.upgrade-btn {
    background: var(--primary);
    color: #000;
    font-weight: 800;
    padding: 10px 20px;
}

#btnShopClose {
    width: 100%;
}

#btnRestart {
    width: 100%;
    justify-content: center;
    background: var(--primary);
    color: #000;
}

/* Animations */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    25% { transform: translate(-1px, -1px) rotate(-1deg); }
    50% { transform: translate(-1px, 1px) rotate(1deg); }
    75% { transform: translate(1px, -1px) rotate(0deg); }
    100% { transform: translate(1px, 1px) rotate(0deg); }
}

@keyframes flash {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
}
