body {
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background-color: #f4f4f4;
    margin: 0;
}

.container {
    background-color: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    max-width: 1020px;
    width: 94%;
    box-sizing: border-box;
}

h1 {
    text-align: center;
    margin-top: 8px;
    font-size: 1.4em;
}

.lead {
    color: #555;
    font-size: 0.95em;
    text-align: center;
    margin-top: 0;
}

.navigation-links {
    margin-bottom: 8px;
    font-size: 0.9em;
}

.navigation-links a {
    color: #007aff;
    text-decoration: none;
}

.navigation-links a:hover {
    text-decoration: underline;
}

code {
    background: #f0f0f0;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

details {
    margin: 12px 0;
}

details summary {
    cursor: pointer;
    font-weight: bold;
}

details ol {
    padding-left: 1.5em;
    line-height: 1.7;
}

.sr-only {
    position: absolute;
    left: -9999px;
}

/* ===== レイアウト ===== */

.editor {
    display: flex;
    gap: 20px;
    margin: 16px 0;
    align-items: flex-start;
}

@media (max-width: 860px) {
    .editor {
        flex-direction: column;
    }

    .side-pane {
        width: 100%;
    }
}

.edit-pane {
    flex: 11;
    min-width: 0;
}

.side-pane {
    flex: 9;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.board-wrap {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
}

#editorSvg {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    box-shadow: 0 0 0 1px #e0e0e0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#editorSvg .q-point {
    cursor: grab;
}

.status {
    min-height: 1.3em;
    font-size: 0.82em;
    color: #007aff;
    margin: 6px 0;
    text-align: center;
}

/* ===== パネル共通 ===== */

.panel {
    background: #f7f7f7;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.tb-label {
    font-size: 0.85em;
    font-weight: bold;
    color: #555;
}

.small-btn {
    padding: 4px 10px;
    font-size: 0.85em;
}

button.danger {
    background-color: #d64545;
}

button.danger:hover:not(:disabled) {
    background-color: #b53030;
}

/* ===== 点エディタ ===== */

.point-editor fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

.point-editor fieldset:disabled {
    opacity: 0.5;
}

.pe-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.pe-row label {
    font-size: 0.85em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.pe-row input[type="text"],
.pe-row input[type="number"],
.pe-row select {
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95em;
    background: #fff;
}

.pe-row input[type="number"] {
    width: 4.5em;
}

.pe-row input[type="color"] {
    width: 30px;
    height: 24px;
    padding: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}

.pe-hint {
    font-size: 0.78em;
    color: #888;
    margin: 4px 0 0;
}

/* ===== レイヤーパネル ===== */

.layer-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
    border-bottom: 1px solid #e6e6e6;
    font-size: 0.85em;
}

.layer-row:last-child {
    border-bottom: none;
}

.layer-row .chk {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.layer-row .layer-name {
    font-weight: bold;
    width: 8.5em;
    flex-shrink: 0;
}

.layer-row input[type="color"] {
    width: 30px;
    height: 24px;
    padding: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}

.layer-row input[type="range"] {
    width: 110px;
}

.opacity-val {
    min-width: 3em;
    color: #666;
}

.layer-hint {
    font-size: 0.9em;
    color: #888;
}

button.ghost {
    background-color: #8e8e93;
}

button.ghost:hover:not(:disabled) {
    background-color: #6d6d72;
}

#editorSvg.drop-target {
    box-shadow: 0 0 0 2px #007aff;
}

/* ===== 画像ギャラリー ===== */

.upload-label {
    display: inline-block;
    background-color: #007aff;
    color: white;
    border-radius: 6px;
    cursor: pointer;
}

.upload-label:hover {
    background-color: #005bbf;
}

.image-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 30px;
}

.gallery-empty {
    font-size: 0.8em;
    color: #888;
    margin: 4px 0;
}

.image-thumb {
    position: relative;
    width: 56px;
    text-align: center;
    cursor: grab;
}

.image-thumb.dragging {
    opacity: 0.4;
}

.image-thumb img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #ccc;
    display: block;
    margin: 0 auto;
}

.image-thumb:hover img {
    border-color: #007aff;
}

.image-thumb .thumb-name {
    font-size: 0.65em;
    color: #666;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-thumb .thumb-del {
    position: absolute;
    top: -6px;
    right: 0;
    width: 18px;
    height: 18px;
    padding: 0;
    font-size: 11px;
    line-height: 1;
    border-radius: 50%;
    background: #999;
}

