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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #1a1a1a;
    color: #ffffff;
    display: flex;
    justify-content: center;
    /* スワイプバック等は防ぐが、スクロール自体は許可する */
    overscroll-behavior-y: none;
}

.app-container {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 1200px; /* 横持ち時に広く使えるように制限を緩和 */
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: 10px;
    overflow: hidden; /* 画面外へのハミ出しを強制カットし、内部スクロールを活かす */
}

.mode-badge {
    text-align: center;
    padding: 6px;
    font-size: 14px;
    font-weight: bold;
    color: white;
    border-radius: 6px;
    margin-bottom: 8px;
    max-width: 500px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}
.mode-badge.new-mode, .mode-badge.my-stock-mode {
    background-color: #2563eb; /* Blue */
}
.mode-badge.shared-mode {
    background-color: #059669; /* Green */
}
.mode-badge.coach-mode {
    background-color: #d97706; /* Orange */
}

.top-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px 0;
    flex-shrink: 0;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.controls-row {
    display: flex;
    width: 100%;
    gap: 6px;
    height: 44px; /* タップしやすい標準的な高さ */
}

button {
    flex: 1;
    padding: 0; /* 高さは親要素で決まるため0に */
    height: 100%;
    background-color: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

button:active {
    background-color: #555;
}

.preset-dropdown {
    flex: 1.5;
    padding: 0 8px;
    height: 100%;
    background-color: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    min-width: 0; /* 縮小可能に */
}

main {
    flex: 1;
    display: block; /* FlexboxによるスクロールHeight計算バグを回避 */
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* コートの縦横比（アスペクト比）はJSで絶対制御するためCSSから削除 */
#canvasContainer {
    position: relative;
    background-color: #000;
    border: 2px solid #555;
    border-radius: 8px;
    overflow: hidden;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Canvas上のデフォルトブラウザアクションを無効化 */
    touch-action: none; 
}

/* フェーズ3：モード切替用トグルボタン */
.mode-toggle {
    display: flex;
    flex: 3;
    background-color: #222;
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
    min-width: 0;
}

.mode-toggle input[type="radio"] {
    display: none;
}

.mode-toggle label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 2px;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    color: #ccc;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.mode-toggle input[type="radio"]:checked + label {
    background-color: #4ade80;
    color: #000;
}

/* リセットボタンスタイル */
.reset-stack {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 2px;
    height: 100%;
}

.reset-stack button {
    font-size: 10px;
    padding: 0;
    line-height: 1;
}

/* フェーズ4: メインワークスペース */
.main-workspace {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0 auto; /* mainをblockにしたので中央揃えに */
    min-height: 100%;
    align-items: center;
    justify-content: flex-start;
    padding-bottom: 60px; /* スクロール時の下部余白を大きめに取る（ツールバー回避） */
}

.canvas-container {
    position: relative;
    background-color: #000;
    border: 2px solid #555;
    border-radius: 8px;
    overflow: hidden;
}

.spawn-btn {
    flex: 0.8;
    font-size: 12px;
}

.spawn-btn.blue {
    background-color: #457b9d;
    border-color: #2c5670;
}

.spawn-btn.red {
    background-color: #e63946;
    border-color: #a82732;
}

.trash-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #333;
    border: 2px dashed #666;
    border-radius: 8px;
    color: #888;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    transition: all 0.2s;
}

/* ドラッグ中にゴミ箱の上にきたときのハイライト */
.trash-zone.hover {
    background-color: #ff4d4d;
    border-color: #fff;
    color: #fff;
    transform: scale(1.05);
}

/* 大画面でもヘッダー幅とキャンバス幅を揃える */
@media (min-width: 500px) {
    .top-controls {
        padding-top: 10px;
    }
}

