/* グローバルCSS変数 */
:root {
    --bg: #f5f7fa;  /* ページ背景：ページ全体のライトグレー背景 */
    --surface: #ffffff;  /* カード背景：白色のカード背景 */
    --surface-muted: #edf2f0;  /* サブ背景：ショートカットキーやタグなどの明るい背景用 */

    --text: #16201d;  /* メインテキスト：見出しや本文用 */
    --muted: #60706b;  /* サブテキスト：説明・補足情報・キャプション用 */

    --line: #d8e0dd;  /* ボーダー：カードや入力フォームの薄いグレーグリーン枠線 */

    --primary: #1d6f5f;  /* メインカラー：ページのメイングリーン */
    --primary-dark: #145245;  /* ダークメインカラー：強調テキストやボタンホバー状態用 */
    --accent: #b65f32;  /* アクセントカラー：見出し上のサブテキスト（アイブロウ）用ブラウンオレンジ */

    /* 角丸 */
    --radius-small: 6px;
    --radius-medium: 10px;

    /* シャドウ */
    --shadow-card: 0 10px 24px rgba(22, 32, 29, 0.06);
}

/* ページ全体 */
* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
    background: var(--bg);
}

body {
    margin: 0;

    color: var(--text);
    background: var(--bg);

    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

h1,
h2,
h3,
p,
dl,
dd {
    margin-top: 0;
}

h1 {
    margin-bottom: 20px;

    font-size: clamp(2.7rem, 7vw, 4.5rem);
    line-height: 1;
    letter-spacing: -0.04em;
}

h2 {
    margin-bottom: 0;

    font-size: 1.35rem;
    line-height: 1.3;
}

/* サブテキスト */
.eyebrow {
    margin-bottom: 10px;

    color: var(--accent);

    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ヘッダー部分紹介用文字 */
.lead {
    max-width: 680px;
    margin-bottom: 0;

    color: var(--muted);

    font-size: 1.05rem;
    line-height: 1.7;
}

/* ページ全体の幅を制御 */
.game-page {
    width: min(1180px, calc(100% - 48px));
    margin: 0 auto;
    padding: 64px 0 80px;
}

/* 
    ヘッダーエリアのレイアウト 
    上揃え・両端揃え
*/
.game-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 32px;

    margin-bottom: 36px;
}

/* 右上：対戦相手 カード */
.opponent-status {
    flex-shrink: 0;

    margin: 12px 0 0;
    padding: 12px 16px;

    color: var(--muted);
    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-small);

    box-shadow: var(--shadow-card);
}

/* 右上：対戦相手文字 */
.opponent-status strong {
    color: var(--primary-dark);
}

/* 二列設定 */
.game-layout {
    display: grid;

    grid-template-columns:
        minmax(0, 1fr)
        minmax(280px, 360px);

    gap: 24px;
    align-items: start;
}

/* 左列を縮小できるようにする */
.play-area {
    min-width: 0;
}

/* 右列を縦方向に配置 */
.side-panel {
    display: grid;
    gap: 16px;
}

/* タイトル距離設定 */
.section-heading {
    margin-bottom: 20px;
}

.section-heading .eyebrow {
    margin-bottom: 6px;
}

/* 3つの出拳ボタンを同じ幅で並べる選択グリッド */
.choice-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

/* 出拳ボタン本体と状態変化 */
.choice-button {
    display: grid;
    min-width: 0;
    min-height: 190px;
    place-items: center;
    align-content: center;
    gap: 8px;

    padding: 20px 14px;

    color: var(--text);
    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-medium);

    box-shadow: var(--shadow-card);

    text-align: center;

    /* アニメーション */
    transition:
        color 0.2s ease,
        background 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

/* Emojiサイズ */
.choice-emoji {
    display: block;

    font-size: 3.5rem;
    line-height: 1;

    transition: transform 0.2s ease;
}

/* 文字サイズ */
.choice-button strong {
    font-size: 1.1rem;
    line-height: 1.3;
}

/* 補足情報 */
.choice-description {
    color: var(--muted);

    font-size: 0.82rem;
    line-height: 1.5;
}

/* ホバー状態 */
.choice-button:hover {
    color: var(--primary-dark);
    background: #fbfdfc;

    border-color: var(--primary);

    box-shadow:
        0 14px 30px rgba(22, 32, 29, 0.1),
        0 0 0 3px rgba(29, 111, 95, 0.08);

    transform: translateY(-3px);
}

.choice-button:hover .choice-emoji {
    transform: scale(1.08);
}

/* 非活性状態 */
.choice-button:disabled {
    color: var(--muted);
    background: var(--surface-muted);

    border-color: var(--line);

    box-shadow: none;

    cursor: not-allowed;
    opacity: 0.65;

    transform: none;
}

