/* Reddit Markdown Editor - tool-specific styles. Composes shared
 * primitives in tools.css; only this tool's layout and the Reddit-styled
 * preview live here. */

:root {
    --rme-accent: #d93a00;
    --rme-accent-tint: #fff4ef;
    --rme-link: #0079d3;
    --rme-near: #d97706;
    --rme-over: #dc2626;
    --rme-border: #e6e8eb;
}

/* ---- Title row ---- */
.rme-top { margin-bottom: 12px; }
.rme-field-label { display: block; font-weight: 600; font-size: 0.92rem; color: #333; margin-bottom: 6px; }
.rme-field-opt { font-weight: 400; color: #94a3b8; font-size: 0.82rem; }
.rme-title-row { display: flex; align-items: center; gap: 10px; }
.rme-title-input { flex: 1 1 auto; min-width: 0; }
.rme-title-count { font-size: 0.82rem; color: #64748b; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rme-title-count.is-near { color: var(--rme-near); font-weight: 600; }
.rme-title-count.is-over { color: var(--rme-over); font-weight: 700; }

/* ---- Toolbar ---- */
.rme-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    margin-bottom: 12px;
    border: 1px solid var(--rme-border);
    border-radius: 10px;
    background: #f8fafc;
}
.rme-tb {
    font: inherit;
    font-size: 0.82rem;
    line-height: 1;
    padding: 8px 10px;
    border: 1px solid #d7dbe0;
    border-radius: 8px;
    background: #fff;
    color: #1f2937;
    cursor: pointer;
    min-width: 34px;
}
.rme-tb:hover { border-color: var(--rme-accent); color: var(--rme-accent); background: var(--rme-accent-tint); }
.rme-tb:focus-visible { outline: 2px solid var(--rme-accent); outline-offset: 1px; }
.rme-tb-bold { font-weight: 800; }
.rme-tb-italic { font-style: italic; font-family: Georgia, "Times New Roman", serif; }
.rme-tb-strike { text-decoration: line-through; }
.rme-tb-mono { font-family: SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 0.78rem; }

/* ---- Two-pane editor ---- */
.rme-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.rme-col { display: flex; flex-direction: column; min-width: 0; }
.rme-textarea {
    width: 100%;
    box-sizing: border-box;
    min-height: 320px;
    resize: vertical;
    line-height: 1.55;
    flex: 0 0 auto;
    font-family: SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.9rem;
    tab-size: 4;
}
.rme-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.rme-copy-btn { padding: 9px 18px; font-size: 0.92rem; }

.rme-preview-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 6px; }
.rme-preview-head .rme-field-label { margin-bottom: 0; }
.rme-mode { display: inline-flex; border: 1px solid #d7dbe0; border-radius: 999px; overflow: hidden; background: #fff; }
.rme-mode-btn {
    font: inherit;
    font-size: 0.78rem;
    padding: 6px 12px;
    border: 0;
    background: transparent;
    color: #475569;
    cursor: pointer;
}
.rme-mode-btn + .rme-mode-btn { border-left: 1px solid #d7dbe0; }
.rme-mode-btn.is-active { background: var(--rme-accent); color: #fff; }
.rme-mode-btn:focus-visible { outline: 2px solid var(--rme-accent); outline-offset: -2px; }

.rme-preview-card {
    flex: 1 1 auto;
    min-height: 320px;
    box-sizing: border-box;
    border: 1px solid var(--rme-border);
    border-radius: 10px;
    background: #fff;
    padding: 14px 16px;
    overflow: auto;
}
.rme-preview-meta { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: #64748b; margin-bottom: 8px; }
.rme-preview-meta strong { color: #1f2937; }
.rme-avatar { width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, #ff4500, #ffb000); display: inline-block; }
.rme-dot { color: #94a3b8; }
.rme-preview-title { font-size: 1.15rem; font-weight: 600; line-height: 1.3; margin: 0 0 10px; color: #1a1a1b; word-break: break-word; }
.rme-hint { font-size: 0.82rem; color: #94a3b8; margin: 8px 0 0; }

/* ---- Reddit-styled rendered content (preview + cheat-sheet samples) ---- */
.rme-preview {
    font-size: 0.92rem;
    line-height: 1.55;
    color: #1a1a1b;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.rme-preview > :first-child { margin-top: 0; }
.rme-preview > :last-child { margin-bottom: 0; }
.rme-preview p { margin: 0 0 0.9em; }
.rme-preview-empty { color: #94a3b8; }
.rme-preview h1, .rme-preview h2, .rme-preview h3, .rme-preview h4, .rme-preview h5, .rme-preview h6 { margin: 0.8em 0 0.4em; line-height: 1.25; font-weight: 700; color: #1a1a1b; }
.rme-preview h1 { font-size: 1.5rem; }
.rme-preview h2 { font-size: 1.3rem; }
.rme-preview h3 { font-size: 1.12rem; }
.rme-preview h4, .rme-preview h5, .rme-preview h6 { font-size: 1rem; }
.rme-preview a { color: var(--rme-link); text-decoration: underline; }
.rme-preview strong { font-weight: 700; }
.rme-preview del { color: #7c7c7c; }
.rme-preview sup { font-size: 0.72em; line-height: 0; vertical-align: super; }
.rme-preview code {
    font-family: SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.86em;
    background: #f6f7f8;
    border: 1px solid #edeff1;
    border-radius: 4px;
    padding: 1px 5px;
}
.rme-preview pre {
    background: #f6f7f8;
    border: 1px solid #edeff1;
    border-radius: 6px;
    padding: 10px 12px;
    margin: 0 0 0.9em;
    overflow-x: auto;
    white-space: pre;
}
.rme-preview pre code { background: none; border: 0; padding: 0; font-size: 0.84rem; line-height: 1.5; }
.rme-preview blockquote {
    margin: 0 0 0.9em;
    padding: 2px 0 2px 12px;
    border-left: 4px solid #c1c1c1;
    color: #4a4a4a;
}
.rme-preview blockquote > :last-child { margin-bottom: 0; }
.rme-preview ul, .rme-preview ol { margin: 0 0 0.9em; padding-left: 1.6em; }
.rme-preview li { margin: 0.15em 0; }
.rme-preview li > ul, .rme-preview li > ol { margin-bottom: 0; }
.rme-preview hr { border: 0; border-top: 1px solid #c1c1c1; margin: 1em 0; }
.rme-preview table { border-collapse: collapse; margin: 0 0 0.9em; max-width: 100%; }
.rme-preview th, .rme-preview td { border: 1px solid #c1c1c1; padding: 5px 10px; text-align: left; vertical-align: top; }
.rme-preview th { font-weight: 700; background: #f6f7f8; }
.rme-preview .md-spoiler {
    background: #1a1a1b;
    color: transparent;
    border-radius: 3px;
    padding: 0 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.rme-preview .md-spoiler .md-spoiler-text { visibility: hidden; }
.rme-preview .md-spoiler.is-revealed { background: #e9eaeb; color: inherit; }
.rme-preview .md-spoiler.is-revealed .md-spoiler-text { visibility: visible; }
.rme-preview .md-spoiler:focus-visible { outline: 2px solid var(--rme-accent); outline-offset: 1px; }

/* ---- Stats ---- */
.rme-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin: 18px 0 4px;
}
.rme-stat {
    background: #fff;
    border: 1px solid var(--rme-border);
    border-radius: 12px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.rme-stat-num { font-size: 1.6rem; font-weight: 800; line-height: 1.1; color: #1f2937; font-variant-numeric: tabular-nums; }
.rme-stat-num small { font-size: 0.85rem; font-weight: 500; color: #94a3b8; }
.rme-stat-label { font-size: 0.8rem; color: #64748b; }
.rme-stat-bar { display: block; height: 6px; border-radius: 999px; background: #eef2f7; overflow: hidden; margin-top: 4px; }
.rme-stat-bar i { display: block; height: 100%; background: var(--rme-accent); border-radius: 999px; transition: width 0.2s; }
.rme-stat.is-near .rme-stat-bar i { background: var(--rme-near); }
.rme-stat.is-near .rme-stat-num { color: var(--rme-near); }
.rme-stat.is-over .rme-stat-bar i { background: var(--rme-over); }
.rme-stat.is-over .rme-stat-num { color: var(--rme-over); }

/* ---- Cheat-sheet ---- */
.rme-sheet { margin: 28px 0 8px; }
.rme-sheet-heading { font-size: 1.35rem; font-weight: 700; margin: 0 0 6px; color: #1f2937; }
.rme-sheet-intro { color: #64748b; font-size: 0.92rem; margin: 0 0 14px; }
.rme-sheet-wrap { overflow-x: auto; border: 1px solid var(--rme-border); border-radius: 12px; background: #fff; }
.rme-sheet-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.rme-sheet-table th, .rme-sheet-table td { padding: 12px 14px; border-bottom: 1px solid var(--rme-border); vertical-align: top; text-align: left; font-size: 0.9rem; }
.rme-sheet-table thead th { background: #f8fafc; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: #64748b; }
.rme-sheet-table tbody tr:last-child th, .rme-sheet-table tbody tr:last-child td { border-bottom: 0; }
.rme-sheet-row:target { background: var(--rme-accent-tint); }
.rme-sheet-row:target .rme-sheet-what { box-shadow: inset 4px 0 0 var(--rme-accent); }
.rme-sheet-what { width: 16%; font-weight: 700; color: #1f2937; }
.rme-sheet-md { width: 30%; }
.rme-sheet-out { width: 28%; }
.rme-sheet-note { width: 26%; color: #475569; font-size: 0.85rem; }
.rme-anchor { color: inherit; text-decoration: none; }
.rme-anchor:hover { color: var(--rme-accent); text-decoration: underline; }
.rme-md-sample {
    margin: 0 0 8px;
    font-family: SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f6f7f8;
    border: 1px solid #edeff1;
    border-radius: 6px;
    padding: 8px 10px;
}
.rme-sample-out { font-size: 0.88rem; }
.rme-sample-out pre { margin-bottom: 0; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
    .rme-columns { grid-template-columns: 1fr; }
    .rme-textarea { min-height: 220px; }
    .rme-preview-card { min-height: 160px; }
    .rme-toolbar { gap: 5px; padding: 6px; }
    .rme-tb { padding: 7px 8px; font-size: 0.78rem; }
    .rme-title-row { flex-wrap: wrap; }
    .rme-sheet-table { min-width: 640px; }
}
@media (max-width: 420px) {
    .rme-stats { grid-template-columns: 1fr 1fr; }
    .rme-stat-num { font-size: 1.3rem; }
}
