/* ==========================================
   ひらめき錬金術｜色と形の脳トレ
   共通スタイルシート (style.css)
   ========================================== */

/* ------------------------------------------
   カラーパレット & デザインシステム定義
   ------------------------------------------ */
:root {
    /* 通常モードの配色 (アイボリー背景、ミント・琥珀・すみれを基調) */
    --bg-primary: #FAF9F6;          /* 淡いアイボリー */
    --bg-card: #FFFFFF;             /* 純白カード */
    --text-main: #3E3B30;           /* 深みのあるダークブラウン（コントラスト比の確保） */
    --text-muted: #706B5C;          /* 補助的な文字色 */
    
    /* アクセントカラー */
    --mint-bg: #E8F5E9;
    --mint-text: #2E7D32;
    --amber-bg: #FFF8E1;
    --amber-text: #E65100;
    --violet-bg: #F3E5F5;
    --violet-text: #7B1FA2;
    
    /* ボタン用カラー */
    --color-primary: #4CAF50;       /* ミントグリーン */
    --color-primary-hover: #45A049;
    --color-primary-text: #FFFFFF;
    
    --color-secondary: #E3F2FD;     /* 淡いブルー */
    --color-secondary-hover: #BBDEFB;
    --color-secondary-text: #1565C0;

    --color-danger: #FFEBEE;
    --color-danger-text: #C62828;

    /* 図形識別用カラー（通常モード） */
    --shape-red: #E53935;
    --shape-blue: #1E88E5;
    --shape-yellow: #FDD835;
    --shape-green: #43A047;

    /* シャドウと境界 */
    --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
    --button-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 8px;

    /* トランジション */
    --transition-speed: 0.3s;
}

/* 高コントラストモード用のカラー上書き */
body.high-contrast {
    --bg-primary: #000000;
    --bg-card: #121212;
    --text-main: #FFFFFF;
    --text-muted: #D3D3D3;

    --mint-bg: #002200;
    --mint-text: #00FF00;
    --amber-bg: #221100;
    --amber-text: #FF9900;
    --violet-bg: #220033;
    --violet-text: #FF66FF;

    --color-primary: #FFFF00;      /* 黄色（黒背景で最も視認性が高い） */
    --color-primary-hover: #CCCC00;
    --color-primary-text: #000000;

    --color-secondary: #00FFFF;    /* 水色 */
    --color-secondary-hover: #00CCCC;
    --color-secondary-text: #000000;

    --color-danger: #FF0000;
    --color-danger-text: #FFFFFF;

    /* 高コントラスト用のくっきりした図形色 */
    --shape-red: #FF3333;
    --shape-blue: #3399FF;
    --shape-yellow: #FFFF00;
    --shape-green: #33FF33;

    --card-shadow: 0 0 0 2px #FFFFFF;
    --button-shadow: none;
}

/* ------------------------------------------
   基本スタイル
   ------------------------------------------ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'M PLUS Rounded 1c', 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent; /* タップ時のハイライトを無効化 */
}

body {
    background-color: var(--bg-primary);
    color: var(--text-main);
    line-height: 1.6;
    transition: background-color var(--transition-speed), color var(--transition-speed);
    display: flex;
    justify-content: center;
    align-items: flex-start; /* 上寄せにして縦スクロール時に自然に見えるようにする */
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto; /* 縦スクロールを明示的に許可 */
}

/* アプリのコンテナ（最大幅720pxのスマホ・タブレット指向） */
.app-container {
    width: 100%;
    max-width: 600px;
    padding: 16px; /* 余白を少し小さくして1画面に収まりやすくする */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    min-height: 100vh;
}

/* 画面セクションの基本設定 */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    padding-bottom: 40px; /* 下部に見切れ防止の余白を設ける */
    animation: fadeIn 0.4s ease-out;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------
   共通UIコンポーネント (ボタンなど)
   ------------------------------------------ */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 64px; /* タップ領域 最低64px四方 */
    padding: 12px 24px;
    font-size: 20px;
    font-weight: 700;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    box-shadow: var(--button-shadow);
    transition: transform 0.1s ease, background-color var(--transition-speed), box-shadow var(--transition-speed);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-primary-text);
}

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--color-primary-hover);
    outline: 3px solid var(--text-main);
}

.btn-secondary {
    background-color: var(--color-secondary);
    color: var(--color-secondary-text);
}

.btn-secondary:hover, .btn-secondary:focus {
    background-color: var(--color-secondary-hover);
    outline: 3px solid var(--text-main);
}