/* プレイヤー・勝敗・CPUを並べる対戦結果グリッド */
.game-arena {
    display: grid;
    grid-template-columns:
        minmax(0, 1fr)
        minmax(0, 0.9fr)
        minmax(0, 1fr);

    gap: 14px;
    margin-top: 24px;
}

/* 対戦結果を表示する共通カード */
.arena-panel {
    display: grid;
    min-width: 0;
    min-height: 180px;
    place-items: center;
    align-content: center;
    gap: 10px;

    padding: 20px;

    color: var(--text);
    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-medium);

    box-shadow: var(--shadow-card);

    text-align: center;

    transition:
        color 0.25s ease,
        background 0.25s ease,
        border-color 0.25s ease,
        box-shadow 0.25s ease,
        transform 0.25s ease;
}

/* Emojiサイズ */
.arena-emoji {
    display: block;

    font-size: 3.2rem;
    line-height: 1;

    transition:
        transform 0.25s ease,
        opacity 0.25s ease;
}

/* 文字サイズ */
.arena-panel strong {
    font-size: 1rem;
    line-height: 1.4;
}


/* 結果表示 */
.result-panel {
    background: var(--surface-muted);
    border-style: dashed;
}

.result-panel.is-win {
    color: #145245;
    background: #e7f4ef;

    border-color: #75aa99;
    border-style: solid;

    box-shadow:
        0 12px 28px rgba(29, 111, 95, 0.12),
        0 0 0 3px rgba(29, 111, 95, 0.08);
}

.result-panel.is-lose {
    color: #7a3428;
    background: #f9e9e5;

    border-color: #ce9588;
    border-style: solid;

    box-shadow:
        0 12px 28px rgba(122, 52, 40, 0.1),
        0 0 0 3px rgba(182, 95, 50, 0.08);
}

.result-panel.is-draw {
    color: #67501f;
    background: #f7f1df;

    border-color: #c9b574;
    border-style: solid;

    box-shadow:
        0 12px 28px rgba(103, 80, 31, 0.1),
        0 0 0 3px rgba(201, 181, 116, 0.1);
}

/* 結果表示アニメーション */
.result-panel.is-updated {
    animation: result-pop 0.35s ease;
}

/* 結果表示アニメーション設定 */
@keyframes result-pop {
    0% {
        transform: scale(0.96);
        opacity: 0.7;
    }

    70% {
        transform: scale(1.03);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 選択表示アニメーション */
.arena-panel.is-revealed .arena-emoji {
    animation: choice-reveal 0.3s ease;
}

/* 選択表示アニメーション設定 */
@keyframes choice-reveal {
    0% {
        transform: rotate(-8deg) scale(0.8);
        opacity: 0;
    }

    70% {
        transform: rotate(3deg) scale(1.08);
        opacity: 1;
    }

    100% {
        transform: rotate(0) scale(1);
    }
}

/* 設定・統計をまとめる右側パネル */
.control-panel {
    padding: 20px;

    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-medium);

    box-shadow: var(--shadow-card);
}

.control-panel[hidden],
.prediction-panel[hidden] {
    display: none;
}

.control-panel .section-heading {
    margin-bottom: 16px;
}

.control-panel .section-heading h2 {
    font-size: 1.15rem;
}

.form-field {
    display: grid;
    gap: 8px;
}

.form-field > span {
    color: var(--text);

    font-size: 0.88rem;
    font-weight: 700;
}

.form-field select,
.form-field input {
    width: 100%;
    min-height: 44px;

    padding: 0 12px;
    margin: -8px 0 14px;

    color: var(--text);
    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-small);

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background 0.2s ease;
}

.form-field select:focus,
.form-field input:focus {
    border-color: var(--primary);
    outline: none;

    box-shadow:
        0 0 0 3px rgba(29, 111, 95, 0.15);
}

.form-field select:hover,
.form-field input:hover {
    border-color: var(--primary);
}

.form-field option {
    color: var(--text);
    background: var(--surface);
}

.model-description {
    margin: 14px 0 0;
    padding: 12px;

    color: var(--muted);
    background: var(--surface-muted);

    border-radius: var(--radius-small);

    font-size: 0.86rem;
    line-height: 1.65;
}

.learning-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    margin: 14px 0 0;
    padding-top: 14px;

    color: var(--muted);

    border-top: 1px solid var(--line);

    font-size: 0.88rem;
}

.learning-status strong {
    display: inline-grid;
    min-width: 38px;
    min-height: 30px;
    place-items: center;

    color: var(--primary-dark);
    background: var(--surface-muted);

    border: 1px solid var(--line);
    border-radius: var(--radius-small);

    font-size: 0.9rem;
}

