:root {
    --bg: #0b0d10;
    --panel: #121722;
    --text: #e9eef7;
    --muted: #9fb0c6;
    --accent: #6aa7ff;
    --danger: #ff5c7a;
    --border: rgba(255, 255, 255, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* --- Layout --- */
.top {
    padding: 16px 16px 8px;
    border-bottom: 1px solid var(--border);
}

h1 {
    margin: 0 0 12px;
    font-size: 18px;
}

.grid {
    padding: 12px 16px 16px;
    width: 100%;
}

.view-content {
    display: none;
    width: 100%;
}

#editorView.active {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

#libraryView.active,
#syncView.active {
    display: block;
}

@media (max-width: 980px) {
    #editorView.active {
        grid-template-columns: 1fr;
    }
}

/* --- UI Consistency (Buttons & Inputs) --- */
/* タブ以外の全ての操作要素の高さを38pxに固定 */
#renderBtn,
.saveBtn,
.switch-label,
.controls button,
.controls input,
.transpose button,
#insertChordBtn,
.modal-actions button,
.btn {
    height: 38px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    font-size: 13px;
    font-weight: 600;
    border-radius: 12px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    padding: 0 16px;
    cursor: pointer;
}

/* --- Specific Button Designs --- */
#renderBtn {
    background: rgba(106, 167, 255, 0.05);
    color: var(--accent);
    border: 2px solid var(--accent) !important;
}

#renderBtn img {
    margin-right: 6px;
    filter: invert(67%) sepia(15%) saturate(3000%) hue-rotate(190deg) brightness(105%) contrast(105%);
}

#renderBtn:hover {
    background: var(--accent);
    color: #fff;
}

#renderBtn:hover img {
    filter: brightness(0) invert(1);
    transform: rotate(360deg);
}

.saveBtn {
    background: var(--accent) !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(106, 167, 255, 0.2);
}

.saveBtn:hover {
    background: #89b9ff !important;
    transform: translateY(-1px);
}

button:not(.saveBtn):not(#renderBtn):not(.tab-btn) {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}

/* --- Tabs --- */
.view-tabs {
    display: flex;
    gap: 8px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    height: 48px !important;
    background: transparent !important;
    border: none !important;
    border-bottom: 2px solid transparent !important;
    border-radius: 0 !important;
    color: var(--muted);
    padding: 0 20px;
    font-size: 14px;
    font-weight: 600;
}

.tab-btn.active {
    color: var(--accent) !important;
    border-bottom: 2px solid var(--accent) !important;
}

/* --- Panel & Controls Layout --- */
.controls,
.panel h2 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.transpose {
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 1px solid var(--border);
    padding-left: 12px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
}

.panel h2 {
    margin: 0 0 16px;
    font-size: 14px;
    color: var(--muted);
}

/* --- Toggle Switch --- */
.switch-label {
    background: rgba(255, 255, 255, 0.03);
    position: relative;
    padding-left: 42px !important;
}

.switch-label input {
    display: none;
}

.switch-label::before {
    content: "";
    position: absolute;
    left: 8px;
    width: 30px;
    height: 16px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    transition: 0.3s;
}

.switch-label::after {
    content: "";
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}

.switch-label:has(input:checked) {
    border-color: var(--accent) !important;
    background: rgba(106, 167, 255, 0.1);
}

.switch-label:has(input:checked)::before {
    background: var(--accent);
}

.switch-label:has(input:checked)::after {
    transform: translate(14px, -50%);
}

/* --- Lyrics Rendering (重要：ここが壊れていました) --- */
.lyrics {
    white-space: pre-wrap;
    line-height: 2.2;
    font-size: 16px;
    padding: 10px;
}

.line {
    display: block;
    margin-bottom: 1.2em;
    clear: both;
}

/* 行の崩れを防止 */
.unit {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin: 0 2px;
    vertical-align: bottom;
    position: relative;
}

.chord {
    font-weight: bold;
    color: var(--accent);
    font-size: 0.85em;
    min-height: 1.3em;
    font-family: 'Roboto Condensed', sans-serif;
}

/* --- Other Elements --- */
textarea {
    width: 100%;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, .02);
    color: var(--text);
    font-family: monospace;
}

.insert-chord {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

#insertChordText {
    height: 32px !important;
    width: 140px;
}

.chord-canvas-small {
    display: block;
    background: #fff;
    border-radius: 4px;
    margin-bottom: 2px;
}

.chord-popup {
    position: absolute;
    left: 50%;
    bottom: 100%;
    transform: translateX(-50%);
    display: none;
    z-index: 100;
    background: #111;
    padding: 8px;
    border: 1px solid var(--accent);
    border-radius: 10px;
}

.unit:hover .chord-popup {
    display: block;
}

.chord-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
}

.chord-item {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 15px;
    text-align: center;
}

.chord-item canvas {
    background: #fff;
    border-radius: 6px;
    width: 100%;
}

#jsonIO {
    width: 100%;
    min-height: 200px;
    background: #000;
    color: #4ade80;
    font-family: monospace;
    padding: 12px;
    border-radius: 8px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--panel);
    border: 1px solid var(--accent);
    padding: 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
}

/* --- PDF Export Styles --- */
/* PDF生成中のみ適用される強制スタイル */
/* --- PDF出力用スタイル (print-mode) --- */
.print-mode {
    background-color: #ffffff !important;
    color: #121722 !important;
    /* 真っ黒より少し高級感のある黒 */
    padding: 40px !important;
}

/* 歌詞のテキストを黒に */
.print-mode .lyrics,
.print-mode .unit {
    color: #121722 !important;
}

/* コード名を濃い青に（白背景で見やすい色） */
.print-mode .chord {
    color: #0044cc !important;
    text-shadow: none !important;
}

/* ダイヤグラム（Canvas）の背景を整える */
.print-mode .chord-canvas-small {
    background: #ffffff !important;
    border: 1px solid #eeeeee !important;
}

/* PDFに不要な要素（もしあれば）を隠す */
.print-mode .chord-popup {
    display: none !important;
}
.print-mode .line {
    page-break-inside: avoid;
    /* 行の途中でページが切れるのを防ぐ（ブラウザ依存あり） */
    break-inside: avoid;
    margin-bottom: 1.5em !important;
    /* PDFでは少し行間を広げて読みやすく */
}