.nonogram-app {
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    color: #333;
    line-height: 1.5;
    max-width: 1000px;
    margin: 0 auto;
    padding: 12px;
    overflow: hidden;
}

.nonogram-app h1 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
    border-bottom: 2px solid #ddd;
    padding-bottom: 0.5rem;
}

.nonogram-app h3 {
    margin-top: 0 !important;
    margin-bottom: 1rem !important;
    font-size: 1.1rem !important;
    border-left: 4px solid #007bff !important;
    padding-left: 0.5rem !important;
    /* WPテーマのアイコン・装飾をリセット */
    background: none !important;
    border-top: none !important;
    border-right: none !important;
    border-bottom: none !important;
    padding-top: 0 !important;
    padding-right: 0 !important;
    padding-bottom: 0 !important;
    position: relative !important;
    line-height: 1.4 !important;
    color: #333 !important;
}

.nonogram-app h3::before,
.nonogram-app h3::after {
    content: none !important;
    display: none !important;
}

.nonogram-app h4 {
    margin: 0 0 8px 0;
    font-size: 1rem;
    color: #555;
}

.nonogram-app .section {
    margin-bottom: 30px;
}

.nonogram-app .controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.nonogram-app .controls label,
.nonogram-app .controls select,
.nonogram-app .controls button {
    display: inline-flex;
    width: auto;
    flex: none;
}

.nonogram-app .board-load-status {
    font-size: 0.85rem;
    color: #666;
}

.nonogram-app .board-load-note {
    display: block;
    font-size: 0.78rem;
    color: #e07000;
    margin-top: 4px;
}

.nonogram-app button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background-color: #eee;
    transition: background-color 0.2s;
}

.nonogram-app button:hover {
    background-color: #ddd;
}

.nonogram-app button.primary {
    background-color: #007bff;
    color: white;
}

.nonogram-app button.primary:hover {
    background-color: #0056b3;
}

.nonogram-app button.secondary {
    background-color: #6c757d;
    color: white;
}

.nonogram-app button.secondary:hover {
    background-color: #545b62;
}

.nonogram-app select {
    padding: 6px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

/* ========== モード切替タブ ========== */
.nonogram-app .mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 2px solid #007bff;
}

.nonogram-app .mode-tab {
    padding: 10px 24px;
    border: 2px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background-color: #e9ecef;
    color: #666;
    font-weight: bold;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    bottom: -2px;
}

.nonogram-app .mode-tab:hover {
    background-color: #dee2e6;
    color: #333;
}

.nonogram-app .mode-tab.active {
    background-color: #fff;
    color: #007bff;
    border-color: #007bff;
    border-bottom: 2px solid #fff;
}

/* ========== モードパネル ========== */
.nonogram-app .mode-panel {
    border: 2px solid #007bff;
    border-top: none;
    padding: 15px;
    background: #fff;
    border-radius: 0 0 6px 6px;
}

.nonogram-app .mode-panel.hidden {
    display: none;
}

.nonogram-app .mode-desc {
    margin: 0 0 12px 0;
    font-size: 0.9em;
    color: #666;
}

/* ========== CSV一括入力モード ========== */
.nonogram-app .csv-input-sections {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.nonogram-app .csv-input-section {
    flex: 1;
    min-width: 240px;
}

.nonogram-app .csv-textarea {
    width: 100%;
    min-height: 200px;
    max-height: 400px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
    line-height: 1.6;
    resize: vertical;
    box-sizing: border-box;
    background: #fafafa;
}

.nonogram-app .csv-textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.15);
}

/* ========== 数字入力モード（リスト形式） ========== */
.nonogram-app .hint-lists {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.nonogram-app .hint-list-section {
    flex: 1;
    min-width: 240px;
}

.nonogram-app .hint-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fafafa;
}

.nonogram-app .hint-list-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-bottom: 1px solid #eee;
}

.nonogram-app .hint-list-row:last-child {
    border-bottom: none;
}

.nonogram-app .hint-list-row:hover {
    background-color: #f0f4ff;
}

.nonogram-app .hint-list-label {
    font-size: 0.85em;
    font-weight: bold;
    color: #555;
    min-width: 36px;
    text-align: right;
    flex-shrink: 0;
}

.nonogram-app .hint-list-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: monospace;
    min-width: 60px;
}

.nonogram-app .hint-list-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.15);
}

.nonogram-app .hint-list-count {
    font-size: 0.8em;
    color: #999;
    min-width: 30px;
    text-align: right;
    flex-shrink: 0;
}

/* ========== 画像入力モード ========== */
.nonogram-app .image-input-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nonogram-app .image-upload-btn {
    display: inline-block;
    padding: 10px 20px;
    background: #007bff;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    text-align: center;
    transition: background 0.2s;
    align-self: flex-start;
}

.nonogram-app .image-upload-btn:hover {
    background: #0056b3;
}

.nonogram-app .image-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    padding: 10px;
    background: #f0f4ff;
    border-radius: 6px;
}

.nonogram-app .image-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
}

.nonogram-app .image-controls select {
    padding: 4px 8px;
    font-size: 0.9rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}

