* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    padding: 20px;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

input, button, select, textarea {
    touch-action: manipulation;
}

.container {
    margin: 0 auto;
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.main-layout {
    display: grid;
    grid-template-columns: minmax(300px, 450px) 1fr;
    gap: 30px;
    margin-top: 20px;
}

.left-panel {
    min-width: 0;
    max-width: 450px;
}

.right-panel {
    min-width: 0;
}

h1 {
    color: #333;
    margin-bottom: 10px;
    text-align: center;
}

.service-description {
    text-align: center;
    color: #666;
    font-size: 0.95em;
    line-height: 1.6;
    margin-bottom: 25px;
    padding: 0 20px;
}

h2 {
    color: #555;
    margin: 20px 0 15px;
    border-bottom: 2px solid #4CAF50;
    padding-bottom: 5px;
}

h3 {
    color: #666;
    margin: 10px 0;
    font-size: 1.1em;
}

.input-section, .options-section, .preview-section, .export-section, .split-section {
    margin-bottom: 30px;
}

.input-section {
    background: #fafafa;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 2px solid #4CAF50;
}

.tab-btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: #666;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
    font-size: 1em;
    position: relative;
}

.tab-btn:hover {
    background: #f5f5f5;
    color: #333;
}

.tab-btn.active {
    background: white;
    color: #4CAF50;
    border-bottom-color: #4CAF50;
    font-weight: 600;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: white;
}

.tab-content {
    display: none;
    padding: 20px;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 5px 5px;
}

.tab-content.active {
    display: block;
}

input[type="file"] {
    display: block;
    margin-bottom: 15px;
    padding: 10px;
    border: 2px dashed #ddd;
    border-radius: 5px;
    width: 100%;
}

#sgf-list {
    margin-top: 15px;
}

.sgf-item {
    padding: 10px;
    margin: 5px 0;
    background: #f9f9f9;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
}

.sgf-item:hover {
    background: #e8f5e9;
}

.sgf-item.selected {
    background: #c8e6c9;
    border-left: 4px solid #4CAF50;
}

textarea {
    width: 100%;
    min-height: 150px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-family: monospace;
    margin-bottom: 10px;
}

.option-group {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
}

.option-group.collapsible {
    padding: 0;
    overflow: hidden;
}

.option-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    cursor: pointer;
    user-select: none;
    transition: background 0.3s;
}

.option-header:hover {
    background: #f0f0f0;
}

.option-header h3 {
    margin: 0;
    flex: 1;
}

.collapse-icon {
    font-size: 0.8em;
    transition: transform 0.3s;
    color: #666;
}

.option-group.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.option-content {
    padding: 0 15px 15px 15px;
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s;
}

.option-group.collapsed .option-content {
    max-height: 0;
    padding: 0 15px;
}

label {
    display: inline-block;
    margin: 10px 15px 10px 0;
    color: #555;
}

input[type="number"], select {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 3px;
    margin-left: 5px;
}

input[type="number"] {
    width: 80px;
}

select {
    min-width: 150px;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
    background: #2196F3;
    color: white;
}

button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.primary-btn {
    background: #4CAF50;
    font-size: 1.1em;
    padding: 15px 30px;
}

#preview-canvas {
    border: 1px solid #ddd;
    border-radius: 5px;
    max-width: 100%;
    display: block;
    margin: 0 auto;
    background: white;
}

.preview-info {
    margin-top: 10px;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 5px;
    font-size: 0.9em;
    color: #666;
}

.export-section {
    display: flex;
    gap: 15px;
    justify-content: center;
}