.btn-text {
    background: transparent;
    color: var(--text-main);
    box-shadow: none;
    border: 2px dashed var(--text-muted);
}

.btn-text:hover, .btn-text:focus {
    background: rgba(0, 0, 0, 0.02);
    border-color: var(--text-main);
    outline: none;
}

.btn-text-danger {
    background: transparent;
    color: var(--color-danger-text);
    box-shadow: none;
    border: 2px dashed var(--color-danger-text);
}

.btn-danger {
    background-color: var(--color-danger);
    color: var(--color-danger-text);
    border: 1px solid var(--color-danger-text);
}

/* 設定画面のON/OFFトグルボタン */
.btn-toggle {
    min-width: 80px;
    min-height: 48px;
    border-radius: var(--border-radius-lg);
    border: 2px solid var(--text-main);
    background-color: var(--bg-card);
    color: var(--text-main);
    font-weight: 700;
    font-size: 18px;
    cursor: pointer;
}
.btn-toggle[aria-pressed="true"] {
    background-color: var(--color-primary);
    color: var(--color-primary-text);
}

/* ------------------------------------------
   1. タイトル画面
   ------------------------------------------ */
.game-title {
    text-align: center;
    margin-bottom: 24px;
}

.game-title .sub-title {
    display: block;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.2em;
    margin-bottom: 4px;
}

.game-title .main-title {
    display: block;
    font-size: 38px;
    font-weight: 700;
    color: var(--color-primary-text);
    background: linear-gradient(135deg, var(--mint-text) 0%, var(--violet-text) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
body.high-contrast .game-title .main-title {
    -webkit-text-fill-color: var(--text-main);
    background: none;
}

.game-concept {
    font-size: 18px;
    color: var(--text-muted);
    text-align: center;
    max-width: 420px;
    margin-bottom: 32px;
}

/* メニューボタン群 */
.menu-buttons {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ------------------------------------------
   フラスコと粒子のグラフィック
   ------------------------------------------ */
.flask-container {
    margin-bottom: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.flask {
    width: 100px;
    height: 120px;
    border: 6px solid var(--text-main);
    border-bottom-left-radius: 40px;
    border-bottom-right-radius: 40px;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    position: relative;
    overflow: hidden;
    background-color: rgba(255, 255, 255, 0.4);
}

.flask::before {
    content: '';
    position: absolute;
    top: 0;
    left: 35px;
    width: 18px;
    height: 15px;
    border-bottom: 6px solid var(--text-main);
}

.flask-liquid {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40%;
    background-color: var(--violet-text);
    opacity: 0.6;
    transition: height 0.5s ease;
}

/* タイトル画面のフラスコふわふわアニメーション */
.home-flask .flask {
    animation: floatFlask 3s ease-in-out infinite;
}

@keyframes floatFlask {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(2deg); }
}

/* 装飾的な浮遊粒子 */
.alchemy-deco {
    position: absolute;
    top: 10%;
    left: 0;
    width: 100%;
    height: 300px;
    pointer-events: none;
    z-index: -1;
}

.sparkle {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: var(--amber-text);
    border-radius: 50%;
    opacity: 0.6;
}

.particle-1 { top: 20%; left: 20%; animation: floatParticle 6s infinite; }
.particle-2 { top: 40%; right: 15%; animation: floatParticle 8s infinite 1s; }
.particle-3 { bottom: 10%; left: 40%; animation: floatParticle 7s infinite 2s; }

@keyframes floatParticle {
    0%, 100% { transform: translateY(0) scale(1); opacity: 0.3; }
    50% { transform: translateY(-20px) scale(1.3); opacity: 0.8; }
}

/* ------------------------------------------
   2. 遊び方画面
   ------------------------------------------ */
.screen-title-sub {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-main);
}

.howto-content {
    background-color: var(--bg-card);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    box-shadow: var(--card-shadow);
    max-width: 480px;
    width: 100%;
    margin-bottom: 24px;
}

.howto-desc {
    font-size: 18px;
    margin-bottom: 20px;
    text-align: center;
}

.howto-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.howto-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    border-left: 5px solid var(--text-muted);
    background-color: var(--bg-primary);
    border-radius: var(--border-radius-sm);
}

.howto-card p {
    font-size: 16px;
}

.instruction-badge {
    display: inline-block;
    padding: 4px 12px;
    font-size: 14px;
    font-weight: 700;
    border-radius: 12px;
    width: fit-content;
}

.color-inst { background-color: var(--mint-bg); color: var(--mint-text); }
.shape-inst { background-color: var(--amber-bg); color: var(--amber-text); }
.diff-color-inst { background-color: var(--violet-bg); color: var(--violet-text); }
.diff-shape-inst { background-color: #E3F2FD; color: #1565C0; }

.howto-tips {
    border-top: 1px solid rgba(0,0,0,0.1);
    padding-top: 16px;
    font-size: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ------------------------------------------
   3. ゲーム画面
   ------------------------------------------ */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin-bottom: 16px;
    background-color: var(--bg-card);
    padding: 12px 20px;
    border-radius: var(--border-radius-md);
    box-shadow: var(--card-shadow);
}

.header-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header-item .label {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 700;
}

.header-item .value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-main);
}

