/* ============ CSS Variables & Theme ============ */
:root {
    --bg: #f5f7fa; --card-bg: #ffffff; --text: #1a1a2e; --text-secondary: #6c757d;
    --primary: #0f4c75; --primary-hover: #0a3147; --border: #ced4da; --shadow: rgba(0,0,0,0.05);
    --danger: #c92a2a; --success: #1b7a4b; --warning-bg: #fff3cd;
    --radius: 12px;
}
.dark {
    --bg: #1a1a2e; --card-bg: #16213e; --text: #e6e6e6; --text-secondary: #a0a0b0;
    --primary: #4a8bb5; --primary-hover: #3a6b8f; --border: #2a3a4e;
    --shadow: rgba(0,0,0,0.2);
}

/* ============ Reset & Base ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); padding: 20px; transition: background 0.3s, color 0.3s; }
.container { max-width: 1000px; margin: 0 auto; }

/* ============ Header & Navigation ============ */
header { text-align: center; margin-bottom: 20px; position: relative; }
.site-title { font-size: 2rem; color: var(--primary); text-decoration: none; font-weight: 700; }
.site-subtitle { color: var(--text-secondary); margin-top: 4px; }
.theme-toggle { position: absolute; top: 0; right: 0; background: var(--card-bg); border: 1px solid var(--border); padding: 8px 12px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 6px; color: var(--text); }
nav { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 20px; }
nav a, nav button { background: var(--card-bg); border: 1px solid var(--border); padding: 8px 16px; border-radius: 20px; cursor: pointer; color: var(--text); font-size: 0.9rem; transition: all 0.2s; text-decoration: none; }
nav a.active, nav button.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ============ Cards (Homepage) ============ */
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin: 20px 0; }
.card { background: var(--card-bg); border-radius: var(--radius); padding: 24px; box-shadow: 0 4px 12px var(--shadow); text-decoration: none; color: var(--text); transition: transform 0.2s, box-shadow 0.2s; display: block; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--shadow); }
.card-icon { font-size: 2rem; margin-bottom: 12px; }
.card h3 { margin-bottom: 6px; color: var(--primary); }
.card p { color: var(--text-secondary); font-size: 0.9rem; }

/* ============ Tool Sections ============ */
.tool-section { background: var(--card-bg); border-radius: var(--radius); padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 12px var(--shadow); }
.tool-section h2 { margin-bottom: 12px; }
label { font-weight: 600; display: block; margin-bottom: 8px; }
textarea, input[type="text"], input[type="url"], select { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; font-family: monospace; background: var(--bg); color: var(--text); resize: vertical; }
.btn-group { display: flex; gap: 10px; margin: 15px 0; flex-wrap: wrap; }
button { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 8px; font-size: 1rem; cursor: pointer; transition: background 0.2s; display: inline-flex; align-items: center; gap: 6px; }
button:hover { background: var(--primary-hover); }
button.clear { background: var(--text-secondary); }
button.download { background: var(--success); }
button.small { padding: 6px 12px; font-size: 0.85rem; }

/* ============ File Drop Area ============ */
.file-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 30px; text-align: center; margin: 15px 0; transition: border-color 0.2s; cursor: pointer; }
.file-area:hover, .file-area.drag-over { border-color: var(--primary); background: rgba(0,0,0,0.02); }

/* ============ Preview ============ */
.preview-img { max-width: 200px; max-height: 200px; margin: 15px 0; border-radius: 8px; box-shadow: 0 2px 8px var(--shadow); }
.base64-preview { background: var(--bg); padding: 12px; border-radius: 8px; margin: 10px 0; word-break: break-all; font-family: monospace; font-size: 0.9rem; color: var(--text-secondary); }
.warning-text { color: var(--danger); font-size: 0.9rem; margin-top: 8px; }
.loading-text { color: var(--primary); font-size: 0.9rem; }
.output-card { background: var(--bg); border-radius: 8px; padding: 15px; margin: 10px 0; }

/* ============ Ad Placeholder ============ */
.ad-placeholder { background: var(--card-bg); border: 2px dashed var(--border); border-radius: var(--radius); padding: 20px; text-align: center; margin: 20px 0; color: var(--text-secondary); font-size: 0.9rem; }

/* ============ History Panel ============ */
.history-panel { position: fixed; right: 20px; top: 80px; width: 260px; max-height: 70vh; overflow-y: auto; background: var(--card-bg); border-radius: var(--radius); box-shadow: 0 8px 20px var(--shadow); padding: 15px; z-index: 100; display: none; }
.history-panel.open { display: block; }
.history-item { padding: 8px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 0.85rem; }
.history-item:hover { background: var(--bg); }
.close-btn { float: right; background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--text-secondary); }

/* ============ Modal ============ */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 200; justify-content: center; align-items: center; }
.modal.open { display: flex; }
.modal-content { background: var(--card-bg); border-radius: var(--radius); padding: 30px; max-width: 600px; width: 90%; max-height: 80vh; overflow-y: auto; position: relative; }
.modal-close { position: absolute; top: 10px; right: 15px; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); }

/* ============ Footer ============ */
footer { text-align: center; margin-top: 40px; padding: 20px; font-size: 0.85rem; color: var(--text-secondary); }
footer a { color: var(--primary); text-decoration: none; }
.note { font-size: 0.9rem; color: var(--text-secondary); margin-top: 10px; }

/* ============ Homepage Hero ============ */
.hero { text-align: center; padding: 20px 0 10px; }
.hero h2 { font-size: 1.6rem; color: var(--text); margin-bottom: 6px; }
.hero p { color: var(--text-secondary); }

/* ============ Markdown Preview ============ */
.markdown-split { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.markdown-preview-content { background: var(--bg); border-radius: 8px; padding: 16px; min-height: 200px; overflow-y: auto; }
.markdown-preview-content h1, .markdown-preview-content h2, .markdown-preview-content h3 { margin: 12px 0 6px; }
.markdown-preview-content p { margin-bottom: 8px; }
.markdown-preview-content code { background: var(--card-bg); padding: 2px 6px; border-radius: 4px; }
.markdown-preview-content pre { background: var(--card-bg); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }

/* ============ Result Bar ============ */
.result-bar { margin: 10px 0; padding: 8px 12px; border-radius: 6px; font-size: 0.9rem; display: none; }
.result-bar.success { display: block; background: #d3f9d8; color: #2b8a3e; }
.result-bar.error { display: block; background: #ffe0e0; color: #c92a2a; }

/* ============ Responsive ============ */
@media (max-width: 600px) {
    .card-grid { grid-template-columns: 1fr; }
    .markdown-split { grid-template-columns: 1fr; }
    .history-panel { right: 5px; width: 220px; }
}
