/* Rewrite mode (src/ui/rewrite.js): the task and the feedback on the original
   on the left, a plain writing area with an optional timer on the right.
   The root fills its container (give it a definite height on wide screens);
   below 860px it flows with the page, as #layout does. */
.rw {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--bg);
  color: var(--ink);
}
.rw-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.rw-spacer { flex: 1; }

/* ------------------------------------------------------------------- bar */

.rw-bar {
  position: relative;
  z-index: 3;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.rw-back { flex: none; padding: 6px 10px; border-radius: 8px; color: var(--ink-2); white-space: nowrap; }
.rw-heading { flex: 0 1 auto; min-width: 0; display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.rw-heading strong { flex: none; font-size: 15px; }
.rw-heading-task { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 13px; }
.rw-saved { flex: none; color: var(--muted); font-size: 12px; white-space: nowrap; }
.rw-finish { flex: none; padding: 6px 16px; border-radius: 8px; font-weight: 600; white-space: nowrap; }

/* --------------------------------------------------------------- columns */

.rw-cols {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 340px) minmax(0, 1fr);
}
.rw-brief {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px 16px 40px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  font-size: 13px;
}
.rw-write {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding-bottom: 120px;
}

/* ------------------------------------------------------------- the brief */

.rw-sec + .rw-sec { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.rw-sec > summary {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 0;
  border-radius: 6px;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.rw-sec > summary::-webkit-details-marker { display: none; }
.rw-sec > summary::before {
  content: "›";
  flex: none;
  width: 10px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  transition: transform .15s;
}
.rw-sec[open] > summary::before { transform: rotate(90deg); }
.rw-sec > summary:hover::before { color: var(--ink-2); }
.rw-sec > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rw-sec > summary small { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; white-space: nowrap; }
.rw-kind { color: var(--muted); font-weight: 500; }
.rw-kind::before { content: "·"; margin-right: 6px; }

.rw-theme { margin: 4px 0 8px 16px; color: var(--muted); }
.rw-theme b { color: var(--ink); font-weight: 600; }

.rw-statements {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0 2px;
  padding: 0;
  list-style: none;
  counter-reset: rw-st;
}
.rw-statements li {
  position: relative;
  counter-increment: rw-st;
  padding: 8px 10px 8px 34px;
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font: 14.5px/1.5 var(--serif);
}
.rw-statements li::before {
  content: counter(rw-st);
  position: absolute;
  left: 10px;
  top: 10px;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 10.5px/1 var(--sans);
}

.rw-steps { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 0; padding-left: 22px; color: var(--ink); line-height: 1.5; }
.rw-steps li::marker { color: var(--accent); font-weight: 600; }
.rw-scores { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 0; padding: 0; list-style: none; }
.rw-scores li {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.rw-scores b { color: var(--ink); }
.rw-summary { margin: 8px 0 0; color: var(--ink-2); font-size: 12.5px; line-height: 1.5; }
.rw-empty { margin: 6px 0 0; color: var(--muted); line-height: 1.5; }

.rw-original {
  margin-top: 6px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-2);
  font: 15px/1.65 var(--serif);
  overflow-wrap: break-word;
}
.rw-original p { margin: 0 0 .8em; white-space: pre-wrap; }
.rw-original p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------ the writing area */

/* Tools (and the time's-up note) stay in view while the essay scrolls. Side
   padding lines them up with the paper below. */
.rw-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0 max(24px, calc((100% - 760px) / 2));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.rw-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 12px 0 10px; }
.rw-timer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-left: auto; }

.rw-ghost, .rw-go, .rw-reset { padding: 4px 10px; border-radius: 7px; font-size: 12.5px; white-space: nowrap; }
.rw-ghost { box-shadow: inset 0 0 0 1px var(--line-strong); }
.rw-ghost.armed { background: var(--proposed-soft); color: var(--proposed); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--proposed) 45%, transparent); }

/* Off / 30:00 / Custom: native radios (arrow keys move between them) drawn as a segmented control */
.rw-seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.rw-seg-opt { position: relative; display: block; }
.rw-seg-opt input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.rw-seg-opt input:disabled { cursor: default; }
.rw-seg-opt span {
  display: block;
  padding: 3px 10px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background-color .12s, color .12s;
}
.rw-seg-opt:hover input:not(:disabled):not(:checked) + span { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.rw-seg-opt input:checked + span { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line-strong); }
.rw-seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.rw-seg-opt input:disabled:not(:checked) + span { opacity: .45; }

