:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #e5e5e5;
    --text: #222;
    --text-sub: #666;
    --text-dim: #999;
    --accent: #2563eb;
    --red: #dc2626;
    --green: #16a34a;
    --amber: #d97706;
    --purple: #7c3aed;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(37,99,235,0.15);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', 'Noto Sans JP', system-ui, sans-serif;
    font-size: 14px;
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ========== Layout ========== */

.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 12px;
    gap: 8px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 6px;
}

.logo h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 700;
}

.machine-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.machine-thumb {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    color: #fff;
    user-select: none;
}

.machine-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#current-machine-name {
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    border-bottom: 1px dashed var(--text-dim);
}

#current-machine-name:hover {
    color: var(--accent);
}

.status-badge {
    padding: 2px 10px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.normal {
    background: #f0f0f0;
    color: var(--text-sub);
}

.status-badge.rush {
    background: #fef2f2;
    color: var(--red);
}

/* ========== Dashboard Grid ========== */

.dashboard {
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    gap: 8px;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    padding: 12px;
}

.panel h2 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

/* ========== Settings ========== */

.settings-panel {
    overflow-y: auto;
}

.settings-grid {
    display: none;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}
.settings-grid.is-open {
    display: flex;
}

/* オンボーディングカード */
.onboarding-card {
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    border-radius: 8px;
    padding: 20px 24px;
    margin-bottom: 12px;
    position: relative;
    box-shadow: 0 6px 24px rgba(37, 99, 235, 0.25);
}
.onboarding-card h2 {
    font-size: 18px;
    margin-bottom: 16px;
}
.onboarding-subtitle {
    display: inline-block;
    font-size: 13px;
    font-weight: 400;
    margin-left: 8px;
    opacity: 0.85;
}
.onboarding-steps {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
}
.onboarding-step {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.onboarding-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
}
.onboarding-step strong {
    display: block;
    font-size: 14px;
    margin-bottom: 4px;
}
.onboarding-step p {
    font-size: 12px;
    opacity: 0.9;
    line-height: 1.5;
}
.onboarding-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    opacity: 0.7;
    width: 32px;
    height: 32px;
}
.onboarding-close:hover { opacity: 1; }
.onboarding-cta {
    background: #fff;
    color: #2563eb;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    font-size: 14px;
}
.onboarding-cta:hover { opacity: 0.9; }
@media (max-width: 700px) {
    .onboarding-card { padding: 16px; }
    .onboarding-steps { grid-template-columns: 1fr; gap: 10px; }
    .onboarding-card h2 { font-size: 16px; }
}

/* 機種情報サマリー（P1-1） */
.machine-summary {
    background: linear-gradient(135deg, #eff6ff, #f5f3ff);
    border: 1px solid #dbeafe;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 12px;
}
.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
}
.summary-row + .summary-row {
    border-top: 1px dashed #c7d2fe;
}
.summary-row--highlight {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 2px solid #c7d2fe !important;
}
.summary-label {
    color: #475569;
    font-weight: 600;
}
.summary-label small {
    display: block;
    font-size: 10px;
    color: #94a3b8;
    font-weight: normal;
}
.summary-value {
    font-weight: 800;
    color: #1e40af;
    font-variant-numeric: tabular-nums;
}
.summary-value.positive { color: var(--green); }
.summary-value.negative { color: var(--red); }

/* 再抽選ボタン（P1-5） */
.btn-retry {
    width: 100%;
    padding: 11px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
    animation: btn-retry-pulse 2s infinite;
}
@keyframes btn-retry-pulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3); }
    50% { box-shadow: 0 2px 16px rgba(245, 158, 11, 0.6); }
}

