:root {
  --blue: #1e3a5f;
  --blue-soft: #eaf1f9;
  --orange: #e8590c;
  --text: #1c2733;
  --muted: #5b7187;
  --bg: #f5f8fc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
  padding: 20px 20px 4px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

h1 { font-size: 1.4rem; margin: 0; color: var(--blue); }

main { flex: 1; padding: 16px 20px; max-width: 480px; width: 100%; margin: 0 auto; }

.due-card {
  background: #fff;
  border: 1px solid #dce6f1;
  border-radius: 16px;
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 20px;
}

.due-num { font-size: 3rem; font-weight: 800; color: var(--blue); line-height: 1; }

.action {
  display: block;
  width: 100%;
  padding: 16px;
  margin: 10px 0;
  border: 0;
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--orange);
  color: #fff;
  cursor: pointer;
}

.action.secondary { background: var(--blue); }

.action.ghost { background: var(--blue-soft); color: var(--blue); }

.action small { display: block; font-weight: 500; font-size: 0.8rem; opacity: 0.85; margin-top: 2px; }

#crop-stage { position: relative; margin: 10px 0; touch-action: none; overflow: hidden; border-radius: 12px; }
#crop-img { display: block; width: 100%; max-height: 55vh; object-fit: contain; border-radius: 12px; }
#crop-box {
  position: absolute;
  border: 2px solid var(--orange);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(30, 58, 95, 0.35);
  cursor: move;
}
.crop-h {
  position: absolute;
  width: 26px; height: 26px;
  background: var(--orange);
  border: 3px solid #fff;
  border-radius: 50%;
}
.crop-h[data-c="nw"] { left: -13px; top: -13px; }
.crop-h[data-c="ne"] { right: -13px; top: -13px; }
.crop-h[data-c="sw"] { left: -13px; bottom: -13px; }
.crop-h[data-c="se"] { right: -13px; bottom: -13px; }

#cap-livetext { margin: 10px 0; }
#cap-livetext img { width: 100%; border-radius: 12px; margin-top: 8px; }
#cap-livetext summary { color: var(--muted); cursor: pointer; }

.action:disabled { opacity: 0.4; cursor: default; }

h2 { color: var(--blue); font-size: 1.2rem; margin: 4px 0 14px; }

textarea {
  width: 100%;
  border: 1px solid #dce6f1;
  border-radius: 12px;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  margin: 8px 0;
}

.cap-textbox {
  background: #fff;
  border: 1px solid #dce6f1;
  border-radius: 12px;
  padding: 14px;
  min-height: 120px;
  font-size: 1.05rem;
  line-height: 1.6; /* P001 field test: 2.1 felt double-spaced; tap padding lives on .tok */
  margin: 10px 0;
  -webkit-user-select: none;
  user-select: none; /* taps, not iOS text selection */
  max-height: 45vh;
  overflow-y: auto;
}

.para { margin: 0 0 12px; }

.tok {
  padding: 4px 3px;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap-zoom delay on iOS */
  -webkit-tap-highlight-color: transparent;
}

.tok.sel { background: var(--orange); color: #fff; }

/* uncertain = low OCR confidence or junk-shaped; still selectable, visibly doubtful */
.tok.uncertain { color: #9db0c2; border-bottom: 1px dashed #c4d2e0; }
.tok.uncertain.sel { color: #fff; border-bottom-color: transparent; }
.uncertain-demo { color: #9db0c2; border-bottom: 1px dashed #c4d2e0; }

.save-card {
  position: relative;
  background: #fff;
  border: 1px solid #dce6f1;
  border-radius: 14px;
  padding: 12px 12px 8px;
  margin: 10px 0;
}

label.f { display: block; font-size: 0.78rem; color: var(--muted); margin: 6px 0; }

label.f input, label.f textarea {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 9px 10px;
  border: 1px solid #dce6f1;
  border-radius: 9px;
  font-size: 0.98rem;
  font-family: inherit;
}

.card-x {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.row-sb { display: flex; justify-content: space-between; align-items: center; margin: 4px 0; }

.rev-context { user-select: text; -webkit-user-select: text; }

.blank-slot {
  display: inline-block;
  min-width: 68px;
  height: 1em;
  border-bottom: 2px solid var(--orange);
  vertical-align: middle;
  margin: 0 3px;
}

#rev-form { display: flex; gap: 8px; margin: 12px 0; }

#rev-form input {
  flex: 1;
  padding: 12px;
  border: 1px solid #dce6f1;
  border-radius: 12px;
  font-size: 1.05rem;
}

#rev-form .action { width: auto; margin: 0; padding: 12px 18px; }

.feedback {
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  margin: 10px 0;
}

.feedback-correct { background: #e9f7e9; color: #1b5e20; border: 1px solid #8fd08f; }
.feedback-almost { background: #fff7e6; color: #92400e; border: 1px solid #fcd34d; }
.feedback-wrong { background: #fdeaea; color: #b3261e; border: 1px solid #f5b5b0; }
.feedback-sub { font-weight: 400; font-size: 0.9rem; margin-top: 4px; }

.rev-row {
  display: flex;
  justify-content: space-between;
  background: #fff;
  border: 1px solid #dce6f1;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 6px 0;
}

.toast {
  background: #e9f7e9;
  border: 1px solid #8fd08f;
  border-radius: 12px;
  padding: 10px 12px;
  color: #1b5e20;
  margin: 0 0 14px;
}

.warn {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 12px;
  padding: 10px 12px;
  margin: 8px 0;
  color: #92400e;
}

#cap-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; min-height: 34px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue);
  color: #fff;
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-size: 0.95rem;
  font-weight: 600;
}

#cap-gate {
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0;
  text-align: center;
}

.gate-msg { margin: 2px 0 12px; color: #9a3412; font-weight: 600; }

.chip button {
  background: rgba(255, 255, 255, 0.25);
  border: 0;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.row { display: flex; gap: 10px; }
.half { flex: 1; }

footer { padding: 12px 20px; text-align: center; display: flex; gap: 16px; justify-content: center; align-items: center; }

.linklike {
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.err { color: #b3261e; font-weight: 600; }

.prog-h { color: var(--blue); font-size: 1rem; margin: 16px 0 6px; }
.prog-key { color: var(--orange); }