/* 円形タイマーのスタイル */
.timer-container-circle {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.timer-svg {
    width: 80px;
    height: 80px;
}

.timer-circle-bg {
    fill: none;
    stroke: rgba(0, 0, 0, 0.1);
    stroke-width: 6;
}

.timer-circle-progress {
    fill: none;
    stroke: var(--mint-text);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 213.6; /* 2 * PI * 34 */
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.1s linear, stroke var(--transition-speed);
}

/* タイマー色変化 */
.timer-circle-progress.timer-normal {
    stroke: var(--mint-text);
}
.timer-circle-progress.timer-warning {
    stroke: var(--amber-text);
}
.timer-circle-progress.timer-critical {
    stroke: var(--color-danger-text);
}

.timer-text-container {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
}

.timer-number-val {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
}

/* タイマー脈打ち（時間少） */
.timer-pulse {
    animation: gentlePulse 1s infinite ease-in-out;
}

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

/* アニメーション軽減用のクラス */
.reduced-motion .timer-pulse,
.reduced-motion .home-flask .flask,
.reduced-motion .sparkle,
.reduced-motion .light-particle,
.reduced-motion .absorb-animation {
    animation: none !important;
    transform: none !important;
    transition: none !important;
}

/* 難易度選択リスト */
.difficulty-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 480px;
}

.btn-diff-select {
    background-color: var(--bg-card);
    border: 3px solid var(--text-muted);
    color: var(--text-main);
    padding: 12px 16px;
    border-radius: var(--border-radius-md);
    box-shadow: var(--card-shadow);
    text-align: left;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    min-height: 80px;
    cursor: pointer;
    transition: border-color var(--transition-speed);
    box-shadow: var(--button-shadow);
}

.btn-diff-select:hover, .btn-diff-select:focus {
    border-color: var(--text-main);
    outline: none;
}

.diff-btn-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.diff-name {
    font-size: 20px;
    font-weight: 700;
}

.diff-desc {
    font-size: 14px;
    color: var(--text-muted);
}