/* 右側に表示する対戦成績カード */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat-grid article {
    display: grid;
    min-width: 0;
    min-height: 92px;
    align-content: center;
    gap: 6px;

    padding: 14px;

    background: var(--surface-muted);

    border: 1px solid var(--line);
    border-radius: var(--radius-small);

    transition:
        border-color 0.2s ease,
        background 0.2s ease,
        transform 0.2s ease;
}

.stat-grid span {
    color: var(--muted);

    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.4;
}

.stat-grid strong {
    color: var(--text);

    font-size: 1.65rem;
    line-height: 1;
    letter-spacing: -0.03em;
}

/* 勝利、連勝、総 */
#win-count,
#current-streak,
#best-streak {
    color: var(--primary-dark);
}

/* 失敗 */
#lose-count {
    color: #8d4032;
}

/* 引き分け */
#draw-count {
    color: #806522;
}

/* マウスホバー効果 */
.stat-grid article:hover {
    background: #f7faf9;
    border-color: rgba(29, 111, 95, 0.45);

    transform: translateY(-1px);
}

/* 数字更新アニメーション */
.stat-grid strong.is-updated {
    animation: score-pop 0.3s ease;
}

@keyframes score-pop {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    70% {
        transform: scale(1.18);
        opacity: 1;
    }

    100% {
        transform: scale(1);
    }
}

.stat-grid span,
.stat-grid strong {
    overflow-wrap: anywhere;
}

.secondary-button,
.danger-button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;

    padding: 0 16px;

    border: 1px solid;
    border-radius: var(--radius-small);

    font-weight: 700;
    line-height: 1.3;
    text-align: center;

    cursor: pointer;

    transition:
        color 0.2s ease,
        background 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

.secondary-button {
    color: var(--primary-dark);
    background: var(--surface);

    border-color: var(--primary);
}

.secondary-button:hover {
    color: #ffffff;
    background: var(--primary-dark);

    border-color: var(--primary-dark);

    box-shadow:
        0 8px 18px rgba(29, 111, 95, 0.16);

    transform: translateY(-1px);
}

.danger-button {
    color: #8d4032;
    background: #fffaf8;

    border-color: #c98f82;
}

.danger-button:hover {
    color: #ffffff;
    background: #8d4032;

    border-color: #8d4032;

    box-shadow:
        0 8px 18px rgba(141, 64, 50, 0.16);

    transform: translateY(-1px);
}

.secondary-button:active,
.danger-button:active {
    transform: translateY(0);
}

.secondary-button:focus-visible,
.danger-button:focus-visible {
    outline: 3px solid rgba(29, 111, 95, 0.22);
    outline-offset: 3px;
}

.danger-button:focus-visible {
    outline-color: rgba(141, 64, 50, 0.22);
}

.full-button {
    width: 100%;
}

.reset-actions {
    display: grid;
    gap: 10px;
}

.control-description {
    margin: 12px 0 0;

    color: var(--muted);

    font-size: 0.82rem;
    line-height: 1.6;
}

.operation-message {
    min-height: 0;
    margin: 0;

    font-size: 0.82rem;
    line-height: 1.55;
}

.operation-message.is-success {
    margin-top: 12px;
    padding: 10px 12px;

    color: var(--primary-dark);
    background: #e7f4ef;

    border: 1px solid #9bc4b7;
    border-radius: var(--radius-small);
}

.operation-message.is-error {
    margin-top: 12px;
    padding: 10px 12px;

    color: #7a3428;
    background: #f9e9e5;

    border: 1px solid #ce9588;
    border-radius: var(--radius-small);
}

.operation-message.is-info {
    margin-top: 12px;
    padding: 10px 12px;

    color: #67501f;
    background: #f7f1df;

    border: 1px solid #c9b574;
    border-radius: var(--radius-small);
}

.secondary-button:disabled,
.danger-button:disabled {
    color: var(--muted);
    background: var(--surface-muted);

    border-color: var(--line);

    box-shadow: none;

    cursor: not-allowed;
    opacity: 0.65;

    transform: none;
}

.import-panel {
    position: relative;
    overflow: hidden;
}

.import-panel::before {
    content: "";

    position: absolute;
    top: 0;
    right: 0;
    left: 0;

    height: 3px;

    background: var(--primary);
}

/* ページ下部に表示する直近の対戦履歴 */
.history-section {
    margin-top: 32px;
    padding: 24px;

    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-medium);

    box-shadow: var(--shadow-card);
}

/* 記録縦表示 */
.history-list {
    display: grid;
    gap: 10px;
}

/* 記録なし */
.empty-message {
    margin: 0;
    padding: 28px 20px;

    color: var(--muted);
    background: var(--surface-muted);

    border: 1px dashed var(--line);
    border-radius: var(--radius-small);

    font-size: 0.9rem;
    line-height: 1.6;
    text-align: center;
}

