:root {
  color-scheme: light;
  --bg: #f4f4f4;
  --fg: #333;
  --fg-muted: #666;
  --input-bg: #fff;
  --border: #ddd;
  --added-bg: #e6ffed;
  --added-fg: #22863a;
  --removed-bg: #ffeef0;
  --removed-fg: #cb2431;
  --modified-bg: #fff5b1;
  --modified-fg: #735c0f;
  --accent: #4CAF50;
  --accent-hover: #45a049;
  --clear-bg: #f0f0f0;
  --clear-fg: #666;
  --table-header-bg: #e9e9e9;
  --table-cell-bg: #fafafa;
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1e1e1e;
  --fg: #e0e0e0;
  --fg-muted: #999;
  --input-bg: #2d2d2d;
  --border: #444;
  --added-bg: #1e4620;
  --added-fg: #7ec787;
  --removed-bg: #4e2c2d;
  --removed-fg: #f9c9c9;
  --modified-bg: #5c4f1c;
  --modified-fg: #fff2b1;
  --accent: #388E3C;
  --accent-hover: #2e7d32;
  --clear-bg: #333;
  --clear-fg: #999;
  --table-header-bg: #2c2c2c;
  --table-cell-bg: #252525;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1e1e1e;
    --fg: #e0e0e0;
    --fg-muted: #999;
    --input-bg: #2d2d2d;
    --border: #444;
    --added-bg: #1e4620;
    --added-fg: #7ec787;
    --removed-bg: #4e2c2d;
    --removed-fg: #f9c9c9;
    --modified-bg: #5c4f1c;
    --modified-fg: #fff2b1;
    --accent: #388E3C;
    --accent-hover: #2e7d32;
    --clear-bg: #333;
    --clear-fg: #999;
    --table-header-bg: #2c2c2c;
    --table-cell-bg: #252525;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color .3s ease, color .3s ease;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--input-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 1rem; margin: 0; font-weight: 500; flex: 1; color: var(--fg-muted); }
.app-header .back { color: var(--fg); text-decoration: none; font-size: .9rem; }
.app-header .back:hover { color: var(--accent); }

.app-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.container {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}
.input-container, .result-container {
  flex: 1;
  position: relative;
  min-width: 0;
}
h2, h3 { color: var(--fg); }
.container h2 { font-size: 1rem; margin: 0 0 8px; }
.container h3 { font-size: .95rem; margin: 0 0 8px; color: var(--fg-muted); }
.section-heading { margin: 30px 0 12px; font-size: 1.2rem; }

textarea {
  width: 100%;
  height: 260px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
  background: var(--input-bg);
  color: var(--fg);
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: .92rem;
  line-height: 1.5;
}

.result-wrapper {
  border: 1px solid var(--border);
  background: var(--input-bg);
  border-radius: 6px;
  overflow-x: auto;
  min-height: 200px;
}
.result-text {
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: .92rem;
  line-height: 1.5;
}
.added { background: var(--added-bg); color: var(--added-fg); padding: 0 2px; border-radius: 2px; }
.removed { background: var(--removed-bg); color: var(--removed-fg); text-decoration: line-through; padding: 0 2px; border-radius: 2px; }
.modified { background: var(--modified-bg); color: var(--modified-fg); padding: 0 2px; border-radius: 2px; }

.copy-btn, .clear-btn, .download-btn {
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background-color .2s;
  font-family: inherit;
}
.copy-btn {
  position: absolute;
  top: 32px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  font-size: .8rem;
}
.copy-btn:hover { background: var(--accent-hover); }
.clear-btn {
  background: var(--clear-bg);
  color: var(--clear-fg);
  font-size: .85rem;
  margin-top: 8px;
}
.clear-btn:hover { opacity: .85; }

.text-info {
  margin-top: 8px;
  font-size: .82rem;
  color: var(--fg-muted);
  line-height: 1.7;
}

.download-btn {
  display: block;
  margin: 20px auto;
  background: var(--accent);
  color: #fff;
  font-size: .95rem;
  padding: 10px 22px;
}
.download-btn:hover { background: var(--accent-hover); }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  background: var(--input-bg);
}
th, td {
  border: 1px solid var(--border);
  padding: 10px;
  text-align: left;
  font-size: .9rem;
  word-break: break-word;
}
th { background: var(--table-header-bg); font-weight: 700; }
td { background: var(--table-cell-bg); }
td.added { background: var(--added-bg); color: var(--added-fg); }
td.removed { background: var(--removed-bg); color: var(--removed-fg); }
td.modified { background: var(--modified-bg); color: var(--modified-fg); }