.name-relax { color: var(--text-muted); }
.name-easy { color: var(--mint-text); }
.name-normal { color: #1565C0; }
.name-hard { color: var(--amber-text); }
.name-alchemist { color: var(--violet-text); }

/* 錬金術師の選択肢用非表示クラス */
.option-hidden {
    display: none !important;
}

/* ゲーム進行の指示 */
.instruction-container {
    width: 100%;
    text-align: center;
    margin-bottom: 16px;
}

.instruction-lead {
    font-size: 16px;
    color: var(--text-muted);
    font-weight: 700;
}

.instruction-text {
    font-size: 26px;
    font-weight: 700;
    display: inline-block;
    padding: 8px 24px;
    border-radius: var(--border-radius-lg);
    background-color: var(--bg-card);
    box-shadow: var(--card-shadow);
    border: 3px solid var(--text-main);
    margin-top: 4px;
}

/* 中央ステージ（お題とフラスコ） */
.center-stage {
    display: flex;
    width: 100%;
    max-width: 500px;
    gap: 16px;
    margin-bottom: 12px;
}

.stage-left, .stage-right {
    flex: 1;
    background-color: var(--bg-card);
    border-radius: var(--border-radius-md);
    box-shadow: var(--card-shadow);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.question-title {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 4px;
}

/* お題の表示エリア */
.target-shape-box {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
}

.flask-stage-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-flask {
    width: 70px;
    height: 85px;
}

/* 4つ〜6つの選択肢コンテナ */
.options-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 500px;
    margin-bottom: 12px;
}

/* 選択肢ボタン */
.option-btn {
    position: relative;
    min-height: 72px; /* タップ領域64px以上を担保しつつ縮小 */
    background-color: var(--bg-card);
    border: 3px solid var(--text-muted);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    box-shadow: var(--button-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: border-color var(--transition-speed), transform 0.1s ease;
    padding: 8px 12px;
}

.option-btn:hover, .option-btn:focus {
    border-color: var(--text-main);
    outline: none;
}

.option-btn:active {
    transform: scale(0.95);
}

.option-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

/* キーボードヒント表示 */
.key-hint {
    position: absolute;
    top: 6px;
    left: 8px;
    font-size: 12px;
    font-weight: 700;
    background-color: var(--text-muted);
    color: var(--bg-card);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
}

/* ------------------------------------------
   図形描画用 CSS (色と形)
   ------------------------------------------ */
.shape {
    width: 50px;
    height: 50px;
    display: inline-block;
    transition: background-color var(--transition-speed);
}

/* 形の定義 */
.shape-circle {
    border-radius: 50%;
}

.shape-square {
    /* 四角は標準の四角 */
}

.shape-triangle {
    width: 0;
    height: 0;
    border-left: 25px solid transparent;
    border-right: 25px solid transparent;
    border-bottom: 50px solid var(--text-main); /* JSでborderBottomColorを設定 */
    background-color: transparent !important;
}

.shape-star {
    /* クリッピングを使った星型 */
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

/* 色・形・テキストをサポートするためのラベル */
.shape-label {
    font-size: 14px;
    font-weight: 700;
    margin-top: 4px;
    color: var(--text-main);
}

/* ------------------------------------------
   正解・不正解などのフィードバック
   ------------------------------------------ */
.game-feedback {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    min-height: 36px;
    margin-bottom: 8px;
    width: 100%;
}

.feedback-correct {
    color: var(--mint-text);
}

.feedback-incorrect {
    color: var(--amber-text);
}

/* 粒子エミッター（演出用） */
.particles-emitter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    pointer-events: none;
}

/* 吸い込まれる演出のアニメーションクラス */
.absorb-animation {
    animation: absorbToFlask 0.4s ease-in forwards;
}

@keyframes absorbToFlask {
    0% {
        transform: scale(1) translate(0, 0);
        opacity: 1;
    }
    100% {
        transform: scale(0.2) translate(150px, -50px); /* 右のフラスコ方向へ吸い込まれる */
        opacity: 0;
    }
}

/* 上昇する光の粒子のスタイリング */
.light-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    animation: riseAndFade 0.8s ease-out forwards;
}

@keyframes riseAndFade {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--x, 0px), var(--y, -100px)) scale(0.5);
        opacity: 0;
    }
}

/* ------------------------------------------
   4. 結果画面
   ------------------------------------------ */
.result-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--color-primary-text);
    background: linear-gradient(135deg, var(--mint-text) 0%, var(--violet-text) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    text-align: center;
}
body.high-contrast .result-title {
    -webkit-text-fill-color: var(--text-main);
    background: none;
}

.result-subtitle {
    font-size: 18px;
    color: var(--text-muted);
    margin-bottom: 24px;
    text-align: center;
}

.result-card {
    background-color: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.result-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.primary-score {
    border-bottom: 2px dashed rgba(0,0,0,0.1);
    padding-bottom: 16px;
}

.primary-score .label {
    font-size: 18px;
    color: var(--text-muted);
    font-weight: 700;
}

.primary-score .value {
    font-size: 48px;
    font-weight: 700;
    color: var(--violet-text);
}
body.high-contrast .primary-score .value {
    color: var(--color-primary);
}

.result-grid {
    display: flex;
    justify-content: space-around;
    width: 100%;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-item .label {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 700;
}

.result-item .value-sub {
    font-size: 24px;
    font-weight: 700;
}

.result-best {
    background-color: var(--bg-primary);
    padding: 12px 24px;
    border-radius: var(--border-radius-md);
    text-align: center;
    font-size: 16px;
}

.result-best .value-best {
    font-weight: 700;
    color: var(--mint-text);
}

/* トースト通知 */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--text-main);
    color: var(--bg-primary);
    padding: 12px 24px;
    border-radius: var(--border-radius-lg);
    font-size: 16px;
    font-weight: 700;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 0.9;
}

/* ------------------------------------------
   5. 設定画面
   ------------------------------------------ */
.settings-list {
    background-color: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.setting-info {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.setting-label {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
}

.setting-desc {
    font-size: 14px;
    color: var(--text-muted);
}

/* ------------------------------------------
   ゲーム画面あきらめるエリア
   ------------------------------------------ */
.game-footer {
    margin-top: 16px;
    width: 100%;
    max-width: 320px;
}
