:root {
  --bg: #f2f4f3; --surface: #ffffff; --ink: #1b2421; --muted: #66726d;
  --accent: #0f766e; --accent-ink: #ffffff; --line: #d9dfdc;
  --ok-bg: #e2f4ec; --ok-ink: #0b5b3c; --err-bg: #fbe6e4; --err-ink: #8a1f16;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121816; --surface: #1b2421; --ink: #eef2f0; --muted: #93a19b;
    --accent: #2dd4bf; --accent-ink: #062a25; --line: #2c3833;
    --ok-bg: #12322a; --ok-ink: #8ce6c1; --err-bg: #3a1a17; --err-ink: #ffb4ab;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
.wrap { max-width: 520px; margin: 0 auto; padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 14px; }
h1 { margin: 8px 0 0; font-size: 1.5rem; letter-spacing: -0.01em; }
h2 { margin: 18px 0 0; font-size: 1.1rem; }
.sub { margin: 0; color: var(--muted); font-size: .95rem; }
a { color: var(--accent); }

.bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: .9rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
label { font-size: .9rem; color: var(--muted); }
input[type=text], input[type=password] {
  width: 100%; padding: 14px; font-size: 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-family: inherit;
}
select {
  width: 100%;
  padding: 14px 42px 14px 14px;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background-color: var(--bg);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;

  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}


input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

.btn {
  display: block; width: 100%; padding: 16px; border-radius: 12px; border: 0; margin-top: 6px;
  font-size: 1.05rem; font-weight: 600; text-align: center; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-family: inherit;
}
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn[hidden] { display: none; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn:focus-visible, .modes button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.notice { padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-size: .95rem; }
.notice.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.notice.err { background: var(--err-bg); color: var(--err-ink); border-color: transparent; }

/* search */
.seg { display: flex; gap: 8px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { flex: 1; text-align: center; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
.seg input:checked + label { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.result { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.result span { color: var(--muted); font-size: .9rem; }

/* scan */
.patient { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.patient span { color: var(--muted); font-size: .9rem; }
.patient a { font-size: .9rem; margin-top: 4px; }
#app { display: flex; flex-direction: column; gap: 14px; }
.stage { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; min-height: 260px; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 14px; }
#canvas { max-width: 100%; max-height: 62vh; display: none; }
.empty { text-align: center; color: var(--muted); padding: 24px; font-size: .95rem; line-height: 1.5; }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

.cropwrap { display: none; position: relative; line-height: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
#cropCanvas { max-width: 100%; max-height: 62vh; display: block; }
.cropclip { position: absolute; inset: 0; overflow: hidden; }
.box { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(0,0,0,.5); cursor: move; touch-action: none; }
.box::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to right, transparent 33.2%, rgba(255,255,255,.35) 33.3%, rgba(255,255,255,.35) 33.5%, transparent 33.6%, transparent 66.5%, rgba(255,255,255,.35) 66.6%, rgba(255,255,255,.35) 66.8%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.2%, rgba(255,255,255,.35) 33.3%, rgba(255,255,255,.35) 33.5%, transparent 33.6%, transparent 66.5%, rgba(255,255,255,.35) 66.6%, rgba(255,255,255,.35) 66.8%, transparent 66.9%);
}
.h { position: absolute; width: 44px; height: 44px; touch-action: none; }
.h::after { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; left: 11px; top: 11px; }
.h[data-h="tl"] { left: -22px; top: -22px; }
.h[data-h="tr"] { right: -22px; top: -22px; }
.h[data-h="bl"] { left: -22px; bottom: -22px; }
.h[data-h="br"] { right: -22px; bottom: -22px; }

.modes { display: none; gap: 8px; }
.modes.on { display: flex; }
.modes button { flex: 1; padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: .9rem; font-family: inherit; }
.modes button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
#descWrap { display: flex; flex-direction: column; gap: 6px; }
#descWrap[hidden] { display: none; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { margin-top: 0; }
input[type=file] { display: none; }
.hint { color: var(--muted); font-size: .85rem; text-align: center; min-height: 1.2em; }

.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.doc { display: flex; flex-direction: column; gap: 2px; padding: 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: .85rem; }
.doc img { width: 100%; height: 130px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.doc small { color: var(--muted); }


