:root {
  --primary-color: #4a90e2;
  --secondary-color: #50e3c2;
  --accent-color: #f5a623;
  --danger-color: #d0021b;
  --light-color: #f8f9fa;
  --dark-color: #343a40;
  --text-color: #495057;
  --bg-color: #f8f9fa;
  --card-bg-color: #ffffff;
  --border-color: #dee2e6;
  --shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  --border-radius: 12px;
}

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

body {
  font-family: 'Noto Sans JP', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

/* ヘッダー */
.title-container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  margin-bottom: 30px;
}

h1 {
  font-size: 2.2em;
  color: var(--dark-color);
  font-weight: 700;
}

#help-button {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background-color: var(--secondary-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: var(--shadow);
  transition: background-color 0.3s ease;
  padding: 0; /* Ensure padding is reset */
}

#help-button:hover {
  background-color: #27ae60;
}

/* カードスタイル */
.card {
  background: var(--card-bg-color);
  padding: 25px;
  border-radius: var(--border-radius);
  margin-bottom: 25px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
}

.card h3 {
  margin-top: 0;
  margin-bottom: 15px;
  color: var(--dark-color);
  font-size: 1.2em;
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 8px;
}

/* フォーム要素 */
input[type="text"],
textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  font-size: 1em;
  font-family: 'Noto Sans JP', sans-serif;
  transition: border-color 0.3s, box-shadow 0.3s;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.control-group label {
  font-weight: 700;
  flex-basis: 80px;
}

/* ボタン */
button {
  padding: 12px 24px;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 1em;
  font-weight: 700;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
  letter-spacing: 0.5px;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}