/* タブレット・スマートフォン対応 */
@media (max-width: 1024px) {
    .main-layout {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }
    
    .left-panel,
    .right-panel {
        display: contents;
    }
    
    /* スマホでの表示順序 */
    .input-section {
        order: 1;
    }
    
    .preview-section {
        order: 2;
    }
    
    .export-section {
        order: 3;
    }
    
    .options-section {
        order: 4;
    }
    
    .split-section {
        order: 5;
    }
    
    .container {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 15px;
    }
    
    h1 {
        font-size: 1.5em;
        margin-bottom: 8px;
    }
    
    .service-description {
        font-size: 0.85em;
        margin-bottom: 15px;
        padding: 0 10px;
    }
    
    h2 {
        font-size: 1.2em;
        margin: 15px 0 10px;
    }
    
    h3 {
        font-size: 1em;
    }
    
    label {
        display: block;
        margin: 10px 0;
    }
    
    /* 数値入力以外の通常の入力フィールド */
    input[type="number"]:not(.number-input-group input[type="number"]), 
    select {
        width: 100%;
        max-width: 200px;
        margin-left: 0;
        margin-top: 5px;
        padding: 10px;
        font-size: 1em;
    }
    
    /* チェックボックスのラベル */
    label:has(input[type="checkbox"]) {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 0;
    }
    
    input[type="checkbox"] {
        width: 20px;
        height: 20px;
        cursor: pointer;
    }
    
    .tab-btn {
        font-size: 0.95em;
        padding: 10px 15px;
    }
    
    /* プレビューセクションをコンパクトに */
    .preview-section {
        margin-top: 0;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
    }
    
    .preview-section h2 {
        margin-top: 0;
        margin-bottom: 5px;
        order: 1;
    }
    
    .preview-info {
        order: 2;
        font-size: 0.8em;
        padding: 4px 6px;
        background: #f0f0f0;
        border-radius: 5px;
        margin-bottom: 5px;
        line-height: 1.4;
    }
    
    #preview-canvas {
        order: 3;
        max-width: 100%;
        height: auto;
        margin-bottom: 0;
    }
    
    /* エクスポートボタンをコンパクトに盤面側に寄せる */
    .export-section {
        display: flex;
        gap: 6px;
        margin-top: -10px;
        margin-bottom: 5px;
        justify-content: flex-start;
    }
    
    .export-section button {
        flex: 0 1 auto;
        padding: 8px 12px;
        font-size: 0.85em;
        white-space: nowrap;
    }
    
    .primary-btn {
        padding: 8px 12px;
        font-size: 0.85em;
    }
    
    /* JSONボタンを非表示 */
    #export-json {
        display: none;
    }
    
    /* 表示オプションのマージンを詰める */
    .options-section {
        margin-top: 5px;
        margin-bottom: 10px;
    }
    
    .options-section h2 {
        margin-top: 0;
        margin-bottom: 8px;
    }
    
    /* 手数表示範囲セクションのマージンを調整 */
    .option-group.collapsible:first-child {
        margin-bottom: 8px;
    }
    
    button:not(.number-btn):not(.export-section button) {
        width: 100%;
        margin-bottom: 10px;
        padding: 14px 20px;
        font-size: 1em;
    }
    
    .option-group {
        padding: 10px;
    }
    
    /* 譜分けボタンを縦並びに */
    #split-options > div[style*="display: flex"] {
        flex-direction: column !important;
    }
    
    #split-options button {
        width: 100%;
    }
    
    /* サムネイルを小さく */
    #split-thumbnails-container canvas {
        max-width: 150px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.3em;
    }
    
    .option-group {
        padding: 8px;
        margin-bottom: 10px;
    }
    
    input[type="number"], select {
        max-width: 100%;
    }
    
    #split-thumbnails-container canvas {
        max-width: 120px;
    }
}

/* 譜分けサムネイル */
#split-thumbnails {
    background: #fff;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

#split-thumbnails h4 {
    color: #666;
    font-size: 1em;
    margin-bottom: 10px;
}

#split-thumbnails-container {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

#split-thumbnails-container canvas {
    border: 1px solid #ccc;
    max-width: 200px;
    cursor: pointer;
    transition: all 0.3s;
}

#split-thumbnails-container canvas:hover {
    border-color: #4CAF50;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
    transform: scale(1.05);
}

/* フッター */
.site-footer {
    margin-top: 50px;
    padding-top: 30px;
    border-top: 1px solid #ddd;
    text-align: center;
    color: #666;
    font-size: 0.9em;
}

.site-footer p {
    margin: 5px 0;
}

.site-footer a {
    color: #4CAF50;
    text-decoration: none;
    transition: opacity 0.3s;
}

.site-footer a:hover {
    opacity: 0.7;
    text-decoration: underline;
}

/* 数値入力コントロール */
.number-control {
    margin: 15px 0;
}

.number-control > label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.number-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.number-input-group input[type="number"] {
    flex: 1;
    max-width: 150px;
    padding: 12px 16px;
    font-size: 1.1em;
    text-align: center;
    border: 2px solid #ddd;
    border-radius: 5px;
    transition: border-color 0.3s;
}

.number-input-group input[type="number"]:focus {
    outline: none;
    border-color: #4CAF50;
}

.number-btn {
    width: 45px;
    height: 45px;
    padding: 0;
    font-size: 1.5em;
    font-weight: bold;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.number-btn-small {
    width: 50px;
    font-size: 0.85em;
    background: #64B5F6;
}

.number-btn-small:hover {
    background: #42A5F5;
}

.number-btn:hover {
    background: #1976D2;
    transform: scale(1.05);
}

.number-btn:active {
    transform: scale(0.95);
}

/* スマホ対応 */
@media (max-width: 768px) {
    .number-control > label {
        font-size: 0.95em;
    }
    
    .number-input-group {
        gap: 4px;
    }
    
    .number-input-group input[type="number"] {
        padding: 10px 8px;
        font-size: 1em;
        max-width: none;
        min-width: 60px;
    }
    
    .number-btn {
        width: 42px;
        height: 42px;
        font-size: 1.4em;
        border-radius: 8px;
    }
    
    .number-btn-small {
        width: 46px;
        font-size: 0.75em;
    }
}