/* 記録 */
.history-item {
    display: grid;
    grid-template-columns:
        minmax(100px, 0.7fr)
        minmax(0, 2fr)
        auto;

    align-items: center;
    gap: 16px;

    padding: 14px 16px;

    background: var(--surface-muted);

    border: 1px solid var(--line);
    border-radius: var(--radius-small);

    transition:
        background 0.2s ease,
        border-color 0.2s ease;
}

.history-round {
    display: grid;
    gap: 3px;
}

.history-round span {
    color: var(--text);

    font-size: 0.86rem;
    font-weight: 700;
}

.history-round time {
    color: var(--muted);

    font-size: 0.75rem;
}

.history-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.history-choices span {
    display: inline-flex;
    min-height: 32px;
    align-items: center;

    padding: 0 10px;

    color: var(--muted);
    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-small);

    font-size: 0.82rem;
    font-weight: 700;
}

.history-result {
    display: inline-flex;
    min-width: 58px;
    min-height: 32px;
    align-items: center;
    justify-content: center;

    padding: 0 10px;

    border: 1px solid;
    border-radius: var(--radius-small);

    font-size: 0.8rem;
    font-weight: 800;
}

.history-result.is-win {
    color: var(--primary-dark);
    background: #e7f4ef;

    border-color: #9bc4b7;
}

.history-result.is-lose {
    color: #7a3428;
    background: #f9e9e5;

    border-color: #ce9588;
}

.history-result.is-draw {
    color: #67501f;
    background: #f7f1df;

    border-color: #c9b574;
}

.history-item:hover {
    background: #f7faf9;
    border-color: rgba(29, 111, 95, 0.4);
}

.history-item.is-new {
    animation: history-enter 0.35s ease;
}

.prediction-panel {
    margin-top: 24px;
    padding: 20px;

    background: var(--surface);

    border: 1px solid var(--line);
    border-radius: var(--radius-medium);

    box-shadow: var(--shadow-card);
}

#prediction-description {
    margin-bottom: 16px;

    color: var(--muted);

    font-size: 0.88rem;
    line-height: 1.65;
}

.probability-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;

    margin-bottom: 0;
}

.probability-list > div {
    display: grid;
    min-width: 0;
    min-height: 96px;
    align-content: center;
    gap: 8px;

    padding: 14px;

    background: var(--surface-muted);

    border: 1px solid var(--line);
    border-radius: var(--radius-small);

    text-align: center;
}

.probability-list dt {
    color: var(--muted);

    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.4;
}

.probability-list dd {
    margin: 0;

    color: var(--primary-dark);

    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.03em;
}

#rock-probability {
    color: #59636d;
}

#scissors-probability {
    color: #8d4032;
}

#paper-probability {
    color: var(--primary-dark);
}

.probability-list > div.is-highest {
    background: #e7f4ef;

    border-color: var(--primary);

    box-shadow:
        0 0 0 3px rgba(29, 111, 95, 0.08);
}

.probability-list dd.is-updated {
    animation: probability-pop 0.3s ease;
}

@keyframes probability-pop {
    0% {
        transform: scale(0.85);
        opacity: 0.5;
    }

    70% {
        transform: scale(1.12);
        opacity: 1;
    }

    100% {
        transform: scale(1);
    }
}

.prediction-panel.is-visible {
    animation: prediction-enter 0.3s ease;
}

@keyframes prediction-enter {
    0% {
        transform: translateY(-6px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes history-enter {
    0% {
        transform: translateY(-8px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}



/* タブレット幅ではゲーム領域と設定領域を1列に変更 */
@media (max-width: 900px) {
    .game-header {
        display: grid;
    }

    .opponent-status {
        width: fit-content;
        margin-top: 0;
    }

    .game-layout {
        grid-template-columns: 1fr;
    }
}

/* スマートフォン幅では出拳・結果カードも1列に変更 */
@media (max-width: 620px) {
    .game-page {
        width: calc(100% - 28px);
        padding: 42px 0 60px;
    }

    .game-header {
        margin-bottom: 28px;
    }

    .choice-grid {
        grid-template-columns: 1fr;
    }

    .choice-button {
        min-height: 150px;
    }

    .game-arena {
        grid-template-columns: 1fr;
    }

    .arena-panel {
        min-height: 150px;
    }

    .result-panel {
        order: -1;
    }

    .stat-grid article {
        min-height: 86px;
        padding: 12px;
    }

    .stat-grid strong {
        font-size: 1.45rem;
    }

    .history-section {
        padding: 18px;
    }

    .history-item {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .history-result {
        width: fit-content;
    }
    
    .prediction-panel {
        padding: 18px;
    }

    .probability-list {
        grid-template-columns: 1fr;
    }

    .probability-list > div {
        min-height: 82px;
    }
}

/* OSで「視差効果を減らす」が有効な場合は、動きの大きい演出を抑えます。 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
