/* -------------------------------------------------------------
       デザインシステム & ベーススタイル
       ------------------------------------------------------------- */
    :root {
      --bg-lab: radial-gradient(circle, #e0f2fe 0%, #bae6fd 100%);
      --bg-home: radial-gradient(circle, #fef3c7 0%, #fde68a 100%);
      --bg-space: radial-gradient(circle, #1e1b4b 0%, #311042 100%);
      --bg-magic: radial-gradient(circle, #fae8ff 0%, #f5d0fe 100%);
      
      --font-rounded: 'Outfit', 'Kosugi Maru', 'Hiragino Kaku Gothic ProN', sans-serif;
    }

    * {
      box-sizing: border-box;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
    }

    body {
      margin: 0;
      padding: 0;
      width: 100vw;
      height: 100dvh;
      overflow: hidden;
      font-family: var(--font-rounded);
      background-color: #bae6fd;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    /* 基準解像度 (Galaxy S25 Ultra 412x790) にFITさせるための大枠 */
    #app-container {
      width: 100%;
      max-width: 412px;
      height: 100%;
      max-height: 790px;
      position: relative;
      background: var(--bg-lab);
      overflow: hidden;
      display: flex;
      flex-direction: column;
      box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
      transition: background 0.5s ease;
    }

    /* -------------------------------------------------------------
       ユーティリティ & タイポグラフィ
       ------------------------------------------------------------- */
    .screen {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
      padding: 16px;
    }

    .screen.active {
      opacity: 1;
      pointer-events: auto;
      z-index: 10;
    }

    h1, h2, h3 {
      margin: 0;
      text-align: center;
      color: #0369a1;
      text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
    }

    h1 { font-size: 32px; font-weight: 900; }
    h2 { font-size: 24px; }

    .btn {
      background: #38bdf8;
      color: white;
      border: 3px solid #0284c7;
      border-radius: 20px;
      padding: 10px 20px;
      font-size: 20px;
      font-weight: bold;
      cursor: pointer;
      box-shadow: 0 4px 0 #0284c7;
      transition: all 0.1s ease;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }

    .btn:active {
      transform: translateY(4px);
      box-shadow: none;
    }

    .btn-orange {
      background: #fb923c;
      border-color: #ea580c;
      box-shadow: 0 4px 0 #ea580c;
    }

    .btn-pink {
      background: #f472b6;
      border-color: #db2777;
      box-shadow: 0 4px 0 #db2777;
    }

    .btn-green {
      background: #4ade80;
      border-color: #16a34a;
      box-shadow: 0 4px 0 #16a34a;
    }

    .btn-icon {
      width: 48px;
      height: 48px;
      min-width: 48px;
      padding: 0;
      border-radius: 50%;
    }
    #hud-bgm-btn:active, #hud-se-btn:active {
      transform: scale(0.9);
    }

    /* -------------------------------------------------------------
       ヘッダー (スコア、コイン、音量など)
       ------------------------------------------------------------- */
    .top-bar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      margin-bottom: 8px;
      z-index: 20;
    }

    .hud-item {
      background: rgba(255, 255, 255, 0.85);
      border: 2px solid #bae6fd;
      border-radius: 15px;
      padding: 4px 12px;
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 16px;
      font-weight: bold;
      color: #0369a1;
    }

    .hud-coin {
      color: #b45309;
      border-color: #fde68a;
    }

    /* -------------------------------------------------------------
       タイトル画面
       ------------------------------------------------------------- */
    #title-screen {
      justify-content: space-around;
      align-items: center;
    }

    .logo-container {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 12px;
    }

    .logo-badge {
      font-size: 64px;
      animation: bounce 2s infinite ease-in-out;
    }

    .title-buttons {
      display: flex;
      flex-direction: column;
      gap: 16px;
      width: 80%;
    }

    /* -------------------------------------------------------------
       ゲーム画面 layout
       ------------------------------------------------------------- */
    #game-screen {
      justify-content: space-between;
      align-items: center;
      padding-bottom: 8px;
    }

    /* おだい（目標色カード） */
    .target-card {
      width: 90%;
      background: white;
      border: 4px solid #bae6fd;
      border-radius: 24px;
      padding: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      box-shadow: 0 8px 16px rgba(0,0,0,0.05);
      position: relative;
    }

    .target-color-box {
      width: 100%;
      height: 48px;
      border-radius: 16px;
      border: 3px solid #cbd5e1;
      display: flex;
      justify-content: center;
      align-items: center;
      color: white;
      font-weight: bold;
      text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
      font-size: 18px;
    }

    .target-label {
      font-size: 14px;
      color: #64748b;
      margin-top: 4px;
      font-weight: bold;
    }

    /* 実験室の中央：ビーカーとしずく */
    .lab-stage {
      flex: 1;
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
    }

    #lab-canvas {
      width: 100%;
      height: 100%;
      max-height: 320px;
      background: transparent;
    }

    /* できた！／やりなおし等のアクションボタン */
    .action-row {
      display: flex;
      gap: 16px;
      width: 90%;
      justify-content: center;
      margin-bottom: 8px;
    }

    /* ボトル選択エリア */
    .bottles-container {
      width: 100%;
      background: rgba(255, 255, 255, 0.8);
      border: 3px solid #bae6fd;
      border-radius: 20px;
      padding: 8px;
      display: flex;
      justify-content: space-around;
      align-items: flex-end;
    }

    .bottle {
      display: flex;
      flex-direction: column;
      align-items: center;
      cursor: pointer;
      transition: transform 0.1s ease;
      position: relative;
    }

    .bottle:active {
      transform: scale(0.9) translateY(-6px);
    }

    .bottle-cap {
      width: 12px;
      height: 8px;
      background: #64748b;
      border-radius: 4px;
    }

    .bottle-neck {
      width: 8px;
      height: 12px;
      background: #94a3b8;
    }

    .bottle-body {
      width: 38px;
      height: 48px;
      border: 2px solid #475569;
      border-radius: 6px 6px 12px 12px;
      position: relative;
      overflow: hidden;
      box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    }

    .bottle-liquid {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 70%;
      opacity: 0.85;
    }

    .bottle-label {
      font-size: 11px;
      font-weight: bold;
      color: #334155;
      margin-top: 4px;
    }

    /* ボトルごとのカラー設定 */
    .bottle-red .bottle-liquid { background: #ef4444; }
    .bottle-yellow .bottle-liquid { background: #facc15; }
    .bottle-blue .bottle-liquid { background: #3b82f6; }
    .bottle-white .bottle-liquid { background: #ffffff; border-top: 1px solid #cbd5e1; }
    .bottle-black .bottle-liquid { background: #1e293b; }

    /* -------------------------------------------------------------
       ショップ画面
       ------------------------------------------------------------- */
    .shop-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 12px;
    }

    .shop-tabs {
      display: flex;
      justify-content: space-around;
      background: rgba(255, 255, 255, 0.6);
      border-radius: 12px;
      padding: 4px;
      margin-bottom: 8px;
    }

    .shop-tab {
      flex: 1;
      padding: 6px;
      font-size: 14px;
      font-weight: bold;
      border: none;
      background: transparent;
      color: #64748b;
      cursor: pointer;
      text-align: center;
      border-radius: 8px;
    }

    .shop-tab.active {
      background: white;
      color: #0369a1;
      box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

    .shop-grid {
      flex: 1;
      overflow-y: auto;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 12px;
      padding-right: 4px;
    }

    .shop-item {
      background: white;
      border: 3px solid #e2e8f0;
      border-radius: 16px;
      padding: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
      cursor: pointer;
      transition: all 0.2s ease;
    }

    .shop-item.equipped {
      border-color: #4ade80;
      background: #f0fdf4;
    }

    .shop-item.owned {
      border-color: #38bdf8;
    }

    .item-preview {
      width: 60px;
      height: 60px;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 32px;
      position: relative;
    }

    .item-name {
      font-size: 12px;
      font-weight: bold;
      color: #334155;
      text-align: center;
    }

    .item-btn {
      width: 100%;
      min-height: 48px;
      padding: 4px;
      font-size: 11px;
      font-weight: bold;
      border-radius: 12px;
      border: none;
      background: #f1f5f9;
      color: #475569;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      gap: 4px;
    }

    .shop-item.owned .item-btn {
      background: #bae6fd;
      color: #0369a1;
    }

    .shop-item.equipped .item-btn {
      background: #22c55e;
      color: white;
    }

    /* -------------------------------------------------------------
       ポップアップ / オーバーレイ (できた！の判定結果)
       ------------------------------------------------------------- */
    .result-overlay {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,0.4);
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 50;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
    }

    .result-overlay.active {
      opacity: 1;
      pointer-events: auto;
    }

    .result-card {
      width: 80%;
      background: white;
      border: 6px solid #38bdf8;
      border-radius: 32px;
      padding: 24px 16px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 16px;
      transform: scale(0.8);
      transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
      box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    }

    .result-overlay.active .result-card {
      transform: scale(1);
    }

    .result-badge {
      font-size: 54px;
      margin-bottom: -10px;
    }

    .result-title {
      font-size: 32px;
      font-weight: 900;
      text-align: center;
    }

    .result-text {
      font-size: 16px;
      font-weight: bold;
      color: #475569;
      text-align: center;
      line-height: 1.4;
    }

    /* -------------------------------------------------------------
       アニメーション
       ------------------------------------------------------------- */
    @keyframes bounce {
      0%, 100% { transform: translateY(0); }
      50% { transform: translateY(-10px); }
    }

    /* 背景デコレーション用のパーティクル */
    .bg-particle {
      position: absolute;
      border-radius: 50%;
      background: rgba(255,255,255,0.4);
      pointer-events: none;
      animation: floatUp 8s infinite linear;
    }

    @keyframes floatUp {
      0% { transform: translateY(800px) scale(0.8); opacity: 0; }
      10% { opacity: 0.6; }
      90% { opacity: 0.6; }
      100% { transform: translateY(-100px) scale(1.2); opacity: 0; }
    }
    .star-particle {
      position: absolute;
      font-size: 32px;
      pointer-events: none;
      z-index: 100;
      animation: starBurst 1s ease-out forwards;
    }
    @keyframes starBurst {
      0% { transform: translate(-50%, -50%) scale(0) rotate(0deg); opacity: 1; }
      50% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2) rotate(180deg); opacity: 1; }
      100% { transform: translate(calc(-50% + var(--dx) * 1.5), calc(-50% + var(--dy) * 1.5)) scale(0) rotate(360deg); opacity: 0; }
    }