.btn-primary:hover { background-color: #2980b9; }

.btn-secondary {
  background-color: var(--secondary-color);
  color: white;
}
.btn-secondary:hover { background-color: #27ae60; }

.remove-section {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
  color: #95a5a6;
}

.remove-section:hover {
  background-color: #f2f2f2;
  color: var(--danger-color);
}

.btn-danger {
  background-color: var(--danger-color);
  color: white;
}
.btn-danger:hover { background-color: #c0392b; }

.btn-light {
    background-color: var(--light-color);
    color: var(--dark-color);
    border: 1px solid var(--border-color);
}
.btn-light:hover { background-color: #bdc3c7; }

.io-buttons,
.transpose-controls,
.button-group {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.button-group {
    justify-content: center;
    margin-top: 30px;
}

/* テキスト入出力 */
#text-io {
  height: 250px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  resize: vertical;
}

/* 移調 */
.transpose-controls {
  align-items: center;
  justify-content: center;
}

.transpose-controls button {
  min-width: 44px;
  width: 44px;
  height: 44px;
  font-size: 1.5em;
  background-color: var(--dark-color);
  color: white;
}

#transpose-display {
  font-size: 2em;
  font-weight: 700;
  min-width: 50px;
  text-align: center;
  color: var(--primary-color);
}

/* メモセクション */
.memo-preview {
    margin: 20px 0;
    padding: 15px;
    background-color: #f9f9f9;
    border-left: 4px solid var(--primary-color);
    white-space: pre-wrap; /* 改行をそのまま表示 */
    font-size: 1rem;
    line-height: 1.6;
}

.memo-section .section-header .section-name {
    font-weight: bold;
    color: var(--primary-color);
}

.memo-input-area {
    width: 100%;
    min-height: 100px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
}

/* セクション */
.section {
  border: 1px solid var(--border-color);
  padding: 25px;
  border-radius: var(--border-radius);
  margin-bottom: 25px;
  background-color: var(--card-bg-color);
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.section:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  transform: translateY(-3px);
}

.section-header {
    display: flex;
    /* justify-content: space-between; */
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.drag-handle {
    cursor: grab;
    color: var(--text-color-light);
}

.drag-handle:active {
    cursor: grabbing;
}

.sortable-ghost {
    opacity: 0.4;
    background: #c8ebfb;
}

.section-name {
    flex-grow: 1;
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    background: transparent;
    padding: 5px;
}

.section-header .section-name {
    flex-grow: 1;
}

.section-header .remove-section {
    margin-left: auto;
  transition: all 0.3s ease;
}

.drag-handle {
    cursor: grab;
    color: #b0b0b0;
    margin-right: 4px;
}

.drag-handle:active {
    cursor: grabbing;
}

.collapse-icon {
    color: #95a5a6;
    transition: transform 0.2s ease-in-out;
    margin-right: 8px;
}

.section.collapsed .rows {
    display: none;
}

.section.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.section-name:hover {
  border-color: #e9ecef;
}

.section-name:focus {
  outline: none;
  border-color: var(--primary-color);
  background-color: white;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
}

/* 行 */
.row {
  margin-bottom: 15px;
  border: 1px solid #e9ecef;
  border-radius: var(--border-radius);
  padding: 20px;
  background: #fdfdfd;
  position: relative;
}

.row-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}

.bar-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-input, .memo-input {
  font-family: 'Courier New', monospace;
}

.bar-input {
  font-weight: bold;
  font-size: 1.1em;
}

.memo-input {
  font-size: 0.9em;
  color: #555;
}

.add-row {
    margin-top: 15px;
}

/* モーダル */
.modal {
  display: none; 
  position: fixed; 
  z-index: 1000; 
  left: 0;
  top: 0;
  width: 100%; 
  height: 100%; 
  overflow: auto; 
  background-color: rgba(0,0,0,0.6); 
}

.modal-content {
  background-color: var(--card-bg-color);
  margin: 8% auto; 
  padding: 40px;
  border: none;
  width: 90%; 
  max-width: 700px;
  border-radius: var(--border-radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  position: relative;
  animation: modal-fade-in 0.3s;
}

@keyframes modal-fade-in {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.close-button {
  color: #aaa;
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 36px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.3s;
}

.close-button:hover,
.close-button:focus {
  color: var(--dark-color);
  text-decoration: none;
}

.modal h2 {
  margin-top: 0;
  color: var(--dark-color);
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 10px;
  margin-bottom: 25px;
}

.modal h3 {
  color: var(--dark-color);
  margin-top: 25px;
  margin-bottom: 10px;
}

.modal p, .modal ul {
  line-height: 1.8;
  color: var(--text-color);
}

.modal ul {
  padding-left: 20px;
}

.modal li {
  margin-bottom: 12px;
}

.modal pre {
  background-color: var(--light-color);
  padding: 15px;
  border-radius: var(--border-radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  border: 1px solid var(--border-color);
  font-size: 0.9em;
}

/* プレビュー画面 */
.preview-view {
  background: var(--card-bg-color);
  padding: 20px;
}

.preview-header {
  margin-bottom: 20px;
}

.back-button {
  background: var(--dark-color);
  color: white;
  border: none;
  padding: 12px 25px;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 1em;
}

/* コード譜レイアウト（印刷に最適化） */
.chord-chart {
  font-family: 'Arial', sans-serif;
  max-width: 800px;
  margin: 0 auto;
}

.chart-title {
  text-align: center;
  font-size: 16pt;
  font-weight: bold;
  margin-bottom: 8mm;
}

.chart-section {
  page-break-inside: avoid;
  margin-bottom: 0;
}

.chart-row-group {
  margin-bottom: 2mm;
}

/* セクション間に区切り線を追加 (印刷時は非表示) */
.chart-section + .chart-section {
  border-top: 1.5pt solid #000;
  margin-top: 5mm;
  padding-top: 5mm;
}
@media print {
  .chart-section + .chart-section {
    border-top: none !important;
  }
}

/* 奇数行の背景色を変更して視認性を向上 */
.chart-row-group:nth-child(odd) {
  background-color: #f5f5f5;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.chart-row {
  display: table;
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.row-label {
  display: table-cell;
  font-size: 10pt;
  font-weight: bold;
  width: 15mm;
  vertical-align: middle;
  padding: 4px 8px;
  text-align: left;
}

.bars-row {
  display: table-cell;
}

.bars-table {
  display: table;
  width: 100%;
  border-collapse: collapse;
  border-left: 0.5pt solid #000;
}

.bar-cell {
  display: table-cell;
  width: 25%;
  border-right: 0.5pt solid #000;
  vertical-align: top;
  position: relative;
}

.chord-content {
  font-size: 14pt;
  font-weight: bold;
  padding: 1mm 1mm 0.5mm;
  display: flex;
  align-items: baseline;
  min-height: 24px;
}

.chord-content span {
  flex: 1;
  text-align: left;
  padding-left: 5px;
}

.memo-content {
  font-size: 8pt;
  color: #333;
  padding: 0.5mm;
  text-align: left;
  border-top: 0.5pt solid #000;
  min-height: 20px;
}

/* 改ページインジケーター */
.page-break-indicator {
    display: none !important; /* 印刷時に非表示 */
}


.row-controls {
    display: flex;
    align-items: center;
    width: 100%;
}

.row-drag-handle {
    cursor: grab;
    color: #b0b0b0;
    margin-right: 10px;
}

.row-drag-handle:active {
    cursor: grabbing;
}

.remove-row {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-left: 10px;
    color: #ccc;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.2s;
}

.row:hover .remove-row {
    visibility: visible;
    opacity: 1;
}

.remove-row:hover {
    color: var(--danger-color);
}


.chord-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 8px;
    background-color: #fff;
    border: 1px solid var(--border-color);
}

.row-drag-handle {
    cursor: grab;
    color: #b0b0b0;
    margin-right: 10px;
}

.row-drag-handle:active {
    cursor: grabbing;
}

.row-inputs {
    display: flex;
    flex-grow: 1;
    gap: 10px;
}

.row-buttons {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 10px;
}

.row-buttons button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
    color: #95a5a6;
}

.row-buttons button:hover {
    background-color: #f2f2f2;
    color: var(--dark-color);
}

.row-buttons .remove-row:hover {
    color: var(--danger-color);
}

/* 印刷用スタイル */
@media print {
  @page {
      size: A4;
      margin: 15mm;
  }
  
  body {
      background: white;
      margin: 0;
      padding: 0;
  }
  
  .container {
      max-width: 100%;
      padding: 0;
  }
  
  .editor-view,
  .no-print,
  .page-break-indicator {
      display: none !important;
  }
  
  .preview-view {
      display: block !important;
      padding: 0;
      background: none;
      box-shadow: none;
      border: none;
  }
  
  .chord-chart {
      max-width: 100%;
  }
}

.hidden {
  display: none;
}

/* ----- 画像挿入機能 ----- */
.section-name-input {
    flex-grow: 1;
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    background: transparent;
    padding: 5px;
    margin-left: 4px;
    color: var(--dark-color);
}

.section-name-input:focus {
    outline: none;
    background: #f0f0f0;
    border-radius: 4px;
}

.image-section .rows {
    padding: 15px;
}

.image-input {
    margin-bottom: 15px;
    width: 100%;
    font-size: 1rem;
}

.image-preview-container {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 10px;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fafafa;
    margin-top: 10px;
}

.image-preview {
    max-width: 100%;
    max-height: 400px;
    display: none; /* Initially hidden */
    object-fit: contain;
}

.chart-image-container {
    width: 100%;
    margin: 20px 0;
    page-break-inside: avoid;
    text-align: center; /* Center the image */
}

.chart-image-container img {
    max-width: 100%;
    height: auto;
    border: 1px solid #ccc;
}

@media print {
    .chart-image-container img {
        max-height: 240mm; /* A4 height minus margins */
    }
}

