:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2027;
  --muted: #5d6573;
  --line: #dde1e7;
  --line-strong: #c3c9d2;
  --accent: #2563c9;
  --accent-text: #ffffff;
  --active: #eef4ff;
  --done: #1d7a46;
  --done-bg: #e3f4ea;
  --review: #8a5a00;
  --review-bg: #fdf1d8;
  --untr: #9b2c2c;
  --untr-bg: #fbe5e5;
  --warn: #a14a00;
  --changed: #7a3fd1;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans CJK JP", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e4e7ec;
    --muted: #9aa3b2;
    --line: #2d333d;
    --line-strong: #414a57;
    --accent: #6ea2ff;
    --accent-text: #0d1117;
    --active: #1f2a3d;
    --done: #6fd39b;
    --done-bg: #173325;
    --review: #f0c062;
    --review-bg: #3a2e12;
    --untr: #ff9a9a;
    --untr-bg: #3d1d1d;
    --warn: #ffb067;
    --changed: #b892ff;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}

a { color: var(--accent); }
kbd {
  font: 0.85em var(--mono);
  padding: 0 0.35em;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
}
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button, .button, select, input[type="search"], input[type="text"] {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 0.35em 0.75em;
}
button, .button { cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.icon { width: 2.2em; padding-inline: 0; font-weight: 700; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- header ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0.6rem 1rem;
  display: grid;
  gap: 0.5rem;
}
.bar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; }
.bar h1 { font-size: 1.05rem; margin: 0; white-space: nowrap; }
.lang select { max-width: 22rem; font-weight: 600; }
.section select { max-width: 30rem; font-weight: 600; }
.section select:disabled { font-weight: 400; color: var(--muted); }
.progress { display: flex; align-items: center; gap: 0.6rem; flex: 1 1 30rem; min-width: 0; font-size: 0.85rem; color: var(--muted); }
.meter { flex: 0 0 8rem; height: 0.5rem; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--done); transition: width 0.2s; }
.actions { display: flex; gap: 0.5rem; margin-left: auto; }
.filters input[type="search"] { flex: 1 1 18rem; min-width: 12rem; }
.filters select { max-width: 18rem; }
.check { display: inline-flex; align-items: center; gap: 0.35em; white-space: nowrap; }
.hint { font-size: 0.8rem; color: var(--muted); margin-left: auto; }

/* ---------- grid ---------- */

main { padding: 0 1rem 2rem; }
.empty { color: var(--muted); padding: 3rem 0; text-align: center; }

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  margin-top: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.c-src { width: 34%; }
.c-tr { width: 38%; }
.c-st { width: 9.5rem; }
.c-cm { width: 18%; }

.grid thead th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
tr.ctx th {
  text-align: left;
  font: 600 0.8rem var(--mono);
  color: var(--muted);
  background: var(--bg);
  padding: 0.5rem 0.75rem 0.35rem;
  border-bottom: 1px solid var(--line);
}
tr.msg td {
  vertical-align: top;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
tr.msg { scroll-margin-top: 9rem; }
tr.msg td:first-child { border-left: 3px solid transparent; }
tr.msg.changed td:first-child { border-left-color: var(--changed); }
tr.msg.active td { background: var(--active); }
tr.msg.obsolete { opacity: 0.6; }

.srctext { white-space: pre-wrap; overflow-wrap: anywhere; }
.ws { color: var(--muted); background: var(--bg); border-radius: 3px; }
.devnote { font-size: 0.82rem; color: var(--muted); margin-top: 0.3rem; }
.loc { margin-top: 0.3rem; font: 0.75rem var(--mono); display: flex; flex-wrap: wrap; gap: 0.15rem 0.6rem; }
.loc a { color: var(--muted); text-decoration: none; }
.loc a:hover { color: var(--accent); text-decoration: underline; }

.form { display: block; }
.form + .form { margin-top: 0.35rem; }
.form-label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.1rem; }

textarea {
  display: block;
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
  resize: vertical;
  min-height: 2.25rem;
  max-height: 24rem;
  field-sizing: content;
}
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
textarea[readonly] { background: transparent; }
textarea.c { font-size: 0.88rem; }
textarea::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

.warn { list-style: none; margin: 0; padding: 0; }
.warn:not(:empty) { margin-top: 0.3rem; }
.warn li { font-size: 0.8rem; color: var(--warn); }
.warn li::before { content: "⚠ "; }

.st { font-size: 0.85rem; }
.badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
  margin-bottom: 0.35rem;
}
.badge.edited { color: var(--changed); background: color-mix(in srgb, var(--changed) 14%, transparent); }
.badge.untranslated { color: var(--untr); background: var(--untr-bg); }
.badge.obsolete { color: var(--muted); background: var(--bg); }

.state-group { display: grid; gap: 0.2rem; }
.state-opt {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.state-opt input { margin: 0; cursor: inherit; }
.state-opt.done:has(input:checked) { color: var(--done); background: var(--done-bg); font-weight: 600; }
.state-opt.review:has(input:checked) { color: var(--review); background: var(--review-bg); font-weight: 600; }
.state-opt:has(input:disabled) { opacity: 0.5; cursor: default; }
.state-opt.done input { accent-color: var(--done); }
.state-opt.review input { accent-color: var(--review); }
.revert { display: block; margin-top: 0.3rem; font-size: 0.82rem; }
.revert[hidden] { display: none; }

/* ---------- footer, toast, dialogs ---------- */

.foot { padding: 0 1rem 2rem; font-size: 0.82rem; color: var(--muted); }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(40rem, 90vw);
  background: var(--text);
  color: var(--bg);
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgb(0 0 0 / 0.25);
  z-index: 20;
  font-size: 0.9rem;
}
.toast[hidden] { display: none; }

dialog {
  max-width: min(40rem, 92vw);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 1.25rem 1.5rem;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
dialog h3 { margin: 1rem 0 0.4rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.9rem; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; }
.steps { padding-left: 1.2rem; }
.small { font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: default; }
.file-list { margin: 0 0 0.5rem; padding-left: 1.2rem; font-size: 0.9rem; }
.file-list b { font-family: var(--mono); font-weight: 600; font-size: 0.85rem; }
.section-picks { display: grid; gap: 0.35rem; max-height: 50vh; overflow: auto; margin: 0.75rem 0; }
.pick {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.6rem;
  align-items: baseline;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.pick:has(input:checked) { border-color: var(--accent); background: var(--active); }
.pick input { grid-row: span 3; margin: 0; align-self: center; }
.pick-title { font-weight: 600; }
.pick-detail { font-size: 0.85rem; color: var(--muted); }
.pick-file { font: 0.78rem var(--mono); color: var(--muted); }
.field { display: grid; gap: 0.25rem; margin: 0.75rem 0; font-size: 0.9rem; }
.field textarea { font: 0.85rem var(--mono); field-sizing: fixed; }
.dialog-actions { display: flex; gap: 0.5rem; justify-content: flex-end; align-items: center; margin-top: 1rem; }
.dialog-actions form { margin: 0; }
dialog > form[method="dialog"] { text-align: right; margin-top: 1rem; }

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  .grid, .grid tbody, .grid tr, .grid td, .grid th { display: block; width: auto; }
  .grid thead, .grid colgroup { display: none; }
  tr.msg { border-bottom: 1px solid var(--line); }
  tr.msg td { border-bottom: 0; padding-block: 0.3rem; }
  tr.msg td.st { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
  .revert { margin: 0; }
  .state-group { grid-auto-flow: column; }
  .hint { display: none; }
}