.image-thumb .thumb-del:hover {
    background: #d64545;
}

/* ===== ラベル入力 ===== */

.labels-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.labels-editor input[type="text"] {
    padding: 5px 7px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
    background: #fff;
    min-width: 0;
}

.lbl-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
}

.lbl-row input {
    flex: 1;
}

.axis-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.axis-row .axis-name {
    font-size: 0.85em;
    font-weight: bold;
    color: #555;
    width: 2.8em;
    flex-shrink: 0;
}

.axis-row input {
    flex: 1;
    width: 100%;
}

.arrow-sep {
    color: #888;
    flex-shrink: 0;
}

.quad-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

/* ===== コード入力 ===== */

.input-area {
    min-width: 0;
}

.input-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 12px;
    flex-wrap: wrap;
}

.input-label {
    font-weight: bold;
    font-size: 0.95em;
}

.sample-label {
    font-size: 0.85em;
    color: #555;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sample-label select {
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
    background: white;
}

textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.85em;
    line-height: 1.5;
    resize: vertical;
}

textarea:focus {
    outline: none;
    border-color: #007aff;
}

.input-meta {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
    font-size: 0.85em;
    min-height: 1.2em;
}

.input-meta .error {
    color: #c0392b;
    font-weight: bold;
}

.code-buttons,
.download-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.download-buttons {
    justify-content: center;
}

button {
    padding: 8px 14px;
    cursor: pointer;
    border: none;
    border-radius: 6px;
    background-color: #007aff;
    color: white;
    font-size: 0.9em;
    transition: background-color 0.2s;
}

button:hover:not(:disabled) {
    background-color: #005bbf;
}

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

#downloadSvgBtn {
    background-color: #34c759;
}

#downloadSvgBtn:hover:not(:disabled) {
    background-color: #28a745;
}

/* ===== Mermaid プレビュー ===== */

.mermaid-preview .preview-box {
    width: 100%;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px;
    box-sizing: border-box;
    overflow: auto;
    margin-top: 8px;
}

.preview-box svg {
    max-width: 100%;
    height: auto;
}

.preview-box .placeholder,
.preview-box .render-error {
    color: #888;
    font-size: 0.9em;
    text-align: center;
    margin: 0;
}

.preview-box .render-error {
    color: #c0392b;
}

/* ===== リファレンス ===== */

.ref-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85em;
    margin-top: 8px;
}

.ref-table th,
.ref-table td {
    border: 1px solid #e0e0e0;
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}

.ref-table th {
    background: #f7f7f7;
}

.note {
    font-size: 0.85em;
    color: #666;
    margin-top: 10px;
}

/* ===== theme (skin) overrides — chrome のみ token 化。エディタ図とプレビュー SVG は
   可読性のため据置（var は /css/theme.css 由来） ===== */
body { background-color: var(--color-bg-base); color: var(--color-fg-primary); }
.container { background-color: var(--color-bg-surface); box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); }
.lead { color: var(--color-fg-muted); }
.navigation-links a { color: var(--color-accent); }
code { background: var(--color-bg-elevated); color: var(--color-fg-primary); }
.panel { background: var(--color-bg-elevated); }
.tb-label, .axis-row .axis-name { color: var(--color-fg-muted); }
.pe-row input[type="text"], .pe-row input[type="number"], .pe-row select,
.labels-editor input[type="text"], textarea, .sample-label select {
    background: var(--color-bg-surface);
    color: var(--color-fg-primary);
    border-color: var(--color-border-base);
}
.status { color: var(--color-fg-muted); }
.pe-hint, .gallery-empty, .image-thumb .thumb-name { color: var(--color-fg-muted); }
.layer-row { border-color: var(--color-border-base); }
.layer-hint, .opacity-val { color: var(--color-fg-muted); }
.layer-row input[type="color"] { border-color: var(--color-border-base); background: var(--color-bg-surface); }
.input-meta { color: var(--color-fg-muted); }
button, .upload-label { background-color: var(--color-accent); color: var(--color-accent-fg); }
.ref-table th, .ref-table td { border-color: var(--color-border-base); }
.ref-table th { background: var(--color-bg-elevated); color: var(--color-fg-primary); }
.note { color: var(--color-fg-muted); }
#editorSvg { box-shadow: 0 0 0 1px var(--color-border-base); }