/* モンテカルロボタン（P3-1） */
.btn-monte {
    width: 100%;
    padding: 10px;
    background: #1e293b;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    margin-bottom: 10px;
}
.btn-monte:hover { background: #0f172a; }
.btn-monte:disabled { opacity: 0.5; cursor: wait; }
.monte-result {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
}
.monte-result h3 {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.monte-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    font-size: 12px;
    margin-bottom: 10px;
}
.monte-stat {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    background: #fff;
    border-radius: 3px;
}
.monte-stat-label { color: var(--text-dim); }
.monte-stat-value { font-weight: 800; font-variant-numeric: tabular-nums; }
.monte-chart-wrap { height: 160px; position: relative; }

/* 大当たり演出（P2-1） */
.hit-effect {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
    background: radial-gradient(circle at center, rgba(245, 158, 11, 0.35), transparent 60%);
}
.hit-effect.show { opacity: 1; }
.hit-effect-inner {
    text-align: center;
    transform: scale(0.5);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hit-effect.show .hit-effect-inner { transform: scale(1); }
.hit-effect-text {
    font-size: 96px;
    font-weight: 900;
    background: linear-gradient(135deg, #fbbf24, #f59e0b, #ef4444);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 16px rgba(251, 191, 36, 0.6);
    letter-spacing: 4px;
    line-height: 1;
    animation: hit-text-pulse 0.6s ease-out;
}
@keyframes hit-text-pulse {
    0% { transform: scale(0.3) rotate(-10deg); opacity: 0; }
    50% { transform: scale(1.15) rotate(2deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
.hit-effect-sub {
    margin-top: 12px;
    font-size: 20px;
    font-weight: 700;
    color: #1e40af;
    text-shadow: 0 2px 8px rgba(255,255,255,0.9);
}
@media (max-width: 600px) {
    .hit-effect-text { font-size: 64px; }
    .hit-effect-sub { font-size: 16px; }
}

/* 詳細設定トグル（常時表示） */
.advanced-toggle {
    display: flex;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-sub);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    transition: all 0.15s;
}
.advanced-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.advanced-toggle-arrow {
    font-size: 11px;
    transition: transform 0.2s;
}
.advanced-toggle[aria-expanded="true"] .advanced-toggle-arrow {
    transform: rotate(180deg);
}

.field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 3px;
}

.field select,
.field input[type="number"],
.field input[type="text"] {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    outline: none;
}

.field select:focus,
.field input:focus {
    border-color: var(--accent);
}

/* ステップバッジ */
.step-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    border-radius: 3px;
    margin-right: 6px;
    letter-spacing: 0.5px;
}
.step-badge--green {
    background: var(--green);
}

/* 強調フィールド */
.field--highlight label {
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 6px;
}

/* Machine Select Button */
.machine-select-btn {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.15s;
}

.machine-select-btn:hover {
    border-color: var(--accent);
}

/* メインCTAの機種選択ボタン（目立たせる） */
.machine-select-btn--primary {
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 700;
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border: 2px solid var(--accent);
    color: var(--accent);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.12);
}

.machine-select-btn--primary:hover {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
    transform: translateY(-1px);
}

.machine-select-btn--primary .machine-select-arrow {
    color: var(--accent);
    font-size: 13px;
}

/* シミュレーション実行ボックス */
.simulation-box {
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    border: 2px solid #86efac;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 12px;
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.08);
}

.simulation-box-header {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #166534;
    margin-bottom: 8px;
}

.machine-select-arrow {
    font-size: 10px;
    color: var(--text-dim);
    margin-left: 4px;
}

/* Speed Slider */
.speed-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.speed-control input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.speed-control input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.speed-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    min-width: 3em;
    text-align: center;
}

/* Buttons */
.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 0;
}
.simulation-box + .btn-retry,
.simulation-box + .btn-monte {
    margin-top: 10px;
}

.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary.auto {
    background: var(--purple);
}

.btn-primary:hover:not(:disabled) {
    opacity: 0.85;
}

.btn-primary:disabled {
    background: #d4d4d4;
    color: #999;
    cursor: not-allowed;
}

.btn-secondary {
    background: #f5f5f5;
    color: var(--text-sub);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #ebebeb;
}

/* ========== Graph ========== */

.graph-panel {
    min-width: 0;
}

.panel-header { flex-shrink: 0; }

.chart-container {
    flex: 1;
    position: relative;
    min-height: 0;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.chart-scroller {
    height: 100%;
    min-width: 100%;
    position: relative;
}

.chart-container canvas {
    display: block;
    width: 100%;
    height: 100% !important;
}

/* ========== Stats ========== */

.stats-panel {
    overflow-y: auto;
}

.main-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 10px;
}

.stat-card {
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--bg);
    border: none;
}

.stat-card.return { border-left: none; }
.stat-card.return .stat-value span { color: var(--green); }

.stat-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 2px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stat-value {
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
    display: flex;
    align-items: baseline;
    font-variant-numeric: tabular-nums;
}