.nonogram-app .image-controls input[type="range"] {
    width: 140px;
}

.nonogram-app .image-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.nonogram-app .image-preview-area {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 8px;
    background: #fafafa;
    overflow: auto;
}

.nonogram-app .image-compare {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.nonogram-app .image-compare-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.nonogram-app .image-compare-label {
    font-size: 0.8rem;
    color: #666;
    font-weight: bold;
}

.nonogram-app .image-preview-area canvas {
    image-rendering: pixelated;
    border: 1px solid #ddd;
}

/* ========== ドット入力モード ========== */
.nonogram-app .dot-grid-wrapper {
    overflow: auto;
    max-width: 100%;
    max-height: 600px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
    background: #fafafa;
    touch-action: none; /* ピンチ操作をJSで制御 */
    -webkit-overflow-scrolling: touch;
}

.nonogram-app .dot-grid-wrapper .grid-board {
    transform-origin: 0 0;
    transition: none;
}

/* グリッド盤面（共通） */
.nonogram-app .grid-board {
    display: grid;
    /* grid-template-columns はJSで設定 */
    border: 2px solid #333;
    background-color: #fff;
}

.nonogram-app .cell {
    border: 1px solid #ccc;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    font-weight: bold;
    line-height: 1;
}

/* 5マスごとの太線 */
.nonogram-app .cell.thick-right {
    border-right: 2px solid #333;
}
.nonogram-app .cell.thick-bottom {
    border-bottom: 2px solid #333;
}

.nonogram-app .cell:hover {
    background-color: #eef;
}

.nonogram-app .cell.filled {
    background-color: #333;
    color: #333;
}

.nonogram-app .cell.empty {
    color: #d9534f;
    background-color: #fff5f5;
}

.nonogram-app .cell.error {
    background-color: #fdd;
}

/* ========== 解析結果グリッド ========== */
.nonogram-app .result-grid-wrapper {
    margin-bottom: 15px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fafafa;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.nonogram-app .result-grid-wrapper.hidden {
    display: none;
}

.nonogram-app .result-grid-wrapper h4 {
    margin-bottom: 10px;
}

.nonogram-app .result-board-container {
    display: inline-block;
    border: 2px solid #333;
    padding: 0;
    background: #fff;
}

/* 解析結果のヒント表示 */
.nonogram-app .hints-top-wrapper {
    display: flex;
}

.nonogram-app .main-grid-row {
    display: flex;
}

.nonogram-app .hints-left {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    margin-right: 2px;
}

.nonogram-app .hint-cell-left {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    box-sizing: border-box;
    padding-right: 3px;
    overflow: hidden;
    white-space: nowrap;
}

.nonogram-app .hints-top {
    display: flex;
    margin-bottom: 2px;
}

.nonogram-app .hint-cell-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    box-sizing: border-box;
    padding-bottom: 2px;
    overflow: hidden;
    line-height: 1.1;
}

.nonogram-app .hint-text {
    font-family: monospace;
    font-weight: bold;
    text-align: center;
}

/* ========== 解析ハイライト ========== */

/* 解析結果グリッドのヒントセル: エラー（ヒント不正等） */
.nonogram-app .hint-cell-left.hint-error,
.nonogram-app .hint-cell-top.hint-error {
    background-color: rgba(220, 50, 50, 0.25);
}
.nonogram-app .hint-cell-left.hint-error .hint-text,
.nonogram-app .hint-cell-top.hint-error .hint-text {
    color: #c33;
}

/* 解析結果グリッドのヒントセル: 手詰まりボトルネック（未確定が特に多い） */
.nonogram-app .hint-cell-left.hint-stale,
.nonogram-app .hint-cell-top.hint-stale {
    background-color: rgba(50, 120, 220, 0.15);
}
.nonogram-app .hint-cell-left.hint-stale .hint-text,
.nonogram-app .hint-cell-top.hint-stale .hint-text {
    color: #2568c7;
}

/* 解析結果グリッドのセル: 未確定 */
.nonogram-app .cell.cell-unresolved {
    background-color: rgba(50, 120, 220, 0.12);
}

/* 解析結果グリッドのセル: エラー関連 */
.nonogram-app .cell.cell-error-zone {
    background-color: rgba(220, 50, 50, 0.2);
}

/* ヒント入力欄: OCR読み取り失敗 */
.nonogram-app .hint-list-row.hint-row-ocr-fail {
    background: rgba(255, 80, 80, 0.15) !important;
}
.nonogram-app .hint-list-row.hint-row-ocr-fail .hint-list-count {
    color: #e44;
}
.nonogram-app .hint-list-row.hint-row-ocr-fail .hint-list-label {
    color: #c33;
}

/* ヒント入力欄: 確定済み（正常） */
.nonogram-app .hint-list-row.hint-row-ok {
    background: rgba(40, 167, 69, 0.08) !important;
}
.nonogram-app .hint-list-row.hint-row-ok .hint-list-input {
    border-color: #5a5;
}
.nonogram-app .hint-list-row.hint-row-ok .hint-list-label {
    color: #28a745;
}
.nonogram-app .hint-list-row.hint-row-ok .hint-list-count {
    color: #28a745;
}

/* ヒント入力欄: エラー行/列 */
.nonogram-app .hint-list-row.hint-row-error {
    background: rgba(220, 50, 50, 0.12) !important;
}
.nonogram-app .hint-list-row.hint-row-error .hint-list-input {
    border-color: #d44;
    background: rgba(255, 230, 230, 0.5);
}
.nonogram-app .hint-list-row.hint-row-error .hint-list-label {
    color: #c33;
}
.nonogram-app .hint-list-row.hint-row-error .hint-list-count {
    color: #c33;
}

/* ヒント入力欄: 手詰まりボトルネック行/列 */
.nonogram-app .hint-list-row.hint-row-stale {
    background: rgba(50, 120, 220, 0.08) !important;
}
.nonogram-app .hint-list-row.hint-row-stale .hint-list-input {
    border-color: #68b;
}
.nonogram-app .hint-list-row.hint-row-stale .hint-list-label {
    color: #2568c7;
}

/* ヒント合計不整合の警告 */
.nonogram-app .hint-mismatch-badge {
    display: inline-block;
    font-size: 0.75em;
    color: #a0a;
    font-weight: bold;
    margin-left: 4px;
}

/* ヒント色凡例 */
.nonogram-app .hint-color-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 6px 10px;
    margin-bottom: 8px;
    background: #f5f6f8;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.8em;
}
.nonogram-app .legend-item {
    white-space: nowrap;
}
.nonogram-app .legend-ok { color: #28a745; }
.nonogram-app .legend-error { color: #c33; }
.nonogram-app .legend-stale { color: #2568c7; }
.nonogram-app .legend-ocr-fail { color: #e44; }

/* ========== ステータス・ログ ========== */
.nonogram-app .status-box {
    padding: 10px;
    background-color: #e9ecef;
    border-radius: 4px;
    margin-bottom: 10px;
    font-weight: bold;
}

.nonogram-app .log-area {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ddd;
    padding: 10px;
    font-size: 0.9em;
    background: #fafafa;
}

.nonogram-app .log-entry {
    margin-bottom: 4px;
    border-bottom: 1px solid #eee;
    padding-bottom: 2px;
}

/* ========== 投稿エリア ========== */
.nonogram-app .submit-area {
    border: 2px solid #28a745;
    border-radius: 8px;
    padding: 16px;
    background: #f8fff8;
}

.nonogram-app .submit-notice {
    margin: 0 0 12px 0;
    font-size: 0.9em;
    color: #666;
}

.nonogram-app .submit-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nonogram-app .submit-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.nonogram-app .submit-row > label {
    font-weight: bold;
    min-width: 60px;
    flex-shrink: 0;
}

.nonogram-app .submit-difficulty-info {
    font-size: 0.9em;
    color: #28a745;
    font-weight: bold;
    padding: 6px 10px;
    background: #e8f5e9;
    border-radius: 4px;
    border: 1px solid #c8e6c9;
}

.nonogram-app .submit-title {
    flex: 1;
    max-width: 500px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95em;
    box-sizing: border-box;
    font-family: inherit;
}

.nonogram-app .submit-title:focus {
    outline: none;
    border-color: #28a745;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.15);
}

.nonogram-app .submit-description {
    width: 100%;
    max-width: 500px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
}

.nonogram-app .submit-description:focus {
    outline: none;
    border-color: #28a745;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.15);
}

.nonogram-app .submit-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.nonogram-app .submit-actions button.primary {
    background-color: #28a745;
    padding: 10px 28px;
    font-size: 1rem;
    font-weight: bold;
}

.nonogram-app .submit-actions button.primary:hover:not(:disabled) {
    background-color: #218838;
}

.nonogram-app .submit-actions button.primary:disabled {
    background-color: #a0d4ab;
    cursor: not-allowed;
}

.nonogram-app .submit-status {
    font-size: 0.9em;
    color: #28a745;
    font-weight: bold;
}

.nonogram-app .submit-status.error {
    color: #d9534f;
}

/* ========== モバイル対応 ========== */
@media (max-width: 600px) {
    .nonogram-app {
        padding: 8px;
    }

    .nonogram-app h1 {
        font-size: 1.1rem;
    }

    .nonogram-app h3 {
        font-size: 1rem;
    }

    .nonogram-app .controls {
        gap: 6px;
    }

    .nonogram-app button {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    .nonogram-app .mode-tab {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .nonogram-app .mode-panel {
        padding: 10px;
    }

    .nonogram-app .hint-lists,
    .nonogram-app .csv-input-sections {
        flex-direction: column;
        gap: 10px;
    }

    .nonogram-app .hint-list-section,
    .nonogram-app .csv-input-section {
        min-width: unset;
    }

    .nonogram-app .csv-textarea {
        min-height: 120px;
    }

    .nonogram-app .dot-grid-wrapper {
        max-height: 400px;
    }

    .nonogram-app .log-area {
        max-height: 150px;
        font-size: 0.8em;
    }
}