/* ログインオーバーレイ */
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.login-modal { background: #222; padding: 30px; border-radius: 12px; width: 90%; max-width: 400px; display: flex; flex-direction: column; gap: 15px; text-align: center; border: 1px solid #444; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.login-modal h2 { color: #fff; margin-bottom: 5px; font-size: 24px; }
.login-desc { color: #aaa; font-size: 13px; margin-bottom: 10px; }
.login-input { padding: 12px; border-radius: 8px; border: 1px solid #555; background: #111; color: #fff; font-size: 16px; width: 100%; }
.login-options { display: flex; justify-content: center; gap: 10px; color: #ccc; font-size: 14px; }
.primary-btn { background: #4ade80; color: #000; padding: 14px; font-size: 16px; font-weight: bold; border: none; border-radius: 8px; cursor: pointer; transition: background 0.2s; }
.primary-btn:hover { background: #22c55e; }
.error-msg { color: #ff4d4d; font-size: 12px; min-height: 18px; }

/* 3段目：DBボタン群 */
.db-controls {
    justify-content: center;
    border-top: 1px solid #444;
    padding-top: 5px;
}
.db-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: #fff;
    transition: background 0.2s;
    white-space: nowrap;
}
.save-btn { background: #3b82f6; }
.save-btn:hover { background: #2563eb; }
.load-btn { background: #8b5cf6; }
.load-btn:hover { background: #7c3aed; }

/* ダッシュボードモーダル */
.dashboard-modal {
    background: #1e1e1e;
    width: 95%;
    max-width: 600px;
    height: 80vh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #444;
}
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #2a2a2a;
    border-bottom: 1px solid #444;
}
.dashboard-header h2 {
    color: #fff;
    margin: 0;
    font-size: 18px;
}
.close-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 20px;
    cursor: pointer;
}
.tactics-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.tactic-card {
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.2s;
}
.tactic-card:hover {
    border-color: #666;
}
.tactic-info h3 {
    margin: 0 0 5px 0;
    color: #fff;
    font-size: 16px;
}
.tactic-info p {
    margin: 0;
    color: #aaa;
    font-size: 12px;
}
.tactic-actions {
    display: flex;
    gap: 10px;
}
.action-btn {
    background: #444;
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
.action-btn.share { background: #10b981; }
.action-btn.stock { background: #f59e0b; }

/* Dashboard Tabs */
.dashboard-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}
.tab-btn {
    flex: 1;
    background: #333;
    color: #888;
    border: none;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
}
.tab-btn.active {
    background: #4ade80;
    color: #000;
}

/* Info Scroll Area (Memos & Explanations) */
.info-scroll-area {
    margin-top: 15px;
    padding: 15px;
    background: #222;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 500px; /* スマホやタブレットでもキャンバスと同じ幅に収める */
}
.coach-desc-section h3, .player-memo-section h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #4ade80;
}
.player-memo-section h3 {
    color: #60a5fa;
}
.info-scroll-area textarea {
    width: 100%;
    min-height: 80px;
    background: #111;
    color: #fff;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}
.info-scroll-area textarea[readonly] {
    opacity: 0.8;
}
.info-scroll-area button {
    height: auto;
    padding: 12px;
    font-size: 14px;
}

/* --- Phase 2: Extracted Inline Styles --- */
.coach-password-input { margin-top: 10px; }
.modal-overlay-save { z-index: 2000; }
.modal-overlay-system { z-index: 10001; }
.modal-content-center { text-align: center; padding: 20px; }
.modal-content-narrow { text-align: center; padding: 20px; max-width: 300px; }
.modal-title { margin-bottom: 15px; color: white; }
.modal-desc-text { font-size: 12px; color: #aaa; margin-bottom: 15px; text-align: left; }
.mb-15 { margin-bottom: 15px; }
.mb-20 { margin-bottom: 20px; }
.publish-option-box { margin-bottom: 20px; text-align: left; background: #333; padding: 10px; border-radius: 8px; }
.publish-checkbox-label { color: white; font-size: 14px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.checkbox-lg { width: 18px; height: 18px; }
.ml-26 { margin-left: 26px; }
.category-select { padding: 5px; font-size: 13px; margin-bottom: 4px; }
.category-select-mb20 { padding: 5px; font-size: 13px; margin-bottom: 20px; }
.helper-text { font-size: 11px; color: #aaa; margin-top: 4px; margin-left: 26px; line-height: 1.4; }
.action-buttons-col { display: flex; flex-direction: column; gap: 10px; margin-bottom: 15px; }
.action-buttons-col-nomargin { display: flex; flex-direction: column; gap: 10px; }
.btn-blue { background-color: #2563eb; }
.btn-blue-mb10 { background-color: #2563eb; margin-bottom: 10px; }
.btn-green { background-color: #059669; }
.btn-green-mb10 { background-color: #059669; margin-bottom: 10px; }
.btn-gray { background-color: #555; }
.btn-gray-mt15 { background-color: #555; margin-top: 15px; }
.btn-dark-gray { background-color: #4b5563; }
.btn-red { background-color: #dc2626; }
.btn-full-width { width: 100%; margin-top: 10px; }
.btn-full-width-mt5 { width: 100%; margin-top: 5px; }
.badge-container { display: flex; gap: 8px; max-width: 500px; margin: 0 auto 8px auto; align-items: stretch; }
.mode-badge-flex { margin: 0; flex: 1; display: flex; align-items: center; justify-content: center; }
.btn-settings-small { background-color: #555; padding: 0 12px; margin: 0; font-size: 12px; white-space: nowrap; display: flex; align-items: center; justify-content: center; }
.btn-reset-all { background-color: #444; flex: 2; }
.mode-toggle-wide { flex: 5.5; }
.btn-erase-arrows { background-color: #444; flex: 1; font-size: 11px; padding: 0; border-radius: 8px; border: 1px solid #555; font-weight: bold; cursor: pointer; color: white; white-space: nowrap; }
.trash-zone-flex { flex: 1; font-size: 11px; margin-left: 2px; padding: 0; white-space: nowrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-align-center-gap12 { display: flex; align-items: center; gap: 12px; }
.flex-align-center-gap10 { display: flex; align-items: center; gap: 10px; }
.m-0 { margin: 0; }
.favorite-filter-label { color: #fbbf24; font-size: 13px; font-weight: bold; display: flex; align-items: center; gap: 4px; cursor: pointer; border: 1px solid #555; padding: 4px 8px; border-radius: 6px; background-color: #333; }
.checkbox-favorite { accent-color: #fbbf24; transform: scale(1.2); }
.close-btn-static { position: static; }
.category-filters-container { display: flex; gap: 5px; overflow-x: auto; padding: 10px 15px; background: #222; border-bottom: 1px solid #444; }

/* iOS PWA Prompt */
.ios-install-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background-color: rgba(255, 255, 255, 0.95);
    color: #111;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 10000;
    text-align: center;
    font-size: 0.9rem;
    animation: slideUp 0.5s ease-out;
}
.ios-prompt-content { position: relative; }
.ios-prompt-content p { margin: 2px 0; }
.ios-close-btn {
    position: absolute;
    top: -10px;
    right: -5px;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: #555;
    cursor: pointer;
}
.ios-prompt-arrow {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid rgba(255, 255, 255, 0.95);
}
@keyframes slideUp { from { bottom: -100px; opacity: 0; } to { bottom: 20px; opacity: 1; } }