.stat-value span { line-height: 1; }

.stat-value small {
    font-size: 11px;
    font-weight: 600;
    margin-left: 2px;
    color: var(--text-dim);
}

.stat-card.balance .stat-value span { color: var(--accent); }
.stat-card.investment .stat-value span { color: var(--red); }
.stat-card.payout .stat-value span { color: var(--amber); }

.detail-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-top: auto;
}

.detail-stat {
    padding: 5px 8px;
    background: var(--bg);
    border-radius: 3px;
    display: flex;
    flex-direction: column;
}

.detail-stat .label {
    font-size: 10px;
    color: var(--text-dim);
}

.detail-stat .value {
    font-size: 13px;
    font-weight: 700;
}

.detail-stat .value.result {
    color: var(--accent);
}

/* ========== Session History ========== */

.session-panel {
    flex: 0 0 auto;
    max-height: 160px;
    min-height: 0;
    overflow: hidden;
}

.session-summary {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-sub);
    margin-bottom: 6px;
    min-height: 1em;
}

.session-summary strong { font-weight: 700; }

.session-table-wrapper {
    overflow: auto;
    flex: 1;
    min-height: 0;
}

.session-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.session-table th,
.session-table td {
    padding: 4px 8px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.session-table th {
    background: var(--bg);
    color: var(--text-dim);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 1;
}

.session-table td:first-child,
.session-table th:first-child {
    text-align: center;
    width: 2em;
}

.session-table td.session-machine {
    text-align: left;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profit-plus { color: var(--green); font-weight: 700; }
.profit-minus { color: var(--red); font-weight: 700; }

.session-row-active {
    background: #fef3c7;
    animation: session-active-pulse 2s infinite;
}
.session-row-active td {
    border-bottom: 1px solid #fcd34d !important;
}
.session-active-dot {
    color: #f59e0b;
    font-size: 8px;
    margin-right: 4px;
    animation: session-dot-blink 1.2s infinite;
}
@keyframes session-active-pulse {
    0%, 100% { background: #fef3c7; }
    50% { background: #fde68a; }
}
@keyframes session-dot-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ========== Modal ========== */

.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    justify-content: center;
    align-items: center;
}

.modal.show { display: flex; }

.modal-content {
    background: #fff;
    width: 90%;
    max-width: 460px;
    border-radius: 6px;
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
}

.modal-content.modal-wide {
    max-width: 720px;
}

.modal-body-scroll {
    max-height: 60vh;
    overflow-y: auto;
}

/* Machine List Table */
.machine-list-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.machine-list-table th,
.machine-list-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.machine-list-table th {
    background: var(--bg);
    color: var(--text-dim);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 1;
}

.machine-list-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}

.machine-list-table tbody tr:hover {
    background: #f0f4ff;
}

.machine-list-table tbody tr.selected {
    background: #eff6ff;
    font-weight: 700;
}

.machine-list-table tbody tr.selected td:first-child::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 4px;
    vertical-align: middle;
}

.machine-list-table .col-prob,
.machine-list-table .col-entry,
.machine-list-table .col-type {
    text-align: right;
}

.machine-list-table .col-type {
    font-size: 11px;
    color: var(--text-dim);
}

.info-link {
    display: inline-block;
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    margin-left: 4px;
    opacity: 0.5;
    vertical-align: middle;
}

.info-link:hover {
    opacity: 1;
}

.machine-list-table .col-thumb {
    width: 32px;
    padding: 4px 6px;
}

.machine-list-thumb {
    width: 28px;
    height: 28px;
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 11px;
    color: #fff;
    flex-shrink: 0;
}

.machine-list-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 15px;
    color: var(--text);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10001;
    background: #f5f5f5;
    border: 1px solid var(--border);
    font-size: 18px;
    cursor: pointer;
    color: var(--text-dim);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.close-btn:hover {
    background: #fee2e2;
    color: var(--red);
    border-color: #fecaca;
}

.modal-body { padding: 16px; }

.spec-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.spec-item {
    padding: 8px 10px;
    background: var(--bg);
    border-radius: 3px;
}

.spec-label {
    display: block;
    font-size: 10px;
    color: var(--text-dim);
    margin-bottom: 2px;
}

.spec-value {
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
}

/* ========== Animation ========== */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.flashing {
    animation: pulse 1s infinite ease-in-out;
}

/* ========== Responsive ========== */

@media (max-width: 1100px) {
    .dashboard {
        grid-template-columns: 210px 1fr 240px;
    }
}

@media (max-width: 900px) {
    body {
        overflow: auto;
        height: auto;
        font-size: 15px;
    }

    .app-wrapper {
        height: auto;
        padding: 8px;
        min-height: 100vh;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 12px;
    }

    .machine-info {
        width: 100%;
        justify-content: space-between;
    }

    .dashboard {
        grid-template-columns: 1fr;
        overflow: visible;
        flex: none;       /* flex: 1 1 0 を解除（コンテンツに合わせて伸びる） */
        min-height: 0;
        height: auto;
    }

    .settings-panel { order: 1; overflow-y: visible; min-height: 0; flex: none; }
    .graph-panel { order: 2; min-height: 320px; flex: none; }
    .stats-panel { order: 3; overflow-y: visible; min-height: 0; flex: none; }

    .chart-container { min-height: 300px; }

    .session-panel { max-height: none; }
    .session-table-wrapper { max-height: 280px; }

    /* タッチターゲット44px以上 */
    .btn-primary,
    .btn-secondary {
        padding: 12px;
        font-size: 15px;
        min-height: 44px;
    }

    .machine-select-btn {
        padding: 11px 12px;
        font-size: 16px;  /* iOS auto-zoom防止 */
        min-height: 44px;
    }

    /* iOS: font-size 16px未満だと入力フォーカス時に自動ズーム */
    .field select,
    .field input[type="number"],
    .field input[type="text"] {
        padding: 10px 12px;
        font-size: 16px;
        min-height: 44px;
    }

    .speed-control input[type="range"] {
        height: 8px;
    }
    .speed-control input[type="range"]::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }
    .speed-control input[type="range"]::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }

    /* 設定の2x2ボタン配置 */
    .actions {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 14px;
    }

    /* 詳細設定トグル: スマホではタッチターゲット高さ確保 */
    .advanced-toggle {
        min-height: 44px;
    }

    /* 統計カード */
    .main-stats { gap: 8px; }
    .stat-card { padding: 10px 12px; }
    .stat-value { font-size: 18px; }
    .stat-label { font-size: 11px; }

    /* セッションテーブル: 横スクロール時のヒント */
    .session-table-wrapper {
        -webkit-overflow-scrolling: touch;
    }
    .session-table {
        font-size: 12px;
    }
    .session-table th,
    .session-table td {
        padding: 8px 10px;
    }

    /* モーダル: スマホでは全画面近く */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        display: flex;
        flex-direction: column;
    }
    .modal-content.modal-wide {
        max-width: 95%;
    }
    .modal-body,
    .modal-body-scroll {
        max-height: calc(90vh - 60px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-header {
        padding: 12px 16px;
    }
    .close-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 22px;
    }

    /* 機種選択テーブル */
    .machine-list-table {
        font-size: 13px;
    }
    .machine-list-table th,
    .machine-list-table td {
        padding: 10px 8px;
    }
    .machine-list-table tbody tr {
        min-height: 44px;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 8px 10px;
        gap: 6px;
    }
    .logo h1 { font-size: 14px; }
    .panel { padding: 12px; }
    .panel h2 { font-size: 11px; margin-bottom: 10px; }

    /* 細かいラベル類の文字サイズ調整 */
    .field label { font-size: 12px; }

    /* 統計の詳細グリッド: コンパクト化 */
    .detail-stats-grid { gap: 6px; }
    .detail-stat { padding: 8px 10px; }
    .detail-stat .label { font-size: 10px; }
    .detail-stat .value { font-size: 14px; }

    /* モバイルではセッション履歴のテーブル列を絞る */
    .session-table {
        font-size: 11px;
    }
    .session-table th:nth-child(1),  /* # */
    .session-table td:nth-child(1) {
        width: 2em;
    }
    .session-table th,
    .session-table td {
        padding: 6px 4px;
    }
}

@media (max-height: 700px) and (min-width: 901px) {
    .main-stats { margin-bottom: 4px; }
    .stat-card { padding: 5px 8px; }
    .stat-value { font-size: 14px; }
    .detail-stats-grid { gap: 2px; }
    .session-panel { max-height: 120px; }
}