.aligned-prose {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 32px;
  background: var(--input-bg);
  padding: 14px 18px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: .92rem;
  line-height: 1.75;
  color: var(--fg);
}
.aligned-prose .prose-header {
  font-family: var(--font-sans);
  font-size: .85rem;
  font-weight: 500;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 8px;
}
.aligned-prose .prose-row { display: contents; }
.aligned-prose .prose-cell {
  white-space: pre-wrap;
  word-break: break-word;
}
.aligned-prose.hide-matched .prose-row.matched { display: none; }

.alignment-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: .85rem;
  color: var(--fg-muted);
  margin-bottom: 10px;
}
.alignment-controls input[type="range"] { width: 160px; accent-color: var(--accent); }
.alignment-controls #simThresholdValue {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  min-width: 3.2em;
  color: var(--fg);
}
.alignment-controls .hint { font-size: .78rem; opacity: .8; }
.alignment-controls .toggle {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.alignment-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: .82rem;
  color: var(--fg-muted);
  margin: 4px 0 10px;
}
.alignment-legend .legend-item { display: inline-flex; align-items: center; gap: 6px; }
.alignment-legend strong { color: var(--fg); font-weight: 600; min-width: 1.5em; text-align: right; }
.alignment-legend .swatch {
  width: 12px; height: 12px; border-radius: 2px;
  border: 1px solid var(--border);
}
.alignment-legend .swatch.matched { background: var(--input-bg); }
.alignment-legend .swatch.modified { background: var(--modified-bg); }
.alignment-legend .swatch.removed { background: var(--removed-bg); }
.alignment-legend .swatch.added { background: var(--added-bg); }

table.aligned-diff.hide-matched tr.matched { display: none; }

.copy-message {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  display: none;
  z-index: 1000;
  font-size: .9rem;
}
.copy-message.show { display: block; }
.space {
  background: var(--clear-bg);
  padding: 0 4px;
  border-radius: 2px;
  font-size: .75em;
  color: var(--fg-muted);
  white-space: nowrap;
}

.wp-content {
  max-width: 880px;
  margin: 60px auto 0;
  padding: 0 4px;
  color: var(--fg-muted);
  line-height: 1.9;
}
.wp-content h2 {
  font-size: 1.15rem;
  color: var(--fg);
  margin: 32px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: left;
}
.wp-content h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.wp-content h3 { font-size: 1rem; margin: 20px 0 8px; color: var(--fg); text-align: left; }
.wp-content p { margin: 0 0 12px; }
.wp-content ul { padding-left: 1.4em; margin: 0 0 14px; }
.wp-content li { margin-bottom: 4px; }
.wp-content code { background: var(--clear-bg); padding: 1px 6px; border-radius: 3px; font-size: .88em; }
.wp-content .note { font-size: .85rem; opacity: .8; }

.owt-theme-toggle {
  position: fixed;
  top: 10px;
  right: 12px;
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(127, 127, 127, 0.4);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  color: #333;
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.owt-theme-toggle:hover { transform: translateY(-1px); border-color: rgba(127, 127, 127, 0.7); }
.owt-theme-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
:root[data-theme="dark"] .owt-theme-toggle {
  background: rgba(40, 40, 40, 0.85);
  color: #eee;
  border-color: rgba(200, 200, 200, 0.25);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .owt-theme-toggle {
    background: rgba(40, 40, 40, 0.85);
    color: #eee;
    border-color: rgba(200, 200, 200, 0.25);
  }
}
@media print { .owt-theme-toggle { display: none; } }


@media (max-width: 768px) {
  .container { flex-direction: column; gap: 14px; }
  textarea { height: 200px; }
  .app-wrapper { padding: 20px 14px 40px; }
  .copy-btn { top: 30px; right: 6px; }
  .app-header { padding-right: 56px; }

  .aligned-prose {
    column-gap: 12px;
    padding: 10px 12px;
    font-size: .82rem;
    line-height: 1.65;
  }

  .alignment-controls { gap: 8px; }
  .alignment-controls .toggle { margin-left: 0; }
  .alignment-controls .hint { width: 100%; }

  #diff-table { overflow-x: auto; }
  #diff-table table { font-size: .82rem; }
  #diff-table th:first-child,
  #diff-table td:first-child { display: none; }
}
