:root {
  color-scheme: light;
  --bg: #edeff7;
  --card: #ffffff;
  --surface: #f5f6fb;
  --text: #192036;
  --muted: #58607a;
  --border: #d9deec;
  --accent: #4631b5;
  --accent-hover: #372484;
  --accent-on: #fff;
  --error: #9b293c;
  --error-bg: #fff1f3;
  --warning: #764002;
  --warning-bg: #fff3d9;
  --success: #116743;
  --success-bg: #e9f8ef;
  --radius: 20px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141726;
  --card: #1e2336;
  --surface: #252a40;
  --text: #f1f3ff;
  --muted: #b8c0d8;
  --border: #3d4561;
  --accent: #b6aaff;
  --accent-hover: #d1c7ff;
  --accent-on: #1d1347;
  --error: #ffc3cc;
  --error-bg: #482639;
  --warning: #ffe0a2;
  --warning-bg: #453427;
  --success: #a8edcc;
  --success-bg: #1c3b34;
}

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}

.app-shell {
  width: min(100%, 550px);
  margin: 0 auto;
  padding: 22px 16px calc(28px + env(safe-area-inset-bottom));
}
.app-header { padding: 1px 2px 18px; }
.wordmark { font-size: 0.82rem; font-weight: 750; color: var(--accent); letter-spacing: 0.04em; }
h1, h2, p, dl, dd { margin: 0; }
h1 { margin-top: 4px; font-size: clamp(1.45rem, 6vw, 1.93rem); letter-spacing: -0.03em; line-height: 1.15; }
h1:focus { outline: none; }
h2 { font-size: 1rem; line-height: 1.3; }

#page { display: grid; gap: 12px; }
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 16px;
  min-width: 0;
}
.context { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 15px; }
.meta { min-width: 0; }
.meta.wide { grid-column: 1 / -1; }
.meta dt, .value-label, .entry-label { color: var(--muted); font-size: 0.76rem; font-weight: 620; }
.meta dd { margin-top: 2px; overflow-wrap: anywhere; font-size: 0.93rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; overflow-wrap: anywhere; }

.editor, .review, .changes { display: grid; gap: 13px; }
.fields { display: grid; gap: 12px; }
.fields label { display: grid; gap: 5px; color: var(--muted); font-size: .83rem; font-weight: 640; }
input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 11px;
  color: var(--text);
  background: var(--surface);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 450;
}
input[aria-invalid="true"] { border-color: var(--error); }

.actions { display: grid; gap: 8px; }
.button, .candidate {
  cursor: pointer;
  min-height: 44px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  font: inherit;
  font-size: 0.93rem;
  line-height: 1.25;
  font-weight: 680;
}
.primary { background: var(--accent); color: var(--accent-on); }
.primary:not(:disabled):hover { background: var(--accent-hover); }
.secondary, .candidate { background: var(--surface); color: var(--text); border-color: var(--border); }
.button:disabled, .candidate:disabled { cursor: default; opacity: 0.64; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.candidate { text-align: left; display: grid; gap: 3px; overflow-wrap: anywhere; }
.candidate small { color: var(--muted); font-size: .8rem; font-weight: 470; }

.notice, .feedback {
  border-radius: 12px;
  padding: 10px 13px;
  color: var(--muted);
  background: var(--surface);
  overflow-wrap: anywhere;
  font-size: .9rem;
}
.notice-warn { color: var(--warning); background: var(--warning-bg); }
.notice-success { color: var(--success); background: var(--success-bg); }
.notice-error, .feedback { color: var(--error); background: var(--error-bg); }
.feedback { margin-top: 12px; }

.delta + .delta { border-top: 1px solid var(--border); padding-top: 10px; }
.delta-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 6px; }
.delta-fields > div { border-radius: 9px; padding: 7px 9px; background: var(--surface); overflow-wrap: anywhere; }
.delta-fields > div:last-child { background: var(--success-bg); }
.delta-value { display: block; font-size: 0.87rem; }
.outcome, .history-entry { display: grid; gap: 10px; }
.history-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 9px; }
.history-entry .changes { gap: 9px; }

@media (min-width: 460px) {
  .card { padding: 19px; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
