/**
 * HTML/CSS Live Editor - Main Styles
 * Version: 2.0.8
 *
 * 変更点（v2.0.8）：
 *   - .controls-panel に max-height を設定し、HTML/CSSエディタが
 *     位置とサイズ調整パネルに押し出されない構造に修正。
 *   - スライダー＋数値入力をコンパクト化し、8項目でも縦サイズを抑制。
 *
 * 変更点（v2.0.7）：
 *   - 位置とサイズ調整の入力フィールドにスライダー（input[type="range"]）スタイルを追加。
 */

.html-css-live-editor {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    margin: 20px 0;
    position: relative;
}
.html-css-live-editor * { box-sizing: border-box; }

/* ヘッダー */
.editor-header {
    background: #2c3e50;
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 60px;
}
.editor-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    white-space: nowrap;
}
.editor-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

/* ボタン */
.editor-controls button,
.file-input {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.4rem 0.85rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.3s;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
}
.editor-controls button:hover,
.file-input:hover { background: #2980b9; }

.file-input { position: relative; overflow: hidden; }
.file-input input[type=file] { position: absolute; left: -9999px; }

.btn-save     { background: #27ae60 !important; }
.btn-save:hover { background: #219a52 !important; }
.btn-download { background: #e67e22 !important; }
.btn-download:hover { background: #d35400 !important; }

/* メインレイアウト */
.editor-main {
    display: flex;
    height: calc(600px - 60px);
    min-height: 400px;
}

.preview-section {
    flex: 2;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    background: white;
    position: relative;
}

.editor-section {
    flex: 1;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    position: relative;
}

/* プレビューヘッダー */
.preview-header {
    background: #34495e;
    color: white;
    padding: 0.5rem 1rem;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}
.preview-info { font-size: 0.8rem; opacity: 0.8; }

/* プレビューコンテナ（自動スケール対応） */
.preview-container {
    flex: 1;
    position: relative;
    overflow: auto;
    background: #fff;
    padding: 0;
    display: block;
}

.preview-wrapper {
    width: 1440px;
    height: auto;
    transform-origin: top left;
    transition: transform 0.2s ease;
    background: #fff;
    position: relative;
}

.preview-frame {
    width: 100%;
    height: 1200px;
    min-height: 800px;
    border: none;
    background: white;
    display: block;
}

/* コントロールパネル */
.controls-panel {
    flex: 0 1 auto;          /* ★ 縮小も可に変更（伸びすぎ防止） */
    max-height: 50%;         /* ★ エディタセクション内で半分まで */
    background: white;
    border-bottom: 1px solid #ddd;
    padding: 0.75rem 1rem;
    overflow-y: auto;        /* 中身が溢れたらスクロール */
}
.control-group { margin-bottom: 0.85rem; }
.control-group:last-child { margin-bottom: 0; }
.control-group > label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    color: #2c3e50;
    font-size: 0.9rem;
}

/* 要素セレクトボックス */
.element-selector {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 0.9rem;
    cursor: pointer;
}
.element-selector:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52,152,219,0.2);
}

.css-jump-btn {
    background: #e67e22;
    color: white;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.3s;
}
.css-jump-btn:hover { background: #d35400; }

/* ★ 位置とサイズ調整：入力フィールド（コンパクト版） */
.control-row {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 0.4rem;
    flex-wrap: nowrap;       /* ★ X座標とY座標を必ず横並びに */
}
.control-item {
    flex: 1 1 0;
    min-width: 0;
}
.control-item > label {
    display: block;
    font-size: 0.72rem;      /* ★ 縮小 */
    margin-bottom: 0.15rem;  /* ★ 縮小 */
    color: #555;
    font-weight: 400;
    line-height: 1.2;
}
.control-item input[type="number"],
.control-item .number-input {
    width: 100%;
    padding: 0.25rem 0.4rem; /* ★ 縮小 */
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.8rem;       /* ★ 縮小 */
    background: #fff;
    color: #2c3e50;
}
.control-item input[type="number"]:focus,
.control-item .number-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

/* ★ スライダー（input[type="range"].slider）コンパクト版 */
.control-item .slider {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: #ddd;
    outline: none;
    margin: 0 0 0.2rem 0;    /* ★ 数値入力との間隔を縮小 */
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    display: block;
}
.control-item .slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;             /* ★ 14→12 */
    height: 12px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 0 2px rgba(0,0,0,0.25);
    transition: transform 0.15s;
}
.control-item .slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}
.control-item .slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 0 2px rgba(0,0,0,0.25);
}
.control-item .slider:focus {
    outline: none;
}
.control-item .slider:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(52,152,219,0.25);
}

.position-hint code {
    background: #f0f0f0;
    padding: 0 0.2em;
    border-radius: 2px;
    font-size: 0.95em;
}

/* エディタコンテンツ */
.editor-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.editor-tabs {
    display: flex;
    background: #ecf0f1;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
}
.tab-btn {
    background: none;
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: #7f8c8d;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}
.tab-btn.active {
    color: #2c3e50;
    background: white;
    border-bottom-color: #3498db;
}
.tab-btn:hover:not(.active) { background: #e8f4fd; color: #2c3e50; }

.editor-content {
    flex: 1;
    position: relative;
    min-height: 0;
}
.editor-tab { display: none; height: 100%; }
.editor-tab.active { display: block; }

.code-editor {
    width: 100%;
    height: 100%;
    border: none;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 13px;
    padding: 1rem;
    background: #2d3748;
    color: #e2e8f0;
    resize: none;
    outline: none;
    line-height: 1.5;
    transition: background-color 0.3s ease;
}
.code-editor::placeholder { color: #a0aec0; }
.code-editor.highlight {
    background: #f39c12 !important;
    color: #2c3e50 !important;
}

/* ローディング */
.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.loading-spinner {
    width: 40px; height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* メッセージ */
.message-container {
    position: fixed;
    top: 100px; right: 20px;
    z-index: 10000;
    max-width: 300px;
}
.message {
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.message.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.message.error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

@media (max-width: 768px) {
    .editor-main { flex-direction: column; }
    .preview-section,
    .editor-section { flex: 1 1 auto; min-width: auto; }
    .editor-header { flex-direction: column; height: auto; min-height: 60px; }
}