:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #c8d1dc;
  --text: #111827;
  --muted: #5b6675;

  --add-bg: #dff7e7;
  --del-bg: #ffe0e0;
  --add-bd: #1f8f3a;
  --del-bd: #c5222b;
  --same-bg: transparent;

  --guide: rgba(17, 24, 39, 0.06);

  --focus: rgba(37, 99, 235, 0.22);
  --accent: #2563eb;

  --shadow: 0 1px 0 rgba(17, 24, 39, 0.03), 0 8px 24px rgba(17, 24, 39, 0.06);
  --radius: 8px;
  --radius-sm: 7px;
  --header-h: 46px;
}

html[data-theme="dark"] {
  --bg: #0b0d12;
  --panel: #121623;
  --border: #2a3147;
  --text: #e6e8ef;
  --muted: #9aa3b2;

  --add-bg: rgba(46, 160, 67, 0.35);
  --del-bg: rgba(248, 81, 73, 0.35);
  --add-bd: rgba(46, 160, 67, 0.85);
  --del-bd: rgba(248, 81, 73, 0.85);
  --same-bg: transparent;

  --guide: rgba(255, 255, 255, 0.06);

  --focus: rgba(120, 160, 255, 0.28);
  --accent: #7aa0ff;

  --shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 12px 28px rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  min-height: var(--header-h);
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.02);
}

header .title {
  font-weight: 800;
  letter-spacing: 0.3px;
  font-size: 14px;
}

header .controls {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.app-desc {
  padding: 6px 14px 10px;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.95;
}

.controls label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.controls select,
.controls button {
  appearance: none;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  line-height: 1;
  height: 32px;
}

.controls select {
  padding-right: 28px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    linear-gradient(to right, transparent, transparent);
  background-position:
    calc(100% - 16px) 13px,
    calc(100% - 11px) 13px,
    0 0;
  background-size: 5px 5px, 5px 5px, 100% 100%;
  background-repeat: no-repeat;
}

.controls button {
  cursor: pointer;
  transition: transform 60ms ease, border-color 120ms ease, background 120ms ease;
}

.controls button:hover {
  border-color: color-mix(in oklab, var(--border), var(--text) 22%);
  background: color-mix(in oklab, var(--panel), var(--text) 3%);
}

.controls button:active {
  transform: translateY(1px);
}

.controls select:focus-visible,
.controls button:focus-visible,
.input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.wrap {
  padding: 12px 14px 16px;
}

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

.col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  min-height: 60vh;
  display: flex;
  flex-direction: column;
}

/* ===== Editor ===== */
.editor {
  display: grid;
  grid-template-columns: 44px 1fr;
  position: relative;
}

.lines {
  padding: 12px 6px 14px;
  border-right: 1px solid var(--border);
  text-align: right;

  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;

  color: var(--muted);
  user-select: none;
  white-space: pre;

  background: color-mix(in oklab, var(--panel), var(--text) 1%);
  opacity: 0.9;

  /* scroll sync */
  overflow: hidden;
}

html[data-theme="dark"] .lines {
  opacity: 0.75;
}

.lines span {
  display: block;
  line-height: 1.55em;
}

/* IMPORTANT: overlay container must be grid so grid-area works */
.pane {
  display: grid;
  position: relative;
  min-width: 0;
  /* allow horizontal scroll inside */
}

.highlight,
.input {
  grid-area: 1 / 1;
  margin: 0;
  padding: 12px 12px 14px;
  border: 0;
  border-radius: 0;
  width: 100%;

  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 4;
  white-space: pre;

  overflow-y: hidden;
  overflow-x: auto;

  background: transparent;
  min-height: 60vh;
}

.highlight {
  color: var(--text);
  pointer-events: none;
  z-index: 0;
  background:
    linear-gradient(transparent 30px,
      var(--guide) 31px,
      transparent 32px) 0 0 / 100% 1.55em repeat-y;
}

.input {
  color: transparent;
  caret-color: var(--text);
  outline: none;
  resize: none;
  z-index: 1;
}

.input::selection {
  background: var(--focus);
}

.same {
  background: var(--same-bg);
}

.add {
  background: var(--add-bg);
  box-shadow: inset 2px 0 0 var(--add-bd);
}

.del {
  background: var(--del-bg);
  box-shadow: inset 2px 0 0 var(--del-bd);
}

.footer {
  padding: 10px 14px 14px;
  font-size: 12px;
  color: var(--muted);
}

.footer a {
  color: var(--muted);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .col {
    min-height: 40vh;
  }
}
