:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --text: #15201b;
  --muted: #56655e;
  --border: #d6e0db;
  --primary: #0f7b5f;
  --primary-strong: #0a5f49;
  --primary-soft: #e2f2eb;
  --on-primary: #ffffff;
  --warn-bg: #fff3d1;
  --warn-line: #e2b23c;
  --warn-text: #5f4600;
  --error-bg: #fde9e9;
  --error-line: #e79a9a;
  --error-text: #861b1b;
  --info-bg: #e6eff9;
  --info-line: #a9c4e6;
  --info-text: #1b456f;
  --shadow: 0 1px 2px rgb(16 40 30 / 6%), 0 4px 16px rgb(16 40 30 / 6%);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1a16;
    --surface: #14241f;
    --text: #e5eeea;
    --muted: #9fb2a9;
    --border: #2a3e37;
    --primary: #3cbf92;
    --primary-strong: #63d6ae;
    --primary-soft: #183a2f;
    --on-primary: #04201a;
    --warn-bg: #3a2e0c;
    --warn-line: #a17d22;
    --warn-text: #f6dc93;
    --error-bg: #3d1616;
    --error-line: #9b4141;
    --error-text: #ffc5c5;
    --info-bg: #132a40;
    --info-line: #34597f;
    --info-text: #bcd7f6;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

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

.topbar {
  display: flex; align-items: center; gap: 12px;
  max-width: 820px; margin: 0 auto; padding: 16px 16px 4px;
}
.logo { border-radius: 9px; flex: none; }
.brand { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

main { max-width: 820px; margin: 0 auto; padding: 8px 16px 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-top: 14px;
}

h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 1.2rem; }
h3 { margin: 0 0 8px; font-size: 1rem; }
.step {
  display: inline-grid; place-items: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  font-size: 0.95rem; font-weight: 700;
}

/* ---------- buttons ---------- */

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.actions .btn { padding: 0 12px; }
.below-input { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 0 10px; }
.below-input .meta { margin: 0 2px; }
.below-input .btn { min-height: 40px; padding: 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; white-space: nowrap;
  cursor: pointer; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .table-wrap:focus-visible, summary:focus-visible, .check-item:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 2px;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn-quiet { border-color: transparent; color: var(--muted); }
.btn-big { width: 100%; min-height: 56px; font-size: 1.05rem; }
.btn-small { min-height: 40px; padding: 0 14px; font-size: 0.9rem; border-color: var(--primary); color: var(--primary); }

/* ---------- input ---------- */

textarea {
  display: block; width: 100%;
  min-height: 38vh; resize: vertical;
  padding: 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text);
  font: 15px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.meta { margin: 6px 2px 14px; min-height: 1.2em; color: var(--muted); font-size: 0.9rem; }
.hint { margin: 10px 2px; color: var(--muted); font-size: 0.92rem; }

.howto { margin: 0 0 4px; color: var(--muted); }
.howto summary { cursor: pointer; color: var(--primary); font-weight: 600; padding: 6px 0; }
.howto ol { margin: 6px 0; padding-left: 22px; }
.howto li { margin: 3px 0; }
.howto p { margin: 8px 0 4px; }

/* ---------- messages ---------- */

.notice {
  margin: 14px 0 0; padding: 12px 14px;
  border: 1px solid var(--info-line); border-radius: 12px;
  background: var(--info-bg); color: var(--info-text);
}
.notice-error { border-color: var(--error-line); background: var(--error-bg); color: var(--error-text); }
.notice-warn { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-text); }
.notice-info { border-color: var(--info-line); background: var(--info-bg); color: var(--info-text); }
.notice p { margin: 0; }
.notice p + p, .notice .btn { margin-top: 10px; }
.notice .btn { min-height: 40px; }

/* ---------- results ---------- */

.summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 10px; margin-bottom: 6px; }
.summary .big { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 0.88rem; color: var(--muted);
}
.chip-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-text); }

.checks {
  margin: 14px 0 6px; padding: 12px;
  border: 1px solid var(--warn-line); border-radius: 12px; background: var(--warn-bg); color: var(--warn-text);
}
.checks ul { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.check-item {
  display: block; width: 100%; text-align: left;
  margin: 0; padding: 8px 4px; border: 0; border-top: 1px solid var(--warn-line);
  background: none; color: inherit; font: inherit; font-size: 0.93rem; cursor: pointer;
}
.checks li:first-child .check-item { border-top: 0; }
.check-item b { white-space: nowrap; }

.table-wrap {
  overflow: auto; max-height: 65vh;
  border: 1px solid var(--border); border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}
table { border-collapse: separate; border-spacing: 0; font-size: 14px; min-width: 100%; }
th, td {
  padding: 9px 10px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
th {
  position: sticky; top: 0; z-index: 2;
  background: var(--primary-soft); color: var(--text); font-weight: 700;
}
td[data-key] { min-width: 64px; }
td[data-key="notes"] { white-space: normal; min-width: 180px; }
td[data-key]:focus { outline: 2px solid var(--primary); outline-offset: -2px; background: var(--surface); }
td.warn { background: var(--warn-bg); box-shadow: inset 3px 0 0 var(--warn-line); }
td.edited { box-shadow: inset 3px 0 0 var(--primary); }
.rownum {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface); color: var(--muted); font-variant-numeric: tabular-nums;
}
th.rownum { z-index: 3; background: var(--primary-soft); }
.rownum .num { display: inline-block; min-width: 1.6em; }
.rownum.warn { background: var(--warn-bg); }
.remove {
  margin-left: 4px; padding: 0 6px; border: 0; border-radius: 6px;
  background: none; color: var(--muted); font: inherit; font-size: 1.1rem; line-height: 1.2; cursor: pointer;
}
.remove:hover, .remove:focus-visible { color: var(--error-text); background: var(--error-bg); }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--warn-line); } }

.skipped { margin-top: 14px; }
.skipped summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.skipped pre {
  margin: 8px 0; padding: 10px; max-height: 180px; overflow: auto;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  font-size: 13px; white-space: pre-wrap; word-break: break-word;
}

.savebar {
  position: sticky; bottom: 0; z-index: 4;
  display: flex; gap: 8px;
  margin: 14px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.savebar .btn { flex: 1; }

/* ---------- toast & footer ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 10;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: calc(100vw - 32px);
  padding: 12px 16px; border-radius: 12px;
  background: #17211d; color: #f2f7f4; box-shadow: 0 8px 30px rgb(0 0 0 / 30%);
  font-size: 0.95rem;
}
.toast-action {
  flex: none; padding: 6px 10px; border: 0; border-radius: 8px;
  background: none; color: #6fe0b8; font: inherit; font-weight: 700; cursor: pointer;
}

.footer { padding: 8px 16px 28px; text-align: center; color: var(--muted); font-size: 0.85rem; }

@media (min-width: 700px) {
  .card { padding: 22px 24px; }
  .savebar { margin: 14px -24px 0; padding-left: 24px; padding-right: 24px; }
  .btn-big { width: auto; min-width: 220px; }
  #convertBtn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  tr.flash td { animation: none; }
  .btn:active { transform: none; }
}
