:root {
  --paper: #f3efe6;
  --card: #fffcf6;
  --ink: #1a1916;
  --muted: #5c574e;
  --line: #d9d2c4;
  --nori: #1f4f45;
  --nori-dark: #16382f;
  --nori-soft: #e4efe9;
  --danger: #8b2e1f;
  --shadow: 0 10px 30px rgba(26, 25, 22, 0.08);
  --radius: 18px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px 8px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.mark {
  width: 28px;
  height: 28px;
  flex: none;
}

.wordmark {
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

main {
  flex: 1;
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 8px 20px 40px;
  padding-bottom: max(40px, env(safe-area-inset-bottom));
}

h1 {
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 28px 0 12px;
}

.promise {
  display: inline-block;
  margin: 0 0 14px;
  padding: 6px 12px;
  background: var(--nori-soft);
  color: var(--nori-dark);
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: 999px;
}

.sub {
  color: var(--muted);
  max-width: 34rem;
  margin: 0 0 28px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
}

.btn {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 13px 18px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  min-height: 48px;
  user-select: none;
}

.btn.primary {
  background: var(--nori);
  border-color: var(--nori);
  color: #f7f4ec;
}

.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.samples-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.samples {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.sample {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}

.sample img {
  display: block;
  width: 100%;
  height: 92px;
  object-fit: cover;
  background: #e8e2d4;
}

.sample span {
  display: block;
  padding: 8px 10px 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

footer {
  padding: 16px 20px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.88rem;
  width: min(920px, 100%);
  margin: 0 auto;
}

/* Work pane */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 0 16px;
}

.status {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.bar {
  height: 8px;
  background: #e8e2d4;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 12px;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--nori);
  transition: width 0.2s ease;
}

.preview-wrap {
  margin: 12px 0 18px;
  border-radius: var(--radius);
  overflow: auto;
  border: 1px solid var(--line);
  background: #ddd6c8;
  max-height: 220px;
}

.preview-wrap img, .preview-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

.table-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  max-width: 100%;
}

table.grid {
  border-collapse: collapse;
  min-width: 100%;
  font-variant-numeric: tabular-nums;
}

table.grid th, table.grid td {
  border: 1px solid var(--line);
  padding: 0;
  vertical-align: top;
  min-width: 108px;
}

table.grid th {
  background: var(--nori-soft);
  font-weight: 600;
}

table.grid input {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 16px; /* stops iOS zoom */
  padding: 10px 8px;
  color: inherit;
  min-height: 44px;
}

table.grid th.low input, table.grid td.low input {
  background: #fff4e8;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 12px 0 0;
}

.row-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.error {
  background: #fde8e4;
  color: var(--danger);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 12px 0;
}

@media (max-width: 640px) {
  .samples { grid-template-columns: 1fr; }
  .sample img { height: 120px; }
  .actions .btn { flex: 1 1 100%; }
}