.rw-minfield { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12.5px; }
.rw-min {
  width: 46px;
  appearance: textfield; /* no spinner: the arrow keys still step it */
  -moz-appearance: textfield;
  padding: 3px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font: 600 13px var(--sans);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.rw-min::-webkit-inner-spin-button, .rw-min::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.rw-min:disabled { opacity: .6; }

.rw-clock {
  min-width: 64px;
  padding: 2px 8px;
  border-radius: 7px;
  color: var(--ink);
  font: 600 17px/1.3 var(--sans);
  font-variant-numeric: tabular-nums;
  text-align: center;
  transition: background-color .3s, color .3s;
}
.rw-clock.paused { color: var(--muted); }
.rw-clock.low { color: var(--proposed); }
.rw-clock.over { background: var(--proposed-soft); color: var(--proposed); }
.rw-go { min-width: 68px; font-weight: 600; box-shadow: inset 0 0 0 1px var(--line-strong); }
.rw-go.primary { box-shadow: none; }
.rw-reset { color: var(--muted); }
.rw-reset:hover { color: var(--ink); }
.rw-words { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Time's up: a gentle note under the tools, never a lock */
.rw-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 8px 8px 14px;
  border-radius: 10px;
  background: var(--proposed-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--proposed) 30%, transparent);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  animation: rw-in .25s ease-out;
}
.rw-alert::before { content: ""; flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--proposed); }
.rw-alert-text { flex: 1; }
.rw-alert-x { flex: none; width: 22px; height: 22px; padding: 0; color: var(--muted); font-size: 16px; line-height: 1; }
@keyframes rw-in { from { opacity: 0; transform: translateY(-4px); } }

.rw-paper {
  width: min(760px, 100% - 48px);
  margin: 2px auto 0;
  padding: 40px 56px 64px;
  border-radius: 4px;
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: text;
  scroll-margin-top: 120px;
  transition: box-shadow .15s;
}
.rw-paper:focus-within { box-shadow: var(--shadow), 0 0 0 1.5px color-mix(in srgb, var(--accent) 50%, transparent); }
.rw-text {
  display: block;
  width: 100%;
  min-height: 55vh;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--accent);
  font: 18px/1.72 var(--serif);
  resize: none;
  overflow: hidden;
}
/* The paper's ring shows focus; an outline on the text itself would sit on the words. */
.rw-text:focus, .rw-text:focus-visible { outline: none; }
.rw-text::placeholder { color: var(--muted); }
.rw-text[readonly] { caret-color: transparent; }

/* ---------------------------------------------------------- narrow panes */

/* A narrow container on a wide screen: stack the brief above the writing and scroll them together. */
@container (max-width: 720px) {
  .rw-cols { display: block; overflow: auto; overscroll-behavior: contain; }
  .rw-brief { overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
  .rw-write { overflow: visible; }
  .rw-head { padding: 0 12px; }
  .rw-paper { width: calc(100% - 24px); padding: 28px 24px 48px; }
  .rw-text { min-height: 45vh; }
}
@container (max-width: 480px) {
  .rw-bar { gap: 6px; padding: 6px 8px; }
  .rw-back { padding: 6px 8px; }
  .rw-saved { display: none; }
  .rw-tools { gap: 6px 8px; }
  .rw-timer { margin-left: 0; gap: 4px; }
  .rw-seg-opt span { padding: 3px 8px; }
  .rw-clock { min-width: 0; padding: 2px 6px; }
  .rw-go { min-width: 0; }
  .rw-go, .rw-reset { padding: 4px 8px; }
  .rw-head { padding: 0 8px; }
  .rw-paper { width: 100%; padding: 22px 16px 40px; border-radius: 0; }
  .rw-text { font-size: 17px; }
}
@container (max-width: 340px) {
  .rw-heading-task { display: none; }
  .rw-seg-opt span { padding: 3px 6px; }
}

/* A narrow screen: the whole page scrolls (as #layout does), the tools stick to the top. */
@media (max-width: 860px) {
  .rw { height: auto; min-height: 100%; }
  .rw-cols, .rw-brief, .rw-write { overflow: visible; }
}
