*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #fff;
  --text: #1a1a1a;
  --muted: #666;
  --border: #d4d4d4;
  --surface: #f7f7f7;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --removed: #fef2f2;
  --removed-text: #b91c1c;
  --added: #f0fdf4;
  --added-text: #15803d;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Consolas", monospace;
}

[data-theme="dark"] {
  --bg: #121212;
  --text: #e8e8e8;
  --muted: #999;
  --border: #333;
  --surface: #1c1c1c;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --removed: #3f1a1a;
  --removed-text: #f87171;
  --added: #14301f;
  --added-text: #4ade80;
}

html {
  font-size: 14px;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

nav {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 24px;
}

nav a {
  padding: 12px 16px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

nav a:hover {
  color: var(--text);
}

nav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.theme-toggle {
  margin-left: auto;
  align-self: center;
  font-size: 12px;
  padding: 4px 10px;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

h1 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  font-weight: 600;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

button {
  font-family: inherit;
  font-size: inherit;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  background: var(--surface);
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.primary:hover {
  background: var(--accent-hover);
}

textarea,
input[type="text"] {
  font-family: var(--mono);
  font-size: 13px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  resize: vertical;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}

textarea:focus,
input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.panel label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 0.875rem;
}

.panel textarea {
  min-height: 360px;
}

.error-box {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  background: var(--removed);
  color: var(--removed-text);
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
}

.success-box {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #86efac;
  border-radius: 4px;
  background: var(--added);
  color: var(--added-text);
  font-size: 13px;
}

.diff-output {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 13px;
}

.diff-line {
  display: flex;
  padding: 2px 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-line .prefix {
  width: 20px;
  flex-shrink: 0;
  user-select: none;
  color: var(--muted);
}

.diff-line.removed {
  background: var(--removed);
  color: var(--removed-text);
}

.diff-line.added {
  background: var(--added);
  color: var(--added-text);
}

.diff-line.unchanged {
  background: var(--bg);
}

.diff-line.context {
  background: var(--surface);
  color: var(--muted);
}

.preview {
  min-height: 360px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: auto;
  background: var(--bg);
}

.preview h1,
.preview h2,
.preview h3,
.preview h4 {
  margin: 1em 0 0.5em;
  line-height: 1.3;
}

.preview h1 { font-size: 1.5rem; }
.preview h2 { font-size: 1.25rem; }
.preview h3 { font-size: 1.1rem; }

.preview p {
  margin: 0.5em 0;
}

.preview ul,
.preview ol {
  margin: 0.5em 0;
  padding-inline-start: 1.5em;
}

.preview code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
}

.preview pre {
  background: var(--surface);
  padding: 12px;
  border-radius: 4px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 13px;
}

.preview pre code {
  background: none;
  padding: 0;
}

.preview blockquote {
  margin: 0.5em 0;
  padding-inline-start: 12px;
  border-inline-start: 3px solid var(--border);
  color: var(--muted);
}

.preview a {
  color: var(--accent);
}

.preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.preview img {
  max-width: 100%;
}

.preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.95em;
}

.preview th,
.preview td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  vertical-align: top;
}

.preview th {
  background: var(--surface);
  font-weight: 600;
}

.preview.rtl {
  direction: rtl;
  text-align: right;
}

.preview.ltr {
  direction: ltr;
  text-align: left;
}

textarea.rtl {
  direction: rtl;
  text-align: right;
}

textarea.ltr {
  direction: ltr;
  text-align: left;
}

footer {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .panel-grid,
  .panel-grid-3 {
    grid-template-columns: 1fr;
  }
}
