/* ===================================
   CSS変数（ここでフォントサイズ一括管理）
   =================================== */
:root {
    /* フォントサイズ - baseを変えると全体が変わる */
    --font-size-base: 9px;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.85rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.1rem;
    --font-size-xl: 1.2rem;
    --font-size-h1: 1.8rem;
    --font-size-h2: 1.1rem;

    /* カラー */
    --color-bg: #0a0a0a;
    --color-bg-card: #1a1a1a;
    --color-bg-card-dark: #0d0d0d;
    --color-text: #ffffff;
    --color-text-muted: #888;
    --color-text-sub: #aaa;
    --color-border: #333;
    --color-accent: #4ecdc4;
    --color-danger: #ff6b6b;
}

/* ===================================
   リセット・ベース
   =================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', sans-serif;
    font-size: var(--font-size-base);
    background-color: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ===================================
   ヘッダー
   =================================== */
header {
    text-align: center;
    padding: 40px 0;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 40px;
}

header h1 {
    font-size: var(--font-size-h1);
    margin-bottom: 10px;
    letter-spacing: 2px;
}

.subtitle {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* ===================================
   機種カードグリッド（トップページ）
   =================================== */
.machine-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.machine-card {
    display: flex;
    align-items: center;
    background: linear-gradient(145deg, var(--color-bg-card), var(--color-bg-card-dark));
    border: 1px solid var(--color-border);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: var(--color-text);
    transition: all 0.3s ease;
}

.machine-card:hover {
    border-color: #666;
    transform: translateX(8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.machine-image {
    width: 120px;
    height: 80px;
    flex-shrink: 0;
    overflow: hidden;
    background-color: var(--color-bg-card);
}

.machine-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.machine-card:hover .machine-image img {
    transform: scale(1.1);
}

.machine-info {
    padding: 16px 20px;
    flex: 1;
}

.machine-name {
    font-size: var(--font-size-lg);
    font-weight: bold;
    margin-bottom: 4px;
}

.machine-maker {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* ===================================
   戻るリンク
   =================================== */
.back-link {
    margin-bottom: 20px;
}

.back-link a {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: var(--font-size-sm);
    transition: color 0.3s ease;
}

.back-link a:hover {
    color: var(--color-text);
}

/* ===================================
   情報カード（詳細ページ）
   =================================== */
.info-card {
    background: linear-gradient(145deg, var(--color-bg-card), var(--color-bg-card-dark));
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
}

.info-card h2 {
    font-size: var(--font-size-h2);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
}

.info-card h3 {
    font-size: var(--font-size-sm);
    color: var(--color-text-sub);
    margin-bottom: 8px;
}

.info-content {
    padding: 0 8px;
}

/* ===================================
   ハイライトテキスト
   =================================== */
.highlight {
    font-size: var(--font-size-xl);
    font-weight: bold;
    color: var(--color-accent);
    margin-bottom: 8px;
}

.highlight.confirm {
    color: var(--color-danger);
}

/* ===================================
   注釈
   =================================== */
.note {
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

/* ===================================
   比率ボックス
   =================================== */
.ratio-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ratio-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: var(--color-bg);
    border-radius: 8px;
}

.ratio-row .label {
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.ratio-row .value {
    font-size: var(--font-size-md);
    font-weight: bold;
    color: var(--color-accent);
}

/* ===================================
   フッター
   =================================== */
footer {
    text-align: center;
    padding: 40px 0;
    margin-top: 60px;
    border-top: 1px solid var(--color-border);
    color: #666;
    font-size: var(--font-size-xs);
}

/* ===================================
   テーブル
   =================================== */
.setting-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.setting-table th,
.setting-table td {
    padding: 12px 16px;
    text-align: center;
    border-bottom: 1px solid var(--color-border);
}

.setting-table th {
    background-color: var(--color-bg-card);
    color: var(--color-text-sub);
    font-weight: bold;
    font-size: var(--font-size-xs);
}

.setting-table td {
    background-color: var(--color-bg);
}

.setting-table tr:last-child td {
    border-bottom: none;
}

.setting-table tr:hover td {
    background-color: var(--color-bg-card);
}

.setting-table td:first-child {
    font-weight: bold;
    color: var(--color-text-sub);
}

/* ===================================
   設定判別画像
   =================================== */
.setting-image {
    width: 100%;
    margin-top: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.setting-image img {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.setting-image img:hover {
    opacity: 0.8;
}

/* ===================================
   画像モーダル（タップで拡大）
   =================================== */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.image-modal.active {
    display: flex;
}

.image-modal img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.modal-close {
    position: fixed;
    top: 20px;
    right: 20px;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    z-index: 1001;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.modal-hint {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

/* ===================================
   参考文献
   =================================== */
.references {
    margin-top: 40px;
    padding: 20px;
    background-color: var(--color-bg-card-dark);
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.references h3 {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.references ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.references li {
    font-size: var(--font-size-xs);
}

.references a {
    color: var(--color-accent);
    text-decoration: none;
    word-break: break-all;
}

.references a:hover {
    text-decoration: underline;
}

/* ===================================
   レスポンシブ
   =================================== */
@media (max-width: 600px) {
    header h1 {
        font-size: 1.5rem;
    }

    .machine-grid {
        grid-template-columns: 1fr;
    }

    .machine-image {
        width: 100px;
        height: 70px;
    }

    .machine-info {
        padding: 12px 16px;
    }

    .machine-name {
        font-size: var(--font-size-md);
    }

    /* PC用タイトル（デフォルト非表示） */
    .machine-header-title {
        display: none;
        font-size: var(--font-size-h1);
        letter-spacing: 2px;
        color: var(--color-text);
        padding: 20px 0;
    }

    .info-card {
        padding: 14px 12px;
    }

    .highlight {
        font-size: var(--font-size-lg);
    }

    .ratio-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .ratio-row .value {
        font-size: var(--font-size-sm);
    }

    .setting-table th,
    .setting-table td {
        padding: 10px 8px;
        font-size: var(--font-size-xs);
    }
}

@media (min-width: 769px) {
    .machine-header-image {
        display: none;
    }
    .machine-header-title {
        display: block;
    }
}


/* ===================================
   機種別ページヘッダー
   =================================== */
.machine-header {
    text-align: center;
    padding: 10px 0;
    border-bottom: none;
    margin-bottom: 0px;
}

.machine-header .back-link {
    margin-bottom: 16px;
}

.machine-header-image {
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    margin-bottom: 16px;
    overflow: hidden;
}

.machine-header-image img {
    width: 100%;
    height: auto;
    display: block;
}

.machine-header .subtitle {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* ===================================
   計算機ポップアップ
   =================================== */
.calc-button {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 20px;
    background-color: var(--color-accent);
    color: var(--color-bg);
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-sm);
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.calc-button:hover {
    opacity: 0.8;
}

.calc-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.calc-modal.active {
    display: flex;
}

.calc-content {
    background: linear-gradient(145deg, var(--color-bg-card), var(--color-bg-card-dark));
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
}

.calc-content h3 {
    font-size: var(--font-size-lg);
    margin-bottom: 20px;
    text-align: center;
    color: var(--color-text);
}

.calc-input-group {
    margin-bottom: 16px;
}

.calc-input-group label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    margin-bottom: 6px;
}

.calc-input-group input {
    width: 100%;
    padding: 12px;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text);
    font-size: var(--font-size-md);
}

.calc-input-group input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.calc-submit {
    width: 100%;
    padding: 14px;
    background-color: var(--color-accent);
    color: var(--color-bg);
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-md);
    font-weight: bold;
    cursor: pointer;
    margin-top: 8px;
    transition: opacity 0.2s ease;
}

.calc-submit:hover {
    opacity: 0.8;
}

.calc-result {
    margin-top: 20px;
    padding: 16px;
    background-color: var(--color-bg);
    border-radius: 8px;
    text-align: center;
    display: none;
}

.calc-result.show {
    display: block;
}

.calc-result-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.calc-result-value {
    font-size: var(--font-size-h1);
    font-weight: bold;
    color: var(--color-accent);
}

.calc-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    z-index: 1001;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.calc-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* ===================================
   計算機ステップ表示
   =================================== */
.calc-step {
    display: none;
}

.calc-step.active {
    display: block;
}

.calc-nav {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.calc-nav button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-sm);
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.calc-nav button:hover {
    opacity: 0.8;
}

.calc-next {
    background-color: var(--color-accent);
    color: var(--color-bg);
}

.calc-back {
    background-color: var(--color-border);
    color: var(--color-text);
}

.calc-result-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.calc-result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: var(--color-bg);
    border-radius: 8px;
}

.calc-result-row .label {
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.calc-result-row .value {
    font-size: var(--font-size-md);
    font-weight: bold;
    color: var(--color-accent);
}

/* ===================================
   パスワード認証モーダル
   =================================== */
#authModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-bg);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.auth-wrapper {
    width: 100%;
    max-width: 500px;
    padding: 20px;
}

.auth-header {
    text-align: center;
    margin-bottom: 40px;
}

.auth-header h1 {
    font-size: var(--font-size-h1);
    color: var(--color-text);
    letter-spacing: 2px;
}

.auth-content {
    background: linear-gradient(145deg, var(--color-bg-card), var(--color-bg-card-dark));
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
}

.auth-content h2 {
    font-size: var(--font-size-md);
    margin-bottom: 24px;
    color: var(--color-text-muted);
    font-weight: normal;
}

.auth-content input {
    width: 100%;
    padding: 14px;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text);
    font-size: var(--font-size-md);
    text-align: center;
    margin-bottom: 16px;
}

.auth-content input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.auth-content button {
    width: 100%;
    padding: 14px;
    background-color: var(--color-accent);
    color: var(--color-bg);
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-md);
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.auth-content button:hover {
    opacity: 0.8;
}

.auth-error {
    margin-top: 16px;
    color: var(--color-danger);
    font-size: var(--font-size-sm);
    min-height: 20px;
}

/* ===================================
   フローチャート（ブランチツリー）
   =================================== */
.fc-tree {
    padding: 4px 0;
    position: relative;
}

/* --- ボックス共通 --- */
.fc-box {
    border-radius: 8px;
    padding: 10px 14px;
    font-size: var(--font-size-sm);
    font-weight: 700;
    text-align: center;
    line-height: 1.6;
}

.fc-box--start {
    background: var(--color-accent);
    color: var(--color-bg);
}

.fc-box--default {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.fc-box--action {
    background: #1a3a4a;
    color: var(--color-accent);
    border: 1px solid rgba(78, 205, 196, 0.3);
}

.fc-box--hit {
    background: linear-gradient(135deg, #1a4a3a, #0e3a2a);
    color: #6ef5b0;
    border: 1px solid #2a6a4a;
}

.fc-box--go {
    background: linear-gradient(135deg, #12382c, #0a2a20);
    color: var(--color-accent);
    border: 1px solid #1e5040;
}

.fc-box--stop {
    background: linear-gradient(135deg, #4a1414, #2e0a0a);
    color: var(--color-danger);
    border: 1px solid #6a2222;
}

.fc-box--caution {
    background: linear-gradient(135deg, #3e3010, #2e2208);
    color: #ffd666;
    border: 1px solid #5a4818;
}

/* --- ブランチ（ul） --- */
.fc-branch {
    list-style: none;
    margin: 0;
    padding: 0 0 0 16px;
    position: relative;
}

/* ★ 変更: 縦線を最後のアイテムの手前で止める */
.fc-branch::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    width: 2px;
    background: var(--color-border);
    /* bottom ではなく、最後のアイテムの横枝位置まで */
}

/* JSで高さを制御しない代替策：
   最後の子の位置までだけ伸ばす */
.fc-branch {
    --fc-line-extend: 0px;
}

/* --- アイテム（li） --- */
.fc-item {
    position: relative;
    padding: 8px 0 4px 18px;
}

/* 横枝線（├── の横棒部分） */
.fc-item::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 22px;
    width: 18px;
    height: 2px;
    background: var(--color-border);
}

/* ★ 変更: 最後のアイテムの隠し要素を完全削除 */
.fc-item:last-child::after {
    content: none;
}

/* --- 分岐ラベル（条件表示） --- */
.fc-label {
    display: inline-block;
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: var(--color-accent);
    margin-bottom: 6px;
    padding: 2px 0;
    position: relative;
}

.fc-label::before {
    content: none;
}

/* --- 同一ルート内の縦接続線 --- */
.fc-connector {
    width: 2px;
    height: 16px;
    background: var(--color-border);
    margin: 2px 0 2px 20px;
    position: relative;
}

.fc-connector::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: -3px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--color-border);
}

/* --- ノート --- */
.fc-note {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

/* --- 補足セクション --- */
.fc-supplement {
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px dashed var(--color-border);
}

.fc-supplement-title {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.fc-supplement-item {
    border-radius: 6px;
    padding: 10px 12px;
    font-size: var(--font-size-xs);
    line-height: 1.7;
    margin-bottom: 6px;
}

.fc-supplement-item p {
    margin: 0;
}

.fc-supplement-item--info {
    background: rgba(78, 205, 196, 0.06);
    border-left: 3px solid var(--color-accent);
    color: var(--color-text);
}

.fc-supplement-item--warn {
    background: rgba(255, 107, 107, 0.06);
    border-left: 3px solid var(--color-danger);
    color: var(--color-text);
}

/* --- ループバック（戻り参照）ボックス --- */
.fc-box--loop {
    background: transparent;
    color: var(--color-accent);
    border: 2px dashed var(--color-accent);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: var(--font-size-sm);
    font-weight: 700;
    text-align: center;
    line-height: 1.6;
    cursor: pointer;
    transition: background 0.2s ease;
    position: relative;
}

.fc-box--loop:active {
    background: rgba(78, 205, 196, 0.1);
}

/* ループ先アンカー（スクロール位置調整用） */
.fc-loop-anchor {
    position: absolute;
    top: -60px;
    left: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* ループ先のハイライトアニメーション */
@keyframes fc-highlight-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.6); }
    50%  { box-shadow: 0 0 0 8px rgba(78, 205, 196, 0); }
    100% { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0); }
}

.fc-box--highlight {
    animation: fc-highlight-pulse 0.8s ease-out 2;
}

/* --- SVGループ矢印オーバーレイ --- */
.fc-loop-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
}

/* ===================================
   セクション見出し（トップページ）
   =================================== */
.machine-section {
    margin-bottom: 40px;
}

.section-heading {
    font-size: var(--font-size-lg);
    color: var(--color-text);
    padding-bottom: 10px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--color-accent);
    letter-spacing: 1px;
}
