:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #faf7f0;
  --ink: #1d1c1a;
  --ink-soft: #5e5a52;
  --ink-faint: #8f8a80;
  --line: #e2dccf;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --changed: #ffe68a;
  --changed-ink: #3e2e00;
  --error: #b0413e;
  --ok: #3b8f5a;
  --radius: 14px;
  --font: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1d2024;
    --surface-2: #22262b;
    --ink: #ebe8e1;
    --ink-soft: #b4afa5;
    --ink-faint: #7f7a71;
    --line: #2e3238;
    --accent: #5fb094;
    --accent-ink: #0d1a15;
    --changed: #7a5c00;
    --changed-ink: #fff2bf;
    --error: #e07a76;
    --ok: #6fc48c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* --- Topprad -------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: 4px 4px 0 0 color-mix(in srgb, var(--accent) 35%, transparent);
  flex: 0 0 auto;
}

h1 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* Reglaget: hur mycket AI:n får ändra. */
.level {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.level label { font-weight: 600; }

.level input[type="range"] {
  width: 130px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

.level-name {
  display: inline-block;
  min-width: 3.6em;
  padding: 2px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 700;
  text-align: center;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: 0 0 auto;
}
.dot.ok { background: var(--ok); }
.dot.busy { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.dot.err { background: var(--error); }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.6); opacity: 0.5; }
}

.actions { display: flex; gap: 8px; flex: 0 0 auto; }

.btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn-quiet {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}

/* --- Två halvor ----------------------------------------------------------------- */

.panes {
  flex: 1 1 auto;
  display: flex;
  gap: 14px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  min-height: 0;
}

.pane {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  flex: 0 0 auto;
}

h2 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0;
  white-space: nowrap;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea#input,
.output {
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px 20px;
  font: inherit;
  line-height: 1.65;
  color: var(--ink);
  background: transparent;
  overflow-y: auto;
}

textarea#input {
  border: 0;
  outline: none;
  resize: none;
  width: 100%;
}

textarea#input::placeholder { color: var(--ink-faint); }

.output {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.output .para {
  min-height: 1.65em;
}

.output .para.whole {
  /* Ett stycke som har rättats i sin helhet markeras med en tunn kant till vänster. */
  border-left: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  margin-left: -12px;
  padding-left: 9px;
}

.output .placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

.output .pend {
  text-decoration: underline dotted var(--ink-faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* Ändrad text: färgen tänds och tonar sedan bort. animation-delay sätts negativt från
   skriptet så att animationen fortsätter där den var när texten ritas om. */
.output .chg {
  border-radius: 3px;
  animation: flash 2.8s ease-out forwards;
}

@keyframes flash {
  0%   { background: var(--changed); color: var(--changed-ink); box-shadow: 0 0 0 3px var(--changed); }
  35%  { background: var(--changed); color: var(--changed-ink); box-shadow: 0 0 0 1px var(--changed); }
  100% { background: transparent; color: inherit; box-shadow: none; }
}

/* --- Toast ---------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 560px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 10;
}
.toast.error { background: var(--error); color: #fff; }

/* --- Mobil: rättad text upptill, egen text nertill ------------------------------- */

@media (max-width: 760px) {
  body { font-size: 16px; }

  .topbar { gap: 8px; padding: 8px 12px; flex-wrap: wrap; }
  .status { display: none; }
  .btn { padding: 5px 11px; font-size: 0.82rem; }
  .level { gap: 8px; font-size: 0.78rem; }
  .level label { display: none; }
  .level input[type="range"] { width: 90px; }

  .panes {
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .pane-output { order: 1; }
  .pane-input  { order: 2; }

  .pane { flex: 1 1 50%; }

  .pane-head { padding: 8px 14px 6px; }
  .hint { display: none; }

  textarea#input, .output { padding: 14px 16px; }
  .output .para.whole { margin-left: -10px; padding-left: 7px; }
